summaryrefslogtreecommitdiff
path: root/src/modules/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/common')
-rw-r--r--src/modules/common/Makefile.am1
-rw-r--r--src/modules/common/entriesblk.cpp3
-rw-r--r--src/modules/common/lzsscomprs.cpp5
-rw-r--r--src/modules/common/rawstr.cpp168
-rw-r--r--src/modules/common/rawstr4.cpp169
-rw-r--r--src/modules/common/rawverse.cpp64
-rw-r--r--src/modules/common/sapphire.cpp3
-rw-r--r--src/modules/common/swcipher.cpp19
-rw-r--r--src/modules/common/swcomprs.cpp5
-rw-r--r--src/modules/common/zipcomprs.cpp7
-rw-r--r--src/modules/common/zstr.cpp101
-rw-r--r--src/modules/common/zverse.cpp145
12 files changed, 372 insertions, 318 deletions
diff --git a/src/modules/common/Makefile.am b/src/modules/common/Makefile.am
index ac235d8..b411660 100644
--- a/src/modules/common/Makefile.am
+++ b/src/modules/common/Makefile.am
@@ -17,6 +17,5 @@ libsword_la_SOURCES += $(commondir)/zverse.cpp
libsword_la_SOURCES += $(commondir)/zstr.cpp
libsword_la_SOURCES += $(commondir)/entriesblk.cpp
-DEFS += -DUNIX
libsword_la_SOURCES += $(commondir)/sapphire.cpp
diff --git a/src/modules/common/entriesblk.cpp b/src/modules/common/entriesblk.cpp
index d38cf53..f4fbdeb 100644
--- a/src/modules/common/entriesblk.cpp
+++ b/src/modules/common/entriesblk.cpp
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
+SWORD_NAMESPACE_START
+
const int EntriesBlock::METAHEADERSIZE = 4;
// count(4);
const int EntriesBlock::METAENTRYSIZE = 8;
@@ -164,3 +166,4 @@ void EntriesBlock::removeEntry(int entryIndex) {
}
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/lzsscomprs.cpp b/src/modules/common/lzsscomprs.cpp
index 3606fbc..bd8f768 100644
--- a/src/modules/common/lzsscomprs.cpp
+++ b/src/modules/common/lzsscomprs.cpp
@@ -3,10 +3,11 @@
* provides LZSS compression
*/
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <lzsscomprs.h>
+SWORD_NAMESPACE_START
/******************************************************************************
* LZSSCompress Statics
@@ -663,3 +664,5 @@ void LZSSCompress::Decode(void)
}
slen = totalLen;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/rawstr.cpp b/src/modules/common/rawstr.cpp
index 787946c..5c4ef0e 100644
--- a/src/modules/common/rawstr.cpp
+++ b/src/modules/common/rawstr.cpp
@@ -16,11 +16,13 @@
#include <unistd.h>
#endif
-#include <string.h>
#include <stdlib.h>
#include <utilfuns.h>
#include <rawstr.h>
#include <sysdata.h>
+
+SWORD_NAMESPACE_START
+
/******************************************************************************
* RawStr Statics
*/
@@ -93,7 +95,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)
{
int size;
char ch;
@@ -103,14 +105,13 @@ void RawStr::getidxbufdat(long ioffset, char **buf)
if ((ch == '\\') || (ch == 10) || (ch == 13))
break;
}
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
+ *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
if (size) {
lseek(datfd->getFd(), ioffset, SEEK_SET);
read(datfd->getFd(), *buf, size);
}
(*buf)[size] = 0;
- for (size--; size > 0; size--)
- (*buf)[size] = SW_toupper((*buf)[size]);
+ toupperstr_utf8(*buf, size*2);
}
else {
*buf = (*buf) ? (char *)realloc(*buf, 1) : (char *)malloc(1);
@@ -128,7 +129,7 @@ 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)
{
char *trybuf, *targetbuf;
long offset;
@@ -139,18 +140,7 @@ void RawStr::getidxbuf(long ioffset, char **buf)
offset = swordtoarch32(offset);
- getidxbufdat(offset, buf);
- for (trybuf = targetbuf = *buf; *trybuf; trybuf++, targetbuf++) {
-/*
- if (*trybuf == '-') { // ignore '-' because alphabetized silly in file
- targetbuf--;
- continue;
- }
-*/
- *targetbuf = SW_toupper(*trybuf);
- }
- *targetbuf = 0;
- trybuf = 0;
+ getIDXBufDat(offset, buf);
}
}
@@ -164,39 +154,30 @@ void RawStr::getidxbuf(long ioffset, char **buf)
* away - number of entries before of after to jump
* (default = 0)
*
- * RET: error status
+ * 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, long *start, unsigned short *size, long away, long *idxoff)
{
- char *trybuf, *targetbuf, *key, quitflag = 0;
- signed char retval = 0;
+ char *trybuf, *targetbuf, *key = 0, quitflag = 0;
+ signed char retval = -1;
long headoff, tailoff, tryoff = 0, maxoff = 0;
if (idxfd->getFd() >=0) {
tailoff = maxoff = lseek(idxfd->getFd(), 0, SEEK_END) - 6;
+ retval = (tailoff >= 0) ? 0 : -2; // if NOT new file
if (*ikey) {
headoff = 0;
- key = new char [ strlen(ikey) + 1 ];
- strcpy(key, ikey);
+ stdstr(&key, ikey, 3);
+ toupperstr_utf8(key, strlen(key)*3);
- for (trybuf = targetbuf = key; *trybuf; trybuf++, targetbuf++) {
- /*
- if (*trybuf == '-') { // ignore '-' because alphabetized silly in file
- targetbuf--;
- continue;
- }
- */
- *targetbuf = SW_toupper(*trybuf);
- }
- *targetbuf = 0;
trybuf = 0;
while (headoff < tailoff) {
tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff;
lastoff = -1;
- getidxbuf(tryoff, &trybuf);
+ getIDXBuf(tryoff, &trybuf);
if (!*trybuf && tryoff) { // In case of extra entry at end of idx (not first entry)
tryoff += (tryoff > (maxoff / 2))?-6:6;
@@ -288,11 +269,12 @@ signed char RawStr::findoffset(const char *ikey, long *start, unsigned short *si
* text.
*/
-void RawStr::preptext(char *buf) {
- char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
-
- for (to = from = buf; *from; from++) {
- switch (*from) {
+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;
@@ -301,14 +283,16 @@ void RawStr::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;
@@ -317,27 +301,27 @@ void RawStr::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];
}
- *to = 0;
+ buf.setSize(to);
- while (to > (buf+1)) { // remove trailing excess
+ while (to > 1) { // remove trailing excess
to--;
- if ((*to == 10) || (*to == ' '))
- *to = 0;
+ if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
+ buf.setSize(to);
else break;
}
}
/******************************************************************************
- * RawStr::gettext - gets text at a given offset
+ * RawStr::readtext - gets text at a given offset
*
* ENT:
* start - starting offset where the text is located in the file
@@ -346,40 +330,41 @@ void RawStr::preptext(char *buf) {
*
*/
-void RawStr::gettext(long istart, unsigned short isize, char *idxbuf, char *buf)
+void RawStr::readText(long istart, unsigned short *isize, char **idxbuf, SWBuf &buf)
{
- char *ch;
+ unsigned int ch;
char *idxbuflocal = 0;
- getidxbufdat(istart, &idxbuflocal);
+ getIDXBufDat(istart, &idxbuflocal);
long start = istart;
- unsigned short size = isize;
do {
- memset(buf, 0, size);
+ if (*idxbuf)
+ delete [] *idxbuf;
+ buf = "";
+ buf.setFillByte(0);
+ buf.setSize(++(*isize));
+
+ *idxbuf = new char [ (*isize) ];
+
lseek(datfd->getFd(), start, SEEK_SET);
- read(datfd->getFd(), buf, (int)(size - 2));
+ read(datfd->getFd(), buf.getRawData(), (int)((*isize) - 1));
- for (ch = buf; *ch; ch++) { // skip over index string
- if (*ch == 10) {
+ for (ch = 0; buf[ch]; ch++) { // skip over index string
+ if (buf[ch] == 10) {
ch++;
break;
}
}
- size -= (unsigned short)(ch-buf);
- memmove(buf, ch, size);
- buf[size] = 0;
- buf[size+1] = 0;
-
+ buf = SWBuf(buf.c_str()+ch);
// resolve link
- if (!strncmp(buf, "@LINK", 5)) {
- for (ch = buf; *ch; ch++) { // null before nl
- if (*ch == 10) {
- *ch = 0;
+ if (!strncmp(buf.c_str(), "@LINK", 5)) {
+ for (ch = 0; buf[ch]; ch++) { // null before nl
+ if (buf[ch] == 10) {
+ buf[ch] = 0;
break;
}
}
- findoffset(buf + 6, &start, &size);
- // TODO: FIX! THIS IS WRONG!!! buf is not reallocated for the appropriate size!
+ findOffset(buf.c_str() + 6, &start, isize);
}
else break;
}
@@ -387,9 +372,9 @@ void RawStr::gettext(long istart, unsigned short isize, char *idxbuf, char *buf)
if (idxbuflocal) {
int localsize = strlen(idxbuflocal);
- localsize = (localsize < (size - 1)) ? localsize : (size - 1);
- strncpy(idxbuf, idxbuflocal, localsize);
- idxbuf[localsize] = 0;
+ localsize = (localsize < (*isize - 1)) ? localsize : (*isize - 1);
+ strncpy(*idxbuf, idxbuflocal, localsize);
+ (*idxbuf)[localsize] = 0;
free(idxbuflocal);
}
}
@@ -403,7 +388,7 @@ void RawStr::gettext(long istart, unsigned short isize, char *idxbuf, char *buf)
* len - length of buffer (0 - null terminated)
*/
-void RawStr::settext(const char *ikey, const char *buf, long len)
+void RawStr::doSetText(const char *ikey, const char *buf, long len)
{
long start, outstart;
@@ -420,19 +405,22 @@ void RawStr::settext(const char *ikey, const char *buf, long len)
char *outbuf = 0;
char *ch = 0;
- findoffset(ikey, &start, &size, 0, &idxoff);
- stdstr(&key, ikey);
- for (ch = key; *ch; ch++)
- *ch = SW_toupper(*ch);
- ch = 0;
+ char errorStatus = findOffset(ikey, &start, &size, 0, &idxoff);
+ stdstr(&key, ikey, 2);
+ toupperstr_utf8(key, strlen(key)*2);
+
+ len = (len < 0) ? strlen(buf) : len;
- getidxbufdat(start, &dbKey);
+ getIDXBufDat(start, &dbKey);
if (strcmp(key, dbKey) < 0) {
}
else if (strcmp(key, dbKey) > 0) {
- idxoff += 6;
- } else if ((!strcmp(key, dbKey)) && (len || strlen(buf) /*we're not deleting*/)) { // got absolute entry
+ if (errorStatus != -2) // not a new file
+ idxoff += 6;
+ else idxoff = 0;
+ }
+ else if ((!strcmp(key, dbKey)) && (len>0 /*we're not deleting*/)) { // got absolute entry
do {
tmpbuf = new char [ size + 2 ];
memset(tmpbuf, 0, size + 2);
@@ -448,14 +436,14 @@ void RawStr::settext(const char *ikey, const char *buf, long len)
memmove(tmpbuf, ch, size - (unsigned short)(ch-tmpbuf));
// resolve link
- if (!strncmp(tmpbuf, "@LINK", 5) && (len ? len : strlen(buf))) {
+ if (!strncmp(tmpbuf, "@LINK", 5) && (len)) {
for (ch = tmpbuf; *ch; ch++) { // null before nl
if (*ch == 10) {
*ch = 0;
break;
}
}
- findoffset(tmpbuf + 6, &start, &size, 0, &idxoff);
+ findOffset(tmpbuf + 6, &start, &size, 0, &idxoff);
}
else break;
}
@@ -472,11 +460,11 @@ void RawStr::settext(const char *ikey, const char *buf, long len)
read(idxfd->getFd(), idxBytes, shiftSize);
}
- outbuf = new char [ (len ? len : strlen(buf)) + strlen(key) + 5 ];
+ outbuf = new char [ len + strlen(key) + 5 ];
sprintf(outbuf, "%s%c%c", key, 13, 10);
size = strlen(outbuf);
- memcpy (outbuf + size, buf, len ? len : strlen(buf));
- size = outsize = size + (len ? len : strlen(buf));
+ memcpy(outbuf + size, buf, len);
+ size = outsize = size + (len);
start = outstart = lseek(datfd->getFd(), 0, SEEK_END);
@@ -484,7 +472,7 @@ void RawStr::settext(const char *ikey, const char *buf, long len)
outsize = archtosword16(size);
lseek(idxfd->getFd(), idxoff, SEEK_SET);
- if (len ? len : strlen(buf)) {
+ if (len > 0) {
lseek(datfd->getFd(), start, SEEK_SET);
write(datfd->getFd(), outbuf, (int)size);
@@ -521,10 +509,10 @@ void RawStr::settext(const char *ikey, const char *buf, long len)
* srcidxoff - source offset into .vss
*/
-void RawStr::linkentry(const char *destkey, const char *srckey) {
+void RawStr::doLinkEntry(const char *destkey, const char *srckey) {
char *text = new char [ strlen(destkey) + 7 ];
sprintf(text, "@LINK %s", destkey);
- settext(srckey, text);
+ doSetText(srckey, text);
delete [] text;
}
@@ -563,3 +551,5 @@ signed char RawStr::createModule(const char *ipath)
return 0;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/rawstr4.cpp b/src/modules/common/rawstr4.cpp
index d5926ff..e278675 100644
--- a/src/modules/common/rawstr4.cpp
+++ b/src/modules/common/rawstr4.cpp
@@ -15,12 +15,13 @@
#include <unistd.h>
#endif
-#include <string.h>
#include <stdlib.h>
#include <utilfuns.h>
#include <rawstr4.h>
#include <sysdata.h>
+SWORD_NAMESPACE_START
+
/******************************************************************************
* RawStr Statics
*/
@@ -93,8 +94,7 @@ 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) {
int size;
char ch;
if (datfd > 0) {
@@ -103,14 +103,13 @@ void RawStr4::getidxbufdat(long ioffset, char **buf)
if ((ch == '\\') || (ch == 10) || (ch == 13))
break;
}
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
+ *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
if (size) {
lseek(datfd->getFd(), ioffset, SEEK_SET);
read(datfd->getFd(), *buf, size);
}
(*buf)[size] = 0;
- for (size--; size > 0; size--)
- (*buf)[size] = SW_toupper((*buf)[size]);
+ toupperstr_utf8(*buf, size*2);
}
else {
*buf = (*buf) ? (char *)realloc(*buf, 1) : (char *)malloc(1);
@@ -128,7 +127,7 @@ 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)
{
char *trybuf, *targetbuf;
long offset;
@@ -139,18 +138,16 @@ void RawStr4::getidxbuf(long ioffset, char **buf)
offset = swordtoarch32(offset);
- getidxbufdat(offset, buf);
+ getIDXBufDat(offset, buf);
+
+/* What the heck is this supposed to do??????
for (trybuf = targetbuf = *buf; *trybuf; trybuf++, targetbuf++) {
-/*
- if (*trybuf == '-') { // ignore '-' because alphabetized silly in file
- targetbuf--;
- continue;
- }
-*/
- *targetbuf = SW_toupper(*trybuf);
+ *targetbuf = *trybuf;
}
*targetbuf = 0;
trybuf = 0;
+ toupperstr_utf8(targetbuf);
+*/
}
}
@@ -164,39 +161,30 @@ void RawStr4::getidxbuf(long ioffset, char **buf)
* away - number of entries before of after to jump
* (default = 0)
*
- * RET: error status
+ * 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, long *start, unsigned long *size, long away, long *idxoff)
{
- char *trybuf, *targetbuf, *key, quitflag = 0;
- signed char retval = 0;
+ char *trybuf, *targetbuf, *key = 0, quitflag = 0;
+ signed char retval = -1;
long headoff, tailoff, tryoff = 0, maxoff = 0;
if (idxfd->getFd() >=0) {
+ tailoff = maxoff = lseek(idxfd->getFd(), 0, SEEK_END) - 8;
+ retval = (tailoff >= 0) ? 0 : -2; // if NOT new file
if (*ikey) {
headoff = 0;
- tailoff = maxoff = lseek(idxfd->getFd(), 0, SEEK_END) - 8;
- key = new char [ strlen(ikey) + 1 ];
- strcpy(key, ikey);
+ stdstr(&key, ikey, 3);
+ toupperstr_utf8(key, strlen(key)*3);
- for (trybuf = targetbuf = key; *trybuf; trybuf++, targetbuf++) {
- /*
- if (*trybuf == '-') { // ignore '-' because alphabetized silly in file
- targetbuf--;
- continue;
- }
- */
- *targetbuf = SW_toupper(*trybuf);
- }
- *targetbuf = 0;
trybuf = 0;
while (headoff < tailoff) {
tryoff = (lastoff == -1) ? headoff + ((((tailoff / 8) - (headoff / 8))) / 2) * 8 : lastoff;
lastoff = -1;
- getidxbuf(tryoff, &trybuf);
+ getIDXBuf(tryoff, &trybuf);
if (!*trybuf) { // In case of extra entry at end of idx
tryoff += (tryoff > (maxoff / 2))?-8:8;
@@ -288,12 +276,12 @@ signed char RawStr4::findoffset(const char *ikey, long *start, unsigned long *si
* text.
*/
-void RawStr4::preptext(char *buf)
-{
- char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
-
- for (to = from = buf; *from; from++) {
- switch (*from) {
+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;
@@ -302,14 +290,16 @@ void RawStr4::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;
@@ -318,27 +308,27 @@ void RawStr4::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];
}
- *to = 0;
+ buf.setSize(to);
- while (to > (buf+1)) { // remove trailing excess
+ while (to > 1) { // remove trailing excess
to--;
- if ((*to == 10) || (*to == ' '))
- *to = 0;
+ if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
+ buf.setSize(to);
else break;
}
}
/******************************************************************************
- * RawStr4::gettext - gets text at a given offset
+ * RawStr4::readtext - gets text at a given offset
*
* ENT:
* start - starting offset where the text is located in the file
@@ -347,36 +337,41 @@ void RawStr4::preptext(char *buf)
*
*/
-void RawStr4::gettext(long istart, unsigned long isize, char *idxbuf, char *buf)
+void RawStr4::readText(long istart, unsigned long *isize, char **idxbuf, SWBuf &buf)
{
- char *ch;
+ unsigned int ch;
char *idxbuflocal = 0;
- getidxbufdat(istart, &idxbuflocal);
+ getIDXBufDat(istart, &idxbuflocal);
long start = istart;
- unsigned long size = isize;
do {
- memset(buf, 0, size);
+ if (*idxbuf)
+ delete [] *idxbuf;
+ *idxbuf = new char [ (*isize) ];
+
+ buf = "";
+ buf.setFillByte(0);
+ buf.setSize(*isize);
lseek(datfd->getFd(), start, SEEK_SET);
- read(datfd->getFd(), buf, (int)(size - 1));
+ read(datfd->getFd(), buf.getRawData(), (int)((*isize) - 1));
- for (ch = buf; *ch; ch++) { // skip over index string
- if (*ch == 10) {
+ for (ch = 0; buf[ch]; ch++) { // skip over index string
+ if (buf[ch] == 10) {
ch++;
break;
}
}
- memmove(buf, ch, size - (unsigned long)(ch-buf));
-
+ buf = SWBuf(buf.c_str()+ch);
// resolve link
- if (!strncmp(buf, "@LINK", 5)) {
- for (ch = buf; *ch; ch++) { // null before nl
- if (*ch == 10) {
- *ch = 0;
+ if (!strncmp(buf.c_str(), "@LINK", 5)) {
+ for (ch = 0; buf[ch]; ch++) { // null before nl
+ if (buf[ch] == 10) {
+ buf[ch] = 0;
break;
}
}
- findoffset(buf + 8, &start, &size);
+ findOffset(buf.c_str() + 6, &start, isize);
+
}
else break;
}
@@ -384,9 +379,9 @@ void RawStr4::gettext(long istart, unsigned long isize, char *idxbuf, char *buf)
if (idxbuflocal) {
int localsize = strlen(idxbuflocal);
- localsize = (localsize < (size - 1)) ? localsize : (size - 1);
- strncpy(idxbuf, idxbuflocal, localsize);
- idxbuf[localsize] = 0;
+ localsize = (localsize < (*isize - 1)) ? localsize : (*isize - 1);
+ strncpy(*idxbuf, idxbuflocal, localsize);
+ (*idxbuf)[localsize] = 0;
free(idxbuflocal);
}
}
@@ -400,8 +395,7 @@ void RawStr4::gettext(long istart, unsigned long isize, char *idxbuf, char *buf)
* len - length of buffer (0 - null terminated)
*/
-void RawStr4::settext(const char *ikey, const char *buf, long len)
-{
+void RawStr4::doSetText(const char *ikey, const char *buf, long len) {
long start, outstart;
long idxoff;
@@ -417,19 +411,21 @@ void RawStr4::settext(const char *ikey, const char *buf, long len)
char *outbuf = 0;
char *ch = 0;
- findoffset(ikey, &start, &size, 0, &idxoff);
- stdstr(&key, ikey);
- for (ch = key; *ch; ch++)
- *ch = SW_toupper(*ch);
- ch = 0;
+ char errorStatus = findOffset(ikey, &start, &size, 0, &idxoff);
+ stdstr(&key, ikey, 3);
+ toupperstr_utf8(key, strlen(key)*3);
- getidxbufdat(start, &dbKey);
+ len = (len < 0) ? strlen(buf) : len;
+ getIDXBufDat(start, &dbKey);
if (strcmp(key, dbKey) < 0) {
}
else if (strcmp(key, dbKey) > 0) {
- idxoff += 8;
- } else if ((!strcmp(key, dbKey)) && (len || strlen(buf) /*we're not deleting*/)) { // got absolute entry
+ if (errorStatus != -2) // not a new file
+ idxoff += 8;
+ else idxoff = 0;
+ }
+ else if ((!strcmp(key, dbKey)) && (len>0/*we're not deleting*/)) { // got absolute entry
do {
tmpbuf = new char [ size + 2 ];
memset(tmpbuf, 0, size + 2);
@@ -445,14 +441,15 @@ void RawStr4::settext(const char *ikey, const char *buf, long len)
memmove(tmpbuf, ch, size - (unsigned long)(ch-tmpbuf));
// resolve link
- if (!strncmp(tmpbuf, "@LINK", 5) && (len ? len : strlen(buf))) {
+ if (!strncmp(tmpbuf, "@LINK", 5) && (len > 0)) {
for (ch = tmpbuf; *ch; ch++) { // null before nl
if (*ch == 10) {
*ch = 0;
break;
}
}
- findoffset(tmpbuf + 8, &start, &size, 0, &idxoff);
+ findOffset(tmpbuf + 8, &start, &size, 0, &idxoff);
+ ++size;
}
else break;
}
@@ -469,11 +466,11 @@ void RawStr4::settext(const char *ikey, const char *buf, long len)
read(idxfd->getFd(), idxBytes, shiftSize);
}
- outbuf = new char [ (len ? len : strlen(buf)) + strlen(key) + 5 ];
+ outbuf = new char [ len + strlen(key) + 5 ];
sprintf(outbuf, "%s%c%c", key, 13, 10);
size = strlen(outbuf);
- memcpy (outbuf + size, buf, len ? len : strlen(buf));
- size = outsize = size + (len ? len : strlen(buf));
+ memcpy(outbuf + size, buf, len);
+ size = outsize = size + len;
start = outstart = lseek(datfd->getFd(), 0, SEEK_END);
@@ -481,7 +478,7 @@ void RawStr4::settext(const char *ikey, const char *buf, long len)
outsize = archtosword32(size);
lseek(idxfd->getFd(), idxoff, SEEK_SET);
- if (len ? len : strlen(buf)) {
+ if (len>0) {
lseek(datfd->getFd(), start, SEEK_SET);
write(datfd->getFd(), outbuf, (long)size);
@@ -518,10 +515,10 @@ void RawStr4::settext(const char *ikey, const char *buf, long len)
* srcidxoff - source offset into .vss
*/
-void RawStr4::linkentry(const char *destkey, const char *srckey) {
+void RawStr4::doLinkEntry(const char *destkey, const char *srckey) {
char *text = new char [ strlen(destkey) + 7 ];
sprintf(text, "@LINK %s", destkey);
- settext(srckey, text);
+ doSetText(srckey, text);
delete [] text;
}
@@ -560,3 +557,5 @@ signed char RawStr4::createModule(const char *ipath)
return 0;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/rawverse.cpp b/src/modules/common/rawverse.cpp
index 3374da5..b5bff9f 100644
--- a/src/modules/common/rawverse.cpp
+++ b/src/modules/common/rawverse.cpp
@@ -18,7 +18,6 @@
#include <unistd.h>
#endif
-#include <string.h>
#include <utilfuns.h>
#include <rawverse.h>
#include <versekey.h>
@@ -28,12 +27,14 @@
#define O_BINARY 0 // If it hasn't been defined than we probably
#endif // don't need it.
+SWORD_NAMESPACE_START
/******************************************************************************
* RawVerse Statics
*/
- int RawVerse::instance = 0;
+int RawVerse::instance = 0;
+const char *RawVerse::nl = "\r\n";
/******************************************************************************
@@ -48,7 +49,6 @@ RawVerse::RawVerse(const char *ipath, int fileMode)
{
char *buf;
- nl = '\n';
path = 0;
stdstr(&path, ipath);
buf = new char [ strlen(path) + 80 ];
@@ -105,7 +105,7 @@ 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) {
idxoff *= 6;
if (!testmt)
testmt = ((idxfp[1]) ? 1:2);
@@ -137,12 +137,12 @@ void RawVerse::findoffset(char testmt, long idxoff, long *start, unsigned short
* text.
*/
-void RawVerse::preptext(char *buf)
-{
- char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
-
- for (to = from = buf; *from; from++) {
- switch (*from) {
+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;
@@ -151,14 +151,16 @@ void RawVerse::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;
@@ -167,27 +169,27 @@ void RawVerse::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];
}
- *to = 0;
+ buf.setSize(to);
- while (to > (buf+1)) { // remove trailing excess
+ while (to > 1) { // remove trailing excess
to--;
- if ((*to == 10) || (*to == ' '))
- *to = 0;
+ if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
+ buf.setSize(to);
else break;
}
}
/******************************************************************************
- * RawVerse::gettext - gets text at a given offset
+ * RawVerse::readtext - 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
@@ -196,12 +198,16 @@ void RawVerse::preptext(char *buf)
*
*/
-void RawVerse::gettext(char testmt, long start, unsigned short size, char *buf) {
- memset(buf, 0, size+1);
+void RawVerse::readText(char testmt, long start, unsigned short size, SWBuf &buf) {
+ buf = "";
+ buf.setFillByte(0);
+ buf.setSize(size + 1);
+ if (!testmt)
+ testmt = ((idxfp[1]) ? 1:2);
if (size) {
if (textfp[testmt-1]->getFd() >= 0) {
lseek(textfp[testmt-1]->getFd(), start, SEEK_SET);
- read(textfp[testmt-1]->getFd(), buf, (int)size - 2);
+ read(textfp[testmt-1]->getFd(), buf.getRawData(), (int)size);
}
}
}
@@ -216,18 +222,17 @@ void RawVerse::gettext(char testmt, long start, unsigned short size, char *buf)
* len - length of buffer (0 - null terminated)
*/
-void RawVerse::settext(char testmt, long idxoff, const char *buf, long len)
+void RawVerse::doSetText(char testmt, long idxoff, const char *buf, long len)
{
long start, outstart;
unsigned short size;
unsigned short outsize;
- static const char nl[] = {13, 10};
idxoff *= 6;
if (!testmt)
testmt = ((idxfp[1]) ? 1:2);
- size = outsize = len ? len : strlen(buf);
+ size = outsize = (len < 0) ? strlen(buf) : len;
start = outstart = lseek(textfp[testmt-1]->getFd(), 0, SEEK_END);
lseek(idxfp[testmt-1]->getFd(), idxoff, SEEK_SET);
@@ -237,7 +242,7 @@ void RawVerse::settext(char testmt, long idxoff, const char *buf, long len)
write(textfp[testmt-1]->getFd(), buf, (int)size);
// add a new line to make data file easier to read in an editor
- write(textfp[testmt-1]->getFd(), &nl, 2);
+ write(textfp[testmt-1]->getFd(), nl, 2);
}
else {
start = 0;
@@ -261,7 +266,7 @@ void RawVerse::settext(char testmt, long idxoff, const char *buf, long len)
* srcidxoff - source offset into .vss
*/
-void RawVerse::linkentry(char testmt, long destidxoff, long srcidxoff) {
+void RawVerse::doLinkEntry(char testmt, long destidxoff, long srcidxoff) {
long start;
unsigned short size;
@@ -336,6 +341,7 @@ char RawVerse::createModule(const char *ipath)
FileMgr::systemFileMgr.close(fd2);
delete [] path;
+ delete [] buf;
/*
RawVerse rv(path);
VerseKey mykey("Rev 22:21");
@@ -343,3 +349,5 @@ char RawVerse::createModule(const char *ipath)
return 0;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/sapphire.cpp b/src/modules/common/sapphire.cpp
index 686bccb..1c97934 100644
--- a/src/modules/common/sapphire.cpp
+++ b/src/modules/common/sapphire.cpp
@@ -30,6 +30,8 @@
#include "sapphire.h"
+SWORD_NAMESPACE_START
+
unsigned char sapphire::keyrand(int limit,
unsigned char *user_key,
unsigned char keysize,
@@ -226,3 +228,4 @@ void sapphire::hash_final(unsigned char *hash, // Destination
hash[i] = encrypt(0);
}
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/swcipher.cpp b/src/modules/common/swcipher.cpp
index d221b8b..bd4d551 100644
--- a/src/modules/common/swcipher.cpp
+++ b/src/modules/common/swcipher.cpp
@@ -3,10 +3,11 @@
* cipher utilities.
*/
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <swcipher.h>
+SWORD_NAMESPACE_START
/******************************************************************************
* SWCipher Constructor - Initializes data for instance of SWCipher
@@ -30,7 +31,7 @@ SWCipher::~SWCipher()
}
-char *SWCipher::Buf(const char *ibuf, unsigned int ilen)
+char *SWCipher::Buf(const char *ibuf, unsigned long ilen)
{
if (ibuf) {
@@ -54,14 +55,14 @@ char *SWCipher::Buf(const char *ibuf, unsigned int ilen)
}
-char *SWCipher::cipherBuf(unsigned int *ilen, const char *ibuf)
+char *SWCipher::cipherBuf(unsigned long *ilen, const char *ibuf)
{
if (ibuf) {
if (buf)
free(buf);
- buf = (char *) malloc(*ilen);
+ buf = (char *) malloc(*ilen+1);
memcpy(buf, ibuf, *ilen);
len = *ilen;
cipher = true;
@@ -69,7 +70,7 @@ char *SWCipher::cipherBuf(unsigned int *ilen, const char *ibuf)
Encode();
- *ilen = (short)len;
+ *ilen = len;
return buf;
}
@@ -86,7 +87,7 @@ void SWCipher::Encode(void)
{
if (!cipher) {
work = master;
- for (int i = 0; i < len; i++)
+ for (unsigned long i = 0; i < len; i++)
buf[i] = work.encrypt(buf[i]);
cipher = true;
}
@@ -105,8 +106,10 @@ void SWCipher::Decode(void)
{
if (cipher) {
work = master;
- for (int i = 0; i < len; i++)
+ unsigned long i;
+ for (i = 0; i < len; i++)
buf[i] = work.decrypt(buf[i]);
+ buf[i] = 0;
cipher = false;
}
}
@@ -121,3 +124,5 @@ void SWCipher::setCipherKey(const char *ikey) {
unsigned char *key = (unsigned char *)ikey;
master.initialize(key, strlen((char *)key));
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/swcomprs.cpp b/src/modules/common/swcomprs.cpp
index 4bd2e5e..02d7d7b 100644
--- a/src/modules/common/swcomprs.cpp
+++ b/src/modules/common/swcomprs.cpp
@@ -3,10 +3,11 @@
* compression utilities.
*/
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <swcomprs.h>
+SWORD_NAMESPACE_START
/******************************************************************************
* SWCompress Constructor - Initializes data for instance of SWCompress
@@ -188,3 +189,5 @@ void SWCompress::cycleStream() {
zlen = slen = totlen;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/zipcomprs.cpp b/src/modules/common/zipcomprs.cpp
index 01ba430..6a5ed22 100644
--- a/src/modules/common/zipcomprs.cpp
+++ b/src/modules/common/zipcomprs.cpp
@@ -3,13 +3,14 @@
* compression utilities. - using zlib
*/
-#include <string.h>
-#include <string>
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include <zipcomprs.h>
#include <zlib.h>
+SWORD_NAMESPACE_START
+
/******************************************************************************
* ZipCompress Constructor - Initializes data for instance of ZipCompress
*
@@ -156,3 +157,5 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
//printf("Finished decoding\n");
free (zbuf);
}
+
+SWORD_NAMESPACE_END
diff --git a/src/modules/common/zstr.cpp b/src/modules/common/zstr.cpp
index fc02572..92a4960 100644
--- a/src/modules/common/zstr.cpp
+++ b/src/modules/common/zstr.cpp
@@ -14,7 +14,6 @@
#include <unistd.h>
#endif
-#include <string.h>
#include <stdlib.h>
#include <utilfuns.h>
#include <zstr.h>
@@ -23,6 +22,8 @@
#include <sysdata.h>
#include <entriesblk.h>
+SWORD_NAMESPACE_START
+
/******************************************************************************
* zStr Statics
*/
@@ -124,14 +125,13 @@ void zStr::getKeyFromDatOffset(long ioffset, char **buf) {
if ((ch == '\\') || (ch == 10) || (ch == 13))
break;
}
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
+ *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
if (size) {
lseek(datfd->getFd(), ioffset, SEEK_SET);
read(datfd->getFd(), *buf, size);
}
(*buf)[size] = 0;
- for (size--; size > 0; size--)
- (*buf)[size] = SW_toupper((*buf)[size]);
+ toupperstr_utf8(*buf, size*2);
}
else {
*buf = (*buf) ? (char *)realloc(*buf, 1) : (char *)malloc(1);
@@ -183,8 +183,8 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) {
tailoff = maxoff = lseek(idxfd->getFd(), 0, SEEK_END) - IDXENTRYSIZE;
if (*ikey) {
headoff = 0;
- stdstr(&key, ikey);
- toupperstr(key);
+ stdstr(&key, ikey, 3);
+ toupperstr_utf8(key, strlen(key)*3);
while (headoff < tailoff) {
tryoff = (lastoff == -1) ? headoff + (((((tailoff / IDXENTRYSIZE) - (headoff / IDXENTRYSIZE))) / 2) * IDXENTRYSIZE) : lastoff;
@@ -281,11 +281,12 @@ signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) {
* text.
*/
-void zStr::prepText(char *buf) {
- char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
-
- for (to = from = buf; *from; from++) {
- switch (*from) {
+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;
@@ -294,14 +295,16 @@ void zStr::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;
@@ -310,27 +313,27 @@ void zStr::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];
}
- *to = 0;
+ buf.setSize(to);
- while (to > (buf+1)) { // remove trailing excess
+ while (to > 1) { // remove trailing excess
to--;
- if ((*to == 10) || (*to == ' '))
- *to = 0;
+ if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
+ buf.setSize(to);
else break;
}
}
/******************************************************************************
- * zStr::gettext - gets text at a given offset
+ * zStr::getText - gets text at a given offset
*
* ENT:
* offset - idxoffset where the key is located.
@@ -355,8 +358,8 @@ void zStr::getText(long offset, char **idxbuf, char **buf) {
start = swordtoarch32(start);
size = swordtoarch32(size);
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
- *idxbuf = (*idxbuf) ? (char *)realloc(*idxbuf, size + 1) : (char *)malloc(size + 1);
+ *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
+ *idxbuf = (*idxbuf) ? (char *)realloc(*idxbuf, size*2 + 1) : (char *)malloc(size*2 + 1);
memset(*buf, 0, size + 1);
memset(*idxbuf, 0, size + 1);
lseek(datfd->getFd(), start, SEEK_SET);
@@ -378,7 +381,7 @@ void zStr::getText(long offset, char **idxbuf, char **buf) {
break;
}
}
- findKeyIndex(*buf + IDXENTRYSIZE, &offset);
+ findKeyIndex(*buf + 6, &offset);
}
else break;
}
@@ -419,21 +422,24 @@ void zStr::getCompressedText(long block, long entry, char **buf) {
start = swordtoarch32(start);
size = swordtoarch32(size);
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
-
+ SWBuf buf;
+ buf.setSize(size + 5);
lseek(zdtfd->getFd(), start, SEEK_SET);
- read(zdtfd->getFd(), *buf, size);
+ read(zdtfd->getFd(), buf.getRawData(), size);
flushCache();
unsigned long len = size;
- compressor->zBuf(&len, *buf);
- char * rawBuf = compressor->Buf(0, &len);
+ buf.setSize(size);
+ rawZFilter(buf, 0); // 0 = decipher
+
+ compressor->zBuf(&len, buf.getRawData());
+ char *rawBuf = compressor->Buf(0, &len);
cacheBlock = new EntriesBlock(rawBuf, len);
cacheBlockIndex = block;
}
size = cacheBlock->getEntrySize(entry);
- *buf = (*buf) ? (char *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
+ *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
strcpy(*buf, cacheBlock->getEntry(entry));
}
@@ -461,8 +467,9 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
char *outbuf = 0;
char *ch = 0;
- stdstr(&key, ikey);
- toupperstr(key);
+ len = (len < 0) ? strlen(buf) : len;
+ stdstr(&key, ikey, 3);
+ toupperstr_utf8(key, strlen(key)*3);
char notFound = findKeyIndex(ikey, &idxoff, 0);
if (!notFound) {
@@ -473,7 +480,7 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
else if (diff > 0) {
idxoff += IDXENTRYSIZE;
}
- else if ((!diff) && (len || strlen(buf) /*we're not deleting*/)) { // got absolute entry
+ else if ((!diff) && (len > 0 /*we're not deleting*/)) { // got absolute entry
do {
lseek(idxfd->getFd(), idxoff, SEEK_SET);
read(idxfd->getFd(), &start, sizeof(__u32));
@@ -495,7 +502,7 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
memmove(tmpbuf, ch, size - (unsigned long)(ch-tmpbuf));
// resolve link
- if (!strncmp(tmpbuf, "@LINK", 5) && (len ? len : strlen(buf))) {
+ if (!strncmp(tmpbuf, "@LINK", 5) && (len)) {
for (ch = tmpbuf; *ch; ch++) { // null before nl
if (*ch == 10) {
*ch = 0;
@@ -521,10 +528,10 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
read(idxfd->getFd(), idxBytes, shiftSize);
}
- outbuf = new char [ (len ? len : strlen(buf)) + strlen(key) + 5 ];
+ outbuf = new char [ len + strlen(key) + 5 ];
sprintf(outbuf, "%s%c%c", key, 13, 10);
size = strlen(outbuf);
- if (len ? len : strlen(buf)) { // NOT a link
+ if (len > 0) { // NOT a link
if (!cacheBlock) {
flushCache();
cacheBlock = new EntriesBlock();
@@ -544,8 +551,8 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
size += (sizeof(__u32) * 2);
}
else { // link
- memcpy(outbuf + size, buf, len ? len : strlen(buf));
- size += (len ? len : strlen(buf));
+ memcpy(outbuf + size, buf, len);
+ size += len;
}
start = lseek(datfd->getFd(), 0, SEEK_END);
@@ -554,7 +561,7 @@ void zStr::setText(const char *ikey, const char *buf, long len) {
outsize = archtosword32(size);
lseek(idxfd->getFd(), idxoff, SEEK_SET);
- if (len ? len : strlen(buf)) {
+ if (len > 0) {
lseek(datfd->getFd(), start, SEEK_SET);
write(datfd->getFd(), outbuf, size);
@@ -610,6 +617,12 @@ void zStr::flushCache() {
compressor->Buf(rawBuf, &size);
compressor->zBuf(&size);
+ SWBuf buf;
+ buf.setSize(size + 5);
+ memcpy(buf.getRawData(), compressor->zBuf(&size), size); // 1 = encipher
+ buf.setSize(size);
+ rawZFilter(buf, 1); // 1 = encipher
+
long zdxSize = lseek(zdxfd->getFd(), 0, SEEK_END);
long zdtSize = lseek(zdtfd->getFd(), 0, SEEK_END);
@@ -640,20 +653,18 @@ void zStr::flushCache() {
lseek(zdxfd->getFd(), cacheBlockIndex * ZDXENTRYSIZE, SEEK_SET);
lseek(zdtfd->getFd(), start, SEEK_SET);
- rawBuf = compressor->zBuf(&size);
- write(zdtfd->getFd(), rawBuf, size);
+ write(zdtfd->getFd(), buf, size);
// add a new line to make data file easier to read in an editor
write(zdtfd->getFd(), &nl, 2);
write(zdxfd->getFd(), &outstart, sizeof(__u32));
write(zdxfd->getFd(), &outsize, sizeof(__u32));
-
- delete cacheBlock;
}
+ delete cacheBlock;
+ cacheBlock = 0;
}
cacheBlockIndex = -1;
- cacheBlock = 0;
cacheDirty = false;
}
@@ -703,3 +714,5 @@ signed char zStr::createModule(const char *ipath) {
return 0;
}
+
+SWORD_NAMESPACE_END
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