[sword-svn] r2191 - in trunk: examples/cmdline include src/keys src/mgr tests
scribe at www.crosswire.org
scribe at www.crosswire.org
Sat Aug 16 09:16:05 MST 2008
Author: scribe
Date: 2008-08-16 09:16:03 -0700 (Sat, 16 Aug 2008)
New Revision: 2191
Modified:
trunk/examples/cmdline/lookup.cpp
trunk/include/swlocale.h
trunk/include/versekey.h
trunk/src/keys/versekey.cpp
trunk/src/mgr/localemgr.cpp
trunk/src/mgr/swlocale.cpp
trunk/src/mgr/versemgr.cpp
trunk/tests/keytest.cpp
Log:
fixed most headings problems
Modified: trunk/examples/cmdline/lookup.cpp
===================================================================
--- trunk/examples/cmdline/lookup.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/examples/cmdline/lookup.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -18,8 +18,8 @@
int main(int argc, char **argv)
{
- SWMgr manager(new MarkupFilterMgr(FMT_WEBIF));
-// SWMgr manager(new MarkupFilterMgr(FMT_HTMLHREF));
+// SWMgr manager(new MarkupFilterMgr(FMT_WEBIF));
+ SWMgr manager(new MarkupFilterMgr(FMT_HTMLHREF));
SWModule *target;
if (argc != 3) {
Modified: trunk/include/swlocale.h
===================================================================
--- trunk/include/swlocale.h 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/include/swlocale.h 2008-08-16 16:16:03 UTC (rev 2191)
@@ -70,6 +70,7 @@
virtual void augment(SWLocale &addFrom);
virtual SWLocale & operator +=(SWLocale &addFrom) { augment(addFrom); return *this; }
virtual const struct abbrev *getBookAbbrevs(int *retSize);
+ static const char *DEFAULT_LOCALE_NAME;
};
SWORD_NAMESPACE_END
Modified: trunk/include/versekey.h
===================================================================
--- trunk/include/versekey.h 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/include/versekey.h 2008-08-16 16:16:03 UTC (rev 2191)
@@ -72,13 +72,6 @@
/** number of instantiated VerseKey objects or derivitives
*/
static int instance;
-#if 1
- static long otbks[];
- static long otcps[];
- static long ntbks[];
- static long ntcps[];
-#endif
- static int vm[];
static LocaleCache localeCache;
ListKey internalListKey;
Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/src/keys/versekey.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -1422,13 +1422,18 @@
if (!testament) { // if we want module heading
offset = 0;
verse = 0;
+ chapter = 0;
+ book = 0;
}
+ else if (!book) { // we want testament heading
+ offset = ((testament == 2) ? refSys->getNTStartOffset():0) + 1;
+ chapter = 0;
+ verse = 0;
+ }
else {
- if (!book)
- chapter = 0;
- if (!chapter)
+ if (!chapter) {
verse = 0;
-
+ }
offset = refSys->getOffsetFromVerse((((testament>1)?BMAX[0]:0)+book-1), chapter, verse);
}
return offset;
@@ -1466,6 +1471,9 @@
book -= BMAX[0];
testament = 2;
}
+ // special case for Module and Testament heading
+ if (book < 0) { testament = 0; book = 0; }
+ if (chapter < 0) { book = 0; chapter = 0; }
/*
suffix = 0;
Modified: trunk/src/mgr/localemgr.cpp
===================================================================
--- trunk/src/mgr/localemgr.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/src/mgr/localemgr.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -120,7 +120,7 @@
// Locales will be invalidated if you change the StringMgr
// So only use the default hardcoded locale and let the
// frontends change the locale if they want
- stdstr(&defaultLocaleName, "en_US");
+ stdstr(&defaultLocaleName, SWLocale::DEFAULT_LOCALE_NAME);
if (prefixPath)
delete [] prefixPath;
@@ -203,7 +203,7 @@
return (*it).second;
SWLog::getSystemLog()->logWarning("LocaleMgr::getLocale failed to find %s\n", name);
- return 0;
+ return (*locales)[SWLocale::DEFAULT_LOCALE_NAME];
}
Modified: trunk/src/mgr/swlocale.cpp
===================================================================
--- trunk/src/mgr/swlocale.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/src/mgr/swlocale.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -31,6 +31,8 @@
typedef std::map < SWBuf, SWBuf, std::less < SWBuf > >LookupMap;
+const char *SWLocale::DEFAULT_LOCALE_NAME="en_US";
+
// I have bridge patterns, but this hides swconfig and map from lots o stuff
class SWLocale::Private {
public:
@@ -53,7 +55,7 @@
}
else {
localeSource = new SWConfig(0);
- (*localeSource)["Meta"]["Name"] = "en_US";
+ (*localeSource)["Meta"]["Name"] = DEFAULT_LOCALE_NAME;
(*localeSource)["Meta"]["Description"] = "English (US)";
bookAbbrevs = (struct abbrev *)builtin_abbrevs;
for (abbrevsCnt = 0; builtin_abbrevs[abbrevsCnt].osis[0]; abbrevsCnt++);
Modified: trunk/src/mgr/versemgr.cpp
===================================================================
--- trunk/src/mgr/versemgr.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/src/mgr/versemgr.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -122,7 +122,7 @@
}
const VerseMgr::Book *VerseMgr::System::getBook(int number) const {
- return (number < p->books.size()) ? &(p->books[number]) : 0;
+ return (number < (signed int)p->books.size()) ? &(p->books[number]) : 0;
}
@@ -202,7 +202,7 @@
int VerseMgr::Book::getVerseMax(int chapter) const {
chapter--;
- return (chapter < p->verseMax.size()) ? p->verseMax[chapter] : -1;
+ return (chapter < (signed int)p->verseMax.size()) ? p->verseMax[chapter] : -1;
}
@@ -213,9 +213,10 @@
const Book *b = getBook(book);
if (!b) return -1; // assert we have a valid book
- if (chapter >= b->p->offsetPrecomputed.size()) return -1; // assert we have a valid chapter
+ if ((chapter > -1) && (chapter >= (signed int)b->p->offsetPrecomputed.size())) return -1; // assert we have a valid chapter
- offset = b->p->offsetPrecomputed[chapter];
+ offset = b->p->offsetPrecomputed[(chapter > -1)?chapter:0];
+ if (chapter < 0) offset--;
/* old code
*
@@ -231,15 +232,38 @@
char VerseMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
+
+ if (offset < 1) { // just handle the module heading corner case up front (and error case)
+ (*book) = -1;
+ (*chapter) = 0;
+ (*verse) = 0;
+ return offset; // < 0 = error
+ }
+
// binary search for book
vector<Book>::iterator b = lower_bound(p->books.begin(), p->books.end(), offset, BookOffsetLess());
- b--;
+ (*book) = distance(p->books.begin(), b)+1;
+ if (offset < (*(b->p->offsetPrecomputed.begin()))-((((!(*book)) || (*book)==BMAX[0]+1))?2:1)) { // -1 for chapter headings
+ (*book)--;
+ if (b != p->books.begin()) {
+ 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);
+ // if we're a book heading, we are lessthan chapter precomputes, but greater book. This catches corner case.
+ if (c == b->p->offsetPrecomputed.end()) {
+ c--;
+ }
+ if ((offset < *c) && (c == b->p->offsetPrecomputed.begin())) {
+ (*chapter) = (offset - *c)+1; // should be 0 or -1 (for testament heading)
+ (*verse) = 0;
+ }
+ else {
+ if (offset < *c) c--;
+ (*chapter) = distance(b->p->offsetPrecomputed.begin(), c)+1;
+ (*verse) = (offset - *c);
+ }
return 0;
}
Modified: trunk/tests/keytest.cpp
===================================================================
--- trunk/tests/keytest.cpp 2008-08-13 21:08:45 UTC (rev 2190)
+++ trunk/tests/keytest.cpp 2008-08-16 16:16:03 UTC (rev 2191)
@@ -26,13 +26,14 @@
if (argc < 2)
bla = "James 1:19";
- else bla = argv[1];
+ else bla = argv[2];
- std::cout << "\n loop++; (.Index(Index()+1))\n";
+ std::cout << "\n Headings: " << (bool)bla.Headings() << "\n";
+ std::cout << " (.Index(Index()+1))\n";
- max = (argc < 3) ? 10 : atoi(argv[2]);
+ max = (argc < 4) ? 10 : atoi(argv[3]);
- for (loop = 0; loop < max; loop++, bla++) {
+ for (loop = 0; loop < max; loop++) {
index = bla.Index();
std::cout << (const char *)bla << "(" << index << ")";
bla.Index(index+1);
@@ -40,12 +41,12 @@
}
std::cout << "-----------------\n";
- std::cout << "\n loop--; (.Index(Index()-1))\n";
+ std::cout << "\n (.Index(Index()-1))\n";
if (argc < 2)
bla = "James 1:19";
- else bla = argv[1];
+ else bla = argv[2];
- for (loop = max; loop; loop--, bla--) {
+ for (loop = max; loop; loop--) {
index = bla.Index();
std::cout << (const char *)bla << "(" << index << ")";
bla.Index(index-1);
@@ -53,22 +54,38 @@
}
std::cout << "-----------------\n";
- std::cout << "--------- No Headings --------\n";
+ bla.Headings(true);
+ std::cout << "\n Headings: " << (bool)bla.Headings() << "\n";
+ std::cout << " key++\n";
if (argc < 2)
bla = "Matthew 1:5";
- else bla = argv[1];
+ else bla = argv[2];
- for (loop = max; loop; loop--, bla--) {
+ for (loop = 0; loop < max && !bla.Error(); loop++,bla++) {
index = bla.Index();
std::cout << (const char *)bla << "(" << index << ")\n";
}
std::cout << "-----------------\n";
+ bla.Headings(true);
+ std::cout << "\n Headings: " << (bool)bla.Headings() << "\n";
+ std::cout << " key--\n";
if (argc < 2)
+ bla = "Matthew 1:5";
+ else bla = argv[2];
+
+ for (loop = max; loop && !bla.Error(); loop--, bla--) {
+ index = bla.Index();
+ std::cout << (const char *)bla << "(" << index << ")\n";
+ }
+
+ std::cout << "-----------------\n";
+
+ if (argc < 2)
bla = "Genesis 1:5";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla--) {
index = bla.Index();
@@ -79,7 +96,7 @@
if (argc < 2)
bla = "Malachi 4:2";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla++) {
index = bla.Index();
@@ -90,7 +107,7 @@
if (argc < 2)
bla = "Revelation of John 22:17";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla++) {
index = bla.Index();
@@ -105,7 +122,7 @@
if (argc < 2)
bla = "Matthew 1:5";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla--) {
index = bla.Index();
@@ -116,7 +133,7 @@
if (argc < 2)
bla = "Genesis 1:5";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla--) {
index = bla.Index();
@@ -127,7 +144,7 @@
if (argc < 2)
bla = "Malachi 4:2";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla++) {
index = bla.Index();
@@ -138,7 +155,7 @@
if (argc < 2)
bla = "Revelation of John 22:17";
- else bla = argv[1];
+ else bla = argv[2];
for (loop = max; loop; loop--, bla++) {
index = bla.Index();
More information about the sword-cvs
mailing list