const QString CInfoDisplay::decodeCrossReference( const QString& data ) { Q_ASSERT(!data.isEmpty()); if (data.isEmpty()) { return QString("<div class=\"crossrefinfo\"><h3>%1</h3></div>") .arg(tr("Cross references")); } // qWarning("setting crossref %s", data.latin1()); CSwordBackend::DisplayOptions dispOpts; dispOpts.lineBreaks = false; dispOpts.verseNumbers = true; CSwordBackend::FilterOptions filterOpts; filterOpts.headings = false; filterOpts.strongNumbers = false; filterOpts.morphTags = false; filterOpts.lemmas = false; filterOpts.footnotes = false; filterOpts.scriptureReferences = false; CrossRefRendering renderer(dispOpts, filterOpts); CTextRendering::KeyTree tree; // const bool isBible = true; CSwordModuleInfo* module = CBTConfig::get (CBTConfig::standardBible); //a prefixed module gives the module to look into QRegExp re("^[^ ]+:"); // re.setMinimal(true); int pos = re.indexIn(data); if (pos != -1) { pos += re.matchedLength()-1; } if (pos > 0) { const QString moduleName = data.left(pos); // qWarning("found module %s", moduleName.latin1()); module = CPointers::backend()->findModuleByName(moduleName); if (!module) { module = CBTConfig::get (CBTConfig::standardBible); } // Q_ASSERT(module); } //Q_ASSERT(module); //why? the existense of the module is tested later CTextRendering::KeyTreeItem::Settings settings ( false, CTextRendering::KeyTreeItem::Settings::CompleteShort ); if (module && (module->type() == CSwordModuleInfo::Bible)) { VerseKey vk; sword::ListKey refs = vk.ParseVerseList((const char*)data.mid((pos == -1) ? 0 : pos+1).toUtf8(), "Gen 1:1", true); for (int i = 0; i < refs.Count(); ++i) { SWKey* key = refs.getElement(i); Q_ASSERT(key); VerseKey* vk = dynamic_cast<VerseKey*>(key); CTextRendering::KeyTreeItem* itm = (CTextRendering::KeyTreeItem*)0; //explicit conversion for MS VS if (vk && vk->isBoundSet()) { //render a range of keys itm = new CTextRendering::KeyTreeItem( QString::fromUtf8(vk->LowerBound().getText()), QString::fromUtf8(vk->UpperBound().getText()), module, settings ); } else { itm = new CTextRendering::KeyTreeItem( QString::fromUtf8(key->getText()), QString::fromUtf8(key->getText()), module, settings ); } Q_ASSERT(itm); tree.append( itm ); } } else if (module) { CTextRendering::KeyTreeItem* itm = new CTextRendering::KeyTreeItem( data.mid((pos == -1) ? 0 : pos+1), module, settings ); tree.append( itm ); } // qWarning("rendered the tree: %s", renderer.renderKeyTree(tree).latin1()); //spanns containing rtl text need dir=rtl on their parent tag to be aligned properly QString lang = "en"; // default english if (module) lang = module->language()->abbrev(); return QString("<div class=\"crossrefinfo\" lang=\"%1\"><h3>%2</h3><div class=\"para\" dir=\"%3\">%4</div></div>") .arg(lang) .arg(tr("Cross references")) .arg(module ? ((module->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr" : "rtl") : "") .arg(renderer.renderKeyTree(tree)); }
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; char *font = 0; char inputformat = 0; SWBuf encoding; char querytype = 0; if (locale) { LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale); } //deal with queries to "system" if (!::stricmp(text, "system")) { querytype = QT_SYSTEM; systemquery(ref, output); } if (!strnicmp(text, "info", 4)) { querytype = QT_INFO; text = ref; } //otherwise, we have a real book it = manager.Modules.find(text); if (it == manager.Modules.end()) { //book not found return; } target = (*it).second; SWKey *p = target->createKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } if ((sit = manager.config->Sections.find((*it).second->getName())) != manager.config->Sections.end()) { if ((eit = (*sit).second.find("SourceType")) != (*sit).second.end()) { if (!::stricmp((char *)(*eit).second.c_str(), "GBF")) inputformat = FMT_GBF; else if (!::stricmp((char *)(*eit).second.c_str(), "ThML")) 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)""; } if (querytype == QT_INFO) { switch (inputformat) { case FMT_THML : *output << "ThML"; break; case FMT_GBF : *output << "GBF"; break; case FMT_OSIS : *output << "OSIS"; break; case FMT_TEI : *output << "TEI"; break; default: *output << "Other"; } *output << ";"; *output << target->getType(); *output << ";"; delete parser; return; } if (searchtype) querytype = QT_SEARCH; else if (!strcmp(target->getType(), "Biblical Texts")) querytype = QT_BIBLE; else if (!strcmp(target->getType(), "Commentaries")) querytype = QT_COMM; else if (!strcmp(target->getType(), "Lexicons / Dictionaries")) querytype = QT_LD; else if (!strcmp(target->getType(), "Generic Books")) querytype = QT_LD; if (optionfilters & OP_FOOTNOTES) manager.setGlobalOption("Footnotes","On"); else manager.setGlobalOption("Footnotes","Off"); if (optionfilters & OP_HEADINGS) manager.setGlobalOption("Headings","On"); else manager.setGlobalOption("Headings","Off"); if (optionfilters & OP_STRONGS) manager.setGlobalOption("Strong's Numbers","On"); else manager.setGlobalOption("Strong's Numbers","Off"); if (optionfilters & OP_MORPH) manager.setGlobalOption("Morphological Tags","On"); else manager.setGlobalOption("Morphological Tags","Off"); if (optionfilters & OP_CANTILLATION) manager.setGlobalOption("Hebrew Cantillation","On"); else manager.setGlobalOption("Hebrew Cantillation","Off"); if (optionfilters & OP_HEBREWPOINTS) manager.setGlobalOption("Hebrew Vowel Points","On"); else manager.setGlobalOption("Hebrew Vowel Points","Off"); if (optionfilters & OP_GREEKACCENTS) manager.setGlobalOption("Greek Accents","On"); else manager.setGlobalOption("Greek Accents","Off"); if (optionfilters & OP_LEMMAS) manager.setGlobalOption("Lemmas","On"); else manager.setGlobalOption("Lemmas","Off"); if (optionfilters & OP_SCRIPREF) manager.setGlobalOption("Cross-references","On"); else manager.setGlobalOption("Cross-references","Off"); if (optionfilters & OP_RED) manager.setGlobalOption("Words of Christ in Red","On"); else manager.setGlobalOption("Words of Christ in Red","Off"); if (optionfilters & OP_VARIANTS && variants) { if (variants == -1) manager.setGlobalOption("Variants", "All Readings"); else if (variants == 1) manager.setGlobalOption("Variants", "Secondary Readings"); } else manager.setGlobalOption("Variants", "Primary Readings"); if (optionfilters & OP_TRANSLITERATOR && script) manager.setGlobalOption("Transliteration", script); else manager.setGlobalOption("Transliteration", "Off"); if (optionfilters & OP_ARABICPOINTS) manager.setGlobalOption("Arabic Vowel Points","On"); else manager.setGlobalOption("Arabic Vowel Points","Off"); if (querytype == QT_SEARCH) { //this test is just to determine if we've got SWKeys or VerseKeys if (!strcmp(target->getType(), "Biblical Texts")) querytype = QT_BIBLE; else if (!strcmp(target->getType(), "Commentaries")) querytype = QT_BIBLE; else if (!strcmp(target->getType(), "Lexicons / Dictionaries")) querytype = QT_LD; else if (!strcmp(target->getType(), "Generic Books")) querytype = QT_LD; //do search stuff char st = 1 - searchtype; if (querytype == QT_BIBLE) { *output << "Verses containing \""; } else *output << "Entries containing \""; *output << ref; *output << "\"-- "; if (range) { 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.popError()) { if (outputformat == FMT_CGI) *output << "<entry>"; if (querytype == QT_BIBLE) { *parser = listkey; *output << (const char *)*parser; } else *output << (const char *)listkey; if (outputformat == FMT_CGI) *output << "</entry>"; } listkey++; while (!listkey.popError()) { *output << " ; "; if (outputformat == FMT_CGI) *output << "<entry>"; if (querytype == QT_BIBLE) { *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->getName(); *output << ")\n"; } else { *output << "none ("; *output << target->getName(); *output << ")\n"; } } else if (querytype == QT_LD) { //do dictionary stuff target->setKey(ref); const char * text = (const char *) *target; if (outputformat == FMT_RTF) { *output << "{\\rtf1\\ansi{\\fonttbl{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f1\\fdecor\\fprq2 "; if (font) *output << font; else *output << "Times New Roman"; *output << ";}}"; } else if (outputformat == FMT_HTML) { *output << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"; } if (strlen(text)) { *output << (char*)target->getKeyText(); if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << ": <font face=\""; *output << font; *output << "\">"; } else if (outputformat == FMT_RTF) { *output << ": {\\f1 "; } else { *output << ": "; } *output << text; if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << "</font>"; } else if (outputformat == FMT_RTF) { *output << "}"; } *output << "("; *output << target->getName(); *output << ")\n"; } if (outputformat == FMT_RTF) { *output << "}"; } } else if (querytype == QT_BIBLE || querytype == QT_COMM) { //do commentary/Bible stuff if ((sit = manager.config->Sections.find((*it).second->getName())) != manager.config->Sections.end()) { if ((eit = (*sit).second.find("Font")) != (*sit).second.end()) { font = (char *)(*eit).second.c_str(); if (strlen(font) == 0) font = 0; } } listkey = parser->parseVerseList(ref, "Gen1:1", true); int i; if (outputformat == FMT_RTF) { *output << "{\\rtf1\\ansi{\\fonttbl{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f1\\fdecor\\fprq2 "; if (font) *output << font; else *output << "Times New Roman"; *output << ";}{\\f7\\froman\\fcharset2\\fprq2 Symbol;}}"; } else if (outputformat == FMT_HTML) { *output << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"; } for (i = 0; i < listkey.Count() && maxverses; i++) { VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i)); if (element && element->isBoundSet()) { target->setKey(element->getLowerBound()); *parser = element->getUpperBound(); while (maxverses && *target->getKey() <= *parser) { *output << (char*)target->getKeyText(); if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << ": <font face=\""; *output << font; *output << "\">"; } else if (outputformat == FMT_RTF) { *output << ": {\\f1 "; } else { *output << ": "; } *output << (const char*)*target; if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << "</font>"; } 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) *output << "<milestone type=\"line\"/>"; else if (outputformat == FMT_RTF) *output << "\\par "; else if (outputformat == FMT_GBF) *output << "<CM>"; *output << "\n"; if (*target->getKey() == *parser) break; maxverses--; (*target)++; } } else { target->setKey(*listkey.GetElement(i)); *output << (char*)target->getKeyText(); if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << ": <font face=\""; *output << font; *output << "\">"; } else if (outputformat == FMT_RTF) { *output << ": {\\f1 "; } else { *output << ": "; } *output << (const char*)*target; if (font && (outputformat == FMT_HTML || outputformat == FMT_THML || outputformat == FMT_CGI)) { *output << "</font>"; } 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) *output << "<milestone type=\"line\"/>"; else if (outputformat == FMT_RTF) *output << "\\par "; else if (outputformat == FMT_GBF) *output << "<CM>"; *output << "\n"; maxverses--; } } *output << "("; *output << target->getName(); *output << ")\n"; if (outputformat == FMT_RTF) { *output << "}"; } } delete parser; }