summaryrefslogtreecommitdiff
path: root/src/modules/comments/rawfiles/rawfiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/comments/rawfiles/rawfiles.cpp')
-rw-r--r--src/modules/comments/rawfiles/rawfiles.cpp58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/modules/comments/rawfiles/rawfiles.cpp b/src/modules/comments/rawfiles/rawfiles.cpp
index b0e24fc..7c2d524 100644
--- a/src/modules/comments/rawfiles/rawfiles.cpp
+++ b/src/modules/comments/rawfiles/rawfiles.cpp
@@ -1,10 +1,12 @@
/******************************************************************************
- * rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs
- * pointing to actual text desired. Uses standard
+ *
+ * rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML
+ * HREFs pointing to actual text desired. Uses standard
* files: ot and nt using indexs ??.bks ??.cps ??.vss
*
+ * $Id: rawfiles.cpp 2833 2013-06-29 06:40:28Z chrislit $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -57,31 +59,31 @@ RawFiles::~RawFiles()
/** Is the module writable? :)
* @return yes or no
*/
-bool RawFiles::isWritable() {
+bool RawFiles::isWritable() const {
return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
}
/******************************************************************************
- * RawFiles::getRawEntry - Returns the correct verse when char * cast
- * is requested
+ * RawFiles::getRawEntry - Retrieve the unprocessed entry contents at
+ * the current key position of this module
*
- * RET: string buffer with verse
+ * RET: entry contents
*/
-SWBuf &RawFiles::getRawEntryBuf() {
+SWBuf &RawFiles::getRawEntryBuf() const {
FileDesc *datafile;
long start = 0;
unsigned short size = 0;
VerseKey *key = &getVerseKey();
- findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
+ findOffset(key->getTestament(), key->getTestamentIndex(), &start, &size);
entryBuf = "";
if (size) {
SWBuf tmpbuf = path;
tmpbuf += '/';
- readText(key->Testament(), start, size, entryBuf);
+ readText(key->getTestament(), start, size, entryBuf);
tmpbuf += entryBuf;
entryBuf = "";
datafile = FileMgr::getSystemFileMgr()->open(tmpbuf.c_str(), FileMgr::RDONLY);
@@ -102,7 +104,7 @@ SWBuf &RawFiles::getRawEntryBuf() {
/******************************************************************************
- * RawFiles::setEntry(char *)- Update the modules current key entry with
+ * RawFiles::setEntry(char *)- Update the module's current key entry with
* provided text
*/
@@ -114,13 +116,13 @@ void RawFiles::setEntry(const char *inbuf, long len) {
len = (len<0)?strlen(inbuf):len;
- findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
+ findOffset(key->getTestament(), key->getTestamentIndex(), &start, &size);
if (size) {
SWBuf tmpbuf;
entryBuf = path;
entryBuf += '/';
- readText(key->Testament(), start, size, tmpbuf);
+ readText(key->getTestament(), start, size, tmpbuf);
entryBuf += tmpbuf;
}
else {
@@ -128,7 +130,7 @@ void RawFiles::setEntry(const char *inbuf, long len) {
entryBuf = path;
entryBuf += '/';
tmpbuf = getNextFilename();
- doSetText(key->Testament(), key->TestamentIndex(), tmpbuf);
+ doSetText(key->getTestament(), key->getTestamentIndex(), tmpbuf);
entryBuf += tmpbuf;
}
datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
@@ -152,14 +154,14 @@ void RawFiles::linkEntry(const SWKey *inkey) {
unsigned short size;
const VerseKey *key = &getVerseKey();
- findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
+ findOffset(key->getTestament(), key->getTestamentIndex(), &start, &size);
if (size) {
SWBuf tmpbuf;
- readText(key->Testament(), start, size + 2, tmpbuf);
+ readText(key->getTestament(), start, size + 2, tmpbuf);
key = &getVerseKey(inkey);
- doSetText(key->Testament(), key->TestamentIndex(), tmpbuf.c_str());
+ doSetText(key->getTestament(), key->getTestamentIndex(), tmpbuf.c_str());
}
}
@@ -172,7 +174,7 @@ void RawFiles::linkEntry(const SWKey *inkey) {
void RawFiles::deleteEntry() {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->TestamentIndex(), "");
+ doSetText(key->getTestament(), key->getTestamentIndex(), "");
}
@@ -183,22 +185,22 @@ void RawFiles::deleteEntry() {
* RET: filename
*/
-char *RawFiles::getNextFilename() {
- static char incfile[255];
- __u32 number;
+const char *RawFiles::getNextFilename() {
+ static SWBuf incfile;
+ __u32 number = 0;
FileDesc *datafile;
- sprintf(incfile, "%s/incfile", path);
+ incfile.setFormatted("%s/incfile", path);
datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::RDONLY);
-
- if (datafile->read(&number, 4) != 4) number = 0;
- number = swordtoarch32(number);
-
+ if (datafile->getFd() != -1) {
+ if (datafile->read(&number, 4) != 4) number = 0;
+ number = swordtoarch32(number);
+ }
number++;
FileMgr::getSystemFileMgr()->close(datafile);
datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
- sprintf(incfile, "%.7d", number-1);
+ incfile.setFormatted("%.7d", number-1);
number = archtosword32(number);
datafile->write(&number, 4);
@@ -208,7 +210,7 @@ char *RawFiles::getNextFilename() {
}
-char RawFiles::createModule (const char *path) {
+char RawFiles::createModule(const char *path) {
char *incfile = new char [ strlen (path) + 16 ];
__u32 zero = 0;