diff options
author | Teus Benschop <teusjannette@gmail.com> | 2018-10-28 11:51:26 +0100 |
---|---|---|
committer | Teus Benschop <teusjannette@gmail.com> | 2018-10-28 11:51:26 +0100 |
commit | 1d0ff54794b5edea7cdf1d2d66710a0fa885bcc5 (patch) | |
tree | 8ece5f9ef437fbb151f2b22ed0c6e1a714879c7c /utilities/imp2vs.cpp | |
parent | c7dbdc9161a7c460526b80fe01af49d714856126 (diff) |
New upstream version 1.8.1
Diffstat (limited to 'utilities/imp2vs.cpp')
-rw-r--r-- | utilities/imp2vs.cpp | 117 |
1 files changed, 87 insertions, 30 deletions
diff --git a/utilities/imp2vs.cpp b/utilities/imp2vs.cpp index cc26f0b..3e51cd4 100644 --- a/utilities/imp2vs.cpp +++ b/utilities/imp2vs.cpp @@ -2,9 +2,9 @@ * * imp2vs.cpp - Utility to import IMP formatted VerseKey modules * - * $Id: imp2vs.cpp 2833 2013-06-29 06:40:28Z chrislit $ + * $Id: imp2vs.cpp 3515 2017-11-01 11:38:09Z scribe $ * - * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2002-2014 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -34,8 +34,17 @@ #include <rawtext4.h> #include <ztext.h> #include <lzsscomprs.h> +#ifndef EXCLUDEZLIB #include <zipcomprs.h> +#endif +#ifndef EXCLUDEBZIP2 +#include <bz2comprs.h> +#endif +#ifndef EXCLUDEXZ +#include <xzcomprs.h> +#endif #include <localemgr.h> +#include <cipherfil.h> #ifndef NO_SWORD_NAMESPACE using namespace sword; @@ -43,15 +52,15 @@ using namespace sword; using namespace std; -void writeEntry(const SWBuf &key, const SWBuf &entry, SWModule *module); +void writeEntry(SWModule *module, const SWBuf &key, const SWBuf &entry); void usage(const char *progName, const char *error = 0) { if (error) fprintf(stderr, "\n%s: %s\n", progName, error); - fprintf(stderr, "\n=== imp2vs (Revision $Rev: 2234 $) SWORD Bible/Commentary importer.\n"); + fprintf(stderr, "\n=== imp2vs (Revision $Rev: 3515 $) SWORD Bible/Commentary 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, " -z <l|z|b|x>\t\t use compression (default: none):\n"); + fprintf(stderr, "\t\t\t\t l - LZSS; z - ZIP; b - bzip2; x - xz\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 <2|3|4>\t\t compression block size (default 4):\n"); @@ -62,8 +71,10 @@ void usage(const char *progName, const char *error = 0) { StringList av11n = vmgr->getVersificationSystems(); for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) { fprintf(stderr, "\t\t\t\t\t%s\n", (*loop).c_str()); - } + } fprintf(stderr, " -l <locale>\t\t specify a locale scheme to use (default is en)\n"); + fprintf(stderr, " -c <cipher_key>\t encipher module using supplied key\n"); + fprintf(stderr, "\t\t\t\t (default no enciphering)\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" @@ -89,24 +100,32 @@ int main(int argc, char **argv) { const char *progName = argv[0]; const char *inFileName = argv[1]; - SWBuf v11n = "KJV"; - SWBuf outPath = "./"; + SWBuf v11n = "KJV"; + SWBuf outPath = "./"; SWBuf locale = "en"; bool fourByteSize = false; - bool append = false; - int iType = 4; + bool append = false; + int iType = 4; + SWBuf cipherKey = ""; SWCompress *compressor = 0; - SWBuf compType = ""; + SWBuf compType = ""; 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"; + if (i+1 < argc && argv[i+1][0] != '-') { + switch (argv[++i][0]) { + case 'l': compType = "LZSS"; break; + case 'z': compType = "ZIP"; break; + case 'b': compType = "BZIP2"; break; + case 'x': compType = "XZ"; break; + } + } } else if (!strcmp(argv[i], "-Z")) { if (compType.size()) usage(*argv, "Cannot specify both -z and -Z"); @@ -135,23 +154,42 @@ int main(int argc, char **argv) { if (i+1 < argc) locale = argv[++i]; else usage(progName, "-l requires <locale>"); } + else if (!strcmp(argv[i], "-c")) { + if (i+1 < argc) cipherKey = argv[++i]; + else usage(*argv, "-c requires <cipher_key>"); + } else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str()); } // ----------------------------------------------------- const VersificationMgr::System *v = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem(v11n); if (!v) std::cout << "Warning: Versification " << v11n << " not found. Using KJV versification...\n"; - if (compType == "ZIP") { + if (compType == "LZSS") { + compressor = new LZSSCompress(); + } + else if (compType == "ZIP") { #ifndef EXCLUDEZLIB compressor = new ZipCompress(); #else - usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libzip is available when compiling SWORD library"); + usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library"); #endif } - else if (compType == "LZSS") { - compressor = new LZSSCompress(); + else if (compType == "BZIP2") { +#ifndef EXCLUDEBZIP2 + compressor = new Bzip2Compress(); +#else + usage(*argv, "ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library"); +#endif + } + else if (compType == "XZ") { +#ifndef EXCLUDEXZ + compressor = new XzCompress(); +#else + usage(*argv, "ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library"); +#endif } + // setup module if (!append) { if (compressor) { @@ -190,6 +228,14 @@ int main(int argc, char **argv) { ? (SWModule *)new RawText(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n) : (SWModule *)new RawText4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n); } + + SWFilter *cipherFilter = 0; + + if (cipherKey.length()) { + fprintf(stderr, "Adding cipher filter with phrase: %s\n", cipherKey.c_str() ); + cipherFilter = new CipherFilter(cipherKey.c_str()); + module->addRawFilter(cipherFilter); + } // ----------------------------------------------------- // setup locale manager @@ -211,28 +257,39 @@ int main(int argc, char **argv) { FileDesc *fd = FileMgr::getSystemFileMgr()->open(inFileName, FileMgr::RDONLY); SWBuf lineBuffer; - SWBuf currentKey; - SWBuf currentEntry; + SWBuf keyBuffer; + SWBuf entBuffer; - while (FileMgr::getLine(fd, lineBuffer)) { + bool more = true; + do { + more = FileMgr::getLine(fd, lineBuffer)!=0; if (lineBuffer.startsWith("$$$")) { - writeEntry(currentKey, currentEntry, module); - currentKey = lineBuffer; - currentKey << 3; - currentKey.trim(); - currentEntry = ""; + if ((keyBuffer.size()) && (entBuffer.size())) { + writeEntry(module, keyBuffer, entBuffer); + } + keyBuffer = lineBuffer; + keyBuffer << 3; + keyBuffer.trim(); + entBuffer.size(0); } else { - currentEntry += lineBuffer; + if (keyBuffer.size()) { + entBuffer += lineBuffer; + entBuffer += "\n"; + } } + } while (more); + if ((keyBuffer.size()) && (entBuffer.size())) { + writeEntry(module, keyBuffer, entBuffer); } - writeEntry(currentKey, currentEntry, module); - - FileMgr::getSystemFileMgr()->close(fd); delete module; + if (cipherFilter) + delete cipherFilter; delete vkey; + FileMgr::getSystemFileMgr()->close(fd); + return 0; } @@ -241,7 +298,7 @@ int main(int argc, char **argv) { int page = 0; -void writeEntry(const SWBuf &key, const SWBuf &entry, SWModule *module) +void writeEntry(SWModule *module, const SWBuf &key, const SWBuf &entry) { if (key.size() && entry.size()) { std::cout << "from file: " << key << std::endl; |