void SWMgr::CreateMods(bool multiMod) { SectionMap::iterator it; ConfigEntMap::iterator start; ConfigEntMap::iterator end; ConfigEntMap::iterator entry; SWModule *newmod; SWBuf driver, misc1; for (it = config->Sections.begin(); it != config->Sections.end(); it++) { ConfigEntMap §ion = (*it).second; newmod = 0; driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; if (driver.length()) { newmod = createModule((*it).first, driver, section); if (newmod) { // Filters to add for this module and globally announce as an option to the user // e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally start = (*it).second.lower_bound("GlobalOptionFilter"); end = (*it).second.upper_bound("GlobalOptionFilter"); AddGlobalOptions(newmod, section, start, end); // Only add the option to the module, don't announce it's availability // These are useful for like: filters that parse special entryAttribs in a text // or whatever you might want to happen on entry lookup start = (*it).second.lower_bound("LocalOptionFilter"); end = (*it).second.upper_bound("LocalOptionFilter"); AddLocalOptions(newmod, section, start, end); //STRIP FILTERS // add all basic ones for for the modtype AddStripFilters(newmod, section); // Any special processing for this module when searching: // e.g. for papyri, removed all [](). notation start = (*it).second.lower_bound("LocalStripFilter"); end = (*it).second.upper_bound("LocalStripFilter"); AddStripFilters(newmod, section, start, end); AddRawFilters(newmod, section); AddRenderFilters(newmod, section); AddEncodingFilters(newmod, section); SWModule *oldmod = Modules[newmod->getName()]; if (oldmod) { delete oldmod; } Modules[newmod->getName()] = newmod; } } } }
/* * Class: org_crosswire_android_sword_SWModule * Method: setKeyText * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setKeyText (JNIEnv *env, jobject me, jstring keyTextJS) { init(); SWModule *module = getModule(env, me); if (module) { const char *keyText = env->GetStringUTFChars(keyTextJS, NULL); SWLog::getSystemLog()->logDebug("setKeyText(%s, %s)", module->getName(), keyText); sword::SWKey *key = module->getKey(); sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey && (*keyText=='+' ||*keyText=='-')) { if (!stricmp(keyText+1, "book")) { vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1)); env->ReleaseStringUTFChars(keyTextJS, keyText); return; } else if (!stricmp(keyText+1, "chapter")) { vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1)); env->ReleaseStringUTFChars(keyTextJS, keyText); return; } } module->setKey(keyText); env->ReleaseStringUTFChars(keyTextJS, keyText); } }
/* * Class: org_crosswire_android_sword_InstallMgr * Method: remoteInstallModule * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { initInstall(); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("remoteInstallModule: sourceName: %s\n", sourceName); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); env->ReleaseStringUTFChars(sourceNameJS, sourceName); if (source == installMgr->sources.end()) { return -3; } InstallSource *is = source->second; SWMgr *rmgr = is->getMgr(); SWModule *module; const char *modName = env->GetStringUTFChars(modNameJS, NULL); SWLog::getSystemLog()->logDebug("remoteInstallModule: modName: %s\n", modName); ModMap::iterator it = rmgr->Modules.find(modName); env->ReleaseStringUTFChars(modNameJS, modName); if (it == rmgr->Modules.end()) { return -4; } module = it->second; int error = installMgr->installModule(mgr, 0, module->getName(), is); return error; }
JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getModInfoList (JNIEnv *env, jobject) { init(); int size = 0; for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); ++it) { if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey")))) size++; } SWLog::getSystemLog()->logDebug("getModInfoList returning %d length array\n", size); jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); int i = 0; for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); ++it) { SWModule *module = it->second; if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) { SWBuf type = module->Type(); SWBuf cat = module->getConfigEntry("Category"); SWBuf version = module->getConfigEntry("Version"); if (cat.length() > 0) type = cat; jobject modInfo = env->AllocObject(clazzModInfo); jstring val; val = env->NewStringUTF(assureValidUTF8(module->getName())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getDescription())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getLanguage())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8("")); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); env->SetObjectArrayElement(ret, i++, modInfo); env->DeleteLocalRef(modInfo); } } return ret; }
int main(int argc, char **argv) { SWMgr manager; // create a default manager that looks in the current directory for mods.conf cout << "\nInstalled Modules:\n\n"; ModMap::iterator modIterator; // Loop thru all installed modules and print out information for (modIterator = manager.Modules.begin(); modIterator != manager.Modules.end(); modIterator++) { std::string modName = (*modIterator).first; // mod.conf section name (stored in module->Name()) SWModule *module = (*modIterator).second; cout << modName << "(" << module->getName() << ") | " << module->getType() << "\n"; } // Print out a verse from the first module: cout << "\n" << manager.Modules.begin()->second->getKeyText() << ":\n"; cout << manager.Modules.begin()->second->renderText(); cout << " (" << manager.Modules.begin()->second->getName() << ")\n"; // Print out the same verse from the second module (less confusing): modIterator = manager.Modules.begin(); // get first module modIterator++; // increment to next module SWModule *mod = modIterator->second; cout << "\n" << mod->getKeyText() << ":\n"; // cout << (const char *)(*mod); // we could do this, the same as above cout << mod->renderText(); cout << " (" << mod->getName() << ")\n\n"; return 0; }
/* * Class: org_crosswire_android_sword_InstallMgr * Method: uninstallModule * Signature: (Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_uninstallModule (JNIEnv *env, jobject me, jstring modNameJS) { init(); initInstall(); const char *modName = env->GetStringUTFChars(modNameJS, NULL); SWLog::getSystemLog()->logDebug("uninstallModule %s\n", modName); SWModule *module; ModMap::iterator it = mgr->Modules.find(modName); if (it == mgr->Modules.end()) { return -2; } module = it->second; installMgr->removeModule(mgr, module->getName()); env->ReleaseStringUTFChars(modNameJS, modName); return 0; }
const char *SWModule_getName(SWHANDLE hmodule) { SWModule *module = (SWModule *)hmodule; return (const char *)((module) ? module->getName() : 0); }
/* * Class: org_crosswire_android_sword_InstallMgr * Method: getRemoteModInfoList * Signature: (Ljava/lang/String;)[Lorg/crosswire/android/sword/SWMgr/ModInfo; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModInfoList (JNIEnv *env, jobject me, jstring sourceNameJS) { SWLog::getSystemLog()->logDebug("getRemoteModInfoList\n"); init(); initInstall(); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("sourceName: %s\n", sourceName); jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); if (source == installMgr->sources.end()) { SWLog::getSystemLog()->logDebug("remoteListModules returning 0 length array\n"); return (jobjectArray) env->NewObjectArray(0, clazzModInfo, NULL); } SWLog::getSystemLog()->logDebug("found source: %s\n", sourceName); map<SWModule *, int> modStats = installMgr->getModuleStatus(*mgr, *source->second->getMgr()); int size = 0; for (map<SWModule *, int>::iterator it = modStats.begin(); it != modStats.end(); ++it) { size++; } SWLog::getSystemLog()->logDebug("remoteListModules returning %d length array\n", size); jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); int i = 0; for (map<SWModule *, int>::iterator it = modStats.begin(); it != modStats.end(); ++it) { SWModule *module = it->first; int status = it->second; SWBuf version = module->getConfigEntry("Version"); SWBuf statusString = " "; if (it->second & InstallMgr::MODSTAT_NEW) statusString = "*"; if (it->second & InstallMgr::MODSTAT_OLDER) statusString = "-"; if (it->second & InstallMgr::MODSTAT_UPDATED) statusString = "+"; SWBuf type = module->Type(); SWBuf cat = module->getConfigEntry("Category"); if (cat.length() > 0) type = cat; jobject modInfo = env->AllocObject(clazzModInfo); jstring val; val = env->NewStringUTF(assureValidUTF8(module->getName())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getDescription())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(module->getLanguage())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); val = env->NewStringUTF(assureValidUTF8(statusString.c_str())); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); env->SetObjectArrayElement(ret, i++, modInfo); env->DeleteLocalRef(modInfo); } env->ReleaseStringUTFChars(sourceNameJS, sourceName); return ret; }
/* * Class: org_crosswire_android_sword_SWModule * Method: search * Signature: (Ljava/lang/String;IJLjava/lang/String;Lorg/crosswire/android/sword/SWModule/SearchProgressReporter;)[Lorg/crosswire/android/sword/SWModule/SearchHit; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search (JNIEnv *env, jobject me, jstring expressionJS, jint srchType, jlong flags, jstring scopeJS, jobject progressReporter) { init(); const int MAX_RETURN_COUNT = 999999; const char *expression = env->GetStringUTFChars(expressionJS, NULL); const char *scope = env->GetStringUTFChars(scopeJS, NULL); jclass clazzSearchHit = env->FindClass("org/crosswire/android/sword/SWModule$SearchHit"); jobjectArray ret = 0; SWModule *module = getModule(env, me); struct pu peeuuu(env, progressReporter); if (module) { sword::ListKey lscope; sword::ListKey result; if ((scope) && (strlen(scope)) > 0) { sword::SWKey *p = module->CreateKey(); sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); if (!parser) { delete p; parser = new VerseKey(); } *parser = module->getKeyText(); lscope = parser->ParseVerseList(scope, *parser, true); result = module->search(expression, srchType, flags, &lscope, 0, &percentUpdate, &peeuuu); delete parser; } else result = module->search(expression, srchType, flags, 0, 0, &percentUpdate, &peeuuu); int count = 0; for (result = sword::TOP; !result.Error(); result++) count++; if (count > MAX_RETURN_COUNT) count = MAX_RETURN_COUNT; ret = (jobjectArray) env->NewObjectArray(count, clazzSearchHit, NULL); // if we're sorted by score, let's re-sort by verse, because Java can always re-sort by score result = sword::TOP; if ((count) && (long)result.getElement()->userData) result.sort(); int i = 0; jstring modName = env->NewStringUTF(assureValidUTF8(module->getName())); jfieldID fieldIDModName = env->GetFieldID(clazzSearchHit, "modName", "Ljava/lang/String;"); jfieldID fieldIDKey = env->GetFieldID(clazzSearchHit, "key" , "Ljava/lang/String;"); jfieldID fieldIDScore = env->GetFieldID(clazzSearchHit, "score" , "J"); for (result = sword::TOP; !result.Error(); result++) { jfieldID fieldID; jobject searchHit = env->AllocObject(clazzSearchHit); env->SetObjectField(searchHit, fieldIDModName, modName); jstring key = env->NewStringUTF(assureValidUTF8((const char *)result)); env->SetObjectField(searchHit, fieldIDKey, key); env->DeleteLocalRef(key); env->SetLongField(searchHit, fieldIDScore, (long)result.getElement()->userData); env->SetObjectArrayElement(ret, i++, searchHit); env->DeleteLocalRef(searchHit); if (i >= MAX_RETURN_COUNT) break; } env->DeleteLocalRef(modName); } env->ReleaseStringUTFChars(scopeJS, scope); env->ReleaseStringUTFChars(expressionJS, expression); return (ret) ? ret : (jobjectArray) env->NewObjectArray(0, clazzSearchHit, NULL); }
char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *module) { if (option) { char token[2112]; // cheese. Fix. int tokpos = 0; bool intoken = false; int word = 1; char val[128]; char *valto; char *ch; char wordstr[5]; unsigned int textStart = 0, lastAppendLen = 0, textEnd = 0; SWBuf tmp; bool newText = false; bool needWordOut = false; AttributeValue *wordAttrs = 0; SWBuf modName = (module)?module->getName():""; SWBuf wordSrcPrefix = modName; const SWBuf orig = text; const char * from = orig.c_str(); VerseKey *vkey = 0; if (key) { vkey = SWDYNAMIC_CAST(VerseKey, key); } for (text = ""; *from; from++) { if (*from == '<') { intoken = true; tokpos = 0; token[0] = 0; token[1] = 0; token[2] = 0; textEnd = text.length(); continue; } if (*from == '>') { // process tokens intoken = false; if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) { // Strongs valto = val; for (unsigned int i = 27; token[i] != '\"' && i < 150; i++) *valto++ = token[i]; *valto = 0; if (atoi((!isdigit(*val))?val+1:val) < 5627) { // normal strongs number sprintf(wordstr, "%03d", word++); needWordOut = (word > 2); wordAttrs = &(module->getEntryAttributes()["Word"][wordstr]); (*wordAttrs)["Strongs"] = val; //printf("Adding: [\"Word\"][%s][\"Strongs\"] = %s\n", wordstr, val); tmp = ""; tmp.append(text.c_str()+textStart, (int)(textEnd - textStart)); (*wordAttrs)["Text"] = tmp; text.append("</span>"); SWBuf ts; ts.appendFormatted("%d", textStart); (*wordAttrs)["TextStart"] = ts; //printf("Adding: [\"Word\"][%s][\"Text\"] = %s\n", wordstr, tmp.c_str()); newText = true; } else { // verb morph (*wordAttrs)["Morph"] = val; //printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val); } } if (!strncmp(token, "sync type=\"morph\"", 17)) { for (ch = token+17; *ch; ch++) { if (!strncmp(ch, "class=\"", 7)) { valto = val; for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++) *valto++ = ch[i]; *valto = 0; (*wordAttrs)["MorphClass"] = val; //printf("Adding: [\"Word\"][%s][\"MorphClass\"] = %s\n", wordstr, val); } if (!strncmp(ch, "value=\"", 7)) { valto = val; for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++) *valto++ = ch[i]; *valto = 0; (*wordAttrs)["Morph"] = val; //printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val); } } newText = true; } // if not a strongs token, keep token in text text += '<'; text += token; text += '>'; if (needWordOut) { char wstr[10]; sprintf(wstr, "%03d", word-2); AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]); needWordOut = false; SWBuf strong = (*wAttrs)["Strongs"]; SWBuf morph = (*wAttrs)["Morph"]; SWBuf morphClass = (*wAttrs)["MorphClass"]; SWBuf wordText = (*wAttrs)["Text"]; SWBuf textSt = (*wAttrs)["TextStart"]; if (strong.size()) { char gh = 0; gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; SWModule *sLex = 0; SWModule *sMorph = 0; if (gh == 'G') { sLex = defaultGreekLex; sMorph = defaultGreekParse; } if (gh == 'H') { sLex = defaultHebLex; sMorph = defaultHebParse; } SWBuf lexName = ""; if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") lexName = "H"; } SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); } for (unsigned int i = 0; i < wordID.size(); i++) { if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) { wordID[i] = '_'; } } wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr)); if (textSt.size()) { int textStr = atoi(textSt.c_str()); textStr += lastAppendLen; SWBuf spanStart = ""; if (!sMorph) sMorph = 0; // avoid unused warnings for now /* if (sMorph) { SWBuf popMorph = "<a onclick=\""; popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s</a>", sMorph->getName(), morph.c_str(), wordID.c_str(), morph.c_str()); morph = popMorph; } */ // 'p' = 'fillpop' to save bandwidth const char *m = strchr(morph.c_str(), ':'); if (m) m++; else m = morph.c_str(); spanStart.appendFormatted("<span class=\"clk\" onclick=\"p('%s','%s','%s','%s','','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m, modName.c_str()); text.insert(textStr, spanStart); lastAppendLen = spanStart.length(); } } } if (newText) { textStart = text.length(); newText = false; } continue; } if (intoken) { if (tokpos < 2045) { token[tokpos++] = *from; // TODO: why is this + 2 ? token[tokpos+2] = 0; } } else { text += *from; } } char wstr[10]; sprintf(wstr, "%03d", word-1); AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]); needWordOut = false; SWBuf strong = (*wAttrs)["Strongs"]; SWBuf morph = (*wAttrs)["Morph"]; SWBuf morphClass = (*wAttrs)["MorphClass"]; SWBuf wordText = (*wAttrs)["Text"]; SWBuf textSt = (*wAttrs)["TextStart"]; if (strong.size()) { char gh = 0; gh = isdigit(strong[0]) ? 0:strong[0]; if (!gh) { if (vkey) { gh = vkey->getTestament() ? 'H' : 'G'; } } else strong << 1; SWModule *sLex = 0; if (gh == 'G') { sLex = defaultGreekLex; } if (gh == 'H') { sLex = defaultHebLex; } SWBuf lexName = ""; if (sLex) { // we can pass the real lex name in, but we have some // aliases in the javascript to optimize bandwidth lexName = sLex->getName(); if (lexName == "StrongsGreek") lexName = "G"; if (lexName == "StrongsHebrew") lexName = "H"; } SWBuf wordID; if (vkey) { // optimize for bandwidth and use only the verse as the unique entry id wordID.appendFormatted("%d", vkey->getVerse()); } else { wordID = key->getText(); } for (unsigned int i = 0; i < wordID.size(); i++) { if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) { wordID[i] = '_'; } } wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr)); if (textSt.size()) { int textStr = atoi(textSt.c_str()); textStr += lastAppendLen; SWBuf spanStart = ""; // 'p' = 'fillpop' to save bandwidth const char *m = strchr(morph.c_str(), ':'); if (m) m++; else m = morph.c_str(); spanStart.appendFormatted("<span class=\"clk\" onclick=\"p('%s','%s','%s','%s','','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m, modName.c_str()); text.insert(textStr, spanStart); } } } return 0; }
void systemquery(const char * key, ostream* output){ DiathekeMgr manager; ModMap::iterator it; SWModule *target; bool types = false, descriptions = false, names = false; if (!::stricmp(key, "localelist")) { LocaleMgr *lm = LocaleMgr::getSystemLocaleMgr(); list<SWBuf> loclist = lm->getAvailableLocales(); list<SWBuf>::iterator li = loclist.begin(); for (;li != loclist.end(); li++) { *output << li->c_str() << endl; } } else if (!::stricmp(key, "modulelist")) { types = true; descriptions = true; names = true; } else if (!::stricmp(key, "modulelistnames")) { names = true; } else if (!::stricmp(key, "modulelistdescriptions")) { descriptions = true; } if (types || descriptions || names) { if (types) *output << "Biblical Texts:\n"; for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { target = it->second; if (!strcmp(target->getType(), "Biblical Texts")) { if (names) *output << target->getName(); if (names && descriptions) *output << " : "; if (descriptions) *output << target->getDescription(); *output << endl; } } if (types) *output << "Commentaries:\n"; for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { target = it->second; if (!strcmp(target->getType(), "Commentaries")) { if (names) *output << target->getName(); if (names && descriptions) *output << " : "; if (descriptions) *output << target->getDescription(); *output << endl; } } if (types) *output << "Dictionaries:\n"; for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { target = it->second; if (!strcmp(target->getType(), "Lexicons / Dictionaries")) { if (names) *output << target->getName(); if (names && descriptions) *output << " : "; if (descriptions) *output << target->getDescription(); *output << endl; } } if (types) *output << "Generic books:\n"; for (it = manager.Modules.begin(); it != manager.Modules.end(); it++) { target = it->second; if (!strcmp(target->getType(), "Generic Books")) { if (names) *output << target->getName(); if (names && descriptions) *output << " : "; if (descriptions) *output << target->getDescription(); *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(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; }