summaryrefslogtreecommitdiff
path: root/src/modules/lexdict/rawld4/rawld4.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/lexdict/rawld4/rawld4.cpp')
-rw-r--r--src/modules/lexdict/rawld4/rawld4.cpp100
1 files changed, 49 insertions, 51 deletions
diff --git a/src/modules/lexdict/rawld4/rawld4.cpp b/src/modules/lexdict/rawld4/rawld4.cpp
index 0fd1058..6d60d9a 100644
--- a/src/modules/lexdict/rawld4/rawld4.cpp
+++ b/src/modules/lexdict/rawld4/rawld4.cpp
@@ -1,11 +1,24 @@
/******************************************************************************
* rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and
- * dictionary files: *.dat *.idx
+ * dictionary files: *.dat *.idx
+ *
+ *
+ * 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 <ctype.h>
-#include <stdio.h>
#include <fcntl.h>
#include <filemgr.h>
@@ -13,6 +26,8 @@
#include <rawstr4.h>
#include <rawld4.h>
+#include <stdio.h>
+
SWORD_NAMESPACE_START
/******************************************************************************
@@ -44,50 +59,6 @@ bool RawLD4::isWritable() {
/******************************************************************************
- * RawLD4::strongsPad - Pads a key if (it-1) is 100% digits to 5 places
- * allows for final to be alpha, e.g. '123B'
- *
- * ENT: buf - buffer to check and pad
- */
-
-void RawLD4::strongsPad(char *buf)
-{
- char *check;
- int size = 0;
- int len = strlen(buf);
- char subLet = 0;
- bool bang = false;
- if ((len < 8) && (len > 0)) {
- for (check = buf; *(check+1); check++) {
- if (!isdigit(*check))
- break;
- else size++;
- }
-
- if (size && ((size == (len-1)) || (size == (len-2)))) {
- if (*check == '!') {
- bang = true;
- check++;
- }
- if (isalpha(*check)) {
- subLet = toupper(*check);
- *(check-(bang?1:0)) = 0;
- }
- sprintf(buf, "%.5d", atoi(buf));
- if (subLet) {
- check = buf+(strlen(buf));
- if (bang) {
- *check++ = '!';
- }
- *check++ = subLet;
- *check = 0;
- }
- }
- }
-}
-
-
-/******************************************************************************
* RawLD4::getEntry - Looks up entry from data file. 'Snaps' to closest
* entry and sets 'entrybuf'.
*
@@ -98,10 +69,10 @@ void RawLD4::strongsPad(char *buf)
char RawLD4::getEntry(long away)
{
- long start = 0;
- unsigned long size = 0;
+ __u32 start = 0;
+ __u32 size = 0;
char *idxbuf = 0;
- char retval = 0;
+ char retval = 0;
char *buf = new char [ strlen(*key) + 6 ];
strcpy(buf, *key);
@@ -189,4 +160,31 @@ void RawLD4::deleteEntry() {
doSetText(*key, "");
}
+long RawLD4::getEntryCount() const {
+ if (idxfd < 0) return 0;
+ return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
+}
+
+long RawLD4::getEntryForKey(const char *key) const {
+ __u32 start, offset;
+ __u32 size;
+
+ char *buf = new char [ strlen(key) + 6 ];
+ strcpy(buf, key);
+
+ strongsPad(buf);
+
+ findOffset(buf, &start, &size, 0, &offset);
+
+ delete [] buf;
+
+ return offset / IDXENTRYSIZE;
+}
+
+char *RawLD4::getKeyForEntry(long entry) const {
+ char *key = 0;
+ getIDXBuf(entry * IDXENTRYSIZE, &key);
+ return key;
+}
+
SWORD_NAMESPACE_END