[sword-svn] r2293 - in trunk: include src/modules/comments/zcom src/modules/common src/modules/lexdict/rawld src/modules/lexdict/rawld4 src/modules/lexdict/zld src/modules/texts/ztext

scribe at crosswire.org scribe at crosswire.org
Sun Mar 29 07:09:43 MST 2009


Author: scribe
Date: 2009-03-29 07:09:43 -0700 (Sun, 29 Mar 2009)
New Revision: 2293

Modified:
   trunk/include/rawverse.h
   trunk/include/rawverse4.h
   trunk/include/zverse.h
   trunk/src/modules/comments/zcom/zcom.cpp
   trunk/src/modules/common/rawstr.cpp
   trunk/src/modules/common/rawstr4.cpp
   trunk/src/modules/common/rawverse.cpp
   trunk/src/modules/common/rawverse4.cpp
   trunk/src/modules/common/zverse.cpp
   trunk/src/modules/lexdict/rawld/rawld.cpp
   trunk/src/modules/lexdict/rawld4/rawld4.cpp
   trunk/src/modules/lexdict/zld/zld.cpp
   trunk/src/modules/texts/ztext/ztext.cpp
Log:
Assorted patches from Ben Morgan.


Modified: trunk/include/rawverse.h
===================================================================
--- trunk/include/rawverse.h	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/include/rawverse.h	2009-03-29 14:09:43 UTC (rev 2293)
@@ -32,7 +32,7 @@
 	static const char *nl;
 	RawVerse(const char *ipath, int fileMode = -1);
 	virtual ~RawVerse();
-	void findOffset(char testmt, long idxoff, long *start,	unsigned short *end);
+	void findOffset(char testmt, long idxoff, long *start,	unsigned short *end) const;
 	void readText(char testmt, long start, unsigned short size, SWBuf &buf);
 	static char createModule(const char *path, const char *v11n = "KJV");
 };

Modified: trunk/include/rawverse4.h
===================================================================
--- trunk/include/rawverse4.h	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/include/rawverse4.h	2009-03-29 14:09:43 UTC (rev 2293)
@@ -32,7 +32,7 @@
 	static const char *nl;
 	RawVerse4(const char *ipath, int fileMode = -1);
 	virtual ~RawVerse4();
-	void findOffset(char testmt, long idxoff, long *start,	unsigned long *end);
+	void findOffset(char testmt, long idxoff, long *start,	unsigned long *end) const;
 	void readText(char testmt, long start, unsigned long size, SWBuf &buf);
 	static char createModule(const char *path, const char *v11n = "KJV");
 };

Modified: trunk/include/zverse.h
===================================================================
--- trunk/include/zverse.h	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/include/zverse.h	2009-03-29 14:09:43 UTC (rev 2293)
@@ -49,8 +49,8 @@
 	zVerse(const char *ipath, int fileMode = -1, int blockType = CHAPTERBLOCKS, SWCompress * icomp = 0);
 	virtual ~zVerse();
 
-	void findOffset(char testmt, long idxoff, long *start, unsigned short *end);
-	void zReadText(char testmt, long start, unsigned short size, SWBuf &buf);
+	void findOffset(char testmt, long idxoff, long *start, unsigned short *size, unsigned long *buffnum) const;
+	void zReadText(char testmt, long start, unsigned short size, unsigned long buffnum, SWBuf &buf);
 	virtual void rawZFilter(SWBuf &buf, char direction = 0) {}
 	static char createModule(const char *path, int blockBound, const char *v11n = "KJV");
 };

