The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 61 of file mod2imp.cpp.

62 {
63  // handle options
64  if (argc < 2) usage(*argv);
65 
66  const char *progName = argv[0];
67  const char *modName = argv[1];
68  bool render = false;
69  bool strip = false;
70  SWBuf renderForm;
71  SWBuf optionName;
72  map<SWBuf, SWBuf> options; // optionName, optionValue;
73 
74  for (int i = 2; i < argc; i++) {
75  if (!strcmp(argv[i], "-r")) {
76  if (strip) usage(progName, "-r can't be supplied when using -s");
77  if (i+1 < argc) renderForm = argv[++i];
78  render = true;
79  }
80  else if (!strcmp(argv[i], "-s")) {
81  if (render) usage(progName, "-s can't be supplied when using -r");
82  strip = true;
83  }
84  else if (!strcmp(argv[i], "-f")) {
85  if (i+1 < argc) optionName = argv[++i];
86  if (i+1 < argc) options[optionName] = argv[++i];
87  else usage(progName, "-f requires <option_name> <option_value>");
88  }
89  else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
90  }
91  // -----------------------------------------------------
92 
93  MarkupFilterMgr *markupMgr = 0;
94  if (renderForm == "HTMLHREF") markupMgr = new MarkupFilterMgr(sword::FMT_HTMLHREF);
95  else if (renderForm == "OSIS") markupMgr = new MarkupFilterMgr(sword::FMT_OSIS);
96  else if (renderForm == "RTF") markupMgr = new MarkupFilterMgr(sword::FMT_RTF);
97  else if (renderForm == "LATEX") markupMgr = new MarkupFilterMgr(sword::FMT_LATEX);
98  else if (renderForm == "XHTML") markupMgr = new MarkupFilterMgr(sword::FMT_XHTML);
99 
100  else if (renderForm.length()) usage(progName, (((SWBuf) "Unknown output_format for -r (")+renderForm+")").c_str());
101 
102  SWMgr *mgr = (markupMgr) ? new SWMgr(markupMgr) : new SWMgr();
103 
104  // set any options filters passed with -f
105  for (map<SWBuf, SWBuf>::iterator it = options.begin(); it != options.end(); it++) {
106  mgr->setGlobalOption(it->first, it->second);
107  }
108 
109  SWModule *module = mgr->getModule(modName);
110 
111  if (!module) usage(progName, (((SWBuf) "Couldn't find module: ") + modName).c_str());
112 
113 
114  SWKey *key = module->getKey();
115  VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
116 
117  if (vkey)
118  vkey->setIntros(true);
119 
120  for ((*module) = TOP; !module->popError(); (*module)++) {
121  std::cout << "$$$" << module->getKeyText() << std::endl;
122  std::cout << ((render) ? module->renderText().c_str() : (strip) ? module->stripText() : module->getRawEntry()) << "\n";
123  }
124 
125  cout << endl;
126 
127  return 0;
128 }
#define TOP
Definition: swkey.h:68
SWText * module
Definition: osis2mod.cpp:105
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
void usage(const char *app)
Definition: imp2gbs.cpp:65
SWMgr * mgr
Definition: installmgr.cpp:46
void usage ( const char *  progName,
const char *  error = 0 
)

Definition at line 47 of file mod2imp.cpp.

47  {
48  if (error) fprintf(stderr, "\n%s: %s\n", progName, error);
49  fprintf(stderr, "\n=== mod2imp (Revision $Rev: 3088 $) SWORD module exporter.\n");
50  fprintf(stderr, "\nusage: %s <module_name> [options]\n"
51  "\t -r [output_format] - render content instead of outputting raw native\n"
52  "\t\tdata. output_format can be: OSIS, XHTML, LATEX, HTMLHREF, RTF.\n"
53  "\t -s - strip markup instead of outputting raw native data.\n"
54  "\t -f <option_name> <option_value> - when rendering (-r, above), option\n"
55  "\t\tfilter values can be set with this option.\n\n"
56  , progName);
57  exit(-1);
58 }