diff options
Diffstat (limited to 'src/modules/lexdict/zld/zld.cpp')
-rw-r--r-- | src/modules/lexdict/zld/zld.cpp | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/src/modules/lexdict/zld/zld.cpp b/src/modules/lexdict/zld/zld.cpp index bcb51ab..4e786bc 100644 --- a/src/modules/lexdict/zld/zld.cpp +++ b/src/modules/lexdict/zld/zld.cpp @@ -1,11 +1,23 @@ /****************************************************************************** * 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 <utilstr.h> @@ -13,6 +25,8 @@ #include <zld.h> #include <filemgr.h> +#include <stdio.h> + SWORD_NAMESPACE_START /****************************************************************************** @@ -44,48 +58,6 @@ bool zLD::isWritable() { /****************************************************************************** - * zLD::strongsPad - Pads a key if it is 100% digits to 5 places - * - * ENT: buf - buffer to check and pad - */ - -void zLD::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; - } - } - } -} - - -/****************************************************************************** * zLD::getEntry - Looks up entry from data file. 'Snaps' to closest * entry and sets 'entrybuf'. * @@ -186,4 +158,36 @@ void zLD::deleteEntry() { setText(*key, ""); } + +long zLD::getEntryCount() const +{ + if (idxfd < 0) return 0; + return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE; +} + + +long zLD::getEntryForKey(const char* key) const +{ + long offset; + char *buf = new char [ strlen(key) + 6 ]; + strcpy(buf, key); + + strongsPad(buf); + + findKeyIndex(buf, &offset); + + delete [] buf; + + return offset/IDXENTRYSIZE; +} + + +char *zLD::getKeyForEntry(long entry) const +{ + char *key = 0; + getKeyFromIdxOffset(entry * IDXENTRYSIZE, &key); + return key; +} + + SWORD_NAMESPACE_END |