The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mod2osis.cpp File Reference
#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <string>
#include <swbuf.h>
#include <ztext.h>
#include <zld.h>
#include <zcom.h>
#include <swmgr.h>
#include <lzsscomprs.h>
#include <zipcomprs.h>
#include <versekey.h>
#include <thmlosis.h>
#include <stdio.h>
#include <markupfiltmgr.h>
#include <algorithm>
+ Include dependency graph for mod2osis.cpp:

Go to the source code of this file.

Functions

void errorOutHelp (char *appName)
 
int main (int argc, char **argv)
 

Function Documentation

void errorOutHelp ( char *  appName)

Definition at line 52 of file mod2osis.cpp.

52  {
53  cerr << appName << " - a tool to output a SWORD module in OSIS format\n";
54  cerr << "usage: "<< appName << " <modname> \n";
55  cerr << "\n\n";
56  exit(-1);
57 }
int main ( int  argc,
char **  argv 
)

Definition at line 60 of file mod2osis.cpp.

61 {
62  SWModule *inModule = 0;
63  ThMLOSIS filter;
64 
65  cerr << "\n\n*** Don't use this utility *** \n\n";
66  cerr << "Its purpose is to prove the engine can do\n";
67  cerr << "lossless import / export, but we are not there yet. \n\n";
68  cerr << "This utility is done, in fact it is already too complex.\n";
69  cerr << "The ENGINE needs more work to assure export as OSIS works\n";
70  cerr << "This utility only gives us occasion to improve the engine.\n";
71  cerr << "Our goal is not to produce an export tool.\n\n";
72  cerr << "In fact, you should never export SWORD modules.\n";
73  cerr << "Many CrossWire modules are licensed for use from publishers\n";
74  cerr << "and you will need to obtain your own permissions.\n";
75  cerr << "We also do not encourage propagating encoding errors\n";
76  cerr << "which you will avoid by obtaining text data from the source.\n\n";
77  cerr << "Please see the TextSource entry in the module's .conf file\n";
78  cerr << "for information where to obtain module data from our source.\n\n";
79  cerr << "If you still must export SWORD module data, use mod2imp.\n";
80  cerr << "It is more lossless; or less lossful, and easier to read.\n\n";
81 
82  if ((argc != 2)) {
83  errorOutHelp(argv[0]);
84  }
85 
86  if ((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
87  errorOutHelp(argv[0]);
88  }
89 
90  SWMgr mgr(new MarkupFilterMgr(FMT_OSIS));
91  StringList options = mgr.getGlobalOptions();
92  for (StringList::iterator it = options.begin(); it != options.end(); it++) {
93  StringList values = mgr.getGlobalOptionValues(it->c_str());
94  if (find(values.begin(), values.end(), "On") != values.end()) {
95  mgr.setGlobalOption(it->c_str(), "On");
96  }
97  if (find(values.begin(), values.end(), "All Readings") != values.end()) {
98  mgr.setGlobalOption(it->c_str(), "All Readings");
99  }
100  }
101 
102 // mgr.setGlobalOption("Strong's Numbers", "Off");
103 // mgr.setGlobalOption("Morphological Tags", "Off");
104 
105  ModMap::iterator it = mgr.Modules.find(argv[1]);
106  if (it == mgr.Modules.end()) {
107  fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
108  exit(-2);
109  }
110 
111  inModule = it->second;
112 // inModule->AddRenderFilter(&filter);
113 
114  SWKey *key = (SWKey *)*inModule;
115  VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
116 
117  char buf[1024];
118  bool opentest = false;
119  bool openbook = false;
120  bool openchap = false;
121  int lastTest = 5;
122  int lastBook = 9999;
123  int lastChap = 9999;
124  if (!vkey) {
125  cerr << "Currently mod2osis only works with verse keyed modules\n\n";
126  exit(-1);
127  }
128 
129  vkey->setIntros(false);
130 
131  cout << "<?xml version=\"1.0\" ";
132  if (inModule->getConfigEntry("Encoding")) {
133  if (*(inModule->getConfigEntry("Encoding")))
134  cout << "encoding=\"" << inModule->getConfigEntry("Encoding") << "\" ";
135  else cout << "encoding=\"UTF-8\" ";
136  }
137  else cout << "encoding=\"UTF-8\" ";
138  cout << "?>\n\n";
139 
140 
141  cout << "<osis";
142  cout << " xmlns=\"http://www.bibletechnologies.net/2003/OSIS/namespace\"";
143  cout << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
144  cout << " xsi:schemaLocation=\"http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd\">\n\n";
145  cout << "<osisText";
146  cout << " osisIDWork=\"";
147  cout << inModule->getName() << "\"";
148  cout << " osisRefWork=\"defaultReferenceScheme\"";
149  if (inModule->getLanguage()) {
150  if (strlen(inModule->getLanguage()))
151  cout << " xml:lang=\"" << inModule->getLanguage() << "\"";
152  }
153  cout << ">\n\n";
154 
155  cout << "\t<header>\n";
156  cout << "\t\t<work osisWork=\"";
157  cout << inModule->getName() << "\">\n";
158  cout << "\t\t\t<title>" << inModule->getDescription() << "</title>\n";
159  cout << "\t\t\t<identifier type=\"OSIS\">Bible." << inModule->getName() << "</identifier>\n";
160  cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
161  cout << "\t\t</work>\n";
162  cout << "\t\t<work osisWork=\"defaultReferenceScheme\">\n";
163  cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
164  cout << "\t\t</work>\n";
165  cout << "\t</header>\n\n";
166 
167 
168  (*inModule) = TOP;
169 
170  SWKey *p = inModule->createKey();
171  VerseKey *tmpKey = SWDYNAMIC_CAST(VerseKey, p);
172  if (!tmpKey) {
173  delete p;
174  tmpKey = new VerseKey();
175  }
176  *tmpKey = inModule->getKeyText();
177 
178  tmpKey->setIntros(true);
179  tmpKey->setAutoNormalize(false);
180 
181  for ((*inModule) = TOP; !inModule->popError(); (*inModule)++) {
182  bool newTest = false;
183  bool newBook = false;
184 
185  if (!strlen(inModule->renderText())) {
186  continue;
187  }
188 
189  if ((vkey->getTestament() != lastTest)) {
190  if (openchap)
191  cout << "\t</chapter>\n";
192  if (openbook)
193  cout << "\t</div>\n";
194  if (opentest)
195  cout << "\t</div>\n";
196  cout << "\t<div type=\"x-testament\">\n";
197  opentest = true;
198  newTest = true;
199  }
200  if ((vkey->getBook() != lastBook) || newTest) {
201  if (!newTest) {
202  if (openchap)
203  cout << "\t</chapter>\n";
204  if (openbook)
205  cout << "\t</div>\n";
206  }
207  *buf = 0;
208  *tmpKey = *vkey;
209  tmpKey->setChapter(0);
210  tmpKey->setVerse(0);
211  sprintf(buf, "\t<div type=\"book\" osisID=\"%s\">\n", tmpKey->getOSISRef());
212 // filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
213  cout << "" << buf << endl;
214  openbook = true;
215  newBook = true;
216  }
217  if ((vkey->getChapter() != lastChap) || newBook) {
218  if (!newBook) {
219  if (openchap)
220  cout << "\t</chapter>\n";
221  }
222  *buf = 0;
223  *tmpKey = *vkey;
224  tmpKey->setVerse(0);
225  sprintf(buf, "\t<chapter osisID=\"%s\">\n", tmpKey->getOSISRef());
226 // filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
227  cout << "" << buf;
228  openchap = true;
229  }
230  SWBuf verseText = inModule->getRawEntry();
231  sprintf(buf, "\t\t<verse osisID=\"%s\">", vkey->getOSISRef());
232  cout << buf << verseText.c_str() << "</verse>\n" << endl;
233  lastChap = vkey->getChapter();
234  lastBook = vkey->getBook();
235  lastTest = vkey->getTestament();
236  }
237  if (openchap)
238  cout << "\t</chapter>\n";
239  if (openbook)
240  cout << "\t</div>\n";
241  if (opentest)
242  cout << "\t</div>\n";
243  cout << "\t</osisText>\n";
244  cout << "</osis>\n";
245  return 0;
246 }
#define TOP
Definition: swkey.h:68
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
void errorOutHelp(char *appName)
Definition: mod2osis.cpp:52
SWMgr * mgr
Definition: installmgr.cpp:46