diff options
Diffstat (limited to 'utilities/diatheke/corediatheke.cpp')
-rw-r--r-- | utilities/diatheke/corediatheke.cpp | 126 |
1 files changed, 82 insertions, 44 deletions
diff --git a/utilities/diatheke/corediatheke.cpp b/utilities/diatheke/corediatheke.cpp index d691a2f..f2dcac9 100644 --- a/utilities/diatheke/corediatheke.cpp +++ b/utilities/diatheke/corediatheke.cpp @@ -1,8 +1,23 @@ // Diatheke 4.2 by Chris Little <chrislit@crosswire.org> -// Copyright 1999-2002 by CrossWire Bible Society +// Copyright 1999-2009 by CrossWire Bible Society // http://www.crosswire.org/sword/diatheke -// Licensed under GNU General Public License (GPL) -// see accompanying LICENSE file for license details + +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ #include "corediatheke.h" #include <regex.h> @@ -64,7 +79,7 @@ void systemquery(const char * key, ostream* output){ if (names && descriptions) *output << " : "; if (descriptions) *output << target->Description(); *output << endl; - } + } } if (types) *output << "Dictionaries:\n"; for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { @@ -76,27 +91,39 @@ void systemquery(const char * key, ostream* output){ *output << endl; } } + if (types) *output << "Generic books:\n"; + for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { + target = it->second; + if (!strcmp(target->Type(), "Generic Books")) { + if (names) *output << target->Name(); + if (names && descriptions) *output << " : "; + if (descriptions) *output << target->Description(); + *output << endl; + } + } + } } -void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAIN, unsigned char outputencoding = ENC_UTF8, unsigned long optionfilters = 0, unsigned char searchtype = ST_NONE, const char *range = 0, const char *text = 0, const char *locale = 0, const char *ref = 0, ostream* output = &cout, const char *script = 0, signed short variants = 0) { - static DiathekeMgr manager; +void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAIN, unsigned char outputencoding = ENC_UTF8, unsigned long optionfilters = 0, unsigned char searchtype = ST_NONE, const char *range = 0, const char *text = 0, const char *locale = 0, const char *ref = 0, ostream* output = &cout, const char *script = 0, signed short variants = 0) { + static DiathekeMgr manager(NULL, NULL, false, outputencoding, outputformat, + ((OP_BIDI & optionfilters) == OP_BIDI), + ((OP_ARSHAPE & optionfilters) == OP_ARSHAPE)); ModMap::iterator it; ListKey listkey; SectionMap::iterator sit; ConfigEntMap::iterator eit; - - SWModule * target; + + SWModule *target; char *font = 0; char inputformat = 0; SWBuf encoding; - char querytype = 0; + char querytype = 0; if (locale) { LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale); } - VerseKey vk; //deal with queries to "system" if (!::stricmp(text, "system")) { @@ -113,12 +140,13 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI return; } target = (*it).second; + SWKey *p = target->CreateKey(); + VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); + if (!parser) { + delete p; + parser = new VerseKey(); + } - manager.Markup(outputformat); - manager.Encoding(outputencoding); - manager.bidi = ((OP_BIDI & optionfilters) == OP_BIDI); - manager.shape = ((OP_ARSHAPE & optionfilters) == OP_ARSHAPE); - if ((sit = manager.config->Sections.find((*it).second->Name())) != manager.config->Sections.end()) { if ((eit = (*sit).second.find("SourceType")) != (*sit).second.end()) { if (!::stricmp((char *)(*eit).second.c_str(), "GBF")) @@ -127,6 +155,8 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI inputformat = FMT_THML; else if (!::stricmp((char *)(*eit).second.c_str(), "OSIS")) inputformat = FMT_OSIS; + else if (!::stricmp((char *)(*eit).second.c_str(), "TEI")) + inputformat = FMT_TEI; } encoding = ((eit = (*sit).second.find("Encoding")) != (*sit).second.end()) ? (*eit).second : (SWBuf)""; } @@ -143,12 +173,16 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI case FMT_OSIS : *output << "OSIS"; break; + case FMT_TEI : + *output << "TEI"; + break; default: *output << "Other"; - } + } *output << ";"; *output << target->Type(); *output << ";"; + delete parser; return; } @@ -160,7 +194,9 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI querytype = QT_COMM; else if (!strcmp(target->Type(), "Lexicons / Dictionaries")) querytype = QT_LD; - + else if (!strcmp(target->Type(), "Generic Books")) + querytype = QT_LD; + if (optionfilters & OP_FOOTNOTES) manager.setGlobalOption("Footnotes","On"); else @@ -208,13 +244,13 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI manager.setGlobalOption("Variants", "Secondary Readings"); } else - manager.setGlobalOption("Transliteration", "Primary Readings"); + manager.setGlobalOption("Variants", "Primary Readings"); if (optionfilters & OP_TRANSLITERATOR && script) manager.setGlobalOption("Transliteration", script); else manager.setGlobalOption("Transliteration", "Off"); - + if (querytype == QT_SEARCH) { //this test is just to determine if we've got SWKeys or VerseKeys @@ -224,7 +260,9 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI querytype = QT_BIBLE; else if (!strcmp(target->Type(), "Lexicons / Dictionaries")) querytype = QT_LD; - + else if (!strcmp(target->Type(), "Generic Books")) + querytype = QT_LD; + //do search stuff char st = 1 - searchtype; if (querytype == QT_BIBLE) { @@ -235,18 +273,17 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI *output << "\"-- "; if (range) { - VerseKey parser; - ListKey scope = parser.ParseVerseList(range, parser, true); + ListKey scope = parser->ParseVerseList(range, "Gen 1:1", true); listkey = target->Search(ref, st, REG_ICASE, &scope); } else listkey = target->Search(ref, st, REG_ICASE); - + if (strlen((const char*)listkey)) { if (!listkey.Error()) { if (outputformat == FMT_CGI) *output << "<entry>"; if (querytype == QT_BIBLE) { - vk = listkey; - *output << (const char *)vk; + *parser = listkey; + *output << (const char *)*parser; } else *output << (const char *)listkey; if (outputformat == FMT_CGI) *output << "</entry>"; @@ -256,20 +293,20 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI *output << " ; "; if (outputformat == FMT_CGI) *output << "<entry>"; if (querytype == QT_BIBLE) { - vk = listkey; - *output << (const char *)vk; + *parser = listkey; + *output << (const char *)*parser; } else *output << (const char *)listkey; if (outputformat == FMT_CGI) *output << "</entry>"; listkey++; } *output << " -- "; - + char *temp = new char[10]; sprintf(temp, "%u", listkey.Count()); *output << temp; delete [] temp; - + *output << " matches total ("; *output << target->Name(); *output << ")\n"; @@ -280,12 +317,12 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI *output << ")\n"; } } - + else if (querytype == QT_LD) { //do dictionary stuff - + target->setKey(ref); - + const char * text = (const char *) *target; if (outputformat == FMT_RTF) { @@ -298,8 +335,8 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI } else if (outputformat == FMT_HTML) { *output << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"; - } - + } + if (strlen(text)) { *output << (char*)target->KeyText(); if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { @@ -324,14 +361,14 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI *output << "("; *output << target->Name(); *output << ")\n"; - } + } if (outputformat == FMT_RTF) { *output << "}"; } } - + else if (querytype == QT_BIBLE || querytype == QT_COMM) { //do commentary/Bible stuff @@ -341,8 +378,8 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI if (strlen(font) == 0) font = 0; } } - - listkey = vk.ParseVerseList(ref, "Gen1:1", true); + + listkey = parser->ParseVerseList(ref, "Gen1:1", true); int i; if (outputformat == FMT_RTF) { @@ -359,10 +396,10 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI for (i = 0; i < listkey.Count() && maxverses; i++) { VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i)); - if (element) { + if (element && element->isBoundSet()) { target->Key(element->LowerBound()); - vk = element->UpperBound(); - while (maxverses && target->Key() <= vk) { + *parser = element->UpperBound(); + while (maxverses && target->Key() <= *parser) { *output << (char*)target->KeyText(); if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << ": <font face=\""; @@ -393,8 +430,8 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI *output << "<CM>"; *output << "\n"; - - if (target->Key() == vk) + + if (target->Key() == *parser) break; maxverses--; (*target)++; @@ -421,7 +458,7 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI else if (outputformat == FMT_RTF) { *output << "}"; } - + if (inputformat != FMT_THML && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) *output << "<br />"; else if (outputformat == FMT_OSIS) @@ -445,5 +482,6 @@ void doquery(unsigned long maxverses = -1, unsigned char outputformat = FMT_PLAI } } + delete parser; } |