diff options
Diffstat (limited to 'src/modules/common')
-rw-r--r-- | src/modules/common/entriesblk.cpp | 17 | ||||
-rw-r--r-- | src/modules/common/lzsscomprs.cpp | 16 | ||||
-rw-r--r-- | src/modules/common/rawstr.cpp | 140 | ||||
-rw-r--r-- | src/modules/common/rawstr4.cpp | 140 | ||||
-rw-r--r-- | src/modules/common/rawverse.cpp | 132 | ||||
-rw-r--r-- | src/modules/common/rawverse4.cpp | 129 | ||||
-rw-r--r-- | src/modules/common/swcipher.cpp | 17 | ||||
-rw-r--r-- | src/modules/common/swcomprs.cpp | 17 | ||||
-rw-r--r-- | src/modules/common/zipcomprs.cpp | 17 | ||||
-rw-r--r-- | src/modules/common/zstr.cpp | 124 | ||||
-rw-r--r-- | src/modules/common/zverse.cpp | 219 |
11 files changed, 414 insertions, 554 deletions
diff --git a/src/modules/common/entriesblk.cpp b/src/modules/common/entriesblk.cpp index 216abd8..6e4c9aa 100644 --- a/src/modules/common/entriesblk.cpp +++ b/src/modules/common/entriesblk.cpp @@ -1,3 +1,20 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + #include <entriesblk.h> #include <stdlib.h> #include <string.h> diff --git a/src/modules/common/lzsscomprs.cpp b/src/modules/common/lzsscomprs.cpp index bd8f768..00177db 100644 --- a/src/modules/common/lzsscomprs.cpp +++ b/src/modules/common/lzsscomprs.cpp @@ -1,6 +1,22 @@ /****************************************************************************** * lzsscomprs.cpp - code for class 'LZSSCompress'- a driver class that * provides LZSS compression + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ #include <stdlib.h> diff --git a/src/modules/common/rawstr.cpp b/src/modules/common/rawstr.cpp index d2da1e9..6f17628 100644 --- a/src/modules/common/rawstr.cpp +++ b/src/modules/common/rawstr.cpp @@ -1,11 +1,26 @@ /****************************************************************************** * rawstr.cpp - code for class 'RawStr'- a module that reads raw text - * files: ot and nt using indexs ??.bks ??.cps ??.vss - * and provides lookup and parsing functions based on - * class StrKey + * files: ot and nt using indexs ??.bks ??.cps ??.vss + * and provides lookup and parsing functions based on + * class StrKey + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ - #include <stdio.h> #include <fcntl.h> #include <errno.h> @@ -27,6 +42,8 @@ SWORD_NAMESPACE_START int RawStr::instance = 0; char RawStr::nl = '\n'; +const int RawStr::IDXENTRYSIZE = 6; + /****************************************************************************** @@ -88,7 +105,7 @@ RawStr::~RawStr() * buf - address of pointer to allocate for storage of string */ -void RawStr::getIDXBufDat(long ioffset, char **buf) +void RawStr::getIDXBufDat(long ioffset, char **buf) const { int size; char ch; @@ -122,9 +139,9 @@ void RawStr::getIDXBufDat(long ioffset, char **buf) * buf - address of pointer to allocate for storage of string */ -void RawStr::getIDXBuf(long ioffset, char **buf) +void RawStr::getIDXBuf(long ioffset, char **buf) const { - long offset; + __u32 offset; if (idxfd > 0) { idxfd->seek(ioffset, SEEK_SET); @@ -149,17 +166,18 @@ void RawStr::getIDXBuf(long ioffset, char **buf) * RET: error status -1 general error; -2 new file */ -signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *size, long away, long *idxoff) +signed char RawStr::findOffset(const char *ikey, __u32 *start, __u16 *size, long away, __u32 *idxoff) const { char *trybuf, *maxbuf, *key = 0, quitflag = 0; signed char retval = -1; long headoff, tailoff, tryoff = 0, maxoff = 0; int diff = 0; + bool awayFromSubstrCheck = false; if (idxfd->getFd() >=0) { tailoff = maxoff = idxfd->seek(0, SEEK_END) - 6; retval = (tailoff >= 0) ? 0 : -2; // if NOT new file - if (*ikey) { + if (*ikey && retval != -2) { headoff = 0; stdstr(&key, ikey, 3); @@ -203,6 +221,7 @@ signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *si if (headoff >= tailoff) { tryoff = headoff; if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) { + awayFromSubstrCheck = true; away--; // if our entry doesn't startwith our key, prefer the previous entry over the next } } @@ -216,17 +235,19 @@ signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *si idxfd->seek(tryoff, SEEK_SET); - *start = *size = 0; - idxfd->read(start, 4); - idxfd->read(size, 2); + __u32 tmpStart; + __u16 tmpSize; + *start = *size = tmpStart = tmpSize = 0; + idxfd->read(&tmpStart, 4); + idxfd->read(&tmpSize, 2); if (idxoff) *idxoff = tryoff; - *start = swordtoarch32(*start); - *size = swordtoarch16(*size); + *start = swordtoarch32(tmpStart); + *size = swordtoarch16(tmpSize); while (away) { - long laststart = *start; + unsigned long laststart = *start; unsigned short lastsize = *size; long lasttry = tryoff; tryoff += (away > 0) ? 6 : -6; @@ -237,7 +258,8 @@ signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *si else if (idxfd->seek(tryoff, SEEK_SET) < 0) bad = true; if (bad) { - retval = -1; + if(!awayFromSubstrCheck) + retval = -1; *start = laststart; *size = lastsize; tryoff = lasttry; @@ -245,15 +267,15 @@ signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *si *idxoff = tryoff; break; } - idxfd->read(start, 4); - idxfd->read(size, 2); + idxfd->read(&tmpStart, 4); + idxfd->read(&tmpSize, 2); if (idxoff) *idxoff = tryoff; - *start = swordtoarch32(*start); - *size = swordtoarch16(*size); + *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; } @@ -271,65 +293,6 @@ signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *si /****************************************************************************** - * RawStr::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void RawStr::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - -/****************************************************************************** * RawStr::readtext - gets text at a given offset * * ENT: @@ -339,12 +302,12 @@ void RawStr::prepText(SWBuf &buf) { * */ -void RawStr::readText(long istart, unsigned short *isize, char **idxbuf, SWBuf &buf) +void RawStr::readText(__u32 istart, __u16 *isize, char **idxbuf, SWBuf &buf) { unsigned int ch; char *idxbuflocal = 0; getIDXBufDat(istart, &idxbuflocal); - long start = istart; + __u32 start = istart; do { if (*idxbuf) @@ -401,12 +364,12 @@ void RawStr::readText(long istart, unsigned short *isize, char **idxbuf, SWBuf & void RawStr::doSetText(const char *ikey, const char *buf, long len) { - long start, outstart; - long idxoff; - long endoff; - long shiftSize; - unsigned short size; - unsigned short outsize; + __u32 start, outstart; + __u32 idxoff; + __u32 endoff; + __s32 shiftSize; + __u16 size; + __u16 outsize; static const char nl[] = {13, 10}; char *tmpbuf = 0; char *key = 0; @@ -526,7 +489,6 @@ void RawStr::doLinkEntry(const char *destkey, const char *srckey) { delete [] text; } - /****************************************************************************** * RawLD::CreateModule - Creates new module files * diff --git a/src/modules/common/rawstr4.cpp b/src/modules/common/rawstr4.cpp index cbc8384..003b2fe 100644 --- a/src/modules/common/rawstr4.cpp +++ b/src/modules/common/rawstr4.cpp @@ -1,8 +1,24 @@ /****************************************************************************** * rawstr.cpp - code for class 'RawStr'- a module that reads raw text - * files: ot and nt using indexs ??.bks ??.cps ??.vss - * and provides lookup and parsing functions based on - * class StrKey + * files: ot and nt using indexs ??.bks ??.cps ??.vss + * and provides lookup and parsing functions based on + * class StrKey + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ #include <stdio.h> @@ -26,6 +42,7 @@ SWORD_NAMESPACE_START */ int RawStr4::instance = 0; +const int RawStr4::IDXENTRYSIZE = 8; /****************************************************************************** @@ -88,7 +105,8 @@ RawStr4::~RawStr4() * buf - address of pointer to allocate for storage of string */ -void RawStr4::getIDXBufDat(long ioffset, char **buf) { +void RawStr4::getIDXBufDat(long ioffset, char **buf) const +{ int size; char ch; if (datfd > 0) { @@ -121,14 +139,14 @@ void RawStr4::getIDXBufDat(long ioffset, char **buf) { * buf - address of pointer to allocate for storage of string */ -void RawStr4::getIDXBuf(long ioffset, char **buf) +void RawStr4::getIDXBuf(long ioffset, char **buf) const { - long offset; + __u32 offset; if (idxfd > 0) { idxfd->seek(ioffset, SEEK_SET); - idxfd->read(&offset, 4); + idxfd->read(&offset, 4); offset = swordtoarch32(offset); getIDXBufDat(offset, buf); @@ -157,17 +175,19 @@ void RawStr4::getIDXBuf(long ioffset, char **buf) * RET: error status -1 general error; -2 new file */ -signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *size, long away, long *idxoff) +signed char RawStr4::findOffset(const char *ikey, __u32 *start, __u32 *size, long away, __u32 *idxoff) const { char *trybuf, *maxbuf, *key = 0, quitflag = 0; signed char retval = -1; long headoff, tailoff, tryoff = 0, maxoff = 0; int diff = 0; + bool awayFromSubstrCheck = false; if (idxfd->getFd() >=0) { tailoff = maxoff = idxfd->seek(0, SEEK_END) - 8; + retval = (tailoff >= 0) ? 0 : -2; // if NOT new file - if (*ikey) { + if (*ikey && retval != -2) { headoff = 0; stdstr(&key, ikey, 3); @@ -211,6 +231,7 @@ signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *si if (headoff >= tailoff) { tryoff = headoff; if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) { + awayFromSubstrCheck = true; away--; // if our entry doesn't startwith our key, prefer the previous entry over the next } } @@ -224,17 +245,18 @@ signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *si idxfd->seek(tryoff, SEEK_SET); - *start = *size = 0; - idxfd->read(start, 4); - idxfd->read(size, 4); + __u32 tmpStart, tmpSize; + *start = *size = tmpStart = tmpSize = 0; + idxfd->read(&tmpStart, 4); + idxfd->read(&tmpSize, 4); if (idxoff) *idxoff = tryoff; - *start = swordtoarch32(*start); - *size = swordtoarch32(*size); + *start = swordtoarch32(tmpStart); + *size = swordtoarch32(tmpSize); while (away) { - long laststart = *start; + unsigned long laststart = *start; unsigned long lastsize = *size; long lasttry = tryoff; tryoff += (away > 0) ? 8 : -8; @@ -245,7 +267,8 @@ signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *si else if (idxfd->seek(tryoff, SEEK_SET) < 0) bad = true; if (bad) { - retval = -1; + if(!awayFromSubstrCheck) + retval = -1; *start = laststart; *size = lastsize; tryoff = lasttry; @@ -253,15 +276,15 @@ signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *si *idxoff = tryoff; break; } - idxfd->read(start, 4); - idxfd->read(size, 4); + idxfd->read(&tmpStart, 4); + idxfd->read(&tmpSize, 4); if (idxoff) *idxoff = tryoff; - *start = swordtoarch32(*start); - *size = swordtoarch32(*size); + *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; } @@ -279,65 +302,6 @@ signed char RawStr4::findOffset(const char *ikey, long *start, unsigned long *si /****************************************************************************** - * RawStr4::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void RawStr4::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - -/****************************************************************************** * RawStr4::readtext - gets text at a given offset * * ENT: @@ -347,12 +311,12 @@ void RawStr4::prepText(SWBuf &buf) { * */ -void RawStr4::readText(long istart, unsigned long *isize, char **idxbuf, SWBuf &buf) +void RawStr4::readText(__u32 istart, __u32 *isize, char **idxbuf, SWBuf &buf) { unsigned int ch; char *idxbuflocal = 0; getIDXBufDat(istart, &idxbuflocal); - long start = istart; + __u32 start = istart; do { if (*idxbuf) @@ -408,12 +372,12 @@ void RawStr4::readText(long istart, unsigned long *isize, char **idxbuf, SWBuf & void RawStr4::doSetText(const char *ikey, const char *buf, long len) { - long start, outstart; - long idxoff; - long endoff; - long shiftSize; - unsigned long size; - unsigned long outsize; + __u32 start, outstart; + __u32 idxoff; + __u32 endoff; + __s32 shiftSize; + __u32 size; + __u32 outsize; static const char nl[] = {13, 10}; char *tmpbuf = 0; char *key = 0; diff --git a/src/modules/common/rawverse.cpp b/src/modules/common/rawverse.cpp index 934082c..99beaa2 100644 --- a/src/modules/common/rawverse.cpp +++ b/src/modules/common/rawverse.cpp @@ -3,9 +3,26 @@ * files: ot and nt using indexs ??.bks ??.cps ??.vss * and provides lookup and parsing functions based on * class VerseKey + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <ctype.h> #include <stdio.h> #include <fcntl.h> @@ -96,18 +113,20 @@ RawVerse::~RawVerse() * 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); if (idxfp[testmt-1]->getFd() >= 0) { idxfp[testmt-1]->seek(idxoff, SEEK_SET); - idxfp[testmt-1]->read(start, 4); - long len = idxfp[testmt-1]->read(size, 2); // read size + __s32 tmpStart; + __u16 tmpSize; + idxfp[testmt-1]->read(&tmpStart, 4); + long len = idxfp[testmt-1]->read(&tmpSize, 2); // read size - *start = swordtoarch32(*start); - *size = swordtoarch16(*size); + *start = swordtoarch32(tmpStart); + *size = swordtoarch16(tmpSize); if (len < 2) { *size = (unsigned short)((*start) ? (textfp[testmt-1]->seek(0, SEEK_END) - (long)*start) : 0); // if for some reason we get an error reading size, make size to end of file @@ -121,65 +140,6 @@ void RawVerse::findOffset(char testmt, long idxoff, long *start, unsigned short /****************************************************************************** - * RawVerse::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void RawVerse::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - -/****************************************************************************** * RawVerse::readtext - gets text at a given offset * * ENT: testmt - testament file to search in (0 - Old; 1 - New) @@ -215,17 +175,16 @@ void RawVerse::readText(char testmt, long start, unsigned short size, SWBuf &buf void RawVerse::doSetText(char testmt, long idxoff, const char *buf, long len) { - long start, outstart; - unsigned short size; - unsigned short outsize; + __s32 start; + __u16 size; idxoff *= 6; if (!testmt) testmt = ((idxfp[1]) ? 1:2); - size = outsize = (len < 0) ? strlen(buf) : len; + size = (len < 0) ? strlen(buf) : len; - start = outstart = textfp[testmt-1]->seek(0, SEEK_END); + start = textfp[testmt-1]->seek(0, SEEK_END); idxfp[testmt-1]->seek(idxoff, SEEK_SET); if (size) { @@ -239,13 +198,11 @@ void RawVerse::doSetText(char testmt, long idxoff, const char *buf, long len) start = 0; } - outstart = archtosword32(start); - outsize = archtosword16(size); - - idxfp[testmt-1]->write(&outstart, 4); - idxfp[testmt-1]->write(&outsize, 2); - + start = archtosword32(start); + size = archtosword16(size); + idxfp[testmt-1]->write(&start, 4); + idxfp[testmt-1]->write(&size, 2); } @@ -258,8 +215,8 @@ void RawVerse::doSetText(char testmt, long idxoff, const char *buf, long len) */ void RawVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { - long start; - unsigned short size; + __s32 start; + __u16 size; destidxoff *= 6; srcidxoff *= 6; @@ -280,13 +237,13 @@ void RawVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { /****************************************************************************** - * RawVerse::CreateModule - Creates new module files + * RawVerse::createModule - Creates new module files * * ENT: path - directory to store module files * RET: error status */ -char RawVerse::createModule(const char *ipath) +char RawVerse::createModule(const char *ipath, const char *v11n) { char *path = 0; char *buf = new char [ strlen (ipath) + 20 ]; @@ -320,11 +277,16 @@ char RawVerse::createModule(const char *ipath) fd2->getFd(); VerseKey vk; + vk.setVersificationSystem(v11n); vk.Headings(1); - long offset = 0; - short size = 0; + + __s32 offset = 0; + __u16 size = 0; + offset = archtosword32(offset); + size = archtosword16(size); + for (vk = TOP; !vk.Error(); vk++) { - if (vk.Testament() == 1) { + if (vk.Testament() < 2) { fd->write(&offset, 4); fd->write(&size, 2); } @@ -333,16 +295,14 @@ char RawVerse::createModule(const char *ipath) fd2->write(&size, 2); } } + fd2->write(&offset, 4); + fd2->write(&size, 2); FileMgr::getSystemFileMgr()->close(fd); FileMgr::getSystemFileMgr()->close(fd2); delete [] path; delete [] buf; -/* - RawVerse rv(path); - VerseKey mykey("Rev 22:21"); -*/ return 0; } diff --git a/src/modules/common/rawverse4.cpp b/src/modules/common/rawverse4.cpp index bd438ec..ee0b207 100644 --- a/src/modules/common/rawverse4.cpp +++ b/src/modules/common/rawverse4.cpp @@ -3,9 +3,26 @@ * files: ot and nt using indexs ??.bks ??.cps ??.vss * and provides lookup and parsing functions based on * class VerseKey + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <ctype.h> #include <stdio.h> #include <fcntl.h> @@ -96,18 +113,20 @@ RawVerse4::~RawVerse4() * 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); if (idxfp[testmt-1]->getFd() >= 0) { idxfp[testmt-1]->seek(idxoff, SEEK_SET); - idxfp[testmt-1]->read(start, 4); - long len = idxfp[testmt-1]->read(size, 4); // read size + __u32 tmpStart; + __u32 tmpSize; + idxfp[testmt-1]->read(&tmpStart, 4); + long len = idxfp[testmt-1]->read(&tmpSize, 4); // read size - *start = swordtoarch32(*start); - *size = swordtoarch32(*size); + *start = swordtoarch32(tmpStart); + *size = swordtoarch32(tmpSize); if (len < 2) { *size = (unsigned long)((*start) ? (textfp[testmt-1]->seek(0, SEEK_END) - (long)*start) : 0); // if for some reason we get an error reading size, make size to end of file @@ -121,65 +140,6 @@ void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long /****************************************************************************** - * RawVerse4::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void RawVerse4::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - -/****************************************************************************** * RawVerse4::readtext - gets text at a given offset * * ENT: testmt - testament file to search in (0 - Old; 1 - New) @@ -215,17 +175,16 @@ void RawVerse4::readText(char testmt, long start, unsigned long size, SWBuf &buf void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len) { - long start, outstart; - unsigned long size; - unsigned long outsize; + __u32 start; + __u32 size; idxoff *= 8; if (!testmt) testmt = ((idxfp[1]) ? 1:2); - size = outsize = (len < 0) ? strlen(buf) : len; + size = (len < 0) ? strlen(buf) : len; - start = outstart = textfp[testmt-1]->seek(0, SEEK_END); + start = textfp[testmt-1]->seek(0, SEEK_END); idxfp[testmt-1]->seek(idxoff, SEEK_SET); if (size) { @@ -239,13 +198,11 @@ void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len) start = 0; } - outstart = archtosword32(start); - outsize = archtosword32(size); - - idxfp[testmt-1]->write(&outstart, 4); - idxfp[testmt-1]->write(&outsize, 4); - + start = archtosword32(start); + size = archtosword32(size); + idxfp[testmt-1]->write(&start, 4); + idxfp[testmt-1]->write(&size, 4); } @@ -258,8 +215,8 @@ void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len) */ void RawVerse4::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { - long start; - unsigned long size; + __u32 start; + __u32 size; destidxoff *= 8; srcidxoff *= 8; @@ -286,7 +243,7 @@ void RawVerse4::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { * RET: error status */ -char RawVerse4::createModule(const char *ipath) +char RawVerse4::createModule(const char *ipath, const char *v11n) { char *path = 0; char *buf = new char [ strlen (ipath) + 20 ]; @@ -320,11 +277,15 @@ char RawVerse4::createModule(const char *ipath) fd2->getFd(); VerseKey vk; + vk.setVersificationSystem(v11n); vk.Headings(1); - long offset = 0; - long size = 0; + __u32 offset = 0; + __u32 size = 0; + offset = archtosword32(offset); + size = archtosword32(size); + for (vk = TOP; !vk.Error(); vk++) { - if (vk.Testament() == 1) { + if (vk.Testament() < 2) { fd->write(&offset, 4); fd->write(&size, 4); } @@ -333,16 +294,14 @@ char RawVerse4::createModule(const char *ipath) fd2->write(&size, 4); } } + fd2->write(&offset, 4); + fd2->write(&size, 4); FileMgr::getSystemFileMgr()->close(fd); FileMgr::getSystemFileMgr()->close(fd2); delete [] path; delete [] buf; -/* - RawVerse4 rv(path); - VerseKey mykey("Rev 22:21"); -*/ return 0; } diff --git a/src/modules/common/swcipher.cpp b/src/modules/common/swcipher.cpp index bd4d551..5ab91ea 100644 --- a/src/modules/common/swcipher.cpp +++ b/src/modules/common/swcipher.cpp @@ -1,8 +1,25 @@ /****************************************************************************** * swcipher.cpp - code for class 'SWCipher'- a driver class that provides * cipher utilities. + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <stdlib.h> #include <string.h> #include <swcipher.h> diff --git a/src/modules/common/swcomprs.cpp b/src/modules/common/swcomprs.cpp index 02d7d7b..378c8b1 100644 --- a/src/modules/common/swcomprs.cpp +++ b/src/modules/common/swcomprs.cpp @@ -1,8 +1,25 @@ /****************************************************************************** * swcomprs.cpp - code for class 'SWCompress'- a driver class that provides * compression utilities. + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <stdlib.h> #include <string.h> #include <swcomprs.h> diff --git a/src/modules/common/zipcomprs.cpp b/src/modules/common/zipcomprs.cpp index 21726bf..534d840 100644 --- a/src/modules/common/zipcomprs.cpp +++ b/src/modules/common/zipcomprs.cpp @@ -1,8 +1,25 @@ /****************************************************************************** * swcomprs.cpp - code for class 'ZipCompress'- a driver class that provides * compression utilities. - using zlib + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <stdlib.h> #include <string.h> #include <stdio.h> diff --git a/src/modules/common/zstr.cpp b/src/modules/common/zstr.cpp index 2539ff0..5b4da64 100644 --- a/src/modules/common/zstr.cpp +++ b/src/modules/common/zstr.cpp @@ -2,8 +2,25 @@ * zstr.cpp - code for class 'zStr'- a module that reads compressed text * files and provides lookup and parsing functions based on * class StrKey + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <stdio.h> #include <fcntl.h> #include <errno.h> @@ -111,7 +128,8 @@ zStr::~zStr() { * buf - address of pointer to allocate for storage of string */ -void zStr::getKeyFromDatOffset(long ioffset, char **buf) { +void zStr::getKeyFromDatOffset(long ioffset, char **buf) const +{ int size; char ch; if (datfd > 0) { @@ -144,12 +162,13 @@ void zStr::getKeyFromDatOffset(long ioffset, char **buf) { * buf - address of pointer to allocate for storage of string */ -void zStr::getKeyFromIdxOffset(long ioffset, char **buf) { +void zStr::getKeyFromIdxOffset(long ioffset, char **buf) const +{ __u32 offset; if (idxfd > 0) { idxfd->seek(ioffset, SEEK_SET); - idxfd->read(&offset, sizeof(__u32)); + idxfd->read(&offset, 4); offset = swordtoarch32(offset); getKeyFromDatOffset(offset, buf); } @@ -168,12 +187,14 @@ void zStr::getKeyFromIdxOffset(long ioffset, char **buf) { * RET: error status */ -signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { +signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) const +{ char *maxbuf = 0, *trybuf = 0, *key = 0, quitflag = 0; signed char retval = 0; __s32 headoff, tailoff, tryoff = 0, maxoff = 0; __u32 start, size; int diff = 0; + bool awayFromSubstrCheck = false; if (idxfd->getFd() >= 0) { tailoff = maxoff = idxfd->seek(0, SEEK_END) - IDXENTRYSIZE; @@ -220,6 +241,7 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { if (headoff >= tailoff) { tryoff = headoff; if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) { + awayFromSubstrCheck = true; away--; // if our entry doesn't startwith our key, prefer the previous entry over the next } } @@ -234,8 +256,8 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { idxfd->seek(tryoff, SEEK_SET); start = size = 0; - retval = (idxfd->read(&start, sizeof(__u32))==sizeof(__u32)) ? retval : -1; - retval = (idxfd->read(&size, sizeof(__u32))==sizeof(__u32)) ? retval : -1; + retval = (idxfd->read(&start, 4) == 4) ? retval : -1; + retval = (idxfd->read(&size, 4) == 4) ? retval : -1; start = swordtoarch32(start); size = swordtoarch32(size); @@ -254,7 +276,8 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { else if (idxfd->seek(tryoff, SEEK_SET) < 0) bad = true; if (bad) { - retval = -1; + if(!awayFromSubstrCheck) + retval = -1; start = laststart; size = lastsize; tryoff = lasttry; @@ -262,8 +285,8 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { *idxoff = tryoff; break; } - idxfd->read(&start, sizeof(__u32)); - idxfd->read(&size, sizeof(__u32)); + idxfd->read(&start, 4); + idxfd->read(&size, 4); start = swordtoarch32(start); size = swordtoarch32(size); @@ -287,65 +310,6 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) { /****************************************************************************** - * zStr::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void zStr::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - -/****************************************************************************** * zStr::getText - gets text at a given offset * * ENT: @@ -366,8 +330,8 @@ void zStr::getText(long offset, char **idxbuf, char **buf) { do { idxfd->seek(offset, SEEK_SET); - idxfd->read(&start, sizeof(__u32)); - idxfd->read(&size, sizeof(__u32)); + idxfd->read(&start, 4); + idxfd->read(&size, 4); start = swordtoarch32(start); size = swordtoarch32(size); @@ -430,8 +394,8 @@ void zStr::getCompressedText(long block, long entry, char **buf) { __u32 start = 0; zdxfd->seek(block * ZDXENTRYSIZE, SEEK_SET); - zdxfd->read(&start, sizeof(__u32)); - zdxfd->read(&size, sizeof(__u32)); + zdxfd->read(&start, 4); + zdxfd->read(&size, 4); start = swordtoarch32(start); size = swordtoarch32(size); @@ -496,8 +460,8 @@ void zStr::setText(const char *ikey, const char *buf, long len) { else if ((!diff) && (len > 0 /*we're not deleting*/)) { // got absolute entry do { idxfd->seek(idxoff, SEEK_SET); - idxfd->read(&start, sizeof(__u32)); - idxfd->read(&size, sizeof(__u32)); + idxfd->read(&start, 4); + idxfd->read(&size, 4); start = swordtoarch32(start); size = swordtoarch32(size); @@ -581,8 +545,8 @@ void zStr::setText(const char *ikey, const char *buf, long len) { // add a new line to make data file easier to read in an editor datfd->write(&nl, 2); - idxfd->write(&outstart, sizeof(__u32)); - idxfd->write(&outsize, sizeof(__u32)); + idxfd->write(&outstart, 4); + idxfd->write(&outsize, 4); if (idxBytes) { idxfd->write(idxBytes, shiftSize); } @@ -644,8 +608,8 @@ void zStr::flushCache() { } else { zdxfd->seek(cacheBlockIndex * ZDXENTRYSIZE, SEEK_SET); - zdxfd->read(&start, sizeof(__u32)); - zdxfd->read(&outsize, sizeof(__u32)); + zdxfd->read(&start, 4); + zdxfd->read(&outsize, 4); start = swordtoarch32(start); outsize = swordtoarch32(outsize); if (start + outsize >= zdtSize) { // last entry, just overwrite @@ -671,8 +635,8 @@ void zStr::flushCache() { // add a new line to make data file easier to read in an editor zdtfd->write(&nl, 2); - zdxfd->write(&outstart, sizeof(__u32)); - zdxfd->write(&outsize, sizeof(__u32)); + zdxfd->write(&outstart, 4); + zdxfd->write(&outsize, 4); } delete cacheBlock; cacheBlock = 0; diff --git a/src/modules/common/zverse.cpp b/src/modules/common/zverse.cpp index 3f91918..fa76467 100644 --- a/src/modules/common/zverse.cpp +++ b/src/modules/common/zverse.cpp @@ -1,11 +1,28 @@ /****************************************************************************** * zverse.h - code for class 'zVerse'- a module that reads raw text - * files: ot and nt using indexs ??.bks ??.cps ??.vss - * and provides lookup and parsing functions based on - * class VerseKey for compressed modules + * files: ot and nt using indexs ??.bks ??.cps ??.vss + * and provides lookup and parsing functions based on + * class VerseKey for compressed modules + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ + #include <ctype.h> #include <stdio.h> #include <fcntl.h> @@ -129,19 +146,15 @@ zVerse::~zVerse() * 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 - unsigned long ulBuffNum=0; // buffer number - unsigned long ulVerseStart=0; // verse offset within buffer - unsigned short usVerseSize=0; // verse size - unsigned long ulCompOffset=0; // compressed buffer start - unsigned long ulCompSize=0; // buffer size compressed - unsigned long ulUnCompSize=0; // buffer size uncompressed - - *start = *size = 0; + *start = *size = *buffnum = 0; //printf ("Finding offset %ld\n", idxoff); idxoff *= 10; if (!testmt) { @@ -159,10 +172,8 @@ void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *s return; } } - else return; - - ulBuffNum = swordtoarch32(ulBuffNum); - + else return; + if (compfp[testmt-1]->read(&ulVerseStart, 4) < 2) { printf ("Error reading ulVerseStart\n"); @@ -174,17 +185,39 @@ void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *s return; } + *buffnum = swordtoarch32(ulBuffNum); *start = swordtoarch32(ulVerseStart); *size = swordtoarch16(usVerseSize); - if (*size) { - if (((long) ulBuffNum == cacheBufIdx) && (testmt == cacheTestament) && (cacheBuf)) { - // have the text buffered - return; - } +} - //printf ("Got buffer number{%ld} versestart{%ld} versesize{%d}\n", ulBuffNum, ulVerseStart, usVerseSize); +/****************************************************************************** + * 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) { @@ -226,7 +259,8 @@ void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *s pcCompText.setSize(ulCompSize); rawZFilter(pcCompText, 0); // 0 = decipher - compressor->zBuf(&ulCompSize, pcCompText.getRawData()); + unsigned long bufSize = ulCompSize; + compressor->zBuf(&bufSize, pcCompText.getRawData()); if (cacheBuf) { flushCache(); @@ -237,26 +271,13 @@ void zVerse::findOffset(char testmt, long idxoff, long *start, unsigned short *s compressor->Buf(0, &len); cacheBuf = (char *)calloc(len + 1, 1); memcpy(cacheBuf, compressor->Buf(), len); - + 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 < strlen(cacheBuf)) ){ //TODO: optimize this, remove strlen + if ((size > 0) && cacheBuf && ((unsigned)start < cacheBufSize)) { inBuf.setFillByte(0); inBuf.setSize(size+1); strncpy(inBuf.getRawData(), &(cacheBuf[start]), size); @@ -290,13 +311,12 @@ void zVerse::doSetText(char testmt, long idxoff, const char *buf, long len) { dirtyCache = true; - unsigned long start, outstart; - unsigned long outBufIdx = cacheBufIdx; - unsigned short size; - unsigned short outsize; + __u32 start; + __u16 size; + __u32 outBufIdx = cacheBufIdx; idxoff *= 10; - size = outsize = len; + size = len; start = strlen(cacheBuf); @@ -304,23 +324,23 @@ void zVerse::doSetText(char testmt, long idxoff, const char *buf, long len) { start = outBufIdx = 0; outBufIdx = archtosword32(outBufIdx); - outstart = archtosword32(start); - outsize = archtosword16(size); + start = archtosword32(start); + size = archtosword16(size); compfp[testmt-1]->seek(idxoff, SEEK_SET); compfp[testmt-1]->write(&outBufIdx, 4); - compfp[testmt-1]->write(&outstart, 4); - compfp[testmt-1]->write(&outsize, 2); + compfp[testmt-1]->write(&start, 4); + compfp[testmt-1]->write(&size, 2); strcat(cacheBuf, buf); } void zVerse::flushCache() { if (dirtyCache) { - unsigned long idxoff; - unsigned long start, outstart; - unsigned long size, outsize; - unsigned long zsize, outzsize; + __u32 idxoff; + __u32 start, outstart; + __u32 size, outsize; + __u32 zsize, outzsize; idxoff = cacheBufIdx * 12; if (cacheBuf) { @@ -331,12 +351,14 @@ void zVerse::flushCache() { // compressor = new LZSSCompress(); // } compressor->Buf(cacheBuf); - compressor->zBuf(&zsize); - outzsize = zsize; + unsigned long tmpSize; + compressor->zBuf(&tmpSize); + outzsize = zsize = tmpSize; SWBuf buf; buf.setSize(zsize + 5); - memcpy(buf.getRawData(), compressor->zBuf(&zsize), zsize); + memcpy(buf.getRawData(), compressor->zBuf(&tmpSize), tmpSize); + outzsize = zsize = tmpSize; buf.setSize(zsize); rawZFilter(buf, 1); // 1 = encipher @@ -369,9 +391,9 @@ void zVerse::flushCache() { */ void zVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { - long bufidx; - long start; - unsigned short size; + __s32 bufidx; + __s32 start; + __u16 size; destidxoff *= 10; srcidxoff *= 10; @@ -400,7 +422,7 @@ void zVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) { * RET: error status */ -char zVerse::createModule(const char *ipath, int blockBound) +char zVerse::createModule(const char *ipath, int blockBound, const char *v11n) { char *path = 0; char *buf = new char [ strlen (ipath) + 20 ]; @@ -446,11 +468,16 @@ char zVerse::createModule(const char *ipath, int blockBound) fd2->getFd(); VerseKey vk; + vk.setVersificationSystem(v11n); vk.Headings(1); - long offset = 0; - short size = 0; + + __s32 offset = 0; + __s16 size = 0; + offset = archtosword32(offset); + size = archtosword16(size); + for (vk = TOP; !vk.Error(); vk++) { - if (vk.Testament() == 1) { + if (vk.Testament() < 2) { fd->write(&offset, 4); //compBufIdxOffset fd->write(&offset, 4); fd->write(&size, 2); @@ -461,78 +488,18 @@ char zVerse::createModule(const char *ipath, int blockBound) fd2->write(&size, 2); } } + fd2->write(&offset, 4); //compBufIdxOffset + fd2->write(&offset, 4); + fd2->write(&size, 2); FileMgr::getSystemFileMgr()->close(fd); FileMgr::getSystemFileMgr()->close(fd2); delete [] path; delete [] buf; -/* - RawVerse rv(path); - VerseKey mykey("Rev 22:21"); -*/ return 0; } -/****************************************************************************** - * zVerse::preptext - Prepares the text before returning it to external - * objects - * - * ENT: buf - buffer where text is stored and where to store the prep'd - * text. - */ - -void zVerse::prepText(SWBuf &buf) { - unsigned int to, from; - char space = 0, cr = 0, realdata = 0, nlcnt = 0; - char *rawBuf = buf.getRawData(); - for (to = from = 0; rawBuf[from]; from++) { - switch (rawBuf[from]) { - case 10: - if (!realdata) - continue; - space = (cr) ? 0 : 1; - cr = 0; - nlcnt++; - if (nlcnt > 1) { -// *to++ = nl; - rawBuf[to++] = 10; -// *to++ = nl[1]; -// nlcnt = 0; - } - continue; - case 13: - if (!realdata) - continue; -// *to++ = nl[0]; - rawBuf[to++] = 10; - space = 0; - cr = 1; - continue; - } - realdata = 1; - nlcnt = 0; - if (space) { - space = 0; - if (rawBuf[from] != ' ') { - rawBuf[to++] = ' '; - from--; - continue; - } - } - rawBuf[to++] = rawBuf[from]; - } - buf.setSize(to); - - while (to > 1) { // remove trailing excess - to--; - if ((rawBuf[to] == 10) || (rawBuf[to] == ' ')) - buf.setSize(to); - else break; - } -} - - SWORD_NAMESPACE_END |