[sword-svn] r3223 - in trunk: src/modules/lexdict/rawld src/modules/lexdict/rawld4 src/modules/lexdict/zld tests tests/testsuite utilities

scribe at crosswire.org scribe at crosswire.org
Wed Apr 30 22:56:07 MST 2014


Author: scribe
Date: 2014-04-30 22:56:07 -0700 (Wed, 30 Apr 2014)
New Revision: 3223

Modified:
   trunk/src/modules/lexdict/rawld/rawld.cpp
   trunk/src/modules/lexdict/rawld4/rawld4.cpp
   trunk/src/modules/lexdict/zld/zld.cpp
   trunk/tests/ldtest.cpp
   trunk/tests/testsuite/ldr12n.good
   trunk/tests/testsuite/ldr12n.sh
   trunk/utilities/imp2ld.cpp
Log:
Applied kalemas' changes to fix ld infinite loop bug


Modified: trunk/src/modules/lexdict/rawld/rawld.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld/rawld.cpp	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/src/modules/lexdict/rawld/rawld.cpp	2014-05-01 05:56:07 UTC (rev 3223)
@@ -147,12 +147,26 @@
 
 
 void RawLD::setEntry(const char *inbuf, long len) {
-	doSetText(*key, inbuf, len);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doSetText(buf, inbuf, len);
+
+	delete [] buf;
 }
 
 
 void RawLD::linkEntry(const SWKey *inkey) {
-	doLinkEntry(*key, *inkey);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doLinkEntry(buf, *inkey);
+
+	delete [] buf;
 }
 
 
@@ -163,7 +177,14 @@
  */
 
 void RawLD::deleteEntry() {
-	doSetText(*key, "");
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doSetText(buf, "");
+
+	delete [] buf;
 }
 
 

Modified: trunk/src/modules/lexdict/rawld4/rawld4.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld4/rawld4.cpp	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/src/modules/lexdict/rawld4/rawld4.cpp	2014-05-01 05:56:07 UTC (rev 3223)
@@ -145,12 +145,26 @@
 
 
 void RawLD4::setEntry(const char *inbuf, long len) {
-	doSetText(*key, inbuf, len);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doSetText(buf, inbuf, len);
+
+	delete [] buf;
 }
 
 
 void RawLD4::linkEntry(const SWKey *inkey) {
-	doLinkEntry(*key, *inkey);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doLinkEntry(buf, *inkey);
+
+	delete [] buf;
 }
 
 
@@ -161,7 +175,14 @@
  */
 
 void RawLD4::deleteEntry() {
-	doSetText(*key, "");
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	doSetText(buf, "");
+
+	delete [] buf;
 }
 
 

Modified: trunk/src/modules/lexdict/zld/zld.cpp
===================================================================
--- trunk/src/modules/lexdict/zld/zld.cpp	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/src/modules/lexdict/zld/zld.cpp	2014-05-01 05:56:07 UTC (rev 3223)
@@ -144,12 +144,26 @@
 
 
 void zLD::setEntry(const char *inbuf, long len) {
-	setText(*key, inbuf, len);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	setText(buf, inbuf, len);
+
+	delete [] buf;
 }
 
 
 void zLD::linkEntry(const SWKey *inkey) {
-	zStr::linkEntry(*key, *inkey);
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	zStr::linkEntry(buf, *inkey);
+
+	delete [] buf;
 }
 
 
@@ -160,7 +174,14 @@
  */
 
 void zLD::deleteEntry() {
-	setText(*key, "");
+	char *buf = new char [ strlen(*key) + 6 ];
+	strcpy(buf, *key);
+
+	if (strongsPadding) strongsPad(buf);
+
+	setText(buf, "");
+
+	delete [] buf;
 }
 
 

Modified: trunk/tests/ldtest.cpp
===================================================================
--- trunk/tests/ldtest.cpp	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/tests/ldtest.cpp	2014-05-01 05:56:07 UTC (rev 3223)
@@ -1,14 +1,20 @@
 #include <swmodule.h>
 #include <swmgr.h>
 #include <iostream>
+#include <stdio.h>
 
 using namespace sword;
 using namespace std;
 
 int main(int argc, char **argv) {
 
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s <lexdict_name>\n", *argv);
+		exit(-1);
+	}
+
 	SWMgr library;