Modified: trunk/src/modules/comments/zcom/zcom.cpp
===================================================================
--- trunk/src/modules/comments/zcom/zcom.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/comments/zcom/zcom.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -73,13 +73,14 @@
 SWBuf &zCom::getRawEntryBuf() {
 	long  start = 0;
 	unsigned short size = 0;
+	unsigned long buffnum;
 	VerseKey *key = &getVerseKey();
 
-	findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
+	findOffset(key->Testament(), key->TestamentIndex(), &start, &size, &buffnum);
 	entrySize = size;        // support getEntrySize call
 
 	entryBuf = "";
-	zReadText(key->Testament(), start, size, entryBuf);
+	zReadText(key->Testament(), start, size, buffnum, entryBuf);
 
 	rawFilter(entryBuf, key);
 
@@ -169,9 +170,10 @@
 void zCom::increment(int steps) {
 	long  start;
 	unsigned short size;
+	unsigned long buffnum;
 	VerseKey *tmpkey = &getVerseKey();
 
-	findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
+	findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size, &buffnum);
 
 	SWKey lastgood = *tmpkey;
 	while (steps) {
@@ -186,7 +188,7 @@
 			break;
 		}
 		long index = tmpkey->TestamentIndex();
-		findOffset(tmpkey->Testament(), index, &start, &size);
+		findOffset(tmpkey->Testament(), index, &start, &size, &buffnum);
 		if (
 			(((laststart != start) || (lastsize != size))	// we're a different entry
 //				&& (start > 0) 
@@ -202,14 +204,14 @@
 bool zCom::isLinked(const SWKey *k1, const SWKey *k2) const {
 	long start1, start2;
 	unsigned short size1, size2;
+	unsigned long buffnum1, buffnum2;
 	VerseKey *vk1 = &getVerseKey(k1);
 	VerseKey *vk2 = &getVerseKey(k2);
 	if (vk1->Testament() != vk2->Testament()) return false;
 
-	findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1);
-	findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2);
-	if (!size1 || !size2) return false;
-	return start1 == start2;
+	findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1, &buffnum1);
+	findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2, &buffnum2);
+	return start1 == start2 && buffnum1 == buffnum2;
 }
 
 

Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/common/rawstr.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -245,7 +245,7 @@
 		*size  = swordtoarch16(tmpSize);
 
 		while (away) {
-			long laststart = *start;
+			unsigned long laststart = *start;
 			unsigned short lastsize = *size;
 			long lasttry = tryoff;
 			tryoff += (away > 0) ? 6 : -6;
@@ -272,7 +272,7 @@
 			*start = swordtoarch32(tmpStart);
 			*size  = swordtoarch16(tmpSize);
 
-			if (((laststart != *start) || (lastsize != *size)) && (*start >= 0) && (*size)) 
+			if (((laststart != *start) || (lastsize != *size)) && (*size))
 				away += (away < 0) ? 1 : -1;
 		}
 	
@@ -364,7 +364,7 @@
 	__u32 start, outstart;
 	__u32 idxoff;
 	__u32 endoff;
-	__u32 shiftSize;
+	__s32 shiftSize;
 	__u16 size;
 	__u16 outsize;
 	static const char nl[] = {13, 10};

Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/common/rawstr4.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -252,7 +252,7 @@
 		*size  = swordtoarch32(tmpSize);
 
 		while (away) {
-			long laststart = *start;
+			unsigned long laststart = *start;
 			unsigned long lastsize = *size;
 			long lasttry = tryoff;
 			tryoff += (away > 0) ? 8 : -8;
@@ -279,7 +279,7 @@
 			*start = swordtoarch32(tmpStart);
 			*size  = swordtoarch32(tmpSize);
 
-			if (((laststart != *start) || (lastsize != *size)) && (*start >= 0) && (*size)) 
+			if (((laststart != *start) || (lastsize != *size)) && (*size)) 
 				away += (away < 0) ? 1 : -1;
 		}
 	
@@ -370,7 +370,7 @@
 	__u32 start, outstart;
 	__u32 idxoff;
 	__u32 endoff;
-	__u32 shiftSize;
+	__s32 shiftSize;
 	__u32 size;
 	__u32 outsize;
 	static const char nl[] = {13, 10};

Modified: trunk/src/modules/common/rawverse.cpp
===================================================================
--- trunk/src/modules/common/rawverse.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/common/rawverse.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -113,7 +113,7 @@
  *	size	- address to store the size of the entry
  */
 
-void RawVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *size) {
+void RawVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *size) const {
 	idxoff *= 6;
 	if (!testmt)
 		testmt = ((idxfp[1]) ? 1:2);

Modified: trunk/src/modules/common/rawverse4.cpp
===================================================================
--- trunk/src/modules/common/rawverse4.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/common/rawverse4.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -113,7 +113,7 @@
  *	size	- address to store the size of the entry
  */
 
-void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long *size) {
+void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long *size) const {
 	idxoff *= 8;
 	if (!testmt)
 		testmt = ((idxfp[1]) ? 1:2);

Modified: trunk/src/modules/common/zverse.cpp
===================================================================
--- trunk/src/modules/common/zverse.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/common/zverse.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -146,19 +146,15 @@
  *	size	- address to store the size of the entry
  */
 
-void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *size)
+void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *size, unsigned long *buffnum) const
 {
+	__u32 ulBuffNum    = 0;	          // buffer number
+	__u32 ulVerseStart = 0;	       // verse offset within buffer
+	__u16 usVerseSize  = 0;	       // verse size
 	// set start to offset in
 	// set size to
 	// set
-	__u32 ulBuffNum    = 0;	          // buffer number
-	__u32 ulVerseStart = 0;	       // verse offset within buffer
-	__u16 usVerseSize  = 0;	       // verse size
-	__u32 ulCompOffset = 0;	       // compressed buffer start
-	__u32 ulCompSize   = 0;	             // buffer size compressed
-	__u32 ulUnCompSize = 0;	          // buffer size uncompressed
-
-	*start = *size = 0;
+	*start = *size = *buffnum = 0;
 	//printf ("Finding offset %ld\n", idxoff);
 	idxoff *= 10;
 	if (!testmt) {
@@ -176,10 +172,8 @@
 			return;
 		}
 	}
-	else return;
-
-	ulBuffNum = swordtoarch32(ulBuffNum);
-
+	else return;	
+	
 	if (compfp[testmt-1]->read(&ulVerseStart, 4) < 2)
 	{
 		printf ("Error reading ulVerseStart\n");
@@ -191,18 +185,40 @@
 		return;
 	}
 
+	*buffnum = swordtoarch32(ulBuffNum);
 	*start = swordtoarch32(ulVerseStart);
 	*size = swordtoarch16(usVerseSize);
 
-	if (*size) {
-		if (((long) ulBuffNum == cacheBufIdx) && (testmt == cacheTestament) && (cacheBuf)) {
-			// have the text buffered
-			return;
-		}
+}
 
+
+/******************************************************************************
+ * zVerse::zreadtext	- gets text at a given offset
+ *
+ * ENT:	testmt	- testament file to search in (0 - Old; 1 - New)
+ *	start	- starting offset where the text is located in the file
+ *	size	- size of text entry + 1 (null)
+ *	buf	- buffer to store text
+ *
+ */
+
+void zVerse::zReadText(char testmt, long start, unsigned short size, unsigned long ulBuffNum, SWBuf &inBuf) {
+	__u32 ulCompOffset = 0;	       // compressed buffer start
+	__u32 ulCompSize   = 0;	             // buffer size compressed
+	__u32 ulUnCompSize = 0;	          // buffer size uncompressed
+
+	if (!testmt) {
+		testmt = ((idxfp[0]) ? 1:2);
+	}
+	
+	// assert we have and valid file descriptor
+	if (compfp[testmt-1]->getFd() < 1)
+		return;
+	
+	if (size && 
+		!(((long) ulBuffNum == cacheBufIdx) && (testmt == cacheTestament) && (cacheBuf))) {
 		//printf ("Got buffer number{%ld} versestart{%ld} versesize{%d}\n", ulBuffNum, ulVerseStart, usVerseSize);
 
-
 		if (idxfp[testmt-1]->seek(ulBuffNum*12, SEEK_SET)!=(long) ulBuffNum*12)
 		{
 			printf ("Error seeking compressed file index\n");
@@ -258,21 +274,8 @@
 		cacheBufSize = strlen(cacheBuf);  // TODO: can we just use len?
 		cacheTestament = testmt;
 		cacheBufIdx = ulBuffNum;
-	}
-}
-
-
-/******************************************************************************
- * zVerse::zreadtext	- gets text at a given offset
- *
- * ENT:	testmt	- testament file to search in (0 - Old; 1 - New)
- *	start	- starting offset where the text is located in the file
- *	size	- size of text entry + 1 (null)
- *	buf	- buffer to store text
- *
- */
-
-void zVerse::zReadText(char testmt, long start, unsigned short size, SWBuf &inBuf) {
+	}	
+	
 	inBuf = "";
 	if ((size > 0) && cacheBuf && ((unsigned)start < cacheBufSize)) {
 		inBuf.setFillByte(0);

Modified: trunk/src/modules/lexdict/rawld/rawld.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld/rawld.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/lexdict/rawld/rawld.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -216,8 +216,13 @@
 long RawLD::getEntryForKey(const char *key) {
 	__u32 start, offset;
 	__u16 size;
+	
+	char *buf = new char [ strlen(key) + 6 ];
+	strcpy(buf, key);
 
-	findOffset(key, &start, &size, 0, &offset);
+	strongsPad(buf);
+	
+	findOffset(buf, &start, &size, 0, &offset);
 	return offset / IDXENTRYSIZE;
 }
 

Modified: trunk/src/modules/lexdict/rawld4/rawld4.cpp
===================================================================
--- trunk/src/modules/lexdict/rawld4/rawld4.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/lexdict/rawld4/rawld4.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -213,7 +213,12 @@
 	__u32 start, offset;
 	__u32 size;
 
-	findOffset(key, &start, &size, 0, &offset);
+	char *buf = new char [ strlen(key) + 6 ];
+	strcpy(buf, key);
+
+	strongsPad(buf);
+	
+	findOffset(buf, &start, &size, 0, &offset);
 	return offset / IDXENTRYSIZE;
 }
 

Modified: trunk/src/modules/lexdict/zld/zld.cpp
===================================================================
--- trunk/src/modules/lexdict/zld/zld.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/lexdict/zld/zld.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -207,10 +207,15 @@
 }
 
 
-long zLD::getEntryForKey(const char *key) {
+long zLD::getEntryForKey(const char* key) {
 	long offset;
-	findKeyIndex(key, &offset);
-	return offset / IDXENTRYSIZE;
+	char *buf = new char [ strlen(key) + 6 ];
+	strcpy(buf, key);
+
+	strongsPad(buf);
+	
+	findKeyIndex(buf, &offset);
+	return offset/IDXENTRYSIZE;
 }
 
 

Modified: trunk/src/modules/texts/ztext/ztext.cpp
===================================================================
--- trunk/src/modules/texts/ztext/ztext.cpp	2009-03-26 05:14:07 UTC (rev 2292)
+++ trunk/src/modules/texts/ztext/ztext.cpp	2009-03-29 14:09:43 UTC (rev 2293)
@@ -77,14 +77,15 @@
 SWBuf &zText::getRawEntryBuf() {
 	long  start = 0;
 	unsigned short size = 0;
+	unsigned long buffnum = 0;
 	VerseKey &key = getVerseKey();
 
-	findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
+	findOffset(key.Testament(), key.TestamentIndex(), &start, &size, &buffnum);
 	entrySize = size;        // support getEntrySize call
 			  
 	entryBuf = "";
 	
-	zReadText(key.Testament(), start, size, entryBuf);
+	zReadText(key.Testament(), start, size, buffnum, entryBuf);
 	rawFilter(entryBuf, &key);
 
 //	if (!isUnicode())
@@ -172,11 +173,12 @@
  */
 
 void zText::increment(int steps) {
-	long  start;
+	long start;
 	unsigned short size;
+	unsigned long buffnum;
 	VerseKey *tmpkey = &getVerseKey();
 
-	findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
+	findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size, &buffnum);
 
 	SWKey lastgood = *tmpkey;
 	while (steps) {
@@ -191,7 +193,7 @@
 			break;
 		}
 		long index = tmpkey->TestamentIndex();
-		findOffset(tmpkey->Testament(), index, &start, &size);
+		findOffset(tmpkey->Testament(), index, &start, &size, &buffnum);
 
 		if (
 			(((laststart != start) || (lastsize != size))	// we're a different entry
@@ -208,13 +210,14 @@
 bool zText::isLinked(const SWKey *k1, const SWKey *k2) const {
 	long start1, start2;
 	unsigned short size1, size2;
+	unsigned long buffnum1, buffnum2;
 	VerseKey *vk1 = &getVerseKey(k1);
 	VerseKey *vk2 = &getVerseKey(k2);
 	if (vk1->Testament() != vk2->Testament()) return false;
 
-	findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1);
-	findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2);
-	return start1 == start2;
+	findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1, &buffnum1);
+	findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2, &buffnum2);
+	return start1 == start2 && buffnum1 == buffnum2;
 }
 
 SWORD_NAMESPACE_END




More information about the sword-cvs mailing list