[sword-svn] r2172 - trunk/src/modules/common
scribe at www.crosswire.org
scribe at www.crosswire.org
Sun May 18 20:33:53 MST 2008
Author: scribe
Date: 2008-05-18 20:33:52 -0700 (Sun, 18 May 2008)
New Revision: 2172
Modified:
trunk/src/modules/common/rawstr.cpp
trunk/src/modules/common/rawstr4.cpp
trunk/src/modules/common/zstr.cpp
Log:
This is ridiculous! I think this should do it!
Modified: trunk/src/modules/common/rawstr.cpp
===================================================================
--- trunk/src/modules/common/rawstr.cpp 2008-05-19 02:38:50 UTC (rev 2171)
+++ trunk/src/modules/common/rawstr.cpp 2008-05-19 03:33:52 UTC (rev 2172)
@@ -151,7 +151,7 @@
signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *size, long away, long *idxoff)
{
- char *trybuf, *key = 0, quitflag = 0;
+ char *trybuf, *maxbuf, *key = 0, quitflag = 0;
signed char retval = -1;
long headoff, tailoff, tryoff = 0, maxoff = 0;
int diff = 0;
@@ -168,10 +168,11 @@
int keylen = strlen(key);
bool substr = false;
- trybuf = 0;
-
+ trybuf = maxbuf = 0;
+ getIDXBuf(maxoff, &maxbuf);
+
while (headoff < tailoff) {
- tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff;
+ tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff;
lastoff = -1;
getIDXBuf(tryoff, &trybuf);
@@ -180,7 +181,7 @@
retval = -1;
break;
}
-
+
diff = strcmp(key, trybuf);
if (!diff)
@@ -201,13 +202,15 @@
// didn't find exact match
if (headoff >= tailoff) {
tryoff = headoff;
- if (!substr && ((tryoff != maxoff)||((keylen>1)&&!strncmp(key, trybuf, keylen-1)))) {
+ if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
away--; // if our entry doesn't startwith our key, prefer the previous entry over the next
}
}
if (trybuf)
free(trybuf);
delete [] key;
+ if (maxbuf)
+ free(maxbuf);
}
else tryoff = 0;
Modified: trunk/src/modules/common/rawstr4.cpp
===================================================================
--- trunk/src/modules/common/rawstr4.cpp 2008-05-19 02:38:50 UTC (rev 2171)
+++ trunk/src/modules/common/rawstr4.cpp 2008-05-19 03:33:52 UTC (rev 2172)
@@ -159,7 +159,7 @@
signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *size, long away, long *idxoff)
{
- char *trybuf, *key = 0, quitflag = 0;
+ char *trybuf, *maxbuf, *key = 0, quitflag = 0;
signed char retval = -1;
long headoff, tailoff, tryoff = 0, maxoff = 0;
int diff = 0;
@@ -176,10 +176,11 @@
int keylen = strlen(key);
bool substr = false;
- trybuf = 0;
+ trybuf = maxbuf = 0;
+ getIDXBuf(maxoff, &maxbuf);
while (headoff < tailoff) {
- tryoff = (lastoff == -1) ? headoff + ((((tailoff / 8) - (headoff / 8))) / 2) * 8 : lastoff;
+ tryoff = (lastoff == -1) ? headoff + ((((tailoff / 8) - (headoff / 8))) / 2) * 8 : lastoff;
lastoff = -1;
getIDXBuf(tryoff, &trybuf);
@@ -188,7 +189,7 @@
retval = -1;
break;
}
-
+
diff = strcmp(key, trybuf);
if (!diff)
@@ -209,7 +210,7 @@
// didn't find exact match
if (headoff >= tailoff) {
tryoff = headoff;
- if (!substr && ((tryoff != maxoff)||((keylen>1)&&!strncmp(key, trybuf, keylen-1)))) {
+ if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
away--; // if our entry doesn't startwith our key, prefer the previous entry over the next
}
}
Modified: trunk/src/modules/common/zstr.cpp
===================================================================
--- trunk/src/modules/common/zstr.cpp 2008-05-19 02:38:50 UTC (rev 2171)
+++ trunk/src/modules/common/zstr.cpp 2008-05-19 03:33:52 UTC (rev 2172)
@@ -169,7 +169,7 @@
*/
signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) {
- char *trybuf = 0, *key = 0, quitflag = 0;
+ char *maxbuf = 0, *trybuf = 0, *key = 0, quitflag = 0;
signed char retval = 0;
__s32 headoff, tailoff, tryoff = 0, maxoff = 0;
__u32 start, size;
@@ -185,6 +185,8 @@
int keylen = strlen(key);
bool substr = false;
+ getKeyFromIdxOffset(maxoff, &maxbuf);
+
while (headoff < tailoff) {
tryoff = (lastoff == -1) ? headoff + (((((tailoff / IDXENTRYSIZE) - (headoff / IDXENTRYSIZE))) / 2) * IDXENTRYSIZE) : lastoff;
lastoff = -1;
@@ -217,7 +219,7 @@
// didn't find exact match
if (headoff >= tailoff) {
tryoff = headoff;
- if (!substr && ((tryoff != maxoff)||((keylen>1)&&!strncmp(key, trybuf, keylen-1)))) {
+ if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
away--; // if our entry doesn't startwith our key, prefer the previous entry over the next
}
}
More information about the sword-cvs
mailing list