utilities/addld.cpp File Reference

#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <io.h>
#include <swmgr.h>
#include <rawld.h>
#include <rawld4.h>
#include <zld.h>
#include <zipcomprs.h>
Include dependency graph for addld.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file addld.cpp.

00050                                 {
00051   
00052   const char * helptext ="addld 1.0 Lexicon & Dictionary module creation tool for the SWORD Project\nUse -a to add a new LD entry from standard input or a file, -d to delete an\nentry, -l to link two LD entries, -c to create a new module.\n  usage:\n   %s -a <filename> <key> [</path/to/file/with/entry>]\n   %s -d <filename> <key>\n   %s -l <filename> <first key (already assigned)> <second key>\n   %s -c <filename>\nTo use 4-byte LD instead of 2-byte, insert a 4 immediately after the '-'.\nTo use zLD instead of 2-byte, insert a z immediately after the '-'.\n";
00053   long entrysize;
00054   
00055   bool fourbyte = false;
00056   bool compress = false;
00057   char mode;
00058   
00059   if (argc < 3) {
00060     fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);
00061     exit(-1);
00062   }
00063   
00064   if (argv[1][1] == '4') {
00065     fourbyte = false;
00066     mode = argv[1][2];
00067   }
00068   else if (argv[1][1] == 'z') {
00069     compress = true;
00070     mode = argv[1][2];
00071   }
00072   else {
00073     mode = argv[1][1];
00074   }
00075   
00076   if ((mode == 'a') && (argc == 4 || argc == 5)) {  
00077     
00078     // Do some initialization stuff
00079     if (fourbyte) {
00080       char buffer[1048576];  //this is the max size of any entry
00081       RawLD4 mod(argv[2]);  // open our datapath with our RawText driver.
00082       SWKey* key = mod.createKey();
00083       key->setPersist(true);      // the magical setting
00084       
00085       // Set our VerseKey
00086       *key = argv[3];
00087      mod.setKey(*key);
00088       FILE *infile;
00089       // case: add from text file
00090       //Open our data file and read its contents into the buffer
00091       if (argc == 5) infile = fopen(argv[4], "r");
00092       // case: add from stdin
00093       else infile = stdin;
00094       
00095       entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
00096       mod.setEntry(buffer, entrysize);  // save text to module at current position
00097     }
00098     else if (compress) {
00099 #ifndef EXCLUDEZLIB
00100       char buffer[1048576];  //this is the max size of any entry
00101       zLD mod(argv[2], 0, 0, 200, new ZipCompress());   // open our datapath with our RawText driver.
00102       SWKey* key = mod.createKey();
00103       key->setPersist(true);      // the magical setting
00104       
00105       // Set our VerseKey
00106       *key = argv[3];
00107      mod.setKey(*key);
00108       FILE *infile;
00109       // case: add from text file
00110       //Open our data file and read its contents into the buffer
00111       if (argc == 5) infile = fopen(argv[4], "r");
00112       // case: add from stdin
00113       else infile = stdin;
00114       
00115       entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
00116       mod.setEntry(buffer, entrysize);  // save text to module at current position
00117 #else
00118       fprintf(stderr, "error: %s: SWORD library not built with ZIP compression support.\n", argv[0]);
00119       exit(-3);
00120 #endif
00121     }
00122     else {
00123       char buffer[65536];  //this is the max size of any entry
00124       RawLD mod(argv[2]);   // open our datapath with our RawText driver.
00125       SWKey* key = mod.createKey();
00126       key->setPersist(true);      // the magical setting
00127       
00128       // Set our VerseKey
00129       *key = argv[3];
00130      mod.setKey(*key);
00131       FILE *infile;
00132       // case: add from text file
00133       //Open our data file and read its contents into the buffer
00134       if (argc == 5) infile = fopen(argv[4], "r");
00135       // case: add from stdin
00136       else infile = stdin;
00137       
00138       entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
00139       mod.setEntry(buffer, entrysize);  // save text to module at current position
00140     }
00141     
00142   }
00143   // Link 2 verses
00144   else if ((mode == 'l') && argc == 5) {
00145     // Do some initialization stuff
00146     if (fourbyte) {
00147       RawLD4 mod(argv[2]);  // open our datapath with our RawText driver.
00148       SWKey* key = mod.createKey();
00149       key->setPersist(true);      // the magical setting
00150       
00151       *key = argv[3];
00152      mod.setKey(*key);
00153       SWKey tmpkey = argv[4];
00154       mod << &(tmpkey);
00155     }
00156     else if (compress) {
00157       zLD mod(argv[2]); // open our datapath with our RawText driver.
00158       SWKey* key = mod.createKey();
00159       key->setPersist(true);      // the magical setting
00160       
00161       *key = argv[3];
00162      mod.setKey(*key);
00163       
00164       SWKey tmpkey = argv[4];
00165       mod << &(tmpkey);
00166     }
00167     else {
00168       RawLD mod(argv[2]);   // open our datapath with our RawText driver.
00169       SWKey* key = mod.createKey();
00170       key->setPersist(true);      // the magical setting
00171       
00172       *key = argv[3];
00173      mod.setKey(*key);
00174       
00175       SWKey tmpkey = argv[4];
00176       mod << &(tmpkey);
00177     }
00178   }
00179   else if ((mode == 'd') && argc == 4) {
00180     if (fourbyte) {
00181       RawLD4 mod(argv[2]);  // open our datapath with our RawText driver.
00182      mod.setKey(argv[3]);
00183       mod.deleteEntry();
00184     }
00185     if (compress) {
00186       zLD mod(argv[2]); // open our datapath with our RawText driver.
00187      mod.setKey(argv[3]);
00188       mod.deleteEntry();
00189     }
00190     else {
00191       RawLD mod(argv[2]);   // open our datapath with our RawText driver.
00192       mod.setKey(argv[3]);
00193       mod.deleteEntry();
00194     }
00195     
00196   }
00197   // Make a new module
00198   else if ((mode == 'c') && argc == 3) {
00199     // Try to initialize a default set of datafiles and indicies at our
00200     // datapath location passed to us from the user.
00201     if (fourbyte) {
00202       if (RawLD4::createModule(argv[2])) {
00203     fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]);
00204     exit(-2);
00205       }
00206     }
00207     if (compress) {
00208       if (zLD::createModule(argv[2])) {
00209     fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]);
00210     exit(-2);
00211       }
00212     }
00213     else {
00214       if (RawLD::createModule(argv[2])) {
00215     fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]);
00216     exit(-2);
00217       }
00218     }
00219   }   
00220   
00221   // Bad arguments, print usage
00222   else {
00223     fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);
00224     exit(-1);
00225   }
00226 }


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