summaryrefslogtreecommitdiff
path: root/src/modules/common/zverse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/common/zverse.cpp')
-rw-r--r--src/modules/common/zverse.cpp145
1 files changed, 85 insertions, 60 deletions
diff --git a/src/modules/common/zverse.cpp b/src/modules/common/zverse.cpp
index 8d30797..1f7f25d 100644
--- a/src/modules/common/zverse.cpp
+++ b/src/modules/common/zverse.cpp
@@ -18,17 +18,18 @@
#include <unistd.h>
#endif
-#include <string.h>
#include <utilfuns.h>
#include <versekey.h>
#include <zverse.h>
#include <sysdata.h>
+#include <swbuf.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
+SWORD_NAMESPACE_START
/******************************************************************************
* zVerse Statics
@@ -133,7 +134,7 @@ 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)
{
// set start to offset in
// set size to
@@ -221,14 +222,17 @@ void zVerse::findoffset(char testmt, long idxoff, long *start, unsigned short *s
printf ("Error: could not seek to right place in compressed text\n");
return;
}
- pcCompText = new char[ulCompSize];
+ SWBuf pcCompText;
+ pcCompText.setSize(ulCompSize+5);
- if (read(textfp[testmt-1]->getFd(), pcCompText, ulCompSize)<(long)ulCompSize)
- {
+ if (read(textfp[testmt-1]->getFd(), pcCompText.getRawData(), ulCompSize)<(long)ulCompSize) {
printf ("Error reading compressed text\n");
return;
}
- compressor->zBuf(&ulCompSize, pcCompText);
+ pcCompText.setSize(ulCompSize);
+ rawZFilter(pcCompText, 0); // 0 = decipher
+
+ compressor->zBuf(&ulCompSize, pcCompText.getRawData());
if (cacheBuf) {
flushCache();
@@ -247,7 +251,7 @@ void zVerse::findoffset(char testmt, long idxoff, long *start, unsigned short *s
/******************************************************************************
- * zVerse::swgettext - gets text at a given offset
+ * 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
@@ -256,12 +260,15 @@ void zVerse::findoffset(char testmt, long idxoff, long *start, unsigned short *s
*
*/
-void zVerse::swgettext(char testmt, long start, unsigned short size, char *inbuf)
-{
- memset(inbuf, 0, size);
- if (size > 2) {
- strncpy(inbuf, &(cacheBuf[start]), size-2);
+void zVerse::zReadText(char testmt, long start, unsigned short size, SWBuf &inBuf) {
+ inBuf = "";
+ inBuf.setFillByte(0);
+ inBuf.setSize(size+1);
+ if (size > 0) {
+ if (cacheBuf)
+ strncpy(inBuf.getRawData(), &(cacheBuf[start]), size);
}
+ inBuf.setSize(strlen(inBuf.c_str()));
}
@@ -274,16 +281,19 @@ void zVerse::swgettext(char testmt, long start, unsigned short size, char *inbuf
* len - length of buffer (0 - null terminated)
*/
-void zVerse::settext(char testmt, long idxoff, const char *buf, long len)
-{
+void zVerse::doSetText(char testmt, long idxoff, const char *buf, long len) {
+
+ len = (len < 0) ? strlen(buf) : len;
+ if (!testmt)
+ testmt = ((idxfp[0]) ? 1:2);
if ((!dirtyCache) || (cacheBufIdx < 0)) {
cacheBufIdx = lseek(idxfp[testmt-1]->getFd(), 0, SEEK_END) / 12;
cacheTestament = testmt;
if (cacheBuf)
free(cacheBuf);
- cacheBuf = (char *)calloc(len ? len : strlen(buf)+1, 1);
+ cacheBuf = (char *)calloc(len + 1, 1);
}
- else cacheBuf = (char *)((cacheBuf)?realloc(cacheBuf, strlen(cacheBuf)+(len ? len : strlen(buf)+1)):calloc((len ? len : strlen(buf)+1), 1));
+ else cacheBuf = (char *)((cacheBuf)?realloc(cacheBuf, strlen(cacheBuf)+(len + 1)):calloc((len + 1), 1));
dirtyCache = true;
@@ -293,7 +303,7 @@ void zVerse::settext(char testmt, long idxoff, const char *buf, long len)
unsigned short outsize;
idxoff *= 10;
- size = outsize = len ? len : strlen(buf);
+ size = outsize = len;
start = strlen(cacheBuf);
@@ -320,28 +330,38 @@ void zVerse::flushCache() {
unsigned long zsize, outzsize;
idxoff = cacheBufIdx * 12;
- size = outsize = zsize = outzsize = strlen(cacheBuf);
- if (size) {
-// if (compressor) {
-// delete compressor;
-// compressor = new LZSSCompress();
-// }
- compressor->Buf(cacheBuf);
- compressor->zBuf(&zsize);
- outzsize = zsize;
-
- start = outstart = lseek(textfp[cacheTestament-1]->getFd(), 0, SEEK_END);
-
- outstart = archtosword32(start);
- outsize = archtosword32(size);
- outzsize = archtosword32(zsize);
-
- write(textfp[cacheTestament-1]->getFd(), compressor->zBuf(&zsize), zsize);
-
- lseek(idxfp[cacheTestament-1]->getFd(), idxoff, SEEK_SET);
- write(idxfp[cacheTestament-1]->getFd(), &outstart, 4);
- write(idxfp[cacheTestament-1]->getFd(), &outzsize, 4);
- write(idxfp[cacheTestament-1]->getFd(), &outsize, 4);
+ if (cacheBuf) {
+ size = outsize = zsize = outzsize = strlen(cacheBuf);
+ if (size) {
+ // if (compressor) {
+ // delete compressor;
+ // compressor = new LZSSCompress();
+ // }
+ compressor->Buf(cacheBuf);
+ compressor->zBuf(&zsize);
+ outzsize = zsize;
+
+ SWBuf buf;
+ buf.setSize(zsize + 5);
+ memcpy(buf.getRawData(), compressor->zBuf(&zsize), zsize);
+ buf.setSize(zsize);
+ rawZFilter(buf, 1); // 1 = encipher
+
+ start = outstart = lseek(textfp[cacheTestament-1]->getFd(), 0, SEEK_END);
+
+ outstart = archtosword32(start);
+ outsize = archtosword32(size);
+ outzsize = archtosword32(zsize);
+
+ write(textfp[cacheTestament-1]->getFd(), buf, zsize);
+
+ lseek(idxfp[cacheTestament-1]->getFd(), idxoff, SEEK_SET);
+ write(idxfp[cacheTestament-1]->getFd(), &outstart, 4);
+ write(idxfp[cacheTestament-1]->getFd(), &outzsize, 4);
+ write(idxfp[cacheTestament-1]->getFd(), &outsize, 4);
+ }
+ free(cacheBuf);
+ cacheBuf = 0;
}
dirtyCache = false;
}
@@ -355,7 +375,7 @@ void zVerse::flushCache() {
* srcidxoff - source offset into .vss
*/
-void zVerse::linkentry(char testmt, long destidxoff, long srcidxoff) {
+void zVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) {
long bufidx;
long start;
unsigned short size;
@@ -446,6 +466,7 @@ char zVerse::createModule(const char *ipath, int blockBound)
FileMgr::systemFileMgr.close(fd2);
delete [] path;
+ delete [] buf;
/*
RawVerse rv(path);
VerseKey mykey("Rev 22:21");
@@ -463,12 +484,12 @@ char zVerse::createModule(const char *ipath, int blockBound)
* text.
*/
-void zVerse::preptext(char *buf)
-{
- char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
-
- for (to = from = buf; *from; from++) {
- switch (*from) {
+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;
@@ -477,14 +498,16 @@ void zVerse::preptext(char *buf)
nlcnt++;
if (nlcnt > 1) {
// *to++ = nl;
- *to++ = nl;
+ rawBuf[to++] = 10;
+// *to++ = nl[1];
// nlcnt = 0;
}
continue;
case 13:
if (!realdata)
continue;
- *to++ = nl;
+// *to++ = nl[0];
+ rawBuf[to++] = 10;
space = 0;
cr = 1;
continue;
@@ -493,21 +516,23 @@ void zVerse::preptext(char *buf)
nlcnt = 0;
if (space) {
space = 0;
- if (*from != ' ') {
- *to++ = ' ';
+ if (rawBuf[from] != ' ') {
+ rawBuf[to++] = ' ';
from--;
continue;
}
}
- *to++ = *from;
+ 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;
}
- *to = 0;
-
- if (to > buf) {
- for (to--; to > buf; to--) { // remove trailing excess
- if ((*to == 10) || (*to == ' '))
- *to = 0;
- else break;
- }
- }
}
+
+
+SWORD_NAMESPACE_END