-	SWModule *module = library.getModule("ldr12n");
+	SWModule *module = library.getModule(argv[1]);
 	if (!module) {
 		cerr << "\nCouldn't find module: " << argv[1] << "\n" << endl;
 		exit(-2);

Modified: trunk/tests/testsuite/ldr12n.good
===================================================================
--- trunk/tests/testsuite/ldr12n.good	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/tests/testsuite/ldr12n.good	2014-05-01 05:56:07 UTC (rev 3223)
@@ -4,9 +4,21 @@
 4
 0005
 0006
+0001
+0002
+0003
+4
+0005
+0006
 0001: Body of 1
 0002: Body of 2
 0003: Body of 3
 0005: Body of 5
 0006: Body of 6
 4: Body of 4
+00001: Body of 1
+00002: Body of 2
+00003: Body of 3
+00004: Body of 4
+00005: Body of 5
+00006: Body of 6

Modified: trunk/tests/testsuite/ldr12n.sh
===================================================================
--- trunk/tests/testsuite/ldr12n.sh	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/tests/testsuite/ldr12n.sh	2014-05-01 05:56:07 UTC (rev 3223)
@@ -11,8 +11,20 @@
 Encoding=UTF-8
 SourceType=Plain
 Lang=en
+StrongsPadding=false
 !
 
-../../utilities/imp2ld ldr12n.imp -o ldr12n/modules/ldr12n 2>&1 | grep -v \$Rev
+cat > ldr12n/mods.d/ldr12np.conf <<!
+[ldr12np]
+DataPath=./modules/ldr12np
+ModDrv=RawLD
+Encoding=UTF-8
+SourceType=Plain
+Lang=en
+StrongsPadding=true
+!
 
-cd ldr12n && ../../ldtest ldr12n
+../../utilities/imp2ld ldr12n.imp -P -o ldr12n/modules/ldr12n 2>&1 | grep -v \$Rev
+../../utilities/imp2ld ldr12n.imp -o ldr12n/modules/ldr12np 2>&1 | grep -v \$Rev
+
+cd ldr12n && ../../ldtest ldr12n && ../../ldtest ldr12np

Modified: trunk/utilities/imp2ld.cpp
===================================================================
--- trunk/utilities/imp2ld.cpp	2014-05-01 05:39:51 UTC (rev 3222)
+++ trunk/utilities/imp2ld.cpp	2014-05-01 05:56:07 UTC (rev 3223)
@@ -56,10 +56,11 @@
 	fprintf(stderr, "  -a\t\t\t augment module if exists (default is to create new)\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, "  -o <output_path>\t\t where to write data files.\n");
 	fprintf(stderr, "  -4\t\t\t use 4 byte size entries (default: 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, "  -P\t\t\t disable key Strong's number padding (by default keys will be padded).");
 	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"
@@ -87,6 +88,7 @@
 	SWCompress *compressor = 0;
 	SWBuf compType         = "";
 	bool fourByteSize      = false;
+	bool strongsPadding    = true;
 
 	if (argc < 2) usage(*argv);
 
@@ -117,6 +119,9 @@
 		else if (!strcmp(argv[i], "-4")) {
 			fourByteSize = true;
 		}
+		else if (!strcmp(argv[i], "-P")) {
+			strongsPadding = false;
+		}
 		else if (!strcmp(argv[i], "-b")) {
 			if (i+1 < argc) {
 				blockCount = atoi(argv[++i]);
@@ -148,7 +153,6 @@
 		exit(-2);
 	}
 
-
 	SWModule *mod = 0;
 	SWKey *key, *linkKey;
 
@@ -196,12 +200,12 @@
 	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);
+		mod = new zLD(outPath, 0, 0, blockCount, compressor, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive, strongsPadding);
 	}
 	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);
+			? (SWModule *)new RawLD (outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive, strongsPadding)
+			: (SWModule *)new RawLD4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive, strongsPadding);
 	}
 
 
@@ -258,8 +262,8 @@
 	infile.close();
 
 	delete linkKey;
+	delete mod;
 	delete key;
-	delete mod;
 
 	return 0;
 }




More information about the sword-cvs mailing list