[sword-svn] r2180 - in trunk: examples/classes include src/keys src/mgr src/modules src/modules/comments src/modules/comments/hrefcom src/modules/comments/rawcom src/modules/comments/rawcom4 src/modules/comments/rawfiles src/modules/comments/zcom src/modules/texts src/modules/texts/rawtext src/modules/texts/rawtext4 src/modules/texts/ztext tests
scribe at www.crosswire.org
scribe at www.crosswire.org
Sun Jul 13 13:29:26 MST 2008
Author: scribe
Date: 2008-07-13 13:29:25 -0700 (Sun, 13 Jul 2008)
New Revision: 2180
Added:
trunk/examples/classes/outplain.cpp
trunk/include/versemgr.h
trunk/src/mgr/versemgr.cpp
Modified:
trunk/include/Makefile.am
trunk/include/apocrypha.h
trunk/include/canon.h
trunk/include/rawtext.h
trunk/include/rawtext4.h
trunk/include/swconfig.h
trunk/include/swlocale.h
trunk/include/versekey.h
trunk/include/versetreekey.h
trunk/src/keys/versekey.cpp
trunk/src/keys/versetreekey.cpp
trunk/src/mgr/Makefile.am
trunk/src/mgr/localemgr.cpp
trunk/src/mgr/swconfig.cpp
trunk/src/mgr/swlocale.cpp
trunk/src/modules/comments/hrefcom/hrefcom.cpp
trunk/src/modules/comments/rawcom/rawcom.cpp
trunk/src/modules/comments/rawcom4/rawcom4.cpp
trunk/src/modules/comments/rawfiles/rawfiles.cpp
trunk/src/modules/comments/swcom.cpp
trunk/src/modules/comments/zcom/zcom.cpp
trunk/src/modules/swmodule.cpp
trunk/src/modules/texts/rawtext/rawtext.cpp
trunk/src/modules/texts/rawtext4/rawtext4.cpp
trunk/src/modules/texts/swtext.cpp
trunk/src/modules/texts/ztext/ztext.cpp
trunk/tests/indextest.cpp
trunk/tests/keytest.cpp
Log:
Added first cut of versification manager
It kindof works
Added: trunk/examples/classes/outplain.cpp
===================================================================
--- trunk/examples/classes/outplain.cpp (rev 0)
+++ trunk/examples/classes/outplain.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * Class SWMgr manages installed modules for a frontend.
+ * SWMgr reads a mods.conf file to discover its information.
+ * It then instantiates the correct decendent of SWModule for each
+ * module entry in mods.conf
+ * The developer may use this class to query what modules are installed
+ * and to retrieve an (SWModule *) for any one of these modules
+ *
+ * SWMgr makes its modules available as an STL Map.
+ * The Map definition is typedef'ed as ModMap
+ * ModMap consists of: FIRST : SWBuf moduleName
+ * SECOND: SWModule *module
+ *
+ */
+
+#include <iostream>
+
+#include <swmgr.h>
+#include <swmodule.h>
+
+using namespace sword;
+using namespace std;
+
+int main(int argc, char **argv) {
+ SWMgr manager; // create a default manager that looks in the current directory for mods.conf
+
+ const char *bookName = (argc > 1) ? argv[1] : "WLC";
+ SWModule &book = *manager.getModule(bookName);
+ for (book = TOP; !book.Error(); book++) {
+ cout << book.StripText() << "\n";
+ }
+}
Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/Makefile.am 2008-07-13 20:29:25 UTC (rev 2180)
@@ -11,6 +11,7 @@
pkginclude_HEADERS += $(swincludedir)/entriesblk.h
pkginclude_HEADERS += $(swincludedir)/femain.h
pkginclude_HEADERS += $(swincludedir)/filemgr.h
+pkginclude_HEADERS += $(swincludedir)/versemgr.h
pkginclude_HEADERS += $(swincludedir)/flatapi.h
pkginclude_HEADERS += $(swincludedir)/ftpparse.h
pkginclude_HEADERS += $(swincludedir)/ftptrans.h
@@ -125,6 +126,7 @@
pkginclude_HEADERS += $(swincludedir)/teiplain.h
pkginclude_HEADERS += $(swincludedir)/teirtf.h
+pkginclude_HEADERS += $(swincludedir)/teihtmlhref.h
pkginclude_HEADERS += $(swincludedir)/treekey.h
pkginclude_HEADERS += $(swincludedir)/treekeyidx.h
Modified: trunk/include/apocrypha.h
===================================================================
--- trunk/include/apocrypha.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/apocrypha.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -29,7 +29,7 @@
//Data based on NRSVA unless otherwise noted; this book ordering is not necessarily optimal.
-struct sbook
+struct VersificationBook
VerseKey::otbooks[] = {
//Catholic Deuterocanon
{"Tobit", "Tob", 14}, //67
Modified: trunk/include/canon.h
===================================================================
--- trunk/include/canon.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/canon.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -19,85 +19,94 @@
*
*/
+#ifndef CANON_H
+#define CANON_H
+
+SWORD_NAMESPACE_START
+
+
/******************************************************************************
* [on]tbooks - initialize static instance for all canonical text names
* and chapmax
*/
-
-struct sbook
- VerseKey::otbooks[] = {
- {"Genesis", "Gen", 50},
- {"Exodus", "Exod", 40},
- {"Leviticus", "Lev", 27},
- {"Numbers", "Num", 36},
- {"Deuteronomy", "Deut", 34},
- {"Joshua", "Josh", 24},
- {"Judges", "Judg", 21},
- {"Ruth", "Ruth", 4},
- {"I Samuel", "1Sam", 31},
- {"II Samuel", "2Sam", 24},
- {"I Kings", "1Kgs", 22},
- {"II Kings", "2Kgs", 25},
- {"I Chronicles", "1Chr", 29},
- {"II Chronicles", "2Chr", 36},
- {"Ezra", "Ezra", 10},
- {"Nehemiah", "Neh", 13},
- {"Esther", "Esth", 10},
- {"Job", "Job", 42},
- {"Psalms", "Ps", 150},
- {"Proverbs", "Prov", 31},
- {"Ecclesiastes", "Eccl", 12},
- {"Song of Solomon", "Song", 8},
- {"Isaiah", "Isa", 66},
- {"Jeremiah", "Jer", 52},
- {"Lamentations", "Lam", 5},
- {"Ezekiel", "Ezek", 48},
- {"Daniel", "Dan", 12},
- {"Hosea", "Hos", 14},
- {"Joel", "Joel", 3},
- {"Amos", "Amos", 9},
- {"Obadiah", "Obad", 1},
- {"Jonah", "Jonah", 4},
- {"Micah", "Mic", 7},
- {"Nahum", "Nah", 3},
- {"Habakkuk", "Hab", 3},
- {"Zephaniah", "Zeph", 3},
- {"Haggai", "Hag", 2},
- {"Zechariah", "Zech", 14},
- {"Malachi", "Mal", 4}
+struct sbook otbooks[] = {
+ {"Genesis", "Gen", "Gen", 50},
+ {"Exodus", "Exod", "Exod", 40},
+ {"Leviticus", "Lev", "Lev", 27},
+ {"Numbers", "Num", "Num", 36},
+ {"Deuteronomy", "Deut", "Deut", 34},
+ {"Joshua", "Josh", "Josh", 24},
+ {"Judges", "Judg", "Judg", 21},
+ {"Ruth", "Ruth", "Ruth", 4},
+ {"I Samuel", "1Sam", "1Sam", 31},
+ {"II Samuel", "2Sam", "2Sam", 24},
+ {"I Kings", "1Kgs", "1Kgs", 22},
+ {"II Kings", "2Kgs", "2Kgs", 25},
+ {"I Chronicles", "1Chr", "1Chr", 29},
+ {"II Chronicles", "2Chr", "2Chr", 36},
+ {"Ezra", "Ezra", "Ezra", 10},
+ {"Nehemiah", "Neh", "Neh", 13},
+ {"Esther", "Esth", "Esth", 10},
+ {"Job", "Job", "Job", 42},
+ {"Psalms", "Ps", "Ps", 150},
+ {"Proverbs", "Prov", "Prov", 31},
+ {"Ecclesiastes", "Eccl", "Eccl", 12},
+ {"Song of Solomon", "Song", "Song", 8},
+ {"Isaiah", "Isa", "Isa", 66},
+ {"Jeremiah", "Jer", "Jer", 52},
+ {"Lamentations", "Lam", "Lam", 5},
+ {"Ezekiel", "Ezek", "Ezek", 48},
+ {"Daniel", "Dan", "Dan", 12},
+ {"Hosea", "Hos", "Hos", 14},
+ {"Joel", "Joel", "Joel", 3},
+ {"Amos", "Amos", "Amos", 9},
+ {"Obadiah", "Obad", "Obad", 1},
+ {"Jonah", "Jonah", "Jonah", 4},
+ {"Micah", "Mic", "Mic", 7},
+ {"Nahum", "Nah", "Nah", 3},
+ {"Habakkuk", "Hab", "Hab", 3},
+ {"Zephaniah", "Zeph", "Zeph", 3},
+ {"Haggai", "Hag", "Hag", 2},
+ {"Zechariah", "Zech", "Zech", 14},
+ {"Malachi", "Mal", "Mal", 4},
+ {"", "", "", 0}
};
-
-struct sbook
- VerseKey::ntbooks[] = {
- {"Matthew", "Matt", 28},
- {"Mark", "Mark", 16},
- {"Luke", "Luke", 24},
- {"John", "John", 21},
- {"Acts", "Acts", 28},
- {"Romans", "Rom", 16},
- {"I Corinthians", "1Cor", 16},
- {"II Corinthians", "2Cor", 13},
- {"Galatians", "Gal", 6},
- {"Ephesians", "Eph", 6},
- {"Philippians", "Phil", 4},
- {"Colossians", "Col", 4},
- {"I Thessalonians", "1Thess", 5},
- {"II Thessalonians", "2Thess", 3},
- {"I Timothy", "1Tim", 6},
- {"II Timothy", "2Tim", 4},
- {"Titus", "Titus", 3},
- {"Philemon", "Phlm", 1},
- {"Hebrews", "Heb", 13},
- {"James", "Jas", 5},
- {"I Peter", "1Pet", 5},
- {"II Peter", "2Pet", 3},
- {"I John", "1John", 5},
- {"II John", "2John", 1},
- {"III John", "3John", 1},
- {"Jude", "Jude", 1},
- {"Revelation of John", "Rev", 22}
+struct sbook ntbooks[] = {
+ {"Matthew", "Matt", "Matt", 28},
+ {"Mark", "Mark", "Mark", 16},
+ {"Luke", "Luke", "Luke", 24},
+ {"John", "John", "John", 21},
+ {"Acts", "Acts", "Acts", 28},
+ {"Romans", "Rom", "Rom", 16},
+ {"I Corinthians", "1Cor", "1Cor", 16},
+ {"II Corinthians", "2Cor", "2Cor", 13},
+ {"Galatians", "Gal", "Gal", 6},
+ {"Ephesians", "Eph", "Eph", 6},
+ {"Philippians", "Phil", "Phil", 4},
+ {"Colossians", "Col", "Col", 4},
+ {"I Thessalonians", "1Thess", "1Thess", 5},
+ {"II Thessalonians", "2Thess", "2Thess", 3},
+ {"I Timothy", "1Tim", "1Tim", 6},
+ {"II Timothy", "2Tim", "2Tim", 4},
+ {"Titus", "Titus", "Titus", 3},
+ {"Philemon", "Phlm", "Phlm", 1},
+ {"Hebrews", "Heb", "Heb", 13},
+ {"James", "Jas", "Jas", 5},
+ {"I Peter", "1Pet", "1Pet", 5},
+ {"II Peter", "2Pet", "2Pet", 3},
+ {"I John", "1John", "1John", 5},
+ {"II John", "2John", "2John", 1},
+ {"III John", "3John", "3John", 1},
+ {"Jude", "Jude", "Jude", 1},
+ {"Revelation of John", "Rev", "Rev", 22},
+ {"", "", "", 0}
};
+/* other OSIS abbrevs
+ "Bar","PrAzar",
+ "Bel","Sus","1Esd","2Esd","AddEsth","EpJer","Jdt","1Macc","2Macc","3Macc",
+ "4Macc","PrMan","Ps151","Sir","Tob","Wis"};
+*/
/******************************************************************************
* Abbreviations - MUST be in alphabetical order & by PRIORITY
@@ -105,8 +114,7 @@
* (e.g. key: "1CH"; match: "1CHRONICLES")
*/
-const struct abbrev
- VerseKey::builtin_abbrevs[] = {
+const struct abbrev builtin_abbrevs[] = {
{"1 C", 46}, // 1 Corinthians
{"1 CHRONICLES", 13}, // 1 Chronicles
{"1 CORINTHIANS", 46}, // 1 Corinthians
@@ -122,7 +130,7 @@
{"1C", 46}, // 1 Corinthians
{"1CHRONICLES", 13}, // 1 Chronicles
{"1CORINTHIANS", 46}, // 1 Corinthians
- {"1JN", 62}, // 1 John
+ {"1JN", 62}, // 1 John
{"1JOHN", 62}, // 1 John
{"1KGS", 11}, // 1 Kings
{"1KINGS", 11}, // 1 Kings
@@ -146,7 +154,7 @@
{"2C", 47}, // 2 Corinthians
{"2CHRONICLES", 14}, // 2 Chronicles
{"2CORINTHIANS", 47}, // 2 Corinthians
- {"2JN", 63}, // 2 John
+ {"2JN", 63}, // 2 John
{"2JOHN", 63}, // 2 John
{"2KGS", 12}, // 2 Kings
{"2KINGS", 12}, // 2 Kings
@@ -203,7 +211,7 @@
{"II C", 47}, // 2 Corinthians
{"II CHRONICLES", 14}, // 2 Chronicles
{"II CORINTHIANS", 47}, // 2 Corinthians
- {"II JN", 63}, // 2 John
+ {"II JN", 63}, // 2 John
{"II JOHN", 63}, // 2 John
{"II KGS", 12}, // 2 Kings
{"II KINGS", 12}, // 2 Kings
@@ -215,7 +223,7 @@
{"IIC", 47}, // 2 Corinthians
{"IICHRONICLES", 14}, // 2 Chronicles
{"IICORINTHIANS", 47}, // 2 Corinthians
- {"III JN", 64}, // 3 John
+ {"III JN", 64}, // 3 John
{"III JOHN", 64}, // 3 John
{"IIIJN", 64}, // 3 John
{"IIIJOHN", 64}, // 3 John
@@ -305,8 +313,7 @@
* Maximum verses per chapter
*/
-int
- VerseKey::vm[] = {
+int vm[] = {
// Genesis
31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38,
18, 34, 24, 20, 67, 34, 35, 46, 22, 35, 43, 55, 32, 20, 31, 29, 43, 36,
@@ -480,8 +487,7 @@
};
-long
- VerseKey::otbks[] = {
+long otbks[] = {
0, 1, 52, 93, 121, 158,
193, 218, 240, 245, 277, 302, 325,
351, 381, 418, 429, 443, 454, 497,
@@ -490,8 +496,7 @@
934, 938, 942, 946, 949, 964
};
-long
- VerseKey::otcps[] = {
+long otcps[] = {
0, 2, 3, 35, 61, 86,
113, 146, 169, 194, 217, 247, 280,
313, 334, 353, 378, 400, 417, 445,
@@ -633,8 +638,7 @@
24056, 24071, 24089, 24108
};
-long
- VerseKey::ntbks[] = {
+long ntbks[] = {
0, 1, 30, 47, 72, 94,
123, 140, 157, 171, 178, 185, 190,
195, 201, 205, 212, 217, 221, 223,
@@ -642,8 +646,7 @@
265
};
-long
- VerseKey::ntcps[] = {
+long ntcps[] = {
0, 2, 3, 29, 53, 71,
97, 146, 181, 211, 246, 285, 328,
359, 410, 469, 506, 546, 575, 603,
@@ -689,9 +692,12 @@
};
-int
- VerseKey::offsize[2][2] =
- { {sizeof (VerseKey::otbks) / sizeof(long), sizeof (VerseKey::otcps) / sizeof(long)}
-, {sizeof (VerseKey::ntbks) / sizeof(long), sizeof (VerseKey::ntcps) / sizeof(long)}
+int offsize[2][2] =
+ { {sizeof (otbks) / sizeof(long), sizeof (otcps) / sizeof(long)}
+, {sizeof (ntbks) / sizeof(long), sizeof (ntcps) / sizeof(long)}
};
+SWORD_NAMESPACE_END
+
+
+#endif
Modified: trunk/include/rawtext.h
===================================================================
--- trunk/include/rawtext.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/rawtext.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -34,8 +34,6 @@
class SWDLLEXPORT RawText : public SWText, public RawVerse {
- RawStr *fastSearch[2];
-
public:
RawText(const char *ipath, const char *iname = 0, const char *idesc = 0, SWDisplay * idisp = 0, SWTextEncoding encoding = ENC_UNKNOWN, SWTextDirection dir = DIRECTION_LTR, SWTextMarkup markup = FMT_UNKNOWN,
@@ -44,12 +42,6 @@
virtual SWBuf &getRawEntryBuf();
virtual void increment(int steps = 1);
virtual void decrement(int steps = 1) { increment(-steps); }
- virtual signed char createSearchFramework(
- void (*percent) (char, void *) = &nullPercent,
- void *percentUserData = 0);
- virtual void deleteSearchFramework();
- virtual bool hasSearchFramework() { return true; }
- virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
// write interface ----------------------------
virtual bool isWritable();
static char createModule(const char *path) { return RawVerse::createModule(path); }
Modified: trunk/include/rawtext4.h
===================================================================
--- trunk/include/rawtext4.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/rawtext4.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -35,8 +35,6 @@
class SWDLLEXPORT RawText4 : public SWText, public RawVerse4 {
- RawStr4 *fastSearch[2];
-
public:
RawText4(const char *ipath, const char *iname = 0, const char *idesc = 0, SWDisplay * idisp = 0, SWTextEncoding encoding = ENC_UNKNOWN, SWTextDirection dir = DIRECTION_LTR, SWTextMarkup markup = FMT_UNKNOWN,
@@ -45,12 +43,6 @@
virtual SWBuf &getRawEntryBuf();
virtual void increment(int steps = 1);
virtual void decrement(int steps = 1) { increment(-steps); }
- virtual signed char createSearchFramework(
- void (*percent) (char, void *) = &nullPercent,
- void *percentUserData = 0);
- virtual void deleteSearchFramework();
- virtual bool hasSearchFramework() { return true; }
- virtual ListKey &search(const char *istr, int searchType = 0, int flags = 0, SWKey * scope = 0, bool * justCheckIfSupported = 0, void (*percent)(char, void *) = &SWModule::nullPercent, void *percentUserData = 0);
// write interface ----------------------------
virtual bool isWritable();
static char createModule(const char *path) { return RawVerse4::createModule(path); }
Modified: trunk/include/swconfig.h
===================================================================
--- trunk/include/swconfig.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/swconfig.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -54,6 +54,7 @@
* @param ifilename The file, which should be used for this config.
*/
SWConfig(const char *ifilename);
+ SWConfig();
virtual ~SWConfig();
/** Load from disk
Modified: trunk/include/swlocale.h
===================================================================
--- trunk/include/swlocale.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/swlocale.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -48,8 +48,9 @@
char *description;
char *encoding;
struct abbrev *bookAbbrevs;
- char *BMAX;
- struct sbook **books;
+ int abbrevsCnt;
+ const char **bookLongNames;
+ const char **bookPrefAbbrev;
public:
SWLocale(const char *ifilename);
@@ -68,8 +69,7 @@
virtual const char *translate(const char *text);
virtual void augment(SWLocale &addFrom);
virtual SWLocale & operator +=(SWLocale &addFrom) { augment(addFrom); return *this; }
- virtual const struct abbrev *getBookAbbrevs();
- virtual void getBooks(char **iBMAX, struct sbook ***ibooks);
+ virtual const struct abbrev *getBookAbbrevs(int *retSize);
};
SWORD_NAMESPACE_END
Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/versekey.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -26,6 +26,7 @@
#include <swkey.h>
#include <swmacs.h>
#include <listkey.h>
+#include <versemgr.h>
#include <defs.h>
@@ -40,33 +41,10 @@
#define MAXBOOK SW_POSITION(POS_MAXBOOK)
-struct sbook
-{
- /**Name of book
- */
- const char *name;
- /**Preferred Abbreviation
- */
- const char *prefAbbrev;
-
- /**Maximum chapters in book
- */
- unsigned char chapmax;
- /** Array[chapmax] of maximum verses in chapters
- */
- int *versemax;
-};
-
-struct abbrev
-{
- const char *ab;
- int book;
-};
-
-
class SWLocale;
+
/**
* Class VerseKey
* The SWKey implementation used for verse based modules like Bibles or commentaries.
@@ -76,11 +54,9 @@
class LocaleCache {
public:
char *name;
- unsigned int abbrevsCnt;
SWLocale *locale;
LocaleCache() {
name = 0;
- abbrevsCnt = 0;
locale = 0;
}
virtual ~LocaleCache() {
@@ -93,14 +69,9 @@
static long *offsets[2][2];
static int offsize[2][2];
- /** number of instantiated VerseKey objects or derivitives
+ /** number of instantiated VerseKey objects or derivitives
*/
static int instance;
- static struct sbook otbooks[];
- static struct sbook ntbooks[];
- static const char *osisotbooks[];
- static const char *osisntbooks[];
- static const char **osisbooks[];
#if 1
static long otbks[];
static long otcps[];
@@ -111,11 +82,11 @@
static LocaleCache localeCache;
ListKey internalListKey;
- const struct abbrev *abbrevs;
+ const VerseMgr::System *refSys;
+
char *locale;
- int abbrevsCnt;
- /** The Testament: 0 - Old; 1 - New
+ /** The Testament: 0 - Module Heading; 1 - Old; 2 - New
*/
signed char testament;
mutable signed char book;
@@ -123,7 +94,7 @@
mutable signed int verse;
mutable char suffix;
- /** flag for auto normalization
+ /** flag for auto normalization
*/
char autonorm;
@@ -131,7 +102,6 @@
*/
char headings;
- int getBookAbbrev(const char *abbr);
void initBounds() const;
/** initialize and allocate books array
@@ -157,12 +127,14 @@
protected:
+ virtual int getBookAbbrev(const char *abbr);
+
/** Refresh keytext based on testament|book|chapter|verse
* default auto normalization to true
* default display headings option is false
*/
void freshtext() const;
- /** Parse a character array into testament|book|chapter|verse
+ /** Parse a character array into testament|book|chapter|verse
*
*/
virtual char parse(bool checkNormalize = true);
@@ -173,11 +145,7 @@
static long ntbks[];
static long ntcps[];
#endif
- static const char builtin_BMAX[2];
- static struct sbook *builtin_books[2];
- static const struct abbrev builtin_abbrevs[];
- const char *BMAX;
- struct sbook **books;
+ int BMAX[2];
/**
* VerseKey Constructor - initializes Instance of VerseKey
@@ -186,23 +154,23 @@
* See parse() for more detailed information)
*/
VerseKey(const char *ikey = 0);
-
+
/**
* VerseKey Constructor - initializes instance of VerseKey
*
* @param ikey base key (will take various forms of 'BOOK CH:VS'.
* See parse() for more detailed information)
- */
+ */
VerseKey(const SWKey *ikey);
-
+
/** VerseKey Constructor - initializes instance of VerseKey
* with boundariess - see also LowerBound()
* and UpperBound()
* @param min the lower boundary of the new VerseKey
* @param max the upper boundary of the new VerseKey
- */
+ */
VerseKey(const char *min, const char *max);
-
+
/** VerseKey Copy Constructor - will create a new VerseKey
* based on an existing SWKey
*
@@ -216,7 +184,7 @@
* @param k the VerseKey to copy from
*/
VerseKey(const VerseKey &k);
-
+
/** VerseKey Destructor
* Cleans up an instance of VerseKey
*/
@@ -229,33 +197,33 @@
* @return the lower boundary the key was set to
*/
VerseKey &LowerBound(const VerseKey &ub);
-
+
/** sets the upper boundary for this VerseKey
* and returns the new boundary
* @param ub the new upper boundary for this VerseKey
* @return the upper boundary the key was set to
*/
VerseKey &UpperBound(const VerseKey &ub);
-
+
/** gets the lower boundary of this VerseKey
* @return the lower boundary of this VerseKey
*/
VerseKey &LowerBound() const;
-
+
/** gets the upper boundary of this VerseKey
* @return the upper boundary of this VerseKey
*/
VerseKey &UpperBound() const;
-
+
/** clears the boundaries of this VerseKey
*/
void ClearBounds();
-
+
/** Creates a new SWKey based on the current VerseKey
* see also the Copy Constructor
*/
virtual SWKey *clone() const;
-
+
/** refreshes keytext before returning if cast to
* a (char *) is requested
*/
@@ -264,29 +232,29 @@
virtual void setText(const char *ikey, bool checkNormalize) { SWKey::setText(ikey); parse(checkNormalize); }
virtual void setText(const char *ikey) { SWKey::setText(ikey); parse(); }
virtual void copyFrom(const SWKey &ikey);
-
+
/** Equates this VerseKey to another VerseKey
*/
virtual void copyFrom(const VerseKey &ikey);
-
+
/** Only repositions this VerseKey to another VerseKey
*/
virtual void positionFrom(const VerseKey &ikey);
-
+
/** Positions this key
*
* @param newpos Position to set to.
* @return *this
*/
virtual void setPosition(SW_POSITION newpos);
-
+
/** Decrements key a number of verses
*
* @param steps Number of verses to jump backward
* @return *this
*/
virtual void decrement(int steps);
-
+
/** Increments key a number of verses
*
* @param steps Number of verses to jump forward
@@ -301,32 +269,38 @@
*
* @return value of testament
*/
- virtual char Testament() const;
-
+ virtual char Testament() const { return getTestament(); } // deprecated
+ virtual char getTestament() const;
+
/** Gets book
*
* @return value of book
*/
- virtual char Book() const;
-
+ virtual char Book() const { return getBook(); } // deprecated
+ virtual char getBook() const;
+
/** Gets chapter
*
* @return value of chapter
*/
- virtual int Chapter() const;
-
+ virtual int Chapter() const { return getChapter(); } // deprecated
+ virtual int getChapter() const;
+ virtual int getChapterMax() const;
+
/** Gets verse
*
* @return value of verse
*/
- virtual int Verse() const;
-
+ virtual int Verse() const { return getVerse(); } // deprecated
+ virtual int getVerse() const;
+ virtual int getVerseMax() const;
+
/** Gets verse suffix
*
* @return value of verse suffix
*/
virtual char getSuffix() const;
-
+
/** Sets/gets testament
*
* @param itestament value which to set testament
@@ -334,8 +308,9 @@
* @return if unchanged -> value of testament,
* if changed -> previous value of testament
*/
- virtual char Testament(char itestament);
-
+ virtual char Testament(char itestament) { char retVal = getTestament(); setTestament(itestament); return retVal; } // deprecated
+ virtual void setTestament(char itestament);
+
/** Sets/gets book
*
* @param ibook value which to set book
@@ -343,8 +318,9 @@
* @return if unchanged -> value of book,
* if changed -> previous value of book
*/
- virtual char Book(char ibook);
-
+ virtual char Book(char ibook) { char retVal = getBook(); setBook(ibook); return retVal; } // deprecated
+ virtual void setBook(char ibook);
+
/** Sets/gets chapter
*
* @param ichapter value which to set chapter
@@ -352,8 +328,9 @@
* @return if unchanged -> value of chapter,
* if changed -> previous value of chapter
*/
- virtual int Chapter(int ichapter);
-
+ virtual int Chapter(int ichapter) { char retVal = getChapter(); setChapter(ichapter); return retVal; } // deprecated
+ virtual void setChapter(int ichapter);
+
/** Sets/gets verse
*
* @param iverse value which to set verse
@@ -361,14 +338,15 @@
* @return if unchanged -> value of verse,
* if changed -> previous value of verse
*/
- virtual int Verse(int iverse);
-
+ virtual int Verse(int iverse) { char retVal = getVerse(); setVerse(iverse); return retVal; } // deprecated;
+ virtual void setVerse(int iverse);
+
/** Sets/gets verse suffix
*
* @param isuffix value which to set verse suffix
*/
virtual void setSuffix(char isuffix);
-
+
/** checks limits and normalizes if necessary (e.g.
* Matthew 29:47 = Mark 2:2). If last verse is
* exceeded, key is set to last Book CH:VS
@@ -376,7 +354,7 @@
* @return *this
*/
virtual void Normalize(char autocheck = 0);
-
+
/** Sets/gets flag that tells VerseKey to
* automatically normalize itself when modified
*
@@ -386,7 +364,7 @@
* if changed -> previous value of autonorm
*/
virtual char AutoNormalize(char iautonorm = MAXPOS(char));
-
+
/** Sets/gets flag that tells VerseKey to include
* chapter/book/testament/module headings
*
@@ -396,15 +374,13 @@
* if changed -> previous value of headings
*/
virtual char Headings(char iheadings = MAXPOS(char));
-
- virtual long NewIndex() const;
-
+
/** Gets index based upon current verse
*
* @return offset
*/
virtual long Index() const;
-
+
/** Sets index based upon current verse
*
* @param iindex value to set index to
@@ -412,9 +388,14 @@
*/
virtual long Index(long iindex);
+ /** Gets index into current testament based upon current verse
+ *
+ * @return offset
+ */
+ virtual long TestamentIndex() const;
+
virtual const char *getOSISRef() const;
virtual const char *getOSISBookName() const;
- static const int getOSISBookNum(const char *bookab);
/** Tries to parse a string and convert it into an OSIS reference
* @param inRef reference string to try to parse
@@ -432,7 +413,7 @@
* 0 if the keys are the same
*/
virtual int compare(const SWKey & ikey);
-
+
/** Compares another VerseKey object
*
* @param ikey key to compare with this one
@@ -441,9 +422,9 @@
* 0 if the keys are the same
*/
virtual int _compare(const VerseKey & ikey);
-
- virtual void setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size = 0 /* default determine size */ );
- virtual void setBooks(const char *iBMAX, struct sbook **ibooks);
+
+ virtual void setVersificationSystem(const char *name);
+ virtual const char *getVersificationSystem() const;
virtual void setLocale(const char *name);
virtual const char *getLocale() const { return locale; }
Added: trunk/include/versemgr.h
===================================================================
--- trunk/include/versemgr.h (rev 0)
+++ trunk/include/versemgr.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -0,0 +1,160 @@
+/******************************************************************************
+ * versemgr.h - definition of class VerseMgr used for managing
+ * versification systems
+ *
+ * $Id: versemgr.cpp 2108 2007-10-13 20:35:02Z scribe $
+ *
+ * Copyright 1998 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 <defs.h>
+#include <swcacher.h>
+#include <swbuf.h>
+
+
+#ifndef VERSEMGR_H
+#define VERSEMGR_H
+
+
+SWORD_NAMESPACE_START
+
+
+struct sbook;
+class TreeKey;
+
+
+struct abbrev
+{
+ const char *ab;
+ int book;
+};
+
+struct sbook {
+ /**Name of book
+ */
+ const char *name;
+
+ /**OSIS name
+ */
+ const char *osis;
+
+ /**Preferred Abbreviation
+ */
+ const char *prefAbbrev;
+
+ /**Maximum chapters in book
+ */
+ unsigned char chapmax;
+ /** Array[chapmax] of maximum verses in chapters
+ */
+ int *versemax;
+};
+
+
+class SWDLLEXPORT VerseMgr : public SWCacher {
+
+
+public:
+ class System;
+
+private:
+ friend class __staticsystemVerseMgr;
+
+ class Private;
+ Private *p;
+
+ void init();
+
+protected:
+ static VerseMgr *systemVerseMgr;
+
+public:
+ class Book {
+ friend class System;
+ friend struct BookOffsetLess;
+ class Private;
+ Private *p;
+
+ /** book name */
+ SWBuf longName;
+
+ /** OSIS Abbreviation */
+ SWBuf osisName;
+
+ /** Preferred Abbreviation */
+ SWBuf prefAbbrev;
+
+ /** Maximum chapters in book */
+ unsigned int chapMax;
+
+ void init();
+
+ public:
+ Book() { init(); }
+ Book(const Book &other);
+ Book &operator =(const Book &other);
+ Book(const char *longName, const char *osisName, const char *prefAbbrev, int chapMax) {
+ this->longName = longName;
+ this->osisName = osisName;
+ this->prefAbbrev = prefAbbrev;
+ this->chapMax = chapMax;
+ init();
+ }
+ ~Book();
+ const char *getLongName() const { return longName.c_str(); }
+ const char *getOSISName() const { return osisName.c_str(); }
+ const char *getPreferredAbbreviation() const { return prefAbbrev.c_str(); }
+ int getChapterMax() const { return chapMax; }
+ int getVerseMax(int chapter) const;
+ };
+
+ class System {
+ class Private;
+ Private *p;
+ SWBuf name;
+ int BMAX[2];
+ long ntStartOffset;
+ void init();
+ public:
+ System() { this->name = ""; init(); }
+ System(const System &other);
+ System &operator =(const System &other);
+ System(const char *name) { this->name = name; init(); }
+ ~System();
+ const char *getName() const { return name.c_str(); }
+ const Book *getBookByName (const char *bookName) const;
+ const Book *getBookByOSISName (const char *bookName) const;
+ const Book *getBook(int number) const;
+ int getBookCount() const;
+ void loadFromSBook(const sbook *ot, const sbook *nt, int *chMax);
+ long getOffsetFromVerse(int book, int chapter, int verse) const;
+ char getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const;
+ const int *getBMAX() const { return BMAX; };
+ long getNTStartOffset() const { return ntStartOffset; }
+ };
+ VerseMgr() { init(); }
+ ~VerseMgr();
+ static VerseMgr *getSystemVerseMgr();
+ static void setSystemVerseMgr(VerseMgr *newVerseMgr);
+ const System *getVersificationSystem(const char *name) const;
+ void registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax);
+ void registerVersificationSystem(const char *name, const TreeKey *);
+};
+
+extern const struct abbrev builtin_abbrevs[];
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/include/versetreekey.h
===================================================================
--- trunk/include/versetreekey.h 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/include/versetreekey.h 2008-07-13 20:29:25 UTC (rev 2180)
@@ -40,11 +40,15 @@
static SWClass classdef;
TreeKey *treeKey;
+// vector<struct sbook> books;
void init(TreeKey *treeKey);
void syncVerseToTree();
long lastGoodOffset;
+protected:
+ virtual int getBookAbbrev(const char *abbr);
+
public:
/**
Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/keys/versekey.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -16,6 +16,7 @@
#include <localemgr.h>
#include <swlocale.h>
#include <roman.h>
+#include <versemgr.h>
SWORD_NAMESPACE_START
@@ -26,11 +27,6 @@
* Initialize static members of VerseKey
*/
-#include <canon.h> // Initialize static members of canonical books structure
-
-struct sbook *VerseKey::builtin_books[2] = {0,0};
-const char VerseKey::builtin_BMAX[2] = {39, 27};
-long *VerseKey::offsets[2][2] = {{VerseKey::otbks, VerseKey::otcps}, {VerseKey::ntbks, VerseKey::ntcps}};
int VerseKey::instance = 0;
VerseKey::LocaleCache VerseKey::localeCache;
@@ -41,8 +37,6 @@
void VerseKey::init() {
myclass = &classdef;
- if (!instance)
- initstatics();
instance++;
autonorm = 1; // default auto normalization to true
@@ -58,6 +52,7 @@
locale = 0;
setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName());
+ setVersificationSystem("KJV");
}
/******************************************************************************
@@ -203,9 +198,16 @@
}
+void VerseKey::setVersificationSystem(const char *name) {
+ refSys = VerseMgr::getSystemVerseMgr()->getVersificationSystem(name);
+ BMAX[0] = refSys->getBMAX()[0];
+ BMAX[1] = refSys->getBMAX()[1];
+}
+
+
+const char *VerseKey::getVersificationSystem() const { return refSys->getName(); }
+
void VerseKey::setLocale(const char *name) {
- char *BMAX;
- struct sbook **lbooks;
bool useCache = false;
if (localeCache.name)
@@ -213,99 +215,24 @@
if (!useCache) { // if we're setting params for a new locale
stdstr(&(localeCache.name), name);
- localeCache.abbrevsCnt = 0;
}
SWLocale *locale = (useCache) ? localeCache.locale : LocaleMgr::getSystemLocaleMgr()->getLocale(name);
localeCache.locale = locale;
- if (locale) {
- locale->getBooks(&BMAX, &lbooks);
- setBooks(BMAX, lbooks);
- setBookAbbrevs(locale->getBookAbbrevs(), localeCache.abbrevsCnt);
- localeCache.abbrevsCnt = abbrevsCnt;
- }
- else {
- setBooks(builtin_BMAX, builtin_books);
- setBookAbbrevs(builtin_abbrevs, localeCache.abbrevsCnt);
- localeCache.abbrevsCnt = abbrevsCnt;
- }
+// setBookAbbrevs((locale)?locale->getBookAbbrevs():builtin_abbrevs, localeCache.abbrevsCnt);
stdstr(&(this->locale), localeCache.name);
if (lowerBound)
LowerBound().setLocale(name);
- if (upperBound)
+ if (upperBound)
UpperBound().setLocale(name);
}
-void VerseKey::setBooks(const char *iBMAX, struct sbook **ibooks) {
- BMAX = iBMAX;
- books = ibooks;
-}
-void VerseKey::setBookAbbrevs(const struct abbrev *bookAbbrevs, unsigned int size) {
- abbrevs = bookAbbrevs;
- if (!size) {
- for (abbrevsCnt = 0; *abbrevs[abbrevsCnt].ab; abbrevsCnt++) {
- /*
- if (strcmp(abbrevs[abbrevsCnt-1].ab, abbrevs[abbrevsCnt].ab) > 0) {
- fprintf(stderr, "ERROR: book abbreviation (canon.h or locale) misordered at entry: %s\n", abbrevs[abbrevsCnt].ab);
- exit(-1);
- }
- */
- }
- if (SWLog::getSystemLog()->getLogLevel() > 0) { //make sure log is wanted, this loop stuff costs a lot of time
- for (int t = 0; t < 2; t++) {
- for (int i = 0; i < BMAX[t]; i++) {
- const int bn = getBookAbbrev(books[t][i].name);
- if ((bn-1)%39 != i) {
- SWLog::getSystemLog()->logError("VerseKey::Book: %s does not have a matching toupper abbrevs entry! book number returned was: %d(%d). Required entry should be:",
- books[t][i].name, bn, i);
- char *abbr = 0;
- stdstr(&abbr, books[t][i].name, 2);
- strstrip(abbr);
-
- StringMgr* stringMgr = StringMgr::getSystemStringMgr();
- const bool hasUTF8Support = StringMgr::hasUTF8Support();
- if (hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales
- stringMgr->upperUTF8(abbr, strlen(abbr)*2);
- }
- else {
- stringMgr->upperLatin1(abbr);
- }
- SWLog::getSystemLog()->logError("%s=%d", abbr, (t*39)+i+1);
- }
- }
- }
- }
- }
- else abbrevsCnt = size;
-}
-
-
/******************************************************************************
- * VerseKey::initstatics - initializes statics. Performed only when first
- * instance on VerseKey (or descendent) is created.
- */
-
-void VerseKey::initstatics() {
- int l1, l2, chaptmp = 0;
-
- builtin_books[0] = otbooks;
- builtin_books[1] = ntbooks;
-
- for (l1 = 0; l1 < 2; l1++) {
- for (l2 = 0; l2 < builtin_BMAX[l1]; l2++) {
- builtin_books[l1][l2].versemax = &vm[chaptmp];
- chaptmp += builtin_books[l1][l2].chapmax;
- }
- }
-}
-
-
-/******************************************************************************
* VerseKey::parse - parses keytext into testament|book|chapter|verse
*
* RET: error status
@@ -314,7 +241,7 @@
char VerseKey::parse(bool checkAutoNormalize)
{
-
+
testament = 2;
book = BMAX[1];
chapter = 1;
@@ -326,7 +253,7 @@
if (keytext) {
ListKey tmpListKey = VerseKey::ParseVerseList(keytext);
if (tmpListKey.Count()) {
-
+
this->positionFrom(tmpListKey.getElement(0));
error = this->error;
/*
@@ -368,7 +295,7 @@
void VerseKey::freshtext() const
{
char buf[2024];
- int realtest = testament;
+ int realTest = testament;
int realbook = book;
if (book < 1) {
@@ -377,14 +304,14 @@
else sprintf(buf, "[ Testament %d Heading ]", (int)testament);
}
else {
- if (realbook > BMAX[realtest-1]) {
- realbook -= BMAX[realtest-1];
- if (realtest < 2)
- realtest++;
- if (realbook > BMAX[realtest-1])
- realbook = BMAX[realtest-1];
+ if (realbook > BMAX[realTest-1]) {
+ realbook -= BMAX[realTest-1];
+ if (realTest < 2)
+ realTest++;
+ if (realbook > BMAX[realTest-1])
+ realbook = BMAX[realTest-1];
}
- sprintf(buf, "%s %d:%d", books[realtest-1][realbook-1].name, chapter, verse);
+ sprintf(buf, "%s %d:%d", refSys->getBook(((realTest>1)?BMAX[0]:0)+realbook-1)->getLongName(), chapter, verse);
if (suffix) {
buf[strlen(buf)+1] = 0;
buf[strlen(buf)] = suffix;
@@ -409,6 +336,18 @@
char *abbr = 0;
+ int abbrevsCnt;
+ bool useCache = false;
+
+ useCache = (localeCache.name && localeCache.locale);
+
+ if (!useCache) { // if we're setting params for a new locale
+ stdstr(&(localeCache.name), locale);
+ localeCache.locale = LocaleMgr::getSystemLocaleMgr()->getLocale(locale);
+ }
+
+ const struct abbrev *abbrevs = localeCache.locale->getBookAbbrevs(&abbrevsCnt);
+
StringMgr* stringMgr = StringMgr::getSystemStringMgr();
const bool hasUTF8Support = StringMgr::hasUTF8Support();
@@ -505,11 +444,11 @@
bool inTerm = true;
int notAllDigits = 0;
- curKey.AutoNormalize(0);
+ curKey.AutoNormalize(AutoNormalize());
lastKey.AutoNormalize(0);
lBound.AutoNormalize(0);
if (defaultKey) lastKey = defaultKey;
-
+
while (*buf) {
switch (*buf) {
case ':':
@@ -539,7 +478,7 @@
break;
}
- case '-':
+ case '-':
case ',': // on number new verse
case ';': // on number new chapter
number[tonumber] = 0;
@@ -700,13 +639,13 @@
else dash = 0;
break;
case 10: // ignore these
- case 13:
- case '[':
- case ']':
- case '(':
- case ')':
- case '{':
- case '}':
+ case 13:
+ case '[':
+ case ']':
+ case '(':
+ case ')':
+ case '{':
+ case '}':
break;
case '.':
if (buf > orig) // ignore (break) if preceeding char is not a digit
@@ -723,7 +662,7 @@
chap = atoi(number);
*number = 0;
break;
-
+
default:
if (isdigit(*buf)) {
number[tonumber++] = *buf;
@@ -789,7 +728,7 @@
break;
}
}
-
+
if ((!stricmp(book, "V")) || (!stricmp(book, "VER"))) { // Verse abbrev.
if (verse == -1) {
verse = chap;
@@ -797,7 +736,7 @@
*book = 0;
}
}
-
+
if ((!stricmp(book, "ch")) || (!stricmp(book, "chap"))) { // Verse abbrev
strcpy(book, lastKey.getBookName());
}
@@ -904,7 +843,7 @@
VerseKey &VerseKey::LowerBound(const VerseKey &lb)
{
- if (!lowerBound)
+ if (!lowerBound)
initBounds();
(*lowerBound) = lb;
@@ -922,7 +861,7 @@
VerseKey &VerseKey::UpperBound(const VerseKey &ub)
{
- if (!upperBound)
+ if (!upperBound)
initBounds();
// need to set upperbound parsing to resolve to max verse/chap if not specified
@@ -965,7 +904,7 @@
VerseKey &VerseKey::LowerBound() const
{
- if (!lowerBound)
+ if (!lowerBound)
initBounds();
return (*lowerBound);
@@ -978,7 +917,7 @@
VerseKey &VerseKey::UpperBound() const
{
- if (!upperBound)
+ if (!upperBound)
initBounds();
return (*upperBound);
@@ -1015,8 +954,9 @@
upperBound->Testament(2);
upperBound->Book(BMAX[1]);
- upperBound->Chapter(books[1][BMAX[1]-1].chapmax);
- upperBound->Verse(books[1][BMAX[1]-1].versemax[upperBound->Chapter()-1]);
+ const VerseMgr::Book *b = refSys->getBook(BMAX[0]+BMAX[1]-1);
+ upperBound->Chapter(b->getChapterMax());
+ upperBound->Verse(b->getVerseMax(b->getChapterMax()));
boundSet = false;
}
@@ -1042,7 +982,7 @@
else sprintf(buf, "[ Testament %d Heading ]", (int)testament);
}
else {
- sprintf(buf, "%s %d:%d", books[testament-1][book-1].prefAbbrev, chapter, verse);
+ sprintf(buf, "%s %d:%d", getBookAbbrev(), chapter, verse);
}
stdstr(&stext, buf);
return stext;
@@ -1050,13 +990,20 @@
const char *VerseKey::getBookName() const {
- return books[testament-1][book-1].name;
+ return refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getLongName();
}
+const char *VerseKey::getOSISBookName() const {
+ return refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getOSISName();
+}
+
+
const char *VerseKey::getBookAbbrev() const {
- return books[testament-1][book-1].prefAbbrev;
+ return refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getPreferredAbbreviation();
}
+
+
/******************************************************************************
* VerseKey::setPosition(SW_POSITION) - Positions this key
*
@@ -1083,21 +1030,29 @@
break;
case POS_MAXVERSE:
Normalize();
- verse = books[testament-1][book-1].versemax[chapter-1];
+ verse = getVerseMax();
suffix = 0;
break;
case POS_MAXCHAPTER:
verse = 1;
suffix = 0;
Normalize();
- chapter = books[testament-1][book-1].chapmax;
+ chapter = getChapterMax();
break;
- }
+ }
Normalize(1);
Error(); // clear error from normalize
}
+int VerseKey::getChapterMax() const {
+ return refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getChapterMax();
+}
+int VerseKey::getVerseMax() const {
+ return refSys->getBook(((testament>1)?BMAX[0]:0)+book-1)->getVerseMax(chapter);
+}
+
+
/******************************************************************************
* VerseKey::increment - Increments key a number of verses
*
@@ -1171,40 +1126,43 @@
continue;
}
- if (chapter > books[testament-1][book-1].chapmax) {
- chapter -= books[testament-1][book-1].chapmax;
+ if (chapter > getChapterMax()) {
+ chapter -= getChapterMax();
book++;
continue;
}
if (chapter < 1) {
if (--book > 0) {
- chapter += books[testament-1][book-1].chapmax;
+ chapter += getChapterMax();
}
else {
if (testament > 1) {
- chapter += books[0][BMAX[0]-1].chapmax;
+ chapter += refSys->getBook(BMAX[0]-1)->getChapterMax();
}
}
continue;
}
- if (verse > books[testament-1][book-1].versemax[chapter-1]) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0]
- verse -= books[testament-1][book-1].versemax[chapter++ - 1];
+ if (verse > getVerseMax()) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0]
+ verse -= getVerseMax();
+ chapter++;
continue;
}
if (verse < 1) {
if (--chapter > 0) {
- verse += books[testament-1][book-1].versemax[chapter-1];
+ verse += getVerseMax();
}
else {
if (book > 1) {
- verse += books[testament-1][book-2].versemax[books[testament-1][book-2].chapmax-1];
+ const VerseMgr::Book *prevBook = refSys->getBook(((testament>1)?BMAX[0]:0)+book-2);
+ verse += prevBook->getVerseMax(prevBook->getChapterMax());
}
else {
if (testament > 1) {
- verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1];
+ const VerseMgr::Book *lastOTBook = refSys->getBook(BMAX[0]-1);
+ verse += lastOTBook->getVerseMax(lastOTBook->getChapterMax());
}
}
}
@@ -1217,8 +1175,8 @@
if (testament > 2) {
testament = 2;
book = BMAX[testament-1];
- chapter = books[testament-1][book-1].chapmax;
- verse = books[testament-1][book-1].versemax[chapter-1];
+ chapter = getChapterMax();
+ verse = getVerseMax();
error = KEYERR_OUTOFBOUNDS;
}
@@ -1249,7 +1207,7 @@
* RET: value of testament
*/
-char VerseKey::Testament() const
+char VerseKey::getTestament() const
{
return testament;
}
@@ -1261,7 +1219,7 @@
* RET: value of book
*/
-char VerseKey::Book() const
+char VerseKey::getBook() const
{
return book;
}
@@ -1273,7 +1231,7 @@
* RET: value of chapter
*/
-int VerseKey::Chapter() const
+int VerseKey::getChapter() const
{
return chapter;
}
@@ -1285,7 +1243,7 @@
* RET: value of verse
*/
-int VerseKey::Verse() const
+int VerseKey::getVerse() const
{
return verse;
}
@@ -1301,15 +1259,12 @@
* if changed -> previous value of testament
*/
-char VerseKey::Testament(char itestament)
+void VerseKey::setTestament(char itestament)
{
- char retval = testament;
-
if (itestament != MAXPOS(char)) {
testament = itestament;
Normalize(1);
}
- return retval;
}
@@ -1323,15 +1278,11 @@
* if changed -> previous value of book
*/
-char VerseKey::Book(char ibook)
+void VerseKey::setBook(char ibook)
{
- char retval = book;
-
Chapter(1);
book = ibook;
Normalize(1);
-
- return retval;
}
@@ -1345,15 +1296,11 @@
* if changed -> previous value of chapter
*/
-int VerseKey::Chapter(int ichapter)
+void VerseKey::setChapter(int ichapter)
{
- int retval = chapter;
-
Verse(1);
chapter = ichapter;
Normalize(1);
-
- return retval;
}
@@ -1367,15 +1314,11 @@
* if changed -> previous value of verse
*/
-int VerseKey::Verse(int iverse)
+void VerseKey::setVerse(int iverse)
{
- int retval = verse;
-
setSuffix(0);
verse = iverse;
Normalize(1);
-
- return retval;
}
@@ -1480,12 +1423,9 @@
if (!chapter)
verse = 0;
- offset = offsets[testament-1][0][book];
- offset = offsets[testament-1][1][(int)offset + chapter];
- if (!(offset|verse)) // if we have a testament but nothing else.
- offset = 1;
+ offset = refSys->getOffsetFromVerse((((testament>1)?BMAX[0]:0)+book-1), chapter, verse);
}
- return (offset + verse);
+ return offset;
}
@@ -1495,11 +1435,10 @@
* RET: offset
*/
-long VerseKey::NewIndex() const
+long VerseKey::TestamentIndex() const
{
- static long otMaxIndex = 32300 - 8245; // total positions - new testament positions
-// static long otMaxIndex = offsets[0][1][(int)offsets[0][0][BMAX[0]] + books[0][BMAX[0]].chapmax];
- return ((testament-1) * otMaxIndex) + Index();
+ long offset = Index();
+ return (testament > 1) ? offset - refSys->getNTStartOffset() : offset;
}
@@ -1513,8 +1452,16 @@
long VerseKey::Index(long iindex)
{
- long offset;
+ int b;
+ error = refSys->getVerseFromOffset(iindex, &b, &chapter, &verse);
+ book = (unsigned char)b;
+ testament = 1;
+ if (book > BMAX[0]) {
+ book -= BMAX[0];
+ testament = 2;
+ }
+/*
suffix = 0;
// This is the dirty stuff --------------------------------------------
@@ -1531,7 +1478,10 @@
}
else {
testament--;
- iindex = (offsets[testament-1][1][offsize[testament-1][1]-1] + books[testament-1][BMAX[testament-1]-1].versemax[books[testament-1][BMAX[testament-1]-1].chapmax-1]) + iindex; // What a doozy! ((offset of last chapter + number of verses in the last chapter) + iindex)
+ const VerseMgr::Book *b = refSys->getBook(BMAX[0]+((testament)?BMAX[1]:0)-1);
+ iindex = offsets[testament-1][1][offsize[testament-1][1]-1]
+ + b->getVerseMax(b->getChapterMax())
+ + iindex; // What a doozy! ((offset of last chapter + number of verses in the last chapter) + iindex)
}
}
@@ -1546,19 +1496,21 @@
chapter = offset - offsets[testament-1][0][VerseKey::book];
verse = (chapter) ? verse : 0; // funny check. if we are index=1 (testmt header) all gets set to 0 exept verse. Don't know why. Fix if you figure out. Think its in the offsets table.
if (verse) { // only check if -1 won't give negative
- if (verse > books[testament-1][book-1].versemax[chapter-1]) {
+ if (verse > getVerseMax()) {
if (testament > 1) {
- verse = books[testament-1][book-1].versemax[chapter-1];
+ verse = getVerseMax();
error = KEYERR_OUTOFBOUNDS;
}
else {
testament++;
- Index(verse - books[testament-2][book-1].versemax[chapter-1]);
+ const VerseMgr::Book *b = refSys->getBook(book-1);
+ Index(verse - b->getVerseMax(chapter-1));
}
}
}
}
}
+*/
if (_compare(UpperBound()) > 0) {
*this = UpperBound();
error = KEYERR_OUTOFBOUNDS;
@@ -1623,27 +1575,7 @@
return keyval1;
}
-const char *VerseKey::osisotbooks[] = {
- "Gen","Exod","Lev","Num","Deut","Josh","Judg","Ruth","1Sam","2Sam",
- "1Kgs","2Kgs","1Chr","2Chr","Ezra","Neh","Esth","Job","Ps",
- "Prov", // added this. Was not in OSIS spec
- "Eccl",
- "Song","Isa","Jer","Lam","Ezek","Dan","Hos","Joel","Amos","Obad",
- "Jonah","Mic","Nah","Hab","Zeph","Hag","Zech","Mal","Bar","PrAzar",
- "Bel","Sus","1Esd","2Esd","AddEsth","EpJer","Jdt","1Macc","2Macc","3Macc",
- "4Macc","PrMan","Ps151","Sir","Tob","Wis"};
-const char *VerseKey::osisntbooks[] = {
- "Matt","Mark","Luke","John","Acts","Rom","1Cor","2Cor","Gal","Eph",
- "Phil","Col","1Thess","2Thess","1Tim","2Tim","Titus","Phlm","Heb","Jas",
- "1Pet","2Pet","1John","2John","3John","Jude","Rev"};
-const char **VerseKey::osisbooks[] = { osisotbooks, osisntbooks };
-
-const char *VerseKey::getOSISBookName() const {
- return osisbooks[Testament()-1][Book()-1];
-}
-
-
const char *VerseKey::getOSISRef() const {
static char buf[5][254];
static int loop = 0;
@@ -1652,38 +1584,16 @@
loop = 0;
if (Verse())
- sprintf(buf[loop], "%s.%d.%d", osisbooks[Testament()-1][Book()-1], (int)Chapter(), (int)Verse());
+ sprintf(buf[loop], "%s.%d.%d", getOSISBookName(), (int)Chapter(), (int)Verse());
else if (Chapter())
- sprintf(buf[loop], "%s.%d", osisbooks[Testament()-1][Book()-1], (int)Chapter());
+ sprintf(buf[loop], "%s.%d", getOSISBookName(), (int)Chapter());
else if (Book())
- sprintf(buf[loop], "%s", osisbooks[Testament()-1][Book()-1]);
+ sprintf(buf[loop], "%s", getOSISBookName());
else buf[loop][0] = 0;
return buf[loop++];
}
-const int VerseKey::getOSISBookNum(const char *bookab) {
- int i;
- for (i=0; i < 39; i++)
- {
- if (!strncmp(bookab, osisotbooks[i], strlen(osisotbooks[i])))
- {
- //printf("VerseKey::getOSISBookNum %s is OT %d\n", bookab, i+1);
- return i+1;
- }
- }
- for (i=0; i < 27; i++)
- {
- if (!strncmp(bookab, osisntbooks[i], strlen(osisotbooks[i])))
- {
- //printf("VerseKey::getOSISBookNum %s is NT %d\n", bookab, i+1);
- return i+1;
- }
- }
- return -1;
-}
-
-
/******************************************************************************
* VerseKey::getRangeText - returns parsable range text for this key
*/
Modified: trunk/src/keys/versetreekey.cpp
===================================================================
--- trunk/src/keys/versetreekey.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/keys/versetreekey.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -68,6 +68,33 @@
}
+int VerseTreeKey::getBookAbbrev(const char *iabbr)
+{
+ int bookno = VerseKey::getBookAbbrev(iabbr);
+ if (bookno < 0) {
+/*
+ vector<struct sbook>::iterator it = find(books, iabbr);
+ if (it == books.end()) {
+ TreeKey *tkey = this->treeKey;
+ int saveError = tkey->Error();
+ long bookmark = tkey->getOffset();
+ SWBuf segment;
+ internalPosChange = true;
+ do {
+ segment = (SWBuf)tkey->getLocalName();
+ } while (tkey->parent());
+ segment << 1;
+ if (saveError) {
+ error = saveError;
+ }
+ tkey->setOffset(bookmark);
+ }
+ books.push_back(sbook(iabbr));
+*/
+ }
+ return 0;
+}
+
/******************************************************************************
* VerseTreeKey Destructor - cleans up instance of VerseTreeKey
*
Modified: trunk/src/mgr/Makefile.am
===================================================================
--- trunk/src/mgr/Makefile.am 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/mgr/Makefile.am 2008-07-13 20:29:25 UTC (rev 2180)
@@ -22,6 +22,7 @@
libsword_la_SOURCES += $(mgrdir)/encfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/markupfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/filemgr.cpp
+libsword_la_SOURCES += $(mgrdir)/versemgr.cpp
libsword_la_SOURCES += $(mgrdir)/ftptrans.cpp
libsword_la_SOURCES += $(mgrdir)/swlocale.cpp
libsword_la_SOURCES += $(mgrdir)/localemgr.cpp
Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/mgr/localemgr.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -51,6 +51,8 @@
LocaleMgr *LocaleMgr::getSystemLocaleMgr() {
if (!systemLocaleMgr)
systemLocaleMgr = new LocaleMgr();
+ SWLocale *locale = new SWLocale(0);
+ systemLocaleMgr->locales->insert(LocaleMap::value_type(locale->getName(), locale));
return systemLocaleMgr;
}
Modified: trunk/src/mgr/swconfig.cpp
===================================================================
--- trunk/src/mgr/swconfig.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/mgr/swconfig.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -28,6 +28,9 @@
SWORD_NAMESPACE_START
+SWConfig::SWConfig() {
+}
+
SWConfig::SWConfig(const char * ifilename) {
filename = ifilename;
Load();
@@ -38,6 +41,9 @@
}
void SWConfig::Load() {
+
+ if (!filename.size()) return; // assert we have a filename
+
FileDesc *cfile;
char *buf, *data;
SWBuf line;
@@ -92,6 +98,9 @@
void SWConfig::Save() {
+
+ if (!filename.size()) return; // assert we have a filename
+
FileDesc *cfile;
SWBuf buf;
SectionMap::iterator sit;
Modified: trunk/src/mgr/swlocale.cpp
===================================================================
--- trunk/src/mgr/swlocale.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/mgr/swlocale.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -25,6 +25,7 @@
#include <map>
#include <swconfig.h>
#include <versekey.h>
+#include <versemgr.h>
SWORD_NAMESPACE_START
@@ -37,17 +38,26 @@
};
-SWLocale::SWLocale(const char * ifilename) {
+SWLocale::SWLocale(const char *ifilename) {
p = new Private;
ConfigEntMap::iterator confEntry;
- name = 0;
- description = 0;
- encoding = 0;
- bookAbbrevs = 0;
- BMAX = 0;
- books = 0;
- localeSource = new SWConfig(ifilename);
+ name = 0;
+ description = 0;
+ encoding = 0;
+ bookAbbrevs = 0;
+ bookLongNames = 0;
+ bookPrefAbbrev = 0;
+ if (ifilename) {
+ localeSource = new SWConfig(ifilename);
+ }
+ else {
+ localeSource = new SWConfig(0);
+ (*localeSource)["Meta"]["Name"] = "en_US";
+ (*localeSource)["Meta"]["Description"] = "English (US)";
+ bookAbbrevs = (struct abbrev *)builtin_abbrevs;
+ for (abbrevsCnt = 0; builtin_abbrevs[abbrevsCnt].book != -1; abbrevsCnt++);
+ }
confEntry = localeSource->Sections["Meta"].find("Name");
if (confEntry != localeSource->Sections["Meta"].end())
@@ -76,15 +86,9 @@
if (name)
delete [] name;
- if (bookAbbrevs)
+ if (bookAbbrevs != builtin_abbrevs)
delete [] bookAbbrevs;
- if (BMAX) {
- for (int i = 0; i < 2; i++)
- delete [] books[i];
- delete [] BMAX;
- delete [] books;
- }
delete p;
}
@@ -147,7 +151,7 @@
//#define NONNUMERICLOCALETHING 1
-const struct abbrev *SWLocale::getBookAbbrevs() {
+const struct abbrev *SWLocale::getBookAbbrevs(int *retSize) {
static const char *nullstr = "";
if (!bookAbbrevs) {
ConfigEntMap::iterator it;
@@ -172,33 +176,12 @@
}
bookAbbrevs[j].ab = nullstr;
bookAbbrevs[j].book = -1;
+ abbrevsCnt = size;
}
+ *retSize = abbrevsCnt;
return bookAbbrevs;
}
-void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) {
- if (!BMAX) {
- BMAX = new char [2];
- BMAX[0] = VerseKey::builtin_BMAX[0];
- BMAX[1] = VerseKey::builtin_BMAX[1];
-
- books = new struct sbook *[2];
- books[0] = new struct sbook[BMAX[0]];
- books[1] = new struct sbook[BMAX[1]];
-
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < BMAX[i]; j++) {
- books[i][j] = VerseKey::builtin_books[i][j];
- books[i][j].name = translate(VerseKey::builtin_books[i][j].name);
- }
- }
- }
-
- *iBMAX = BMAX;
- *ibooks = books;
-}
-
-
SWORD_NAMESPACE_END
Added: trunk/src/mgr/versemgr.cpp
===================================================================
--- trunk/src/mgr/versemgr.cpp (rev 0)
+++ trunk/src/mgr/versemgr.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -0,0 +1,383 @@
+/******************************************************************************
+ * versemgr.cpp - implementation of class VerseMgr used for managing
+ * versification systems
+ *
+ * $Id: versemgr.cpp 2108 2007-10-13 20:35:02Z scribe $
+ *
+ * Copyright 1998 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 <versemgr.h>
+#include <vector>
+#include <map>
+#include <treekey.h>
+#include <canon.h> // KJV internal versification system
+#include <algorithm>
+
+using std::vector;
+using std::map;
+
+using std::lower_bound;
+
+SWORD_NAMESPACE_START
+
+
+class VerseMgr::System::Private {
+public:
+ /** Array[chapmax] of maximum verses in chapters */
+ vector<Book> books;
+
+ Private() {
+ books.clear();
+ }
+ Private(const VerseMgr::System::Private &other) {
+ books.clear();
+ books = other.books;
+ }
+ VerseMgr::System::Private &operator =(const VerseMgr::System::Private &other) {
+ books.clear();
+ books = other.books;
+ return *this;
+ }
+};
+
+
+class VerseMgr::Book::Private {
+friend struct BookOffsetLess;
+public:
+ /** Array[chapmax] of maximum verses in chapters */
+ vector<int> verseMax;
+ vector<long> offsetPrecomputed;
+
+ Private() {
+ verseMax.clear();
+ }
+ Private(const VerseMgr::Book::Private &other) {
+ verseMax.clear();
+ verseMax = other.verseMax;
+ offsetPrecomputed = other.offsetPrecomputed;
+ }
+ VerseMgr::Book::Private &operator =(const VerseMgr::Book::Private &other) {
+ verseMax.clear();
+ verseMax = other.verseMax;
+ offsetPrecomputed = other.offsetPrecomputed;
+ return *this;
+ }
+};
+
+struct BookOffsetLess {
+ bool operator() (const VerseMgr::Book &o1, const long &o2) const { return o1.p->offsetPrecomputed[0] < o2; }
+};
+
+void VerseMgr::Book::init() {
+ p = new Private();
+}
+
+void VerseMgr::System::init() {
+ p = new Private();
+ BMAX[0] = 0;
+ BMAX[1] = 0;
+ ntStartOffset = 0;
+}
+
+
+VerseMgr::System::System(const System &other) {
+ name = other.name;
+ BMAX[0] = other.BMAX[0];
+ BMAX[1] = other.BMAX[1];
+ init();
+ (*p) = *(other.p);
+}
+
+VerseMgr::System::System &VerseMgr::System::operator =(const System &other) {
+ name = other.name;
+ BMAX[0] = other.BMAX[0];
+ BMAX[1] = other.BMAX[1];
+ init();
+ (*p) = *(other.p);
+ return *this;
+}
+
+
+VerseMgr::System::~System() {
+ delete p;
+ p = 0;
+}
+
+const VerseMgr::Book *VerseMgr::System::getBook(int number) const {
+ return &(p->books[number]);
+}
+
+
+void VerseMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMax) {
+ int chap = 0;
+ int book = 0;
+ long offset = 0; // module heading
+ offset++; // testament heading
+ while (ot->chapmax) {
+ p->books.push_back(Book(ot->name, ot->osis, ot->prefAbbrev, ot->chapmax));
+ offset++; // book heading
+ Book &b = p->books[p->books.size()-1];
+ for (int i = 0; i < ot->chapmax; i++) {
+ b.p->verseMax.push_back(chMax[chap]);
+ offset++; // chapter heading
+ b.p->offsetPrecomputed.push_back(offset);
+ offset += chMax[chap++];
+ }
+ ot++;
+ book++;
+ }
+ BMAX[0] = book;
+ book = 0;
+ ntStartOffset = offset;
+ offset++; // testament heading
+ while (nt->chapmax) {
+ p->books.push_back(Book(nt->name, nt->osis, nt->prefAbbrev, nt->chapmax));
+ offset++; // book heading
+ Book &b = p->books[p->books.size()-1];
+ for (int i = 0; i < nt->chapmax; i++) {
+ b.p->verseMax.push_back(chMax[chap]);
+ offset++; // chapter heading
+ b.p->offsetPrecomputed.push_back(offset);
+ offset += chMax[chap++];
+ }
+ nt++;
+ book++;
+ }
+ BMAX[1] = book;
+
+ // TODO: build offset speed array
+}
+
+
+VerseMgr::Book::Book(const Book &other) {
+ longName = other.longName;
+ osisName = other.osisName;
+ prefAbbrev = other.prefAbbrev;
+ chapMax = other.chapMax;
+ init();
+ (*p) = *(other.p);
+}
+
+VerseMgr::Book::Book& VerseMgr::Book::operator =(const Book &other) {
+ longName = other.longName;
+ osisName = other.osisName;
+ prefAbbrev = other.prefAbbrev;
+ chapMax = other.chapMax;
+ init();
+ (*p) = *(other.p);
+ return *this;
+}
+
+
+VerseMgr::Book::~Book() {
+ delete p;
+ p = 0;
+}
+
+
+int VerseMgr::Book::getVerseMax(int chapter) const {
+ return p->verseMax[chapter-1];
+}
+
+
+long VerseMgr::System::getOffsetFromVerse(int book, int chapter, int verse) const {
+ long offset = -1;
+
+ const Book *b = getBook(book);
+ offset = b->p->offsetPrecomputed[chapter-1];
+
+/* old code
+ *
+ offset = offsets[testament-1][0][book];
+ offset = offsets[testament-1][1][(int)offset + chapter];
+ if (!(offset|verse)) // if we have a testament but nothing else.
+ offset = 1;
+
+*/
+
+ return (offset + verse);
+}
+
+
+char VerseMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
+ // binary search for book
+ vector<Book>::iterator b = lower_bound(p->books.begin(), p->books.end(), offset, BookOffsetLess());
+ b--;
+ vector<long>::iterator c = lower_bound(b->p->offsetPrecomputed.begin(), b->p->offsetPrecomputed.end(), offset);
+ c--;
+
+ (*book) = distance(p->books.begin(), b)+1;
+ (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1;
+ (*verse) = (offset - *c);
+
+ return 0;
+}
+
+
+/***************************************************
+ * VerseMgr
+ */
+
+class VerseMgr::Private {
+public:
+ Private() {
+ }
+ Private(const VerseMgr::Private &other) {
+ systems = other.systems;
+ }
+ VerseMgr::Private &operator =(const VerseMgr::Private &other) {
+ systems = other.systems;
+ return *this;
+ }
+ map<SWBuf, System> systems;
+};
+// ---------------- statics -----------------
+VerseMgr *VerseMgr::systemVerseMgr = 0;
+
+class __staticsystemVerseMgr {
+public:
+ __staticsystemVerseMgr() { }
+ ~__staticsystemVerseMgr() { delete VerseMgr::systemVerseMgr; }
+} _staticsystemVerseMgr;
+
+
+void VerseMgr::init() {
+ p = new Private();
+}
+
+
+VerseMgr::~VerseMgr() {
+ delete p;
+ p = 0;
+}
+
+
+VerseMgr *VerseMgr::getSystemVerseMgr() {
+ if (!systemVerseMgr) {
+ systemVerseMgr = new VerseMgr();
+ systemVerseMgr->registerVersificationSystem("KJV", otbooks, ntbooks, vm);
+ }
+
+ return systemVerseMgr;
+}
+
+
+void VerseMgr::setSystemVerseMgr(VerseMgr *newVerseMgr) {
+ if (systemVerseMgr)
+ delete systemVerseMgr;
+ systemVerseMgr = newVerseMgr;
+}
+
+
+const VerseMgr::System *VerseMgr::getVersificationSystem(const char *name) const {
+ return &(p->systems[name]);
+}
+
+void VerseMgr::registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax) {
+ p->systems[name] = System(name);
+ System &s = p->systems[name];
+ s.loadFromSBook(ot, nt, chMax);
+}
+
+
+void VerseMgr::registerVersificationSystem(const char *name, const TreeKey *tk) {
+}
+
+// --------------- end statics --------------
+
+/*
+
+long *VerseKey::offsets[2][2] = {{VerseKey::otbks, VerseKey::otcps}, {VerseKey::ntbks, VerseKey::ntcps}};
+const char VerseKey::builtin_BMAX[2] = {39, 27};
+void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) {
+ if (!BMAX) {
+ BMAX = new char [2];
+ BMAX[0] = VerseKey::builtin_BMAX[0];
+ BMAX[1] = VerseKey::builtin_BMAX[1];
+
+ books = new struct sbook *[2];
+ books[0] = new struct sbook[BMAX[0]];
+ books[1] = new struct sbook[BMAX[1]];
+
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < BMAX[i]; j++) {
+ books[i][j] = VerseKey::builtin_books[i][j];
+ books[i][j].name = translate(VerseKey::builtin_books[i][j].name);
+ }
+ }
+ }
+
+ *iBMAX = BMAX;
+ *ibooks = books;
+}
+
+~() {
+ if (BMAX) {
+ for (int i = 0; i < 2; i++)
+ delete [] books[i];
+ delete [] BMAX;
+ delete [] books;
+ }
+}
+
+
+******************************************************************************
+ * VerseKey::initstatics - initializes statics. Performed only when first
+ * instance on VerseKey (or descendent) is created.
+ */
+
+/*
+void VerseKey::initstatics() {
+ int l1, l2, chaptmp = 0;
+
+ builtin_books[0] = otbooks;
+ builtin_books[1] = ntbooks;
+
+ for (l1 = 0; l1 < 2; l1++) {
+ for (l2 = 0; l2 < builtin_BMAX[l1]; l2++) {
+ builtin_books[l1][l2].versemax = &vm[chaptmp];
+ chaptmp += builtin_books[l1][l2].chapmax;
+ }
+ }
+}
+
+
+const int VerseKey::getOSISBookNum(const char *bookab) {
+ int i;
+ for (i=0; i < 39; i++)
+ {
+ if (!strncmp(bookab, osisotbooks[i], strlen(osisotbooks[i])))
+ {
+ //printf("VerseKey::getOSISBookNum %s is OT %d\n", bookab, i+1);
+ return i+1;
+ }
+ }
+ for (i=0; i < 27; i++)
+ {
+ if (!strncmp(bookab, osisntbooks[i], strlen(osisotbooks[i])))
+ {
+ //printf("VerseKey::getOSISBookNum %s is NT %d\n", bookab, i+1);
+ return i+1;
+ }
+ }
+ return -1;
+}
+
+*/
+
+
+SWORD_NAMESPACE_END
Modified: trunk/src/modules/comments/hrefcom/hrefcom.cpp
===================================================================
--- trunk/src/modules/comments/hrefcom/hrefcom.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/hrefcom/hrefcom.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -63,7 +63,7 @@
if (!key)
key = new VerseKey(this->key);
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
SWBuf tmpbuf;
Modified: trunk/src/modules/comments/rawcom/rawcom.cpp
===================================================================
--- trunk/src/modules/comments/rawcom/rawcom.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/rawcom/rawcom.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -53,7 +53,7 @@
unsigned short size = 0;
VerseKey *key = &getVerseKey();
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -82,7 +82,7 @@
unsigned short size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -96,7 +96,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
(((laststart != start) || (lastsize != size)) // we're a different entry
@@ -113,7 +113,7 @@
void RawCom::setEntry(const char *inbuf, long len) {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->Index(), inbuf, len);
+ doSetText(key->Testament(), key->TestamentIndex(), inbuf, len);
}
@@ -130,7 +130,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index());
+ doLinkEntry(destkey->Testament(), destkey->TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -146,7 +146,7 @@
void RawCom::deleteEntry() {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->Index(), "");
+ doSetText(key->Testament(), key->TestamentIndex(), "");
}
Modified: trunk/src/modules/comments/rawcom4/rawcom4.cpp
===================================================================
--- trunk/src/modules/comments/rawcom4/rawcom4.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/rawcom4/rawcom4.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -53,7 +53,7 @@
unsigned long size = 0;
VerseKey *key = &getVerseKey();
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -82,7 +82,7 @@
unsigned long size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -96,7 +96,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
(((laststart != start) || (lastsize != size)) // we're a different entry
@@ -113,7 +113,7 @@
void RawCom4::setEntry(const char *inbuf, long len) {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->Index(), inbuf, len);
+ doSetText(key->Testament(), key->TestamentIndex(), inbuf, len);
}
@@ -130,7 +130,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index());
+ doLinkEntry(destkey->Testament(), destkey->TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -146,7 +146,7 @@
void RawCom4::deleteEntry() {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->Index(), "");
+ doSetText(key->Testament(), key->TestamentIndex(), "");
}
Modified: trunk/src/modules/comments/rawfiles/rawfiles.cpp
===================================================================
--- trunk/src/modules/comments/rawfiles/rawfiles.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/rawfiles/rawfiles.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -66,7 +66,7 @@
if (!key)
key = new VerseKey(this->key);
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
entryBuf = "";
if (size) {
@@ -115,7 +115,7 @@
if (!key)
key = new VerseKey(this->key);
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
if (size) {
SWBuf tmpbuf;
@@ -129,7 +129,7 @@
entryBuf = path;
entryBuf += '/';
tmpbuf = getNextFilename();
- doSetText(key->Testament(), key->Index(), tmpbuf);
+ doSetText(key->Testament(), key->TestamentIndex(), tmpbuf);
entryBuf += tmpbuf;
}
datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
@@ -163,7 +163,7 @@
if (!key)
key = new VerseKey(this->key);
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
if (size) {
SWBuf tmpbuf;
@@ -179,7 +179,7 @@
SWCATCH ( ... ) {}
if (!key)
key = new VerseKey(this->key);
- doSetText(key->Testament(), key->Index(), tmpbuf.c_str());
+ doSetText(key->Testament(), key->TestamentIndex(), tmpbuf.c_str());
}
if (key != inkey)
@@ -204,7 +204,7 @@
if (!key)
key = new VerseKey(this->key);
- doSetText(key->Testament(), key->Index(), "");
+ doSetText(key->Testament(), key->TestamentIndex(), "");
if (key != this->key)
delete key;
Modified: trunk/src/modules/comments/swcom.cpp
===================================================================
--- trunk/src/modules/comments/swcom.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/swcom.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -45,7 +45,7 @@
if (!key)
key = new VerseKey(this->key);
- entryIndex = key->NewIndex();
+ entryIndex = key->Index();
if (key != this->key)
delete key;
Modified: trunk/src/modules/comments/zcom/zcom.cpp
===================================================================
--- trunk/src/modules/comments/zcom/zcom.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/comments/zcom/zcom.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -60,7 +60,7 @@
unsigned short size = 0;
VerseKey *key = &getVerseKey();
- findOffset(key->Testament(), key->Index(), &start, &size);
+ findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -104,7 +104,7 @@
delete lastWriteKey;
}
- doSetText(key->Testament(), key->Index(), inbuf, len);
+ doSetText(key->Testament(), key->TestamentIndex(), inbuf, len);
lastWriteKey = (VerseKey *)key->clone(); // must delete
}
@@ -124,7 +124,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index());
+ doLinkEntry(destkey->Testament(), destkey->TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -139,7 +139,7 @@
void zCom::deleteEntry() {
VerseKey *key = &getVerseKey();
- doSetText(key->Testament(), key->Index(), "");
+ doSetText(key->Testament(), key->TestamentIndex(), "");
}
@@ -156,7 +156,7 @@
unsigned short size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -170,7 +170,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
(((laststart != start) || (lastsize != size)) // we're a different entry
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/swmodule.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -469,8 +469,7 @@
// end MAJOR KLUDGE
*this = BOTTOM;
- // fix below when we find out the bug
- long highIndex = (vkcheck)?/*32300*/vkcheck->NewIndex():key->Index();
+ long highIndex = key->Index();
if (!highIndex)
highIndex = 1; // avoid division by zero errors.
*this = TOP;
@@ -584,10 +583,7 @@
while ((searchType > -4) && !Error() && !terminateSearch) {
- long mindex = 0;
- if (vkcheck)
- mindex = vkcheck->NewIndex();
- else mindex = key->Index();
+ long mindex = key->Index();
float per = (float)mindex / highIndex;
per *= 93;
per += 5;
@@ -601,7 +597,7 @@
#ifndef _MSC_VER
std::cerr << "Serious error: new percentage complete is less than previous value\n";
std::cerr << "using vk? " << ((vkcheck)?"yes":"no") << "\n";
- std::cerr << "index: " << ((vkcheck)?vkcheck->NewIndex():key->Index()) << "\n";
+ std::cerr << "index: " << (key->Index()) << "\n";
std::cerr << "highIndex: " << highIndex << "\n";
std::cerr << "newperc ==" << (int)newperc << "%" << "is smaller than\n";
std::cerr << "perc == " << (int )perc << "% \n";
@@ -969,7 +965,7 @@
*this = BOTTOM;
- long highIndex = (vkcheck)?/*32300*/vkcheck->NewIndex():key->Index();
+ long highIndex = key->Index();
if (!highIndex)
highIndex = 1; // avoid division by zero errors.
@@ -990,10 +986,7 @@
char err = Error();
while (!err) {
- long mindex = 0;
- if (vkcheck)
- mindex = vkcheck->NewIndex();
- else mindex = key->Index();
+ long mindex = key->Index();
proxBuf = "";
proxLem = "";
Modified: trunk/src/modules/texts/rawtext/rawtext.cpp
===================================================================
--- trunk/src/modules/texts/rawtext/rawtext.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/texts/rawtext/rawtext.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -98,7 +98,7 @@
unsigned short size = 0;
VerseKey &key = getVerseKey();
- findOffset(key.Testament(), key.Index(), &start, &size);
+ findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -114,362 +114,9 @@
}
-signed char RawText::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
-#ifndef USELUCENE
- SWKey *savekey = 0;
- SWKey *searchkey = 0;
- SWKey textkey;
- char *word = 0;
- char *wordBuf = 0;
-
- // dictionary holds words associated with a list
- // containing every module position that contains
- // the word. [0] Old Testament; [1] NT
- map < SWBuf, list<long> > dictionary[2];
-
-
- // save key information so as not to disrupt original
- // module position
- if (!key->Persist()) {
- savekey = CreateKey();
- *savekey = *key;
- }
- else savekey = key;
-
- searchkey = (key->Persist())?key->clone():0;
- if (searchkey) {
- searchkey->Persist(1);
- setKey(*searchkey);
- }
-
- // position module at the beginning
- *this = TOP;
-
- VerseKey *lkey = (VerseKey *)key;
-
- // iterate thru each entry in module
- while (!Error()) {
- long index = lkey->Index();
- wordBuf = (char *)calloc(sizeof(char), strlen(StripText()) + 1);
- strcpy(wordBuf, StripText());
-
- // grab each word from the text
- word = strtok(wordBuf, " !.,?;:()-=+/\\|{}[]\"<>");
- while (word) {
-
- // make word upper case
- toupperstr(word);
-
- // lookup word in dictionary (or make entry in dictionary
- // for this word) and add this module position (index) to
- // the word's associated list of module positions
- dictionary[lkey->Testament()-1][word].push_back(index);
- word = strtok(NULL, " !.,?;:()-=+/\\|{}[]\"<>");
- }
- free(wordBuf);
- (*this)++;
- }
-
- // reposition module back to where it was before we were called
- setKey(*savekey);
-
- if (!savekey->Persist())
- delete savekey;
-
- if (searchkey)
- delete searchkey;
-
-
- // --------- Let's output an index from our dictionary -----------
- FileDesc *datfd;
- FileDesc *idxfd;
- strlist::iterator it;
- longlist::iterator it2;
- unsigned long offset, entryoff;
- unsigned short size;
-
- SWBuf fname;
- fname = path;
- char ch = fname.c_str()[strlen(fname.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- fname += "/";
-
- // for old and new testament do...
- for (int loop = 0; loop < 2; loop++) {
- datfd = FileMgr::getSystemFileMgr()->open((fname + ((loop)?"ntwords.dat":"otwords.dat")).c_str(), FileMgr::CREAT|FileMgr::WRONLY, 00644);
- if (datfd->getFd() == -1)
- return -1;
- idxfd = FileMgr::getSystemFileMgr()->open((fname + ((loop)?"ntwords.idx":"otwords.idx")).c_str(), FileMgr::CREAT|FileMgr::WRONLY, 00644);
- if (idxfd->getFd() == -1) {
- FileMgr::getSystemFileMgr()->close(datfd);
- return -1;
- }
-
- // iterate thru each word in the dictionary
- for (it = dictionary[loop].begin(); it != dictionary[loop].end(); it++) {
- printf("%s: ", it->first.c_str());
-
- // get our current offset in our word.dat file and write this as the start
- // of the next entry in our database
- offset = datfd->seek(0, SEEK_CUR);
- idxfd->write(&offset, 4);
-
- // write our word out to the word.dat file, delineating with a \n
- datfd->write(it->first.c_str(), strlen(it->first.c_str()));
- datfd->write("\n", 1);
-
- // force our mod position list for this word to be unique (remove
- // duplicates that may exist if the word was found more than once
- // in the verse
- it->second.unique();
-
- // iterate thru each mod position for this word and output it to
- // our database
- unsigned short count = 0;
- for (it2 = it->second.begin(); it2 != it->second.end(); it2++) {
- entryoff= *it2;
- datfd->write(&entryoff, 4);
- count++;
- }
-
- // now see what our new position is in our word.dat file and
- // determine the size of this database entry
- size = datfd->seek(0, SEEK_CUR) - offset;
-
- // store the size of this database entry
- idxfd->write(&size, 2);
- printf("%d entries (size: %d)\n", count, size);
- }
- FileMgr::getSystemFileMgr()->close(datfd);
- FileMgr::getSystemFileMgr()->close(idxfd);
- }
- return 0;
-#else
- return SWModule::createSearchFramework(percent, percentUserData);
-#endif
-}
-
-
-void RawText::deleteSearchFramework() {
-#ifndef USELUCENE
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- FileMgr::removeFile(target + "ntwords.dat");
- FileMgr::removeFile(target + "otwords.dat");
- FileMgr::removeFile(target + "ntwords.idx");
- FileMgr::removeFile(target + "otwords.idx");
-#else
- SWModule::deleteSearchFramework();
-#endif
-}
-
-
-/******************************************************************************
- * SWModule::search - Searches a module for a string
- *
- * ENT: istr - string for which to search
- * searchType - type of search to perform
- * >=0 - regex
- * -1 - phrase
- * -2 - multiword
- * flags - options flags for search
- * justCheckIfSupported - if set, don't search, only tell if this
- * function supports requested search.
- *
- * RET: ListKey set to verses that contain istr
- */
-
-ListKey &RawText::search(const char *istr, int searchType, int flags, SWKey *scope, bool *justCheckIfSupported, void (*percent)(char, void *), void *percentUserData) {
-#ifndef USELUCENE
- listKey.ClearList();
-
- if ((fastSearch[0]) && (fastSearch[1])) {
-
- switch (searchType) {
- case -2: {
-
- if ((flags & REG_ICASE) != REG_ICASE) // if haven't chosen to
- // ignore case
- break; // can't handle fast case sensitive searches
-
- // test to see if our scope for this search is bounded by a
- // VerseKey
- VerseKey *testKeyType = 0;
- SWTRY {
- testKeyType = SWDYNAMIC_CAST(VerseKey, ((scope)?scope:key));
- }
- SWCATCH ( ... ) {}
- // if we don't have a VerseKey * decendant we can't handle
- // because of scope.
- // In the future, add bool SWKey::isValid(const char *tryString);
- if (!testKeyType)
- break;
-
-
- // check if we just want to see if search is supported.
- // If we've gotten this far, then it is supported.
- if (justCheckIfSupported) {
- *justCheckIfSupported = true;
- return listKey;
- }
-
- SWKey saveKey = *testKeyType; // save current place
-
- char error = 0;
- char **words = 0;
- char *wordBuf = 0;
- int wordCount = 0;
- long start;
- unsigned short size;
- char *idxbuf = 0;
- SWBuf datBuf;
- list <long> indexes;
- list <long> indexes2;
- VerseKey vk;
- vk = TOP;
-
- (*percent)(10, percentUserData);
-
- // toupper our copy of search string
- stdstr(&wordBuf, istr);
- toupperstr(wordBuf);
-
- // get list of individual words
- words = (char **)calloc(sizeof(char *), 10);
- int allocWords = 10;
- words[wordCount] = strtok(wordBuf, " ");
- while (words[wordCount]) {
- wordCount++;
- if (wordCount == allocWords) {
- allocWords+=10;
- words = (char **)realloc(words, sizeof(char *)*allocWords);
- }
- words[wordCount] = strtok(NULL, " ");
- }
-
- (*percent)(20, percentUserData);
-
- // clear our result set
- indexes.erase(indexes.begin(), indexes.end());
-
- // search both old and new testament indexes
- for (int j = 0; j < 2; j++) {
- // iterate thru each word the user passed to us.
- for (int i = 0; i < wordCount; i++) {
-
- // clear this word's result set
- indexes2.erase(indexes2.begin(), indexes2.end());
- error = 0;
-
- // iterate thru every word in the database that starts
- // with our search word
- for (int away = 0; !error; away++) {
- idxbuf = 0;
-
- // find our word in the database and jump ahead _away_
- error = fastSearch[j]->findOffset(words[i], &start, &size, away);
-
- // get the word from the database
- fastSearch[j]->getIDXBufDat(start, &idxbuf);
-
- // check to see if it starts with our target word
- if (strlen(idxbuf) > strlen(words[i]))
- idxbuf[strlen(words[i])] = 0;
-// else words[i][strlen(idxbuf)] = 0;
- if (!strcmp(idxbuf, words[i])) {
-
- // get data for this word from database
- delete [] idxbuf;
- idxbuf = 0;
- datBuf = "";
- fastSearch[j]->readText(start, &size, &idxbuf, datBuf);
-
- // we know that the data consists of sizof(long)
- // records each a valid module position that constains
- // this word
- //
- // iterate thru each of these module positions
- long *keyindex = (long *)datBuf.getRawData();
- while (keyindex < (long *)(datBuf.getRawData() + size - (strlen(idxbuf) + 1))) {
- if (i) { // if we're not on our first word
-
- // check to see if this word is already in the result set.
- // This is our AND functionality
- if (find(indexes.begin(), indexes.end(), *keyindex) != indexes.end())
- // add to new result set
- indexes2.push_back(*keyindex);
- }
- else indexes2.push_back(*keyindex);
- keyindex++;
- }
- }
- else error = 1; // no more matches
- free(idxbuf);
- }
-
- // make new result set final result set
- indexes = indexes2;
-
- percent((char)(20 + (float)((j*wordCount)+i)/(wordCount * 2) * 78), percentUserData);
- }
-
- // indexes contains our good verses, lets return them in a listKey
- indexes.sort();
-
- // iterate thru each good module position that meets the search
- for (longlist::iterator it = indexes.begin(); it != indexes.end(); it++) {
-
- // set a temporary verse key to this module position
- vk.Testament(j+1);
- vk.Error();
- vk.Index(*it);
-
- // check scope
- // Try to set our scope key to this verse key
- if (scope) {
- *testKeyType = vk;
-
- // check to see if it set ok and if so, add to our return list
- if (*testKeyType == vk)
- listKey << (const char *) vk;
- }
- else listKey << (const char*) vk;
- }
- }
- (*percent)(98, percentUserData);
-
- free(words);
- free(wordBuf);
-
- *testKeyType = saveKey; // set current place back to original
-
- listKey = TOP;
- (*percent)(100, percentUserData);
- return listKey;
- }
-
- default:
- break;
- }
- }
-
- // check if we just want to see if search is supported
- if (justCheckIfSupported) {
- *justCheckIfSupported = false;
- return listKey;
- }
-
-#endif
- // if we don't support this search, fall back to base class
- return SWModule::search(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
-}
-
-
void RawText::setEntry(const char *inbuf, long len) {
VerseKey &key = getVerseKey();
- doSetText(key.Testament(), key.Index(), inbuf, len);
+ doSetText(key.Testament(), key.TestamentIndex(), inbuf, len);
}
@@ -486,7 +133,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey.Testament(), destkey.Index(), srckey->Index());
+ doLinkEntry(destkey.Testament(), destkey.TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -501,7 +148,7 @@
void RawText::deleteEntry() {
VerseKey &key = getVerseKey();
- doSetText(key.Testament(), key.Index(), "");
+ doSetText(key.Testament(), key.TestamentIndex(), "");
}
/******************************************************************************
@@ -517,7 +164,7 @@
unsigned short size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -531,7 +178,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
(((laststart != start) || (lastsize != size)) // we're a different entry
Modified: trunk/src/modules/texts/rawtext4/rawtext4.cpp
===================================================================
--- trunk/src/modules/texts/rawtext4/rawtext4.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/texts/rawtext4/rawtext4.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -98,7 +98,7 @@
unsigned long size = 0;
VerseKey &key = getVerseKey();
- findOffset(key.Testament(), key.Index(), &start, &size);
+ findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -114,362 +114,9 @@
}
-signed char RawText4::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
-#ifndef USELUCENE
- SWKey *savekey = 0;
- SWKey *searchkey = 0;
- SWKey textkey;
- char *word = 0;
- char *wordBuf = 0;
-
- // dictionary holds words associated with a list
- // containing every module position that contains
- // the word. [0] Old Testament; [1] NT
- map < SWBuf, list<long> > dictionary[2];
-
-
- // save key information so as not to disrupt original
- // module position
- if (!key->Persist()) {
- savekey = CreateKey();
- *savekey = *key;
- }
- else savekey = key;
-
- searchkey = (key->Persist())?key->clone():0;
- if (searchkey) {
- searchkey->Persist(1);
- setKey(*searchkey);
- }
-
- // position module at the beginning
- *this = TOP;
-
- VerseKey *lkey = (VerseKey *)key;
-
- // iterate thru each entry in module
- while (!Error()) {
- long index = lkey->Index();
- wordBuf = (char *)calloc(sizeof(char), strlen(StripText()) + 1);
- strcpy(wordBuf, StripText());
-
- // grab each word from the text
- word = strtok(wordBuf, " !.,?;:()-=+/\\|{}[]\"<>");
- while (word) {
-
- // make word upper case
- toupperstr(word);
-
- // lookup word in dictionary (or make entry in dictionary
- // for this word) and add this module position (index) to
- // the word's associated list of module positions
- dictionary[lkey->Testament()-1][word].push_back(index);
- word = strtok(NULL, " !.,?;:()-=+/\\|{}[]\"<>");
- }
- free(wordBuf);
- (*this)++;
- }
-
- // reposition module back to where it was before we were called
- setKey(*savekey);
-
- if (!savekey->Persist())
- delete savekey;
-
- if (searchkey)
- delete searchkey;
-
-
- // --------- Let's output an index from our dictionary -----------
- FileDesc *datfd;
- FileDesc *idxfd;
- strlist::iterator it;
- longlist::iterator it2;
- unsigned long offset, entryoff;
- unsigned long size;
-
- SWBuf fname;
- fname = path;
- char ch = fname.c_str()[strlen(fname.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- fname += "/";
-
- // for old and new testament do...
- for (int loop = 0; loop < 2; loop++) {
- datfd = FileMgr::getSystemFileMgr()->open((fname + ((loop)?"ntwords.dat":"otwords.dat")).c_str(), FileMgr::CREAT|FileMgr::WRONLY, 00644);
- if (datfd->getFd() == -1)
- return -1;
- idxfd = FileMgr::getSystemFileMgr()->open((fname + ((loop)?"ntwords.idx":"otwords.idx")).c_str(), FileMgr::CREAT|FileMgr::WRONLY, 00644);
- if (idxfd->getFd() == -1) {
- FileMgr::getSystemFileMgr()->close(datfd);
- return -1;
- }
-
- // iterate thru each word in the dictionary
- for (it = dictionary[loop].begin(); it != dictionary[loop].end(); it++) {
- printf("%s: ", it->first.c_str());
-
- // get our current offset in our word.dat file and write this as the start
- // of the next entry in our database
- offset = datfd->seek(0, SEEK_CUR);
- idxfd->write(&offset, 4);
-
- // write our word out to the word.dat file, delineating with a \n
- datfd->write(it->first.c_str(), strlen(it->first.c_str()));
- datfd->write("\n", 1);
-
- // force our mod position list for this word to be unique (remove
- // duplicates that may exist if the word was found more than once
- // in the verse
- it->second.unique();
-
- // iterate thru each mod position for this word and output it to
- // our database
- unsigned short count = 0;
- for (it2 = it->second.begin(); it2 != it->second.end(); it2++) {
- entryoff= *it2;
- datfd->write(&entryoff, 4);
- count++;
- }
-
- // now see what our new position is in our word.dat file and
- // determine the size of this database entry
- size = datfd->seek(0, SEEK_CUR) - offset;
-
- // store the size of this database entry
- idxfd->write(&size, 4);
- printf("%d entries (size: %d)\n", count, size);
- }
- FileMgr::getSystemFileMgr()->close(datfd);
- FileMgr::getSystemFileMgr()->close(idxfd);
- }
- return 0;
-#else
- return SWModule::createSearchFramework(percent, percentUserData);
-#endif
-}
-
-
-void RawText4::deleteSearchFramework() {
-#ifndef USELUCENE
- SWBuf target = path;
- char ch = target.c_str()[strlen(target.c_str())-1];
- if ((ch != '/') && (ch != '\\'))
- target += "/lucene";
- FileMgr::removeFile(target + "ntwords.dat");
- FileMgr::removeFile(target + "otwords.dat");
- FileMgr::removeFile(target + "ntwords.idx");
- FileMgr::removeFile(target + "otwords.idx");
-#else
- SWModule::deleteSearchFramework();
-#endif
-}
-
-
-/******************************************************************************
- * SWModule::search - Searches a module for a string
- *
- * ENT: istr - string for which to search
- * searchType - type of search to perform
- * >=0 - regex
- * -1 - phrase
- * -2 - multiword
- * flags - options flags for search
- * justCheckIfSupported - if set, don't search, only tell if this
- * function supports requested search.
- *
- * RET: ListKey set to verses that contain istr
- */
-
-ListKey &RawText4::search(const char *istr, int searchType, int flags, SWKey *scope, bool *justCheckIfSupported, void (*percent)(char, void *), void *percentUserData) {
-#ifndef USELUCENE
- listKey.ClearList();
-
- if ((fastSearch[0]) && (fastSearch[1])) {
-
- switch (searchType) {
- case -2: {
-
- if ((flags & REG_ICASE) != REG_ICASE) // if haven't chosen to
- // ignore case
- break; // can't handle fast case sensitive searches
-
- // test to see if our scope for this search is bounded by a
- // VerseKey
- VerseKey *testKeyType = 0;
- SWTRY {
- testKeyType = SWDYNAMIC_CAST(VerseKey, ((scope)?scope:key));
- }
- SWCATCH ( ... ) {}
- // if we don't have a VerseKey * decendant we can't handle
- // because of scope.
- // In the future, add bool SWKey::isValid(const char *tryString);
- if (!testKeyType)
- break;
-
-
- // check if we just want to see if search is supported.
- // If we've gotten this far, then it is supported.
- if (justCheckIfSupported) {
- *justCheckIfSupported = true;
- return listKey;
- }
-
- SWKey saveKey = *testKeyType; // save current place
-
- char error = 0;
- char **words = 0;
- char *wordBuf = 0;
- int wordCount = 0;
- long start;
- unsigned long size;
- char *idxbuf = 0;
- SWBuf datBuf;
- list <long> indexes;
- list <long> indexes2;
- VerseKey vk;
- vk = TOP;
-
- (*percent)(10, percentUserData);
-
- // toupper our copy of search string
- stdstr(&wordBuf, istr);
- toupperstr(wordBuf);
-
- // get list of individual words
- words = (char **)calloc(sizeof(char *), 10);
- int allocWords = 10;
- words[wordCount] = strtok(wordBuf, " ");
- while (words[wordCount]) {
- wordCount++;
- if (wordCount == allocWords) {
- allocWords+=10;
- words = (char **)realloc(words, sizeof(char *)*allocWords);
- }
- words[wordCount] = strtok(NULL, " ");
- }
-
- (*percent)(20, percentUserData);
-
- // clear our result set
- indexes.erase(indexes.begin(), indexes.end());
-
- // search both old and new testament indexes
- for (int j = 0; j < 2; j++) {
- // iterate thru each word the user passed to us.
- for (int i = 0; i < wordCount; i++) {
-
- // clear this word's result set
- indexes2.erase(indexes2.begin(), indexes2.end());
- error = 0;
-
- // iterate thru every word in the database that starts
- // with our search word
- for (int away = 0; !error; away++) {
- idxbuf = 0;
-
- // find our word in the database and jump ahead _away_
- error = fastSearch[j]->findOffset(words[i], &start, &size, away);
-
- // get the word from the database
- fastSearch[j]->getIDXBufDat(start, &idxbuf);
-
- // check to see if it starts with our target word
- if (strlen(idxbuf) > strlen(words[i]))
- idxbuf[strlen(words[i])] = 0;
-// else words[i][strlen(idxbuf)] = 0;
- if (!strcmp(idxbuf, words[i])) {
-
- // get data for this word from database
- delete [] idxbuf;
- idxbuf = 0;
- datBuf = "";
- fastSearch[j]->readText(start, &size, &idxbuf, datBuf);
-
- // we know that the data consists of sizof(long)
- // records each a valid module position that constains
- // this word
- //
- // iterate thru each of these module positions
- long *keyindex = (long *)datBuf.getRawData();
- while (keyindex < (long *)(datBuf.getRawData() + size - (strlen(idxbuf) + 1))) {
- if (i) { // if we're not on our first word
-
- // check to see if this word is already in the result set.
- // This is our AND functionality
- if (find(indexes.begin(), indexes.end(), *keyindex) != indexes.end())
- // add to new result set
- indexes2.push_back(*keyindex);
- }
- else indexes2.push_back(*keyindex);
- keyindex++;
- }
- }
- else error = 1; // no more matches
- free(idxbuf);
- }
-
- // make new result set final result set
- indexes = indexes2;
-
- percent((char)(20 + (float)((j*wordCount)+i)/(wordCount * 2) * 78), percentUserData);
- }
-
- // indexes contains our good verses, lets return them in a listKey
- indexes.sort();
-
- // iterate thru each good module position that meets the search
- for (longlist::iterator it = indexes.begin(); it != indexes.end(); it++) {
-
- // set a temporary verse key to this module position
- vk.Testament(j+1);
- vk.Error();
- vk.Index(*it);
-
- // check scope
- // Try to set our scope key to this verse key
- if (scope) {
- *testKeyType = vk;
-
- // check to see if it set ok and if so, add to our return list
- if (*testKeyType == vk)
- listKey << (const char *) vk;
- }
- else listKey << (const char*) vk;
- }
- }
- (*percent)(98, percentUserData);
-
- free(words);
- free(wordBuf);
-
- *testKeyType = saveKey; // set current place back to original
-
- listKey = TOP;
- (*percent)(100, percentUserData);
- return listKey;
- }
-
- default:
- break;
- }
- }
-
- // check if we just want to see if search is supported
- if (justCheckIfSupported) {
- *justCheckIfSupported = false;
- return listKey;
- }
-
-#endif
- // if we don't support this search, fall back to base class
- return SWModule::search(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
-}
-
-
void RawText4::setEntry(const char *inbuf, long len) {
VerseKey &key = getVerseKey();
- doSetText(key.Testament(), key.Index(), inbuf, len);
+ doSetText(key.Testament(), key.TestamentIndex(), inbuf, len);
}
@@ -486,7 +133,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey.Testament(), destkey.Index(), srckey->Index());
+ doLinkEntry(destkey.Testament(), destkey.TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -501,7 +148,7 @@
void RawText4::deleteEntry() {
VerseKey &key = getVerseKey();
- doSetText(key.Testament(), key.Index(), "");
+ doSetText(key.Testament(), key.TestamentIndex(), "");
}
/******************************************************************************
@@ -517,7 +164,7 @@
unsigned long size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -531,7 +178,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
(((laststart != start) || (lastsize != size)) // we're a different entry
Modified: trunk/src/modules/texts/swtext.cpp
===================================================================
--- trunk/src/modules/texts/swtext.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/texts/swtext.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -52,7 +52,7 @@
if (!key)
key = new VerseKey(this->key);
- entryIndex = key->NewIndex();
+ entryIndex = key->Index();
if (key != this->key)
delete key;
Modified: trunk/src/modules/texts/ztext/ztext.cpp
===================================================================
--- trunk/src/modules/texts/ztext/ztext.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/src/modules/texts/ztext/ztext.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -64,7 +64,7 @@
unsigned short size = 0;
VerseKey &key = getVerseKey();
- findOffset(key.Testament(), key.Index(), &start, &size);
+ findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
entrySize = size; // support getEntrySize call
entryBuf = "";
@@ -109,7 +109,7 @@
delete lastWriteKey;
}
- doSetText(key.Testament(), key.Index(), inbuf, len);
+ doSetText(key.Testament(), key.TestamentIndex(), inbuf, len);
lastWriteKey = (VerseKey *)key.clone(); // must delete
}
@@ -129,7 +129,7 @@
if (!srckey)
srckey = new VerseKey(inkey);
- doLinkEntry(destkey.Testament(), destkey.Index(), srckey->Index());
+ doLinkEntry(destkey.Testament(), destkey.TestamentIndex(), srckey->TestamentIndex());
if (inkey != srckey) // free our key if we created a VerseKey
delete srckey;
@@ -145,7 +145,7 @@
VerseKey &key = getVerseKey();
- doSetText(key.Testament(), key.Index(), "");
+ doSetText(key.Testament(), key.TestamentIndex(), "");
}
@@ -161,7 +161,7 @@
unsigned short size;
VerseKey *tmpkey = &getVerseKey();
- findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+ findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
SWKey lastgood = *tmpkey;
while (steps) {
@@ -175,7 +175,7 @@
*key = lastgood;
break;
}
- long index = tmpkey->Index();
+ long index = tmpkey->TestamentIndex();
findOffset(tmpkey->Testament(), index, &start, &size);
if (
Modified: trunk/tests/indextest.cpp
===================================================================
--- trunk/tests/indextest.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/tests/indextest.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -16,7 +16,7 @@
vk.Persist(1);
bbe->setKey(vk);
for (; !bbe->Error(); (*bbe)++ ) {
- std::cout << vk.NewIndex() << std::endl;
+ std::cout << vk.Index() << std::endl;
}
}
return 0;
Modified: trunk/tests/keytest.cpp
===================================================================
--- trunk/tests/keytest.cpp 2008-06-20 18:11:41 UTC (rev 2179)
+++ trunk/tests/keytest.cpp 2008-07-13 20:29:25 UTC (rev 2180)
@@ -161,13 +161,13 @@
std::cout << (const char *)bla << "\n";
bla.Testament(1);
bla = BOTTOM;
+ std::cout << bla.TestamentIndex() << "\n";
std::cout << bla.Index() << "\n";
- std::cout << bla.NewIndex() << "\n";
std::cout << bla << "\n";
bla.Testament(2);
bla = BOTTOM;
+ std::cout << bla.TestamentIndex() << "\n";
std::cout << bla.Index() << "\n";
- std::cout << bla.NewIndex() << "\n";
std::cout << bla << "\n";
return 0;
}
More information about the sword-cvs
mailing list