utilities/mod2osis.cpp File Reference

#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <string>
#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 46 of file mod2osis.cpp.

00046                                  {
00047     cerr << appName << " - a tool to output a SWORD module in OSIS format\n";
00048     cerr << "usage: "<< appName << " <modname> \n";
00049     cerr << "\n\n";
00050     exit(-1);
00051 }

int main ( int  argc,
char **  argv 
)

Definition at line 54 of file mod2osis.cpp.

00055 {
00056     SWModule *inModule = 0;
00057     ThMLOSIS filter;
00058 
00059     cerr << "\n\n*** Don't use this utility *** \n\n";
00060     cerr << "Its purpose is to eventually obtain round trip \n";
00061     cerr << "lossless import / export, but we are not there yet. \n\n";
00062     cerr << "In fact, you should never export SWORD modules.\n";
00063     cerr << "Many CrossWire modules are licensed for use from publishers\n";
00064     cerr << "and you will need to obtain your own permissions.\n";
00065     cerr << "We also do not encourage propogating encoding errors\n";
00066     cerr << "which you will avoid by obtaining text data from the source.\n\n";
00067     cerr << "Please see the TextSource entry in the module's .conf file\n";
00068     cerr << "for information where to obtain module data from our source.\n\n";
00069     cerr << "If you still must export SWORD module data, use mod2imp.\n";
00070     cerr << "It is more lossless; or less lossful, and easier to read.\n\n";
00071     
00072     if ((argc != 2)) {
00073         errorOutHelp(argv[0]);
00074     }
00075 
00076     if ((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
00077         errorOutHelp(argv[0]);
00078     }
00079 
00080     SWMgr mgr(new MarkupFilterMgr(FMT_OSIS));
00081     StringList options = mgr.getGlobalOptions();
00082     for (StringList::iterator it = options.begin(); it != options.end(); it++) {
00083         StringList values = mgr.getGlobalOptionValues(it->c_str());
00084         if (find(values.begin(), values.end(), "On") != values.end()) {
00085             mgr.setGlobalOption(it->c_str(), "On");
00086         }
00087         if (find(values.begin(), values.end(), "All Readings") != values.end()) {
00088             mgr.setGlobalOption(it->c_str(), "All Readings");
00089         }
00090     }
00091 
00092 //  mgr.setGlobalOption("Strong's Numbers", "Off");
00093 //  mgr.setGlobalOption("Morphological Tags", "Off");
00094 
00095     ModMap::iterator it = mgr.Modules.find(argv[1]);
00096     if (it == mgr.Modules.end()) {
00097         fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
00098         exit(-2);
00099     }
00100 
00101     inModule = it->second;
00102 //  inModule->AddRenderFilter(&filter);
00103 
00104     SWKey *key = (SWKey *)*inModule;
00105     VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
00106 
00107     char buf[1024];
00108     bool opentest = false;
00109     bool openbook = false;
00110     bool openchap = false;
00111     int lastTest = 5;
00112     int lastBook = 9999;
00113     int lastChap = 9999;
00114     if (!vkey) {
00115         cerr << "Currently mod2osis only works with verse keyed modules\n\n";
00116         exit(-1);
00117     }
00118 
00119     vkey->setIntros(false);
00120 
00121     cout << "<?xml version=\"1.0\" ";
00122         if (inModule->getConfigEntry("Encoding")) {
00123             if (*(inModule->getConfigEntry("Encoding")))
00124                 cout << "encoding=\"" << inModule->getConfigEntry("Encoding") << "\" ";
00125             else cout << "encoding=\"UTF-8\" ";
00126         }
00127         else cout << "encoding=\"UTF-8\" ";
00128         cout << "?>\n\n";
00129 
00130 
00131     cout << "<osis";
00132         cout << " xmlns=\"http://www.bibletechnologies.net/2003/OSIS/namespace\"";
00133         cout << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
00134         cout << " xsi:schemaLocation=\"http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd\">\n\n";
00135     cout << "<osisText";
00136         cout << " osisIDWork=\"";
00137         cout << inModule->getName() << "\"";
00138         cout << " osisRefWork=\"defaultReferenceScheme\"";
00139         if (inModule->getLanguage()) {
00140             if (strlen(inModule->getLanguage()))
00141                 cout << " xml:lang=\"" << inModule->getLanguage() << "\"";
00142         }
00143         cout << ">\n\n";
00144 
00145     cout << "\t<header>\n";
00146     cout << "\t\t<work osisWork=\"";
00147     cout << inModule->getName() << "\">\n";
00148     cout << "\t\t\t<title>" << inModule->getDescription() << "</title>\n";
00149     cout << "\t\t\t<identifier type=\"OSIS\">Bible." << inModule->getName() << "</identifier>\n";
00150     cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
00151     cout << "\t\t</work>\n";
00152     cout << "\t\t<work osisWork=\"defaultReferenceScheme\">\n";
00153     cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
00154     cout << "\t\t</work>\n";
00155     cout << "\t</header>\n\n";
00156 
00157 
00158     (*inModule) = TOP;
00159 
00160     SWKey *p = inModule->createKey();
00161         VerseKey *tmpKey = SWDYNAMIC_CAST(VerseKey, p);
00162     if (!tmpKey) {
00163             delete p;
00164             tmpKey = new VerseKey();
00165     }
00166     *tmpKey = inModule->getKeyText();
00167 
00168     tmpKey->setIntros(true);
00169     tmpKey->setAutoNormalize(false);
00170 
00171     for ((*inModule) = TOP; !inModule->popError(); (*inModule)++) {
00172         bool newTest = false;
00173         bool newBook = false;
00174 
00175         if (!strlen(inModule->renderText())) {
00176             continue;
00177         }
00178 
00179         if ((vkey->getTestament() != lastTest)) {
00180             if (openchap)
00181                 cout << "\t</chapter>\n";
00182             if (openbook)
00183                 cout << "\t</div>\n";
00184             if (opentest)
00185                 cout << "\t</div>\n";
00186             cout << "\t<div type=\"x-testament\">\n";
00187             opentest = true;
00188             newTest = true;
00189         }
00190         if ((vkey->getBook() != lastBook) || newTest) {
00191             if (!newTest) {
00192                 if (openchap)
00193                     cout << "\t</chapter>\n";
00194                 if (openbook)
00195                     cout << "\t</div>\n";
00196             }
00197             *buf = 0;
00198             *tmpKey = *vkey;
00199             tmpKey->setChapter(0);
00200             tmpKey->setVerse(0);
00201             sprintf(buf, "\t<div type=\"book\" osisID=\"%s\">\n", tmpKey->getOSISRef());
00202 //          filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
00203             cout << "" << buf << endl;
00204             openbook = true;
00205             newBook = true;
00206         }
00207         if ((vkey->getChapter() != lastChap) || newBook) {
00208             if (!newBook) {
00209                 if (openchap)
00210                     cout << "\t</chapter>\n";
00211             }
00212             *buf = 0;
00213             *tmpKey = *vkey;
00214             tmpKey->setVerse(0);
00215             sprintf(buf, "\t<chapter osisID=\"%s\">\n", tmpKey->getOSISRef());
00216 //          filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
00217             cout << "" << buf;
00218             openchap = true;
00219         }
00220         SWBuf verseText = inModule->getRawEntry();
00221         sprintf(buf, "\t\t<verse osisID=\"%s\">", vkey->getOSISRef());
00222         cout << buf << verseText.c_str() << "</verse>\n" << endl;
00223         lastChap = vkey->getChapter();
00224         lastBook = vkey->getBook();
00225         lastTest = vkey->getTestament();
00226     }
00227     if (openchap)
00228         cout << "\t</chapter>\n";
00229     if (openbook)
00230         cout << "\t</div>\n";
00231     if (opentest)
00232         cout << "\t</div>\n";
00233     cout << "\t</osisText>\n";
00234     cout << "</osis>\n";
00235     return 0;
00236 }


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