SWModule *getModule(JNIEnv *env, jobject me) { init(); SWModule *module = 0; jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); jfieldID fieldID = env->GetFieldID(clazzSWModule, "name", "Ljava/lang/String;"); jfieldID sourceFieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); jstring modNameJS = (jstring)env->GetObjectField(me, fieldID); jstring sourceNameJS = (jstring)env->GetObjectField(me, sourceFieldID); const char *modName = (modNameJS?env->GetStringUTFChars(modNameJS, NULL):0); const char *sourceName = (sourceNameJS?env->GetStringUTFChars(sourceNameJS, NULL):0); if (sourceName && *sourceName) { initInstall(); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); if (source == installMgr->sources.end()) { SWMgr *mgr = source->second->getMgr(); module = mgr->getModule(modName); } } else module = mgr->getModule(modName); if (modName) env->ReleaseStringUTFChars(modNameJS, modName); if (sourceName) env->ReleaseStringUTFChars(sourceNameJS, sourceName); return module; }
// ret: forward_iterator SWHANDLE SWMgr_getGlobalOptionValuesIterator(SWHANDLE hmgr, const char *option) { SWMgr *mgr = (SWMgr *)hmgr; static StringList::iterator it; if (mgr) it = mgr->getGlobalOptionValues(option).begin(); return (SWHANDLE)⁢ }
int main(int argc, char **argv) { SWMgr library; SWModule *darby = library.getModule("Darby"); darby->setKey("James 1:19"); cout << darby->RenderText(); return 0; }
int main(int argc, char **argv) { SWMgr mgr; SWModule *mod = mgr.getModule("KJVgb"); VerseKey *key1 = (VerseKey *)mod->createKey(); key1->setTestament(2); key1->setBook(4); key1->setChapter(2); key1->setVerse(3); cout << "\n" << key1->getText() << ":\n\n"; ListKey keys; keys << *key1; cout << "\n" << keys.getRangeText() << ":\n\n"; ListKey keys2 = keys; cout << "\n" << keys2.getRangeText() << ":\n\n"; keys = key1->parseVerseList("Lk.4.5"); cout << "\n" << key1->getText() << ":\n\n"; key1->setText("jn.6.7"); cout << "\n" << key1->getText() << ":\n\n"; mod->setKey("lk.2.3"); cout << "\n" << mod->getKeyText() << ":\n" << endl; cout << mod->getRawEntry() << endl; cout << "\nListkey persist key iteration test\n\n"; keys = key1->parseVerseList("mat1", 0, true); for (keys = TOP; !keys.popError(); keys++) { cout << "\n" << keys.getText() << ":\n" << endl; } keys.setPersist(true); mod->setKey(keys); for ((*mod) = TOP; !mod->popError(); (*mod)++) { cout << "\n" << mod->getKeyText() << ":\n" << endl; } delete key1; return 0; }
// ret: forward_iterator SWHANDLE SWMgr_getGlobalOptionsIterator(SWHANDLE hmgr) { SWMgr *mgr = (SWMgr *)hmgr; static StringList::iterator it; static StringList optionslist; if (mgr) { optionslist = mgr->getGlobalOptions(); it = optionslist.begin(); } return (SWHANDLE)⁢ }
int main(int argc, char **argv) { SWMgr library; StringList options = library.getGlobalOptions(); for (StringList::const_iterator it = options.begin(); it != options.end(); ++it) { cout << *it << " (" << library.getGlobalOptionTip(*it) << ")\n"; StringList optionValues = library.getGlobalOptionValues(*it); for (StringList::const_iterator it2 = optionValues.begin(); it2 != optionValues.end(); ++it2) { cout << "\t" << *it2 << "\n"; } } return 0; }
int main(int argc, char **argv) { // SWMgr manager(0, 0, true, new MarkupFilterMgr(FMT_RTF, ENC_RTF)); SWMgr manager; if ((argc < 3) || (argc > 3)) { usage(); exit(-1); } int stripFilters = atoi(argv[1]); if ((stripFilters < 1) || (stripFilters > 15)) { usage(); exit(-1); } SWBuf stripTerm = argv[2]; manager.setGlobalOption("Greek Accents", "Off"); manager.setGlobalOption("Arabic Vowel Points", "Off"); manager.setGlobalOption("Hebrew Vowel Points", "Off"); manager.setGlobalOption("Hebrew Cantillation", "Off"); if (stripFilters & (1 << 3)) manager.filterText("Hebrew Cantillation", stripTerm); if (stripFilters & (1 << 2)) manager.filterText("Hebrew Vowel Points", stripTerm); if (stripFilters & (1 << 1)) manager.filterText("Arabic Vowel Points", stripTerm); if (stripFilters & (1 << 0)) manager.filterText("Greek Accents", stripTerm); fprintf(stdout,"%s\n",stripTerm.c_str()); return 0; }
int main() { SWMgr library; auto const book(library.getModule("KJV")); VerseKey *vk = (VerseKey *) book->getKey(); for (;!vk->popError();vk->setChapter(vk->getChapter()+1)) { vk->setVerse(vk->getVerseMax()); std::string text = book->stripText(); trimString(text); if (!text.empty() && (*text.rbegin()) == ',') { cout << vk->getText() << ":\n\n"; cout << text << endl; } } return 0; }
int main(int argc, char **argv) { const char *modName = "HunKar"; SWMgr library; SWModule *book = library.getModule(modName); if (!book) { cerr << "Can't find module: " << modName << endl; return -1; } VerseKey* key = ((VerseKey *)book->getKey()); key->setIntros(true); book->setSkipConsecutiveLinks(true); book->setPosition(TOP); cout << *key << endl; return 0; }
int main(int argc, char **argv) { SWMgr library; SWModule *book = library.getModule("KJV"); VerseKey *vk = (VerseKey *) book->getKey(); for (;!vk->popError();vk->setChapter(vk->getChapter()+1)) { vk->setVerse(vk->getVerseMax()); SWBuf text = book->stripText(); text = text.trim(); if (text.endsWith(",")) { cout << vk->getText() << ":\n\n"; cout << text << endl; } } return 0; }
int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <Mod Name>\n", argv[0]); std::exit(-1); } SWMgr mgr; auto const it = mgr.modules().find(argv[1]); if (it == mgr.modules().end()) { fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]); std::exit(-2); } SWModule & mod = *it->second; SWKey *key = mod.getKey(); VerseKey * vkey = nullptr; try { vkey = dynamic_cast<VerseKey *>(key); } catch (...) {} if (!vkey) { fprintf(stderr, "error: %s: %s module is not keyed to verses \n", argv[0], argv[1]); std::exit(-3); } vkey->setIntros(false); // turn on mod/testmnt/book/chap headings mod.positionToTop(); while (!mod.popError()) { if (vkey->getVerse()) { if (!mod.renderText().length()) { std::cout << vkey->getText() << std::endl; } mod.increment(); } } }
int main(int argc, char **argv) { cout << "\n"; const char *modName = (argc > 1) ? argv[1] : "KJV"; SWMgr manager; SWModule *bible = manager.getModule(modName); if (!bible) { cout << modName << " module is not installed.\nPlease install to show versification (v11n) from this specific Bible.\nShowing builtin KJV v11n scheme..\n\n"; } VerseKey *vk = (bible) ? (VerseKey *)bible->getKey() : new VerseKey(); for ((*vk) = TOP; !vk->popError(); vk->setBook(vk->getBook()+1)) { cout << vk->getBookName() << "\n"; } // if we 'new'ed a VerseKey unassociated with a module, above, then we should delete it. if (!bible) delete vk; return 0; }
int main() { const char *modName = "RusCARS"; const char *keyTextRegular = "1Sam1.20"; const char *keyTextNeedsNormalization = "1Sam1.200"; SWMgr library; auto const book(library.getModule(modName)); if (!book) { cerr << "Can't find module: " << modName << endl; return -1; } // get two VerseKey objects for a module std::unique_ptr<VerseKey> verse( static_cast<VerseKey *>(book->createKey().release())); std::unique_ptr<VerseKey> verseNormalized( static_cast<VerseKey *>(book->createKey().release())); // turn off autonormalization for one VerseKey reference verse->setAutoNormalize(false); // set a reference not requiring normalization to both VerseKey objects verse->setText(keyTextRegular); verseNormalized->setText(keyTextRegular); // check to see if they are equal cout << verse->getText() << ((*verse) == (*verseNormalized) ? " == " : " != ") << verseNormalized->getText() << endl; // now do the same for a reference which requires normalization in this module's v11n system verse->setText(keyTextNeedsNormalization); verseNormalized->setText(keyTextNeedsNormalization); cout << verse->getText() << ((*verse) == (*verseNormalized) ? " == " : " != ") << verseNormalized->getText() << endl; return 0; }
/* * Class: org_crosswire_android_sword_InstallMgr * Method: getRemoteModuleByName * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; */ JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModuleByName (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { jobject retVal = 0; initInstall(); const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); SWLog::getSystemLog()->logDebug("getRemoteModuleByName: sourceName: %s\n", sourceName); InstallSourceMap::iterator source = installMgr->sources.find(sourceName); env->ReleaseStringUTFChars(sourceNameJS, sourceName); if (source == installMgr->sources.end()) { SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName); return 0; } SWMgr *mgr = source->second->getMgr(); const char *modName = env->GetStringUTFChars(modNameJS, NULL); sword::SWModule *module = mgr->getModule(modName); env->ReleaseStringUTFChars(modNameJS, modName); if (module) { SWBuf type = module->Type(); SWBuf cat = module->getConfigEntry("Category"); if (cat.length() > 0) type = cat; jfieldID fieldID; jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); retVal = env->AllocObject(clazzSWModule); fieldID = env->GetFieldID(clazzSWModule, "name", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->getName()))); fieldID = env->GetFieldID(clazzSWModule, "description", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->getDescription()))); fieldID = env->GetFieldID(clazzSWModule, "category", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(type.c_str()))); fieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, sourceNameJS); } return retVal; }
int main(int argc, char **argv) { SWMgr library; SWModule *kjv = library.getModule((argc > 1)?argv[1]:"KJV"); kjv->setKey(argc > 2 ? argv[2] : "Jn.3.16"); VerseKey *key = (VerseKey *)kjv->getKey(); int curVerse = key->getVerse(); int curChapter = key->getChapter(); int curBook = key->getBook(); for (key->setVerse(1); (key->getBook() == curBook) && (key->getChapter() == curChapter) && !kjv->popError(); (*kjv)++) { if (key->getVerse() == curVerse) cout << "* "; cout << key->getVerse() << " " << kjv->stripText() << "\n"; } return 0; }
/************************************************************************ * getModuleStatus - compare the modules of two SWMgrs and return a * vector describing the status of each. See MODSTAT_* */ map<SWModule *, int> InstallMgr::getModuleStatus(const SWMgr &base, const SWMgr &other) { map<SWModule *, int> retVal; SWBuf targetVersion; SWBuf sourceVersion; SWBuf softwareVersion; bool cipher; bool keyPresent; int modStat; for (ModMap::const_iterator mod = other.Modules.begin(); mod != other.Modules.end(); mod++) { modStat = 0; cipher = false; keyPresent = false; const char *v = mod->second->getConfigEntry("CipherKey"); if (v) { cipher = true; keyPresent = *v; } targetVersion = "0.0"; sourceVersion = "1.0"; softwareVersion = (const char *)SWVersion::currentVersion; v = mod->second->getConfigEntry("Version"); if (v) sourceVersion = v; v = mod->second->getConfigEntry("MinimumVersion"); if (v) softwareVersion = v; const SWModule *baseMod = base.getModule(mod->first); if (baseMod) { targetVersion = "1.0"; v = baseMod->getConfigEntry("Version"); if (v) targetVersion = v; modStat |= (SWVersion(sourceVersion.c_str()) > SWVersion(targetVersion.c_str())) ? MODSTAT_UPDATED : (SWVersion(sourceVersion.c_str()) < SWVersion(targetVersion.c_str())) ? MODSTAT_OLDER : MODSTAT_SAMEVERSION; } else modStat |= MODSTAT_NEW; if (cipher) modStat |= MODSTAT_CIPHERED; if (keyPresent) modStat |= MODSTAT_CIPHERKEYPRESENT; retVal[mod->second] = modStat; } return retVal; }
void SWMgr_setCipherKey(SWHANDLE hmgr, const char *modName, const char *key) { SWMgr *mgr = (SWMgr *)hmgr; if (mgr) mgr->setCipherKey(modName, key); }
int main(int argc, char **argv) { // SWMgr manager(0, 0, true, new MarkupFilterMgr(FMT_RTF, ENC_RTF)); SWMgr manager; SWModule *target; ListKey listkey; ListKey scope; ModMap::iterator it; if ((argc < 3) || (argc > 5)) { fprintf(stderr, "\nusage: %s <modname> <\"search string\"> [\"search_scope\"] [\"search again for string in previous result set\"]\n" "\tExample: search KJV \"swift hear slow speak\"\n\n", argv[0]); exit(-1); } std::string searchTerm = argv[2]; manager.setGlobalOption("Greek Accents", "Off"); manager.setGlobalOption("Strong's Numbers", "On"); manager.setGlobalOption("Hebrew Vowel Points", "Off"); manager.filterText("Greek Accents", searchTerm); it = manager.Modules.find(argv[1]); if (it == manager.Modules.end()) { fprintf(stderr, "Could not find module [%s]. Available modules:\n", argv[1]); for (it = manager.Modules.begin(); it != manager.Modules.end(); ++it) { fprintf(stderr, "[%s]\t - %s\n", (*it).second->getName(), (*it).second->getDescription()); } exit(-1); } target = (*it).second; if (argc > 3) { // if min / max specified SWKey *k = target->getKey(); VerseKey *parser = SWDYNAMIC_CAST(VerseKey, k); VerseKey kjvParser; if (!parser) parser = &kjvParser; // use standard KJV parsing as fallback scope = parser->parseVerseList(argv[3], *parser, true); scope.setPersist(true); target->setKey(scope); } std::cerr << "[0=================================50===============================100]\n "; char lineLen = 70; listkey = target->search(searchTerm.c_str(), SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen); std::cerr << std::endl; if (argc > 4) { // if min / max specified scope = listkey; scope.setPersist(true); target->setKey(scope); printed = 0; std::cerr << " "; listkey = target->search(argv[4], SEARCH_TYPE, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen); std::cerr << std::endl; } // we don't want to sort by verse if we've been given scores // listkey.sort(); while (!listkey.popError()) { std::cout << (const char *)listkey; if (listkey.getElement()->userData) std::cout << " : " << (uint64_t)listkey.getElement()->userData << "%"; std::cout << std::endl; ++listkey; } return 0; }
const char *SWMgr_getGlobalOptionTip(SWHANDLE hmgr, const char *option) { SWMgr *mgr = (SWMgr *)hmgr; return (mgr) ? (const char *)mgr->getGlobalOptionTip(option) : 0; }
void SWMgr_setGlobalOption(SWHANDLE hmgr, const char *option, const char *value) { SWMgr *mgr = (SWMgr *)hmgr; if (mgr) mgr->setGlobalOption(option, value); }
int main(int argc, char **argv) { BlockType iType = BOOKBLOCKS; int compType = 1; string cipherKey = ""; std::unique_ptr<SWCompress> compressor; int compLevel = 0; if ((argc < 3) || (argc > 7)) { errorOutHelp(argv[0]); } if (argc > 3) { switch (std::atoi(argv[3])) { case 2: iType = VERSEBLOCKS; break; case 3: iType = CHAPTERBLOCKS; break; case 4: iType = BOOKBLOCKS; break; default: std::cerr << "Argument 3 must be one of <2|3|4>\n"; errorOutHelp(*argv); } if (argc > 4) { compType = std::atoi(argv[4]); if (argc > 5) { compLevel = std::atoi(argv[5]); if (argc > 6) { cipherKey = argv[6]; } } } } if ((iType < 2) || (compType < 1) || (compType > 4) || compLevel < 0 || compLevel > 9 || (!std::strcmp(argv[1], "-h")) || (!std::strcmp(argv[1], "--help")) || (!std::strcmp(argv[1], "/?")) || (!std::strcmp(argv[1], "-?")) || (!std::strcmp(argv[1], "-help"))) { errorOutHelp(argv[0]); } SWMgr mgr; auto const it = mgr.modules().find(argv[1]); if (it == mgr.modules().end()) { fprintf(stderr, "error: %s: couldn't find module: %s\n", argv[0], argv[1]); std::exit(-2); } SWModule & inModule = *it->second; // Try to initialize a default set of datafiles and indicies at our // datapath location passed to us from the user. #define BIBLE 1 #define LEX 2 #define COM 3 int modType = 0; if (inModule.getType() == "Biblical Texts") { modType = BIBLE; } else if (inModule.getType() == "Lexicons / Dictionaries") { modType = LEX; } else if (inModule.getType() == "Commentaries") { modType = COM; } switch (compType) { // these are deleted by zText case 1: compressor = std::make_unique<LZSSCompress>(); break; case 2: compressor = std::make_unique<ZipCompress>(); break; case 3: compressor = std::make_unique<Bzip2Compress>(); break; case 4: compressor = std::make_unique<XzCompress>(); break; } if (compressor && compLevel > 0) { compressor->setLevel(compLevel); } int result = 0; switch (modType) { case BIBLE: case COM: { SWKey *k = inModule.getKey(); VerseKey *vk = dynamic_cast<VerseKey *>(k); result = zText::createModule(argv[2], iType, vk->getVersificationSystem().c_str()); break; } case LEX: result = zLD::createModule(argv[2]); break; } if (result) { fprintf(stderr, "error: %s: couldn't create module at path: %s\n", argv[0], argv[2]); std::exit(-3); } std::unique_ptr<SWModule> outModule; switch (modType) { case BIBLE: case COM: { SWKey *k = inModule.getKey(); VerseKey *vk = dynamic_cast<VerseKey *>(k); outModule = std::make_unique<zText>(argv[2], nullptr, nullptr, iType, std::move(compressor), ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, nullptr, vk->getVersificationSystem().c_str()); // open our datapath with our RawText driver. static_cast<VerseKey *>(inModule.getKey())->setIntros(true); break; } case LEX: outModule = std::make_unique<zLD>(argv[2], nullptr, nullptr, iType, std::move(compressor)); // open our datapath with our RawText driver. break; } if (!cipherKey.empty()) outModule->addRawFilter( std::make_shared<CipherFilter>(cipherKey.c_str())); string lastBuffer = "Something that would never be first module entry"; SWKey bufferKey; SWKey lastBufferKey; auto const outModuleKey(outModule->createKey()); VerseKey *vkey = dynamic_cast<VerseKey *>(outModuleKey.get()); outModuleKey->setPersist(true); if (vkey) { vkey->setIntros(true); vkey->setAutoNormalize(false); } outModule->setKey(*outModuleKey); inModule.setSkipConsecutiveLinks(false); inModule.positionToTop(); while (!inModule.popError()) { bufferKey.positionFrom(*inModule.getKey()); // pseudo-check for link. Will get most common links. if ((lastBuffer == inModule.getRawEntry()) &&(lastBuffer.length() > 0)) { outModuleKey->positionFrom(bufferKey); outModule->linkEntry(lastBufferKey); // link to last key cout << "Adding [" << bufferKey.getText() << "] link to: [" << lastBufferKey.getText() << "]\n"; } else { lastBuffer = inModule.getRawEntry(); lastBufferKey.setText(inModule.getKeyText()); if (lastBuffer.length() > 0) { cout << "Adding [" << bufferKey.getText() << "] new text.\n"; outModuleKey->positionFrom(bufferKey); // outModule->getRawEntry(); // snap // outModule->setKey(bufferKey); outModule->setEntry(lastBuffer.c_str()); // save new text; } else { cout << "Skipping [" << bufferKey.getText() << "] no entry in Module.\n"; } } inModule.increment(); } }