summaryrefslogtreecommitdiff
path: root/src/modules/genbook/rawgenbook/rawgenbook.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/genbook/rawgenbook/rawgenbook.cpp')
-rw-r--r--src/modules/genbook/rawgenbook/rawgenbook.cpp75
1 files changed, 40 insertions, 35 deletions
diff --git a/src/modules/genbook/rawgenbook/rawgenbook.cpp b/src/modules/genbook/rawgenbook/rawgenbook.cpp
index 22cc51f..eff68f5 100644
--- a/src/modules/genbook/rawgenbook/rawgenbook.cpp
+++ b/src/modules/genbook/rawgenbook/rawgenbook.cpp
@@ -1,9 +1,26 @@
/******************************************************************************
- * rawtext.cpp - code for class 'RawGenBook'- a module that reads raw text files:
- * ot and nt using indexs ??.bks ??.cps ??.vss
+ * rawtext.cpp - code for class 'RawGenBook'- a module that reads raw text
+ * files: ot and nt using indexs ??.bks ??.cps ??.vss
+ *
+ *
+ * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
*/
+
#include <stdio.h>
#include <fcntl.h>
@@ -82,34 +99,16 @@ SWBuf &RawGenBook::getRawEntryBuf() {
__u32 offset = 0;
__u32 size = 0;
- TreeKey *key = 0;
- SWTRY {
- key = SWDYNAMIC_CAST(TreeKey, (this->key));
- }
- SWCATCH ( ... ) {}
-
- if (!key) {
- VerseTreeKey *tkey = 0;
- SWTRY {
- tkey = SWDYNAMIC_CAST(VerseTreeKey, (this->key));
- }
- SWCATCH ( ... ) {}
- if (tkey) key = tkey->getTreeKey();
- }
-
- if (!key) {
- key = (TreeKeyIdx *)CreateKey();
- (*key) = *(this->key);
- }
+ const TreeKey &key = getTreeKey();
int dsize;
- key->getUserData(&dsize);
+ key.getUserData(&dsize);
entryBuf = "";
if (dsize > 7) {
- memcpy(&offset, key->getUserData(), 4);
+ memcpy(&offset, key.getUserData(), 4);
offset = swordtoarch32(offset);
- memcpy(&size, key->getUserData() + 4, 4);
+ memcpy(&size, key.getUserData() + 4, 4);
size = swordtoarch32(size);
entrySize = size; // support getEntrySize call
@@ -120,15 +119,12 @@ SWBuf &RawGenBook::getRawEntryBuf() {
bdtfd->read(entryBuf.getRawData(), size);
rawFilter(entryBuf, 0); // hack, decipher
- rawFilter(entryBuf, key);
+ rawFilter(entryBuf, &key);
// if (!isUnicode())
- RawStr::prepText(entryBuf);
+ SWModule::prepText(entryBuf);
}
- if (key != this->key) // free our key if we created a VerseKey
- delete key;
-
return entryBuf;
}
@@ -137,7 +133,7 @@ void RawGenBook::setEntry(const char *inbuf, long len) {
__u32 offset = archtosword32(bdtfd->seek(0, SEEK_END));
__u32 size = 0;
- TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+ TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
char userData[8];
@@ -156,7 +152,7 @@ void RawGenBook::setEntry(const char *inbuf, long len) {
void RawGenBook::linkEntry(const SWKey *inkey) {
TreeKeyIdx *srckey = 0;
- TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+ TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
// see if we have a VerseKey * or decendant
SWTRY {
srckey = SWDYNAMIC_CAST(TreeKeyIdx, inkey);
@@ -183,7 +179,7 @@ void RawGenBook::linkEntry(const SWKey *inkey) {
*/
void RawGenBook::deleteEntry() {
- TreeKeyIdx *key = ((TreeKeyIdx *)this->key);
+ TreeKeyIdx *key = ((TreeKeyIdx *)&(getTreeKey()));
key->remove();
}
@@ -211,9 +207,18 @@ char RawGenBook::createModule(const char *ipath) {
}
-SWKey *RawGenBook::CreateKey() {
- TreeKeyIdx *newKey = new TreeKeyIdx(path);
- return (verseKey) ? (SWKey *)new VerseTreeKey(newKey) : newKey;
+SWKey *RawGenBook::CreateKey() const {
+ TreeKey *tKey = new TreeKeyIdx(path);
+ if (verseKey) { SWKey *vtKey = new VerseTreeKey(tKey); delete tKey; return vtKey; }
+ return tKey;
+}
+
+bool RawGenBook::hasEntry(const SWKey *k) const {
+ TreeKey &key = getTreeKey(k);
+
+ int dsize;
+ key.getUserData(&dsize);
+ return (dsize > 7) && key.Error() == '\x00';
}
SWORD_NAMESPACE_END