diff options
Diffstat (limited to 'src/modules/lexdict')
-rw-r--r-- | src/modules/lexdict/rawld/rawld.cpp | 99 | ||||
-rw-r--r-- | src/modules/lexdict/rawld4/rawld4.cpp | 100 | ||||
-rw-r--r-- | src/modules/lexdict/swld.cpp | 85 | ||||
-rw-r--r-- | src/modules/lexdict/zld/zld.cpp | 96 |
4 files changed, 232 insertions, 148 deletions
diff --git a/src/modules/lexdict/rawld/rawld.cpp b/src/modules/lexdict/rawld/rawld.cpp index 08be215..e6a4d57 100644 --- a/src/modules/lexdict/rawld/rawld.cpp +++ b/src/modules/lexdict/rawld/rawld.cpp @@ -1,11 +1,24 @@ /****************************************************************************** * rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and * 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 +26,8 @@ #include <rawld.h> #include <filemgr.h> +#include <stdio.h> + SWORD_NAMESPACE_START /****************************************************************************** @@ -44,50 +59,6 @@ bool RawLD::isWritable() { /****************************************************************************** - * RawLD::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 RawLD::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; - } - } - } -} - - -/****************************************************************************** * RawLD::getEntry - Looks up entry from data file. 'Snaps' to closest * entry and sets 'entrybuf'. * @@ -98,8 +69,8 @@ void RawLD::strongsPad(char *buf) char RawLD::getEntry(long away) { - long start = 0; - unsigned short size = 0; + __u32 start = 0; + __u16 size = 0; char *idxbuf = 0; char retval = 0; @@ -191,4 +162,34 @@ void RawLD::deleteEntry() { doSetText(*key, ""); } + +long RawLD::getEntryCount() const { + if (idxfd < 0) return 0; + return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE; +} + + +long RawLD::getEntryForKey(const char *key) const { + __u32 start, offset; + __u16 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 *RawLD::getKeyForEntry(long entry) const { + char *key = 0; + getIDXBuf(entry * IDXENTRYSIZE, &key); + return key; +} + SWORD_NAMESPACE_END 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 diff --git a/src/modules/lexdict/swld.cpp b/src/modules/lexdict/swld.cpp index 518e5c0..bccf5d8 100644 --- a/src/modules/lexdict/swld.cpp +++ b/src/modules/lexdict/swld.cpp @@ -1,8 +1,26 @@ /****************************************************************************** * swld.cpp - code for base class 'SWLD'. SWLD is the basis for all - * types of Lexicon and Dictionary modules (hence the 'LD'). + * types of Lexicon and Dictionary modules (hence the 'LD'). + * + * + * 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 <swld.h> #include <strkey.h> @@ -36,7 +54,7 @@ SWLD::~SWLD() } -SWKey *SWLD::CreateKey() { return new StrKey(); } +SWKey *SWLD::CreateKey() const { return new StrKey(); } /****************************************************************************** @@ -78,5 +96,68 @@ void SWLD::setPosition(SW_POSITION p) { getRawEntryBuf(); } +bool SWLD::hasEntry(const SWKey *key) const { + const char *key_str = *key; + char *buf = new char [ strlen(key_str) + 6 ]; + strcpy(buf, key_str); + + strongsPad(buf); + + bool retVal = !strcmp(buf, getKeyForEntry(getEntryForKey(buf))); + delete buf; + + return retVal; +} + +/****************************************************************************** + * SWLD::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 SWLD::strongsPad(char *buf) +{ + char *check; + int size = 0; + int len = strlen(buf); + char subLet = 0; + bool bang = false, prefix=false; + if ((len < 9) && (len > 0)) { + // Handle initial G or H + if (*buf == 'G' || *buf == 'H' || *buf == 'g' || *buf == 'h') { + buf += 1; + len -= 1; + prefix = true; + } + + for (check = buf; *(check); check++) { + if (!isdigit(*check)) + break; + else size++; + } + + if (size && ((size == len) || (size == len - 1) || (size == (len-2)))) { + if (*check == '!') { + bang = true; + check++; + } + if (isalpha(*check)) { + subLet = toupper(*check); + *(check-(bang?1:0)) = 0; + } + sprintf(buf, prefix?"%.4d":"%.5d", atoi(buf)); + if (subLet) { + check = buf+(strlen(buf)); + if (bang) { + *check++ = '!'; + } + *check++ = subLet; + *check = 0; + } + } + } +} + SWORD_NAMESPACE_END 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 |