371 normalizer = &normalizr;
374 SWBuf program = argv[0];
375 fprintf(stderr,
"You are running %s: $Rev: 3416 $\n", argv[0]);
383 SWBuf path = argv[1];
384 SWBuf teiDoc = argv[2];
387 SWBuf recommendedPath =
"./modules/lexdict/";
388 SWBuf cipherKey =
"";
391 for (
int i = 3; i < argc; i++) {
392 if (!strcmp(argv[i],
"-z")) {
393 if (modDrv.size())
usage(*argv,
"Cannot specify both -z and -s");
395 if (i+1 < argc && argv[i+1][0] !=
'-') {
396 switch (argv[++i][0]) {
397 case 'l': compType =
"LZSS";
break;
398 case 'z': compType =
"ZIP";
break;
399 case 'b': compType =
"BZIP2";
break;
400 case 'x': compType =
"XZ";
break;
404 recommendedPath +=
"zld/";
406 else if (!strcmp(argv[i],
"-Z")) {
407 if (compType.size())
usage(*argv,
"Cannot specify both -z and -Z");
408 if (modDrv.size())
usage(*argv,
"Cannot specify both -Z and -s");
411 recommendedPath +=
"zld/";
413 else if (!strcmp(argv[i],
"-s")) {
414 if (compType.size())
usage(*argv,
"Cannot specify both -s and -z");
416 int size = atoi(argv[++i]);
419 recommendedPath +=
"rawld/";
424 recommendedPath +=
"rawld4/";
428 usage(*argv,
"-s requires one of <2|4>");
430 else if (!strcmp(argv[i],
"-N")) {
433 else if (!strcmp(argv[i],
"-c")) {
434 if (i+1 < argc) cipherKey = argv[++i];
435 else usage(*argv,
"-c requires <cipher_key>");
437 else usage(*argv, (((SWBuf)
"Unknown argument: ")+ argv[i]).c_str());
439 if (!modDrv.size()) {
441 recommendedPath +=
"rawld4/";
447 cout << program <<
" is not compiled with support for ICU. Setting -N flag." << endl;
451 if (compType ==
"LZSS") {
454 else if (compType ==
"ZIP") {
456 compressor =
new ZipCompress();
458 usage(*argv,
"ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library");
461 else if (compType ==
"BZIP2") {
465 usage(*argv,
"ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library");
468 else if (compType ==
"XZ") {
472 usage(*argv,
"ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library");
478 cout <<
"path: " << path <<
" teiDoc: " << teiDoc <<
" compressType: " << compType <<
" ldType: " << modDrv <<
" normalize: " <<
normalize <<
"\n";
483 SWBuf modName = path;
484 int pathlen = path.length();
485 char lastChar = path[pathlen - 1];
486 if (lastChar !=
'/' && lastChar !=
'\\') {
494 vector<string> linkBuf;
496 if (modDrv ==
"zLD") {
498 fprintf(stderr,
"error: %s: couldn't create module at path: %s \n", program.c_str(), modName.c_str());
501 module =
new zLD(modName, 0, 0, 30, compressor);
503 else if (modDrv ==
"RawLD") {
505 fprintf(stderr,
"error: %s: couldn't create module at path: %s \n", program.c_str(), modName.c_str());
508 module =
new RawLD(modName);
512 fprintf(stderr,
"error: %s: couldn't create module at path: %s \n", program.c_str(), modName.c_str());
515 module =
new RawLD4(modName);
520 if (cipherKey.size()) {
521 fprintf(stderr,
"Adding cipher filter with phrase: %s\n", cipherKey.c_str() );
527 fprintf(stderr,
"The module is not writable. Writing text to it will not work.\nExiting.\n" );
532 ifstream infile(teiDoc);
534 fprintf(stderr,
"error: %s: couldn't open input file: %s \n", program.c_str(), teiDoc.c_str());
546 bool intoken =
false;
549 while (infile.good()) {
551 curChar = infile.get();
558 if (!intoken && curChar ==
'<') {
564 if (intoken && curChar ==
'>') {
577 token.append(curChar);
580 case '>' : text.append(
">");
break;
581 case '<' : text.append(
"<");
break;
582 default : text.append(curChar);
break;
614 SWBuf suggestedModuleName = path;
615 if (lastChar ==
'/' || lastChar ==
'\\') {
616 suggestedModuleName.setSize(--pathlen);
619 lastChar = suggestedModuleName[pathlen - 1];
620 if (lastChar ==
'.') {
621 suggestedModuleName =
"???";
628 const char *
m = strrchr(suggestedModuleName.c_str(),
'/');
630 m = strrchr(suggestedModuleName.c_str(),
'\\');
633 suggestedModuleName = m+1;
637 recommendedPath += suggestedModuleName;
638 recommendedPath +=
"/dict";
640 fprintf(stderr,
"\nSuggested conf (replace ??? with appropriate values)\n\n");
641 fprintf(stderr,
"[%s]\n", suggestedModuleName.c_str());
642 fprintf(stderr,
"DataPath=%s\n", recommendedPath.c_str());
643 fprintf(stderr,
"Description=???\n");
644 fprintf(stderr,
"SourceType=TEI\n");
645 fprintf(stderr,
"Encoding=%s\n", (normalize ?
"UTF-8" :
"???"));
646 fprintf(stderr,
"ModDrv=%s\n", modDrv.c_str());
648 fprintf(stderr,
"CompressType=%s\n", compType.c_str());
650 if (cipherKey.size()) {
651 fprintf(stderr,
"CipherKey=%s\n", cipherKey.c_str());
virtual SWKey * createKey() const
bool handleToken(SWBuf &text, XMLTag token)
virtual char setKey(const SWKey *ikey)
static char createModule(const char *path)
static char createModule(const char *path)
virtual bool isWritable() const
virtual SWModule & addRawFilter(SWFilter *newFilter)
void usage(const char *app)
static char createModule(const char *path)