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

Go to the source code of this file.

Macros

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

Functions

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

Macro Definition Documentation

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

Function Documentation

void errorOutHelp ( char *  appName)

Definition at line 67 of file mod2zmod.cpp.

67  {
68  cerr << appName << " - a tool to create compressed Sword modules\n";
69  cerr << "version 0.1\n\n";
70  cerr << "usage: "<< appName << " <modname> <datapath> [blockType [compressType [compressLevel [cipherKey]]]]\n\n";
71  cerr << "datapath: the directory in which to write the zModule\n";
72  cerr << "blockType : (default 4)\n\t2 - verses\n\t3 - chapters\n\t4 - books\n";
73  cerr << "compressType: (default 1):\n\t1 - LZSS\n\t2 - Zip\n\t3 - bzip2\n\t4 - xz\n";
74  cerr << "compressLevel: (default varies by compressType):\n\tA digit from 1-9. Greater values compress more, but require more\n\ttime/memory. Use 0 for the default compression level.\n";
75  cerr << "\n\n";
76  exit(-1);
77 }
int main ( int  argc,
char **  argv 
)

Definition at line 80 of file mod2zmod.cpp.

81 {
82  int iType = 4;
83  int compType = 1;
84  string cipherKey = "";
85  SWCompress *compressor = 0;
86  SWModule *inModule = 0;
87  SWModule *outModule = 0;
88  int compLevel = 0;
89 
90  if ((argc < 3) || (argc > 7)) {
91  errorOutHelp(argv[0]);
92  }
93 
94  if (argc > 3) {
95  iType = atoi(argv[3]);
96  if (argc > 4) {
97  compType = atoi(argv[4]);
98  if (argc > 5) {
99  compLevel = atoi(argv[5]);
100  if (argc > 6) {
101  cipherKey = argv[6];
102  }
103  }
104  }
105  }
106 
107  if ((iType < 2) || (compType < 1) || (compType > 4) || compLevel < 0 || compLevel > 9 || (!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
108  errorOutHelp(argv[0]);
109  }
110 
111  SWMgr mgr;
112 
113  ModMap::iterator it = mgr.Modules.find(argv[1]);
114  if (it == mgr.Modules.end()) {
115  fprintf(stderr, "error: %s: couldn't find module: %s\n", argv[0], argv[1]);
116  exit(-2);
117  }
118 
119  inModule = it->second;
120 
121  // Try to initialize a default set of datafiles and indicies at our
122  // datapath location passed to us from the user.
123 
124 #define BIBLE 1
125 #define LEX 2
126 #define COM 3
127 
128  int modType = 0;
129  if (!strcmp(inModule->getType(), "Biblical Texts")) modType = BIBLE;
130  if (!strcmp(inModule->getType(), "Lexicons / Dictionaries")) modType = LEX;
131  if (!strcmp(inModule->getType(), "Commentaries")) modType = COM;
132 
133  switch (compType) { // these are deleted by zText
134  case 1: compressor = new LZSSCompress(); break;
135  #ifndef EXCLUDEZLIB
136  case 2: compressor = new ZipCompress(); break;
137  #endif
138  #ifndef EXCLUDEBZIP2
139  case 3: compressor = new Bzip2Compress(); break;
140  #endif
141  #ifndef EXCLUDEXZ
142  case 4: compressor = new XzCompress(); break;
143  #endif
144  }
145  if (compressor && compLevel > 0) {
146  compressor->setLevel(compLevel);
147  }
148 
149  int result = 0;
150  switch (modType) {
151  case BIBLE:
152  case COM: {
153  SWKey *k = inModule->getKey();
154  VerseKey *vk = SWDYNAMIC_CAST(VerseKey, k);
155  result = zText::createModule(argv[2], iType, vk->getVersificationSystem());
156  break;
157  }
158  case LEX:
159  result = zLD::createModule(argv[2]);
160  break;
161  }
162 
163  if (result) {
164  fprintf(stderr, "error: %s: couldn't create module at path: %s\n", argv[0], argv[2]);
165  exit(-3);
166  }
167 
168  switch (modType) {
169  case BIBLE:
170  case COM: {
171  SWKey *k = inModule->getKey();
172  VerseKey *vk = SWDYNAMIC_CAST(VerseKey, k);
173  outModule = new zText(argv[2], 0, 0, iType, compressor,
175  vk->getVersificationSystem()); // open our datapath with our RawText driver.
176  ((VerseKey *)(SWKey *)(*inModule))->setIntros(true);
177  break;
178  }
179  case LEX:
180  outModule = new zLD(argv[2], 0, 0, iType, compressor); // open our datapath with our RawText driver.
181  break;
182  }
183 
184  SWFilter *cipherFilter = 0;
185  if (!cipherKey.empty()) {
186  cipherFilter = new CipherFilter(cipherKey.c_str());
187  outModule->addRawFilter(cipherFilter);
188  }
189 
190  string lastBuffer = "Something that would never be first module entry";
191  SWKey bufferKey;
192  SWKey lastBufferKey;
193  SWKey *outModuleKey = outModule->createKey();
194  VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, outModuleKey);
195  outModuleKey->setPersist(true);
196  if (vkey) {
197  vkey->setIntros(true);
198  vkey->setAutoNormalize(false);
199  }
200  outModule->setKey(*outModuleKey);
201 
202  inModule->setSkipConsecutiveLinks(false);
203  (*inModule) = TOP;
204  while (!inModule->popError()) {
205  bufferKey = *(SWKey *)(*inModule);
206  // pseudo-check for link. Will get most common links.
207  if ((lastBuffer == inModule->getRawEntry()) &&(lastBuffer.length() > 0)) {
208  *outModuleKey = bufferKey;
209  outModule->linkEntry(&lastBufferKey); // link to last key
210  cout << "Adding [" << bufferKey << "] link to: [" << lastBufferKey << "]\n";
211  }
212  else {
213  lastBuffer = inModule->getRawEntry();
214  lastBufferKey = inModule->getKeyText();
215  if (lastBuffer.length() > 0) {
216  cout << "Adding [" << bufferKey << "] new text.\n";
217  *outModuleKey = bufferKey;
218 // outModule->getRawEntry(); // snap
219 // outModule->setKey(bufferKey);
220  (*outModule) << lastBuffer.c_str(); // save new text;
221  }
222  else {
223  cout << "Skipping [" << bufferKey << "] no entry in Module.\n";
224  }
225  }
226  (*inModule)++;
227  }
228  delete outModule;
229  delete outModuleKey;
230  if (cipherFilter)
231  delete cipherFilter;
232 }
#define COM
#define TOP
Definition: swkey.h:68
#define LEX
virtual void setLevel(int l)
Definition: swcomprs.h:53
#define BIBLE
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
static char createModule(const char *path, int blockBound, const char *v11n="KJV")
Definition: ztext.h:62
result
Definition: regex.c:5545
static char createModule(const char *path)
Definition: zld.h:49
void errorOutHelp(char *appName)
Definition: mod2osis.cpp:52
SWMgr * mgr
Definition: installmgr.cpp:46
Definition: ztext.h:39