utilities/diatheke/corediatheke.cpp File Reference

#include "corediatheke.h"
#include <regex.h>
#include <list>
#include <utilstr.h>
#include <versekey.h>
#include <swmodule.h>
Include dependency graph for corediatheke.cpp:

Go to the source code of this file.

Functions

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)
void systemquery (const char *key, ostream *output)

Function Documentation

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 
)

Definition at line 108 of file corediatheke.cpp.

00108                                                                                                                                                                                                                                                                                                                                                                        {
00109     static DiathekeMgr manager(NULL, NULL, false, outputencoding, outputformat,
00110         ((OP_BIDI & optionfilters) == OP_BIDI),
00111         ((OP_ARSHAPE & optionfilters) == OP_ARSHAPE));
00112 
00113     ModMap::iterator it;
00114     ListKey listkey;
00115     SectionMap::iterator sit;
00116     ConfigEntMap::iterator eit;
00117 
00118     SWModule *target;
00119     char *font = 0;
00120     char inputformat = 0;
00121     SWBuf encoding;
00122     char querytype = 0;
00123 
00124     if (locale) {
00125         LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale);
00126     }
00127 
00128     //deal with queries to "system"
00129     if (!::stricmp(text, "system")) {
00130         querytype = QT_SYSTEM;
00131         systemquery(ref, output);
00132     }
00133     if (!strnicmp(text, "info", 4)) {
00134             querytype = QT_INFO;
00135         text = ref;
00136     }
00137     //otherwise, we have a real book
00138     it = manager.Modules.find(text);
00139     if (it == manager.Modules.end()) { //book not found
00140         return;
00141     }
00142     target = (*it).second;
00143     SWKey *p = target->createKey();
00144         VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p);
00145     if (!parser) {
00146             delete p;
00147             parser = new VerseKey();
00148     }
00149 
00150     if ((sit = manager.config->Sections.find((*it).second->getName())) != manager.config->Sections.end()) {
00151         if ((eit = (*sit).second.find("SourceType")) != (*sit).second.end()) {
00152             if (!::stricmp((char *)(*eit).second.c_str(), "GBF"))
00153                 inputformat = FMT_GBF;
00154             else if (!::stricmp((char *)(*eit).second.c_str(), "ThML"))
00155                 inputformat = FMT_THML;
00156             else if (!::stricmp((char *)(*eit).second.c_str(), "OSIS"))
00157                 inputformat = FMT_OSIS;
00158             else if (!::stricmp((char *)(*eit).second.c_str(), "TEI"))
00159                 inputformat = FMT_TEI;
00160         }
00161         encoding = ((eit = (*sit).second.find("Encoding")) != (*sit).second.end()) ? (*eit).second : (SWBuf)"";
00162     }
00163 
00164 
00165     if (querytype == QT_INFO) {
00166       switch (inputformat) {
00167       case FMT_THML :
00168         *output << "ThML";
00169         break;
00170       case FMT_GBF :
00171         *output << "GBF";
00172         break;
00173       case FMT_OSIS :
00174         *output << "OSIS";
00175         break;
00176       case FMT_TEI :
00177         *output << "TEI";
00178         break;
00179       default:
00180         *output << "Other";
00181       }
00182       *output << ";";
00183       *output << target->getType();
00184       *output << ";";
00185       delete parser;
00186       return;
00187     }
00188 
00189     if (searchtype)
00190         querytype = QT_SEARCH;
00191     else if (!strcmp(target->getType(), "Biblical Texts"))
00192         querytype = QT_BIBLE;
00193     else if (!strcmp(target->getType(), "Commentaries"))
00194         querytype = QT_COMM;
00195     else if (!strcmp(target->getType(), "Lexicons / Dictionaries"))
00196         querytype = QT_LD;
00197     else if (!strcmp(target->getType(), "Generic Books"))
00198         querytype = QT_LD;
00199 
00200     if (optionfilters & OP_FOOTNOTES)
00201         manager.setGlobalOption("Footnotes","On");
00202     else
00203         manager.setGlobalOption("Footnotes","Off");
00204     if (optionfilters & OP_HEADINGS)
00205         manager.setGlobalOption("Headings","On");
00206     else
00207         manager.setGlobalOption("Headings","Off");
00208     if (optionfilters & OP_STRONGS)
00209         manager.setGlobalOption("Strong's Numbers","On");
00210     else
00211         manager.setGlobalOption("Strong's Numbers","Off");
00212     if (optionfilters & OP_MORPH)
00213         manager.setGlobalOption("Morphological Tags","On");
00214     else
00215         manager.setGlobalOption("Morphological Tags","Off");
00216     if (optionfilters & OP_CANTILLATION)
00217         manager.setGlobalOption("Hebrew Cantillation","On");
00218     else
00219         manager.setGlobalOption("Hebrew Cantillation","Off");
00220     if (optionfilters & OP_HEBREWPOINTS)
00221         manager.setGlobalOption("Hebrew Vowel Points","On");
00222     else
00223         manager.setGlobalOption("Hebrew Vowel Points","Off");
00224     if (optionfilters & OP_GREEKACCENTS)
00225         manager.setGlobalOption("Greek Accents","On");
00226     else
00227         manager.setGlobalOption("Greek Accents","Off");
00228     if (optionfilters & OP_LEMMAS)
00229         manager.setGlobalOption("Lemmas","On");
00230     else
00231         manager.setGlobalOption("Lemmas","Off");
00232     if (optionfilters & OP_SCRIPREF)
00233         manager.setGlobalOption("Cross-references","On");
00234     else
00235         manager.setGlobalOption("Cross-references","Off");
00236     if (optionfilters & OP_RED)
00237         manager.setGlobalOption("Words of Christ in Red","On");
00238     else
00239         manager.setGlobalOption("Words of Christ in Red","Off");
00240     if (optionfilters & OP_VARIANTS && variants) {
00241             if (variants == -1)
00242                 manager.setGlobalOption("Variants", "All Readings");
00243             else if (variants == 1)
00244                 manager.setGlobalOption("Variants", "Secondary Readings");
00245     }
00246     else
00247         manager.setGlobalOption("Variants", "Primary Readings");
00248 
00249     if (optionfilters & OP_TRANSLITERATOR && script)
00250                 manager.setGlobalOption("Transliteration", script);
00251     else
00252         manager.setGlobalOption("Transliteration", "Off");
00253     if (optionfilters & OP_ARABICPOINTS)
00254         manager.setGlobalOption("Arabic Vowel Points","On");
00255     else
00256         manager.setGlobalOption("Arabic Vowel Points","Off");
00257 
00258     if (querytype == QT_SEARCH) {
00259 
00260             //this test is just to determine if we've got SWKeys or VerseKeys
00261             if (!strcmp(target->getType(), "Biblical Texts"))
00262           querytype = QT_BIBLE;
00263         else if (!strcmp(target->getType(), "Commentaries"))
00264           querytype = QT_BIBLE;
00265         else if (!strcmp(target->getType(), "Lexicons / Dictionaries"))
00266           querytype = QT_LD;
00267         else if (!strcmp(target->getType(), "Generic Books"))
00268           querytype = QT_LD;
00269 
00270         //do search stuff
00271         char st = 1 - searchtype;
00272         if (querytype == QT_BIBLE) {
00273           *output << "Verses containing \"";
00274         }
00275         else *output << "Entries containing \"";
00276             *output << ref;
00277         *output << "\"-- ";
00278 
00279         if (range) {
00280             ListKey scope = parser->parseVerseList(range, "Gen 1:1", true);
00281             listkey = target->search(ref, st, REG_ICASE, &scope);
00282         }
00283         else listkey = target->search(ref, st, REG_ICASE);
00284 
00285         if (strlen((const char*)listkey)) {
00286           if (!listkey.popError()) {
00287             if (outputformat == FMT_CGI) *output << "<entry>";
00288             if (querytype == QT_BIBLE) {
00289               *parser = listkey;
00290               *output << (const char *)*parser;
00291             }
00292             else *output << (const char *)listkey;
00293             if (outputformat == FMT_CGI) *output << "</entry>";
00294           }
00295           listkey++;
00296           while (!listkey.popError()) {
00297             *output << " ; ";
00298             if (outputformat == FMT_CGI) *output << "<entry>";
00299             if (querytype == QT_BIBLE) {
00300               *parser = listkey;
00301               *output << (const char *)*parser;
00302             }
00303             else *output << (const char *)listkey;
00304             if (outputformat == FMT_CGI) *output << "</entry>";
00305             listkey++;
00306           }
00307           *output << " -- ";
00308 
00309           char *temp = new char[10];
00310           sprintf(temp, "%u", listkey.Count());
00311           *output << temp;
00312           delete [] temp;
00313 
00314           *output << " matches total (";
00315           *output << target->getName();
00316           *output << ")\n";
00317         }
00318         else {
00319           *output << "none (";
00320           *output << target->getName();
00321           *output << ")\n";
00322         }
00323     }
00324 
00325     else if (querytype == QT_LD) {
00326         //do dictionary stuff
00327 
00328         target->setKey(ref);
00329 
00330         const char * text = (const char *) *target;
00331 
00332         if (outputformat == FMT_RTF) {
00333             *output << "{\\rtf1\\ansi{\\fonttbl{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f1\\fdecor\\fprq2 ";
00334             if (font)
00335                 *output << font;
00336             else
00337                 *output << "Times New Roman";
00338             *output << ";}}";
00339         }
00340         else if (outputformat == FMT_HTML) {
00341             *output << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">";
00342         }
00343 
00344         if (strlen(text)) {
00345             *output << (char*)target->getKeyText();
00346             if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00347                 *output << ": <font face=\"";
00348                 *output << font;
00349                 *output << "\">";
00350             }
00351             else if (outputformat == FMT_RTF) {
00352                 *output << ": {\\f1 ";
00353             }
00354             else {
00355                 *output << ": ";
00356             }
00357             *output << text;
00358             if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00359                 *output << "</font>";
00360             }
00361             else if (outputformat == FMT_RTF) {
00362                 *output << "}";
00363             }
00364 
00365             *output << "(";
00366             *output << target->getName();
00367             *output << ")\n";
00368         }
00369 
00370         if (outputformat == FMT_RTF) {
00371             *output << "}";
00372         }
00373 
00374     }
00375 
00376     else if (querytype == QT_BIBLE || querytype == QT_COMM) {
00377         //do commentary/Bible stuff
00378 
00379         if ((sit = manager.config->Sections.find((*it).second->getName())) != manager.config->Sections.end()) {
00380             if ((eit = (*sit).second.find("Font")) != (*sit).second.end()) {
00381                 font = (char *)(*eit).second.c_str();
00382                 if (strlen(font) == 0) font = 0;
00383             }
00384         }
00385 
00386         listkey = parser->parseVerseList(ref, "Gen1:1", true);
00387         int i;
00388 
00389         if (outputformat == FMT_RTF) {
00390             *output << "{\\rtf1\\ansi{\\fonttbl{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f1\\fdecor\\fprq2 ";
00391             if (font)
00392                 *output << font;
00393             else
00394                 *output << "Times New Roman";
00395             *output << ";}{\\f7\\froman\\fcharset2\\fprq2 Symbol;}}";
00396         }
00397         else if (outputformat == FMT_HTML) {
00398             *output << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">";
00399         }
00400 
00401         for (i = 0; i < listkey.Count() && maxverses; i++) {
00402             VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i));
00403             if (element && element->isBoundSet()) {
00404               target->setKey(element->getLowerBound());
00405                 *parser = element->getUpperBound();
00406                 while (maxverses && *target->getKey() <= *parser) {
00407                     *output << (char*)target->getKeyText();
00408                     if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00409                         *output << ": <font face=\"";
00410                         *output << font;
00411                         *output << "\">";
00412                     }
00413                     else if (outputformat == FMT_RTF) {
00414                         *output << ": {\\f1 ";
00415                     }
00416                     else {
00417                         *output << ": ";
00418                     }
00419                     *output << (const char*)*target;
00420                     if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00421                         *output << "</font>";
00422                     }
00423                     else if (outputformat == FMT_RTF) {
00424                         *output << "}";
00425                     }
00426 
00427                     if (inputformat != FMT_THML && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI))
00428                         *output << "<br />";
00429                     else if (outputformat == FMT_OSIS)
00430                         *output << "<milestone type=\"line\"/>";
00431                     else if (outputformat == FMT_RTF)
00432                         *output << "\\par ";
00433                     else if (outputformat == FMT_GBF)
00434                         *output << "<CM>";
00435 
00436                     *output << "\n";
00437 
00438                     if (*target->getKey() == *parser)
00439                       break;
00440                     maxverses--;
00441                     (*target)++;
00442                 }
00443             }
00444             else {
00445                 target->setKey(*listkey.GetElement(i));
00446                 *output << (char*)target->getKeyText();
00447                 if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00448                     *output << ": <font face=\"";
00449                     *output << font;
00450                     *output << "\">";
00451                 }
00452                 else if (outputformat == FMT_RTF) {
00453                     *output << ": {\\f1 ";
00454                 }
00455                 else {
00456                     *output << ": ";
00457                 }
00458                 *output << (const char*)*target;
00459                 if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) {
00460                     *output << "</font>";
00461                 }
00462                 else if (outputformat == FMT_RTF) {
00463                     *output << "}";
00464                 }
00465 
00466                 if (inputformat != FMT_THML && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI))
00467                     *output << "<br />";
00468                 else if (outputformat == FMT_OSIS)
00469                     *output << "<milestone type=\"line\"/>";
00470                 else if (outputformat == FMT_RTF)
00471                     *output << "\\par ";
00472                 else if (outputformat == FMT_GBF)
00473                     *output << "<CM>";
00474 
00475                 *output << "\n";
00476                 maxverses--;
00477             }
00478         }
00479 
00480         *output << "(";
00481         *output << target->getName();
00482         *output << ")\n";
00483 
00484         if (outputformat == FMT_RTF) {
00485             *output << "}";
00486         }
00487 
00488     }
00489     delete parser;
00490 }

