summaryrefslogtreecommitdiff
path: root/utilities/imp2ld.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
commit7a00574163029c0c2b649878c95d5acbd083564a (patch)
treec13cc5736025834df2874ed87ee8598070025ea6 /utilities/imp2ld.cpp
parentb745315323de9f27538edac9453205ca70e6186e (diff)
Imported Upstream version 1.7.2+dfsg
Diffstat (limited to 'utilities/imp2ld.cpp')
-rw-r--r--utilities/imp2ld.cpp193
1 files changed, 131 insertions, 62 deletions
diff --git a/utilities/imp2ld.cpp b/utilities/imp2ld.cpp
index ec2fcf6..7d8b604 100644
--- a/utilities/imp2ld.cpp
+++ b/utilities/imp2ld.cpp
@@ -1,19 +1,24 @@
-/*
-* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
-* CrossWire Bible Society
-* P. O. Box 2528
-* Tempe, AZ 85280-2528
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms of the GNU General Public License as published by the
-* Free Software Foundation version 2.
-*
-* This program is distributed in the hope that it will be useful, but
-* WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* General Public License for more details.
-*
-*/
+/******************************************************************************
+ *
+ * imp2ld.cpp - Utility to import LD modules in IMP format
+ *
+ * $Id: imp2ld.cpp 2833 2013-06-29 06:40:28Z chrislit $
+ *
+ * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
#ifdef _MSC_VER
#pragma warning( disable: 4251 )
@@ -27,6 +32,7 @@
#include <rawld4.h>
#include <zld.h>
#include <zipcomprs.h>
+#include <lzsscomprs.h>
#include <stdio.h>
using std::string;
@@ -35,78 +41,141 @@ using std::string;
using namespace sword;
#endif
+void usage(const char *progName, const char *error = 0) {
+ if (error) fprintf(stderr, "\n%s: %s\n", progName, error);
+ fprintf(stderr, "\n=== imp2ld (Revision $Rev: 2234 $) SWORD lexicon importer.\n");
+ fprintf(stderr, "\nusage: %s <imp_file> [options]\n", progName);
+ fprintf(stderr, " -a\t\t\t augment module if exists (default is to create new)\n");
+ fprintf(stderr, " -z\t\t\t use ZIP compression (default no compression)\n");
+ fprintf(stderr, " -Z\t\t\t use LZSS compression (default no compression)\n");
+ fprintf(stderr, " -o <output_path>\t where to write data files.\n");
+ fprintf(stderr, " -4\t\t\t use 4 byte size entries (default is 2).\n");
+ fprintf(stderr, " -b <entry_count>\t\t compression block size (default 30 entries)\n");
+ fprintf(stderr, " -s\t\t\t case sensitive keys (default is not case sensitive)\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "'imp' format is a simple standard for importing data into SWORD modules.\n"
+ "Required is a plain text file containing $$$key lines followed by content.\n\n"
+ "$$$Abraham\n"
+ "Abraham was the father of Isaac...\n"
+ "He was called by God to leave his country and journey to the land of Canaan...\n"
+ "$$$Isaac\n"
+ "Isaac was the son of Abraham and Sarah...\n\n");
+ exit(-1);
+}
int main(int argc, char **argv) {
- const char * helptext ="imp2ld 1.0 Lexicon/Dictionary/Daily Devotional/Glossary module creation tool for the SWORD Project\n usage:\n %s <filename> [modname] [ 4 (default) | 2 | z - module driver] [entries per compression block]\n";
-
+ std::vector<string> linkbuffer;
signed long i = 0;
string keybuffer;
string entbuffer;
string linebuffer;
- char modname[16];
char links = 0;
+ string modname;
+ SWBuf outPath = "";
+ bool append = false;
long blockCount = 30;
- std::vector<string> linkbuffer;
+ bool caseSensitive = false;
+ SWCompress *compressor = 0;
+ SWBuf compType = "";
+ bool fourByteSize = false;
- if (argc > 2) {
- strcpy (modname, argv[2]);
- }
- else if (argc > 1) {
- for (i = 0; (i < 16) && (argv[1][i]) && (argv[1][i] != '.'); i++) {
- modname[i] = argv[1][i];
- }
- modname[i] = 0;
- }
- else {
- fprintf(stderr, helptext, argv[0]);
- exit(-1);
- }
+ if (argc < 2) usage(*argv);
- std::ifstream infile(argv[1]);
+ const char *progName = argv[0];
+ const char *inFileName = argv[1];
- char mode = 1;
- if (argc > 3) {
- switch (*argv[3]) {
- case 'z': mode = 3; break;
- case '2': mode = 2; break;
- default: mode = 1;
+ for (int i = 2; i < argc; i++) {
+ if (!strcmp(argv[i], "-a")) {
+ append = true;
}
+ else if (!strcmp(argv[i], "-z")) {
+ if (compType.size()) usage(*argv, "Cannot specify both -z and -Z");
+ if (fourByteSize) usage(*argv, "Cannot specify both -z and -4");
+ compType = "ZIP";
+ }
+ else if (!strcmp(argv[i], "-Z")) {
+ if (compType.size()) usage(*argv, "Cannot specify both -z and -Z");
+ if (fourByteSize) usage(*argv, "Cannot specify both -Z and -4");
+ compType = "LZSS";
+ }
+ else if (!strcmp(argv[i], "-4")) {
+ fourByteSize = true;
+ }
+ else if (!strcmp(argv[i], "-b")) {
+ if (i+1 < argc) {
+ blockCount = atoi(argv[++i]);
+ if (blockCount > 0) continue;
+ }
+ usage(*argv, "-b requires in entry count integer > 0");
+ }
+ else if (!strcmp(argv[i], "-o")) {
+ if (i+1 < argc) outPath = argv[++i];
+ else usage(progName, "-o requires <output_path>");
+ }
+ else if (!strcmp(argv[i], "-s")) {
+ caseSensitive = true;
+ }
+ else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
}
- if (argc > 4) {
- long bcTemp = atoi(argv[4]);
- if (bcTemp > 0) {
- blockCount = bcTemp;
+
+
+ if (outPath.size() < 1) {
+ for (i = 0; (i < 16) && (inFileName[i]) && (inFileName[i] != '.'); i++) {
+ outPath += inFileName[i];
}
}
+ std::ifstream infile(inFileName);
+
+
SWModule *mod = 0;
SWKey *key, *linkKey;
- switch (mode) {
- case 3:
+ if (compType == "ZIP") {
#ifndef EXCLUDEZLIB
- zLD::createModule(modname);
- mod = new zLD(modname, 0, 0, blockCount, new ZipCompress());
+ compressor = new ZipCompress();
#else
- fprintf(stderr, "ERROR: %s: SWORD library not compiled with ZIP compression support.\n\tBe sure libzip is available when compiling SWORD library", *argv);
- exit(-2);
+ usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libzip is available when compiling SWORD library");
#endif
- break;
- case 2:
- RawLD::createModule(modname);
- mod = new RawLD(modname);
- break;
- case 1:
- RawLD4::createModule(modname);
- mod = new RawLD4(modname);
- break;
}
+ else if (compType == "LZSS") {
+ compressor = new LZSSCompress();
+ }
+
+ // setup module
+ if (!append) {
+ if (compressor) {
+ if (zLD::createModule(outPath)) {
+ fprintf(stderr, "ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
+ exit(-1);
+ }
+ }
+ else {
+ if (!fourByteSize)
+ RawLD::createModule(outPath);
+ else RawLD4::createModule(outPath);
+ }
+ }
+
+ if (compressor) {
+ // Create a compressed text module allowing very large entries
+ // Taking defaults except for first, fourth, fifth and last argument
+ mod = new zLD(outPath, 0, 0, blockCount, compressor, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive);
+ }
+ else {
+ mod = (!fourByteSize)
+ ? (SWModule *)new RawLD (outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive)
+ : (SWModule *)new RawLD4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive);
+ }
+
+
+
- key = mod->CreateKey();
- linkKey = mod->CreateKey();
- key->Persist(1);
+ key = mod->createKey();
+ linkKey = mod->createKey();
+ key->setPersist(true);
mod->setKey(key);
while (!infile.eof()) {