[sword-svn] r2477 - trunk/utilities

scribe at crosswire.org scribe at crosswire.org
Thu Nov 19 22:25:56 MST 2009


Author: scribe
Date: 2009-11-19 22:25:56 -0700 (Thu, 19 Nov 2009)
New Revision: 2477

Modified:
   trunk/utilities/imp2vs.cpp
Log:
added compression support to imp2vs


Modified: trunk/utilities/imp2vs.cpp
===================================================================
--- trunk/utilities/imp2vs.cpp	2009-11-18 07:43:01 UTC (rev 2476)
+++ trunk/utilities/imp2vs.cpp	2009-11-20 05:25:56 UTC (rev 2477)
@@ -15,13 +15,17 @@
  *
  */
 
+#include <stdio.h>
 #include <iostream>
+
+#include <swbuf.h>
+#include <filemgr.h>
+#include <versekey.h>
 #include <rawtext.h>
 #include <rawtext4.h>
-#include <versekey.h>
-#include <swbuf.h>
-#include <filemgr.h>
-#include <stdio.h>
+#include <ztext.h>
+#include <lzsscomprs.h>
+#include <zipcomprs.h>
 
 #ifndef NO_SWORD_NAMESPACE
 using namespace sword;
@@ -36,8 +40,12 @@
 	fprintf(stderr, "\n=== imp2vs (Revision $Rev: 2234 $) 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, "  -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");
+	fprintf(stderr, "\t\t\t\t 2 - verse; 3 - chapter; 4 - book\n");
 	fprintf(stderr, "  -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n");
 	fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:\n");
 	VerseMgr *vmgr = VerseMgr::getSystemVerseMgr();
@@ -74,14 +82,34 @@
 	SWBuf outPath          = "./";
 	bool fourByteSize      = false;
 	bool append            = false;
+	int iType              = 4;
+	SWCompress *compressor = 0;
+	SWBuf compType         = "";
 
 	for (int i = 2; i < argc; i++) {
 		if (!strcmp(argv[i], "-a")) {
 			append = true;
 		}
-		if (!strcmp(argv[i], "-4")) {
+		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) {
+				iType = atoi(argv[++i]);
+				if ((iType >= 2) && (iType <= 4)) continue;
+			}
+			usage(*argv, "-b requires one of <2|3|4>");
+		}
 		else if (!strcmp(argv[i], "-o")) {
 			if (i+1 < argc) outPath = argv[++i];
 			else usage(progName, "-o requires <output_path>");
@@ -96,17 +124,49 @@
 	const VerseMgr::System *v = VerseMgr::getSystemVerseMgr()->getVersificationSystem(v11n);
 	if (!v) std::cout << "Warning: Versification " << v11n << " not found. Using KJV versification...\n";
 
+	if (compType == "ZIP") {
+		compressor = new ZipCompress();
+	}
+	else if (compType == "LZSS") {
+		compressor = new LZSSCompress();
+	}
 
 	// setup module
 	if (!append) {
+		if (compressor) {
+			if (zText::createModule(outPath, iType, v11n)) {
+				fprintf(stderr, "ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
+				exit(-1);
+			}
+		}
 		if (!fourByteSize)
 			RawText::createModule(outPath, v11n);
 		else	RawText4::createModule(outPath, v11n);
 	}
 
-	SWModule *module = (!fourByteSize)
+	SWModule *module = 0;
+	if (compressor) {
+		// Create a compressed text module allowing very large entries
+		// Taking defaults except for first, fourth, fifth and last argument
+		module = new zText(
+				outPath,		// ipath
+				0,		// iname
+				0,		// idesc
+				iType,		// iblockType
+				compressor,	// icomp
+				0,		// idisp
+				ENC_UNKNOWN,	// enc
+				DIRECTION_LTR,	// dir
+				FMT_UNKNOWN,	// markup
+				0,		// lang
+				v11n		// versification
+		       );
+	}
+	else {
+		module = (!fourByteSize)
 			? (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);
+	}
 	// -----------------------------------------------------
 			
 




More information about the sword-cvs mailing list