From 8c8aa6b07e595cfac56838b5964ab3e96051f1b2 Mon Sep 17 00:00:00 2001 From: "Roberto C. Sanchez" Date: Sat, 29 Mar 2014 10:53:49 -0400 Subject: Imported Upstream version 1.5.7 --- src/modules/comments/rawfiles/rawfiles.cpp | 112 ++++++++++++----------------- 1 file changed, 45 insertions(+), 67 deletions(-) (limited to 'src/modules/comments/rawfiles') diff --git a/src/modules/comments/rawfiles/rawfiles.cpp b/src/modules/comments/rawfiles/rawfiles.cpp index c8e9388..9ffa00f 100644 --- a/src/modules/comments/rawfiles/rawfiles.cpp +++ b/src/modules/comments/rawfiles/rawfiles.cpp @@ -15,7 +15,6 @@ #include #endif -#include #include #include #include @@ -25,6 +24,7 @@ #define O_BINARY 0 // If it hasn't been defined than we probably #endif // don't need it. +SWORD_NAMESPACE_START /****************************************************************************** * RawFiles Constructor - Initializes data for instance of RawFiles @@ -49,13 +49,13 @@ RawFiles::~RawFiles() /****************************************************************************** - * RawFiles::operator char * - Returns the correct verse when char * cast + * RawFiles::getRawEntry - Returns the correct verse when char * cast * is requested * * RET: string buffer with verse */ -char *RawFiles::getRawEntry() { +SWBuf &RawFiles::getRawEntryBuf() { FileDesc *datafile; long start = 0; unsigned short size = 0; @@ -73,148 +73,125 @@ char *RawFiles::getRawEntry() { if (!key) key = new VerseKey(this->key); - findoffset(key->Testament(), key->Index(), &start, &size); - - if (entrybuf) - delete [] entrybuf; + findOffset(key->Testament(), key->Index(), &start, &size); + entryBuf = ""; if (size) { - tmpbuf = new char [ (size + 2) + strlen(path) + 5 ]; - sprintf(tmpbuf,"%s/",path); - gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf)); - datafile = FileMgr::systemFileMgr.open(tmpbuf, O_RDONLY|O_BINARY); - delete [] tmpbuf; + SWBuf tmpbuf = path; + tmpbuf += '/'; + readText(key->Testament(), start, size, entryBuf); + tmpbuf += entryBuf; + entryBuf = ""; + datafile = FileMgr::systemFileMgr.open(tmpbuf.c_str(), O_RDONLY|O_BINARY); if (datafile->getFd() > 0) { size = lseek(datafile->getFd(), 0, SEEK_END); - entrybuf = new char [ size * FILTERPAD ]; - memset(entrybuf, 0, size * FILTERPAD); + char *tmpBuf = new char [ size + 1 ]; + memset(tmpBuf, 0, size + 1); lseek(datafile->getFd(), 0, SEEK_SET); - read(datafile->getFd(), entrybuf, size); - preptext(entrybuf); - } - else { - entrybuf = new char [2]; - entrybuf[0] = 0; - entrybuf[1] = 0; + read(datafile->getFd(), tmpBuf, size); + entryBuf = tmpBuf; + delete [] tmpBuf; +// preptext(entrybuf); } FileMgr::systemFileMgr.close(datafile); } - else { - entrybuf = new char [2]; - entrybuf[0] = 0; - entrybuf[1] = 0; - } if (key != this->key) delete key; - return entrybuf; + return entryBuf; } /****************************************************************************** - * RawFiles::operator << (char *)- Update the modules current key entry with + * RawFiles::setEntry(char *)- Update the modules current key entry with * provided text - * - * RET: *this */ -SWModule &RawFiles::operator <<(const char *inbuf) { +void RawFiles::setEntry(const char *inbuf, long len) { FileDesc *datafile; long start; unsigned short size; - char *tmpbuf; VerseKey *key = 0; -#ifndef _WIN32_WCE + len = (len<0)?strlen(inbuf):len; try { -#endif key = SWDYNAMIC_CAST(VerseKey, this->key); -#ifndef _WIN32_WCE } catch ( ... ) {} -#endif if (!key) key = new VerseKey(this->key); - findoffset(key->Testament(), key->Index(), &start, &size); + findOffset(key->Testament(), key->Index(), &start, &size); if (size) { - tmpbuf = new char [ (size + 2) + strlen(path) + 1 ]; - sprintf(tmpbuf, "%s/", path); - gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf)); + SWBuf tmpbuf; + entryBuf = path; + entryBuf += '/'; + readText(key->Testament(), start, size, tmpbuf); + entryBuf += tmpbuf; } else { - tmpbuf = new char [ 16 + strlen(path) + 1 ]; - sprintf(tmpbuf, "%s/%s", path, getnextfilename()); - settext(key->Testament(), key->Index(), tmpbuf+strlen(path)+1); + SWBuf tmpbuf; + entryBuf = path; + entryBuf += '/'; + tmpbuf = getNextFilename(); + doSetText(key->Testament(), key->Index(), tmpbuf); + entryBuf += tmpbuf; } - datafile = FileMgr::systemFileMgr.open(tmpbuf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC); - delete [] tmpbuf; + datafile = FileMgr::systemFileMgr.open(entryBuf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC); if (datafile->getFd() > 0) { - write(datafile->getFd(), inbuf, strlen(inbuf)); + write(datafile->getFd(), inbuf, len); } FileMgr::systemFileMgr.close(datafile); if (key != this->key) delete key; - - return *this; } /****************************************************************************** - * RawFiles::operator << (SWKey *)- Link the modules current key entry with + * RawFiles::linkEntry(SWKey *)- Link the modules current key entry with * another module entry * * RET: *this */ -SWModule &RawFiles::operator <<(const SWKey *inkey) { +void RawFiles::linkEntry(const SWKey *inkey) { long start; unsigned short size; char *tmpbuf; const VerseKey *key = 0; -#ifndef _WIN32_WCE try { -#endif key = SWDYNAMIC_CAST(VerseKey, inkey); -#ifndef _WIN32_WCE } catch ( ... ) {} -#endif if (!key) key = new VerseKey(this->key); - findoffset(key->Testament(), key->Index(), &start, &size); + findOffset(key->Testament(), key->Index(), &start, &size); if (size) { - tmpbuf = new char [ size + 2]; - gettext(key->Testament(), start, size + 2, tmpbuf); + SWBuf tmpbuf; + readText(key->Testament(), start, size + 2, tmpbuf); if (key != inkey) delete key; key = 0; -#ifndef _WIN32_WCE try { -#endif key = SWDYNAMIC_CAST(VerseKey, inkey); -#ifndef _WIN32_WCE } catch ( ... ) {} -#endif if (!key) key = new VerseKey(this->key); - settext(key->Testament(), key->Index(), tmpbuf); + doSetText(key->Testament(), key->Index(), tmpbuf.c_str()); } if (key != inkey) delete key; - - return *this; } @@ -239,7 +216,7 @@ void RawFiles::deleteEntry() { if (!key) key = new VerseKey(this->key); - settext(key->Testament(), key->Index(), ""); + doSetText(key->Testament(), key->Index(), ""); if (key != this->key) delete key; @@ -247,13 +224,13 @@ void RawFiles::deleteEntry() { /****************************************************************************** - * RawFiles::getnextfilename - generates a valid filename in which to store + * RawFiles::getNextfilename - generates a valid filename in which to store * an entry * * RET: filename */ -char *RawFiles::getnextfilename() { +char *RawFiles::getNextFilename() { static char incfile[255]; long number; FileDesc *datafile; @@ -289,3 +266,4 @@ char RawFiles::createModule (const char *path) { +SWORD_NAMESPACE_END -- cgit v1.2.3