utilities/mod2zmod.cpp File Reference

#include <fcntl.h>
#include <iostream>
#include <fstream>
#include <string>
#include <io.h>
#include <ztext.h>
#include <zld.h>
#include <zcom.h>
#include <swtext.h>
#include <swmgr.h>
#include <lzsscomprs.h>
#include <zipcomprs.h>
#include <versekey.h>
#include <stdio.h>
#include <cipherfil.h>
Include dependency graph for mod2zmod.cpp:

Go to the source code of this file.

Defines

#define BIBLE   1
#define COM   3
#define LEX   2

Functions

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

Define Documentation

#define BIBLE   1
#define COM   3
#define LEX   2

Function Documentation

void errorOutHelp ( char *  appName  ) 

Definition at line 54 of file mod2zmod.cpp.

00054                                  {
00055     cerr << appName << " - a tool to create compressed Sword modules\n";
00056     cerr << "version 0.1\n\n";
00057     cerr << "usage: "<< appName << " <modname> <datapath> [blockType [compressType [cipherKey]]]\n\n";
00058     cerr << "datapath: the directory in which to write the zModule\n";
00059     cerr << "blockType  : (default 4)\n\t2 - verses\n\t3 - chapters\n\t4 - books\n";
00060     cerr << "compressType: (default 1):\n\t1 - LZSS\n\t2 - Zip\n";
00061     cerr << "\n\n";
00062     exit(-1);
00063 }

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file mod2zmod.cpp.

00067 {
00068     int iType = 4;
00069     int compType = 1;
00070     string cipherKey = "";
00071     SWCompress *compressor = 0;
00072     SWModule *inModule     = 0;
00073     SWModule *outModule    = 0;
00074     
00075 
00076     if ((argc < 3) || (argc > 6)) {
00077         errorOutHelp(argv[0]);
00078     }
00079 
00080     if (argc > 3) {
00081         iType = atoi(argv[3]);
00082         if (argc > 4) {
00083             compType = atoi(argv[4]);
00084             if (argc > 5) {
00085                 cipherKey = argv[5];
00086             }
00087         }
00088     }
00089 
00090     if ((iType < 2) || (compType < 1) || (compType > 2) || (!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
00091         errorOutHelp(argv[0]);
00092     }
00093 
00094     SWMgr mgr;
00095 
00096     ModMap::iterator it = mgr.Modules.find(argv[1]);
00097     if (it == mgr.Modules.end()) {
00098         fprintf(stderr, "error: %s: couldn't find module: %s\n", argv[0], argv[1]);
00099         exit(-2);
00100     }
00101 
00102     inModule = it->second;
00103 
00104     // Try to initialize a default set of datafiles and indicies at our
00105     // datapath location passed to us from the user.
00106     
00107 #define BIBLE 1
00108 #define LEX 2
00109 #define COM 3
00110 
00111     int modType = 0;
00112     if (!strcmp(inModule->getType(), "Biblical Texts")) modType = BIBLE;
00113     if (!strcmp(inModule->getType(), "Lexicons / Dictionaries")) modType = LEX;
00114     if (!strcmp(inModule->getType(), "Commentaries")) modType = COM;
00115 
00116     switch (compType) { // these are deleted by zText
00117     case 1: compressor = new LZSSCompress(); break;
00118     case 2: compressor = new ZipCompress(); break;
00119     }
00120 
00121     int result = 0;
00122     switch (modType) {
00123     case BIBLE:
00124     case COM: {
00125         SWKey *k = inModule->getKey();
00126         VerseKey *vk = SWDYNAMIC_CAST(VerseKey, k);
00127         result = zText::createModule(argv[2], iType, vk->getVersificationSystem());
00128         break;
00129     }
00130     case LEX:
00131         result = zLD::createModule(argv[2]);
00132         break;
00133     }
00134 
00135     if (result) {
00136         fprintf(stderr, "error: %s: couldn't create module at path: %s\n", argv[0], argv[2]);
00137         exit(-3);
00138     }
00139 
00140     switch (modType) {
00141     case BIBLE:
00142     case COM: {
00143         SWKey *k = inModule->getKey();
00144         VerseKey *vk = SWDYNAMIC_CAST(VerseKey, k);
00145         outModule = new zText(argv[2], 0, 0, iType, compressor,
00146             0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0,
00147             vk->getVersificationSystem());  // open our datapath with our RawText driver.
00148         ((VerseKey *)(SWKey *)(*inModule))->setIntros(true);
00149         break;
00150     }
00151     case LEX:
00152         outModule = new zLD(argv[2], 0, 0, iType, compressor);      // open our datapath with our RawText driver.
00153         break;
00154     }
00155 
00156     SWFilter *cipherFilter = 0;
00157     if (!cipherKey.empty()) {
00158         cipherFilter = new CipherFilter(cipherKey.c_str());
00159         outModule->addRawFilter(cipherFilter);
00160     }
00161 
00162     string lastBuffer = "Something that would never be first module entry";
00163     SWKey bufferKey;
00164     SWKey lastBufferKey;
00165     SWKey *outModuleKey = outModule->createKey();
00166     VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, outModuleKey);
00167     outModuleKey->setPersist(true);
00168     if (vkey) {
00169         vkey->setIntros(true);
00170         vkey->setAutoNormalize(false);
00171     }
00172     outModule->setKey(*outModuleKey);
00173 
00174     inModule->setSkipConsecutiveLinks(false);
00175     (*inModule) = TOP;
00176     while (!inModule->popError()) {
00177         bufferKey = *(SWKey *)(*inModule);
00178         // pseudo-check for link.  Will get most common links.
00179         if ((lastBuffer == inModule->getRawEntry()) &&(lastBuffer.length() > 0)) {
00180             *outModuleKey = bufferKey;
00181             outModule->linkEntry(&lastBufferKey);   // link to last key
00182         cout << "Adding [" << bufferKey << "] link to: [" << lastBufferKey << "]\n";
00183         }
00184         else {
00185             lastBuffer = inModule->getRawEntry();
00186             lastBufferKey = inModule->getKeyText();
00187             if (lastBuffer.length() > 0) {
00188                 cout << "Adding [" << bufferKey << "] new text.\n";
00189                 *outModuleKey = bufferKey;
00190 //              outModule->getRawEntry();   // snap
00191 //              outModule->setKey(bufferKey);
00192                 (*outModule) << lastBuffer.c_str(); // save new text;
00193             }
00194             else {
00195                     cout << "Skipping [" << bufferKey << "] no entry in Module.\n";
00196             }
00197         }
00198         (*inModule)++;
00199     }
00200     delete outModule;
00201     delete outModuleKey;
00202     if (cipherFilter)
00203         delete cipherFilter;
00204 }


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