diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:49 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:49 -0400 |
commit | 8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch) | |
tree | da38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/modules/common/rawverse.cpp | |
parent | 8d3fc864d094eeadc721f8e93436b37a5fab173e (diff) |
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/common/rawverse.cpp')
-rw-r--r-- | src/modules/common/rawverse.cpp | 64 |
1 files changed, 36 insertions, 28 deletions
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 |