utilities/mod2imp.cpp File Reference

#include <iostream>
#include <map>
#include <stdio.h>
#include <markupfiltmgr.h>
#include <swmgr.h>
#include <swmodule.h>
#include <versekey.h>
Include dependency graph for mod2imp.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
void usage (const char *progName, const char *error=0)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 56 of file mod2imp.cpp.

00057 {
00058     // handle options
00059     if (argc < 2) usage(*argv);
00060 
00061     const char *progName   = argv[0];
00062     const char *modName    = argv[1];
00063     bool render            = false;
00064     bool strip             = false;
00065     SWBuf renderForm;
00066     SWBuf optionName;
00067     map<SWBuf, SWBuf> options; // optionName, optionValue;
00068 
00069     for (int i = 2; i < argc; i++) {
00070         if (!strcmp(argv[i], "-r")) {
00071             if (strip) usage(progName, "-r can't be supplied when using -s");
00072             if (i+1 < argc) renderForm = argv[++i];
00073             render = true;
00074         }
00075         else if (!strcmp(argv[i], "-s")) {
00076             if (render) usage(progName, "-s can't be supplied when using -r");
00077             strip = true;
00078         }
00079         else if (!strcmp(argv[i], "-f")) {
00080             if (i+1 < argc) optionName          = argv[++i];
00081             if (i+1 < argc) options[optionName] = argv[++i];
00082             else usage(progName, "-f requires <option_name> <option_value>");
00083         }
00084         else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
00085     }
00086     // -----------------------------------------------------
00087 
00088     MarkupFilterMgr *markupMgr = 0;
00089     if       (renderForm == "HTMLHREF") markupMgr = new MarkupFilterMgr(sword::FMT_HTMLHREF);
00090     else if  (renderForm == "OSIS")     markupMgr = new MarkupFilterMgr(sword::FMT_OSIS);
00091     else if  (renderForm == "RTF")      markupMgr = new MarkupFilterMgr(sword::FMT_RTF);
00092     else if  (renderForm.length())      usage(progName, (((SWBuf) "Unknown output_format for -r (")+renderForm+")").c_str());
00093 
00094     SWMgr *mgr = (markupMgr) ? new SWMgr(markupMgr) : new SWMgr();
00095 
00096     // set any options filters passed with -f
00097     for (map<SWBuf, SWBuf>::iterator it = options.begin(); it != options.end(); it++) {
00098         mgr->setGlobalOption(it->first, it->second);
00099     }
00100 
00101     SWModule *module = mgr->getModule(modName);
00102 
00103     if (!module) usage(progName, (((SWBuf) "Couldn't find module: ") + modName).c_str());
00104 
00105 
00106     SWKey *key = module->getKey();
00107     VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
00108 
00109     if (vkey)
00110         vkey->setIntros(true);
00111 
00112     for ((*module) = TOP; !module->popError(); (*module)++) {
00113         std::cout << "$$$" << module->getKeyText() << std::endl;
00114         std::cout << ((render) ? module->renderText() : (strip) ? module->stripText() : module->getRawEntry()) << "\n";
00115     }
00116 
00117     cout << endl;
00118 
00119     return 0;
00120 }

void usage ( const char *  progName,
const char *  error = 0 
)

Definition at line 42 of file mod2imp.cpp.

00042                                                         {
00043     if (error) fprintf(stderr, "\n%s: %s\n", progName, error);
00044     fprintf(stderr, "\n=== mod2imp (Revision $Rev: 2234 $) SWORD module exporter.\n");
00045     fprintf(stderr, "\nusage: %s <module_name> [options]\n"
00046         "\t -r [output_format]  - render content instead of outputting raw native\n"
00047         "\t\tdata.  output_format can be: OSIS, HTMLHREF, RTF.\n"
00048         "\t -s - strip markup instead of outputting raw native data.\n"
00049         "\t -f <option_name> <option_value> - when rendering (-r, above), option\n"
00050         "\t\tfilter values can be set with this option.\n\n"
00051         , progName);
00052     exit(-1);
00053 }


Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1