summaryrefslogtreecommitdiff
path: root/src/modules/common/zverse.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:54:01 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:54:01 -0400
commit71a39f4652cd51df814c930dd268f3c9ad2aee86 (patch)
tree5994350a603908c4e4d660bc9d72c4ec43dd648e /src/modules/common/zverse.cpp
parent03134fa5f6f25d92724ce4c183f9bbe12a9e37dc (diff)
Imported Upstream version 1.6.0+dfsg
Diffstat (limited to 'src/modules/common/zverse.cpp')
-rw-r--r--src/modules/common/zverse.cpp219
1 files changed, 93 insertions, 126 deletions
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