void systemquery ( const char *  key,
ostream *  output 
)

Definition at line 34 of file corediatheke.cpp.

00034                                                    {
00035     DiathekeMgr manager;
00036     ModMap::iterator it;
00037 
00038     SWModule *target;
00039     
00040     bool types = false, descriptions = false, names = false;
00041 
00042     if (!::stricmp(key, "localelist")) {        
00043         LocaleMgr *lm = LocaleMgr::getSystemLocaleMgr();
00044         list<SWBuf> loclist =   lm->getAvailableLocales();
00045         list<SWBuf>::iterator li = loclist.begin();
00046         for (;li != loclist.end(); li++) {
00047           *output << li->c_str() << endl;
00048         }
00049     }
00050     else if (!::stricmp(key, "modulelist")) {
00051         types = true;
00052         descriptions = true;
00053         names = true;
00054     }
00055     else if (!::stricmp(key, "modulelistnames")) {
00056         names = true;
00057     }
00058     else if (!::stricmp(key, "modulelistdescriptions")) {
00059         descriptions = true;
00060     }
00061     
00062     
00063     if (types || descriptions || names) {
00064         if (types) *output << "Biblical Texts:\n";
00065         for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
00066             target = it->second;
00067             if (!strcmp(target->getType(), "Biblical Texts")) {
00068                 if (names) *output << target->getName();
00069                 if (names && descriptions) *output << " : ";
00070                 if (descriptions) *output << target->getDescription();
00071                 *output << endl;
00072             }
00073         }
00074         if (types) *output << "Commentaries:\n";
00075         for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
00076             target = it->second;
00077             if (!strcmp(target->getType(), "Commentaries")) {
00078                 if (names) *output << target->getName();
00079                 if (names && descriptions) *output << " : ";
00080                 if (descriptions) *output << target->getDescription();
00081                 *output << endl;
00082             }
00083         }
00084         if (types) *output << "Dictionaries:\n";
00085         for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
00086             target = it->second;
00087             if (!strcmp(target->getType(), "Lexicons / Dictionaries")) {
00088                 if (names) *output << target->getName();
00089                 if (names && descriptions) *output << " : ";
00090                 if (descriptions) *output << target->getDescription();
00091                 *output << endl;
00092             }
00093         }
00094         if (types) *output << "Generic books:\n";
00095         for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) {
00096             target = it->second;
00097             if (!strcmp(target->getType(), "Generic Books")) {
00098                 if (names) *output << target->getName();
00099                 if (names && descriptions) *output << " : ";
00100                 if (descriptions) *output << target->getDescription();
00101                 *output << endl;
00102             }
00103         }
00104 
00105     }
00106 }


Generated on 18 Mar 2013 for The SWORD Project by  doxygen 1.6.1