[sword-svn] r2160 - trunk/src/modules/common

scribe at www.crosswire.org scribe at www.crosswire.org
Wed May 14 12:53:15 MST 2008


Author: scribe
Date: 2008-05-14 12:53:14 -0700 (Wed, 14 May 2008)
New Revision: 2160

Modified:
   trunk/src/modules/common/rawstr.cpp
   trunk/src/modules/common/rawstr4.cpp
   trunk/src/modules/common/zstr.cpp
Log:
Changed lex drivers to prefer previous entry over next entry


Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp	2008-05-14 05:59:50 UTC (rev 2159)
+++ trunk/src/modules/common/rawstr.cpp	2008-05-14 19:53:14 UTC (rev 2160)
@@ -154,6 +154,7 @@
 	char *trybuf, *key = 0, quitflag = 0;
 	signed char retval = -1;
 	long headoff, tailoff, tryoff = 0, maxoff = 0;
+	int diff = 0;
 
 	if (idxfd->getFd() >=0) {
 		tailoff = maxoff = idxfd->seek(0, SEEK_END) - 6;
@@ -177,20 +178,26 @@
 					break;
 				}
 					
-				if (!strcmp(key, trybuf))
+				diff = strcmp(key, trybuf);
+
+				if (!diff)
 					break;
 
-				int diff = strcmp(key, trybuf);
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
+
 				if (tailoff == headoff + 6) {
 					if (quitflag++)
 						headoff = tailoff;
 				}
 			}
-			if (headoff >= tailoff)
+
+			// didn't find exact match
+			if (headoff >= tailoff) {
 				tryoff = headoff;
+				away--;	// prefer the previous entry over the next
+			}
 			if (trybuf)
 				free(trybuf);
 			delete [] key;

Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp	2008-05-14 05:59:50 UTC (rev 2159)
+++ trunk/src/modules/common/rawstr4.cpp	2008-05-14 19:53:14 UTC (rev 2160)
@@ -162,6 +162,7 @@
 	char *trybuf, *key = 0, quitflag = 0;
 	signed char retval = -1;
 	long headoff, tailoff, tryoff = 0, maxoff = 0;
+	int diff = 0;
 
 	if (idxfd->getFd() >=0) {
 		tailoff = maxoff = idxfd->seek(0, SEEK_END) - 8;
@@ -185,20 +186,26 @@
 					break;
 				}
 					
-				if (!strcmp(key, trybuf))
+				diff = strcmp(key, trybuf);
+
+				if (!diff)
 					break;
 
-				int diff = strcmp(key, trybuf);
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
+
 				if (tailoff == headoff + 8) {
 					if (quitflag++)
 						headoff = tailoff;
 				}
 			}
-			if (headoff >= tailoff)
+
+			// didn't find exact match
+			if (headoff >= tailoff) {
 				tryoff = headoff;
+				away--;	// prefer the previous entry over the next
+			}
 			if (trybuf)
 				free(trybuf);
 			delete [] key;

Modified: trunk/src/modules/common/zstr.cpp
===================================================================
--- trunk/src/modules/common/zstr.cpp	2008-05-14 05:59:50 UTC (rev 2159)
+++ trunk/src/modules/common/zstr.cpp	2008-05-14 19:53:14 UTC (rev 2160)
@@ -173,6 +173,7 @@
 	signed char retval = 0;
 	__s32 headoff, tailoff, tryoff = 0, maxoff = 0;
 	__u32 start, size;
+	int diff = 0;
 
 	if (idxfd->getFd() >= 0) {
 		tailoff = maxoff = idxfd->seek(0, SEEK_END) - IDXENTRYSIZE;
@@ -193,20 +194,26 @@
 					break;
 				}
 
-				int diff = strcmp(key, trybuf);
+				diff = strcmp(key, trybuf);
+
 				if (!diff)
 					break;
 
 				if (diff < 0)
 					tailoff = (tryoff == headoff) ? headoff : tryoff;
 				else headoff = tryoff;
+
 				if (tailoff == headoff + IDXENTRYSIZE) {
 					if (quitflag++)
 						headoff = tailoff;
 				}
 			}
-			if (headoff >= tailoff)
+
+			// didn't find exact match
+			if (headoff >= tailoff) {
 				tryoff = headoff;
+				away--;	// prefer the previous entry over the next
+			}
 			if (trybuf)
 				free(trybuf);
 			delete [] key;




More information about the sword-cvs mailing list