Exemplo n.º 1
0
int main(int argc, char **argv) {

    const char* modName = (argc >= 2) ? argv[1] : "KJV";
    const char* keyName = (argc == 3) ? argv[2] : "John 1:1";

    SWMgr mgr(0, 0, true, new MarkupFilterMgr(FMT_WEBIF, ENC_UTF8));
    mgr.setGlobalOption("Strong's Numbers", "on");
    mgr.setGlobalOption("Morphological Tags", "on");

    SWModule *module = mgr.Modules[modName];
    if (!module) {
        module = mgr.Modules.begin()->second;
    }
    module->setKey(keyName);
    std::cout << module->renderText() << std::endl<< std::endl<< std::endl;

    //------------------------

    SWMgr mgr2(0, 0, true, new MarkupFilterMgr(FMT_HTMLHREF, ENC_UTF8));
    mgr2.setGlobalOption("Strong's Numbers", "on");
    mgr2.setGlobalOption("Morphological Tags", "on");
    module = mgr2.Modules[modName];
    if (!module) {
        module = mgr2.Modules.begin()->second;
    }

    module->setKey(keyName);
    std::cout << module->renderText() << std::endl;

    return 0;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {

	if (argc != 2) {
		cerr << "\nusage: " << *argv << " <modName>\n" << endl;
		exit(-1);
	}

	SWMgr library(new MarkupFilterMgr(FMT_XHTML));
	library.setGlobalOption("Headings", "On");

	SWModule *module = library.getModule(argv[1]);

	if (!module) {
		cerr << "\nCouldn't find module: " << argv[1] << "\n" << endl;
		exit(-2);
	}

	module->setKey("Ps.3.1");
	outputCurrentVerse(module);

	module->setKey("Mark.1.14");
	outputCurrentVerse(module);


	cout << "\nWhitespace tests around headings:\n";
	((VerseKey *)module->getKey())->setIntros(true);
	*module = TOP;
	// module heading
	cout << module->renderText() << "\n";
	(*module)++;
	// testament heading
	cout << module->renderText() << "\n";
	(*module)++;
	// book heading
	cout << module->renderText() << "\n";
	(*module)++;
	// chapter heading
	cout << module->renderText() << "\n";
	(*module)++;
	// verse body
	module->renderText();
	SWBuf header = module->getEntryAttributes()["Heading"]["Preverse"]["0"];
	cout << module->renderText(header) << endl;
	cout << "[ " << module->getKeyText() << " ] " << module->renderText() << "\n";
	(*module)++;
	// verse body
	module->renderText();
	header = module->getEntryAttributes()["Heading"]["Preverse"]["0"];
	cout << module->renderText(header) << endl;
	cout << "[ " << module->getKeyText() << " ] " << module->renderText() << "\n";

	return 0;
}
Exemplo n.º 4
0
/*
 * 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);
	}
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	const char *range = (argc > 1) ? argv[1] : "Mat 2:10,12-15";

	VerseKey parser;
	ListKey result;

	result = parser.parseVerseList(range, parser, true);

	// let's iterate the key and display
	for (result = TOP; !result.popError(); result++) {
		cout << result << "\n";
	}
	cout << endl;

	// Now let's output a module with the entries from the result
	
	// we'll initialize our library of books
	SWMgr library(new MarkupFilterMgr(FMT_PLAIN));	// render plain without fancy markup

	// Let's get a book;
	SWModule *book = library.getModule("KJV");

	// couldn't find our test module
	if (!book) return -1;

	// now let's iterate the book and display
	for (result = TOP; !result.popError(); result++) {
		book->setKey(result);
		cout << "*** " << book->getKeyText() << ": " << book->renderText() << "\n";
	}

	return 0;
}
Exemplo n.º 6
0
int sword__Quick_getJScriptAttribArray(xsd__string modName, xsd__string modKey, xsd__string &arrayText) {
	SWModule *mod = mgr->Modules[modName];
	if (mod) {
		mod->setKey(modKey);
		AttributeTypeList::iterator i1;
		AttributeList::iterator i2;
		AttributeValue::iterator i3;
		int l1, l2, l3;
		char lbuf1[20], lbuf2[20], lbuf3[20];
		static string retVal = "";
		retVal = "var entryAttribs = new Array();\n";
		string l1keys = "entryAttribs[0] = new Array(";
		for (l1=0,i1 = target->getEntryAttributes().begin(); i1 != target->getEntryAttributes().end(); ++i1,++l1) {
			sprintf(lbuf1, "%d", l1+1);
			retVal += "entryAttribs["+lbuf1+"] = new Array();\n";
			string l2keys = "entryAttribs["+lbuf1+"][0] = new Array(";
			cout << "[ " << i1->first << " ]\n";
			for (l2=0,i2 = i1->second.begin(); i2 != i1->second.end(); ++i2,++l2) {
				sprintf(lbuf2, "%d", l2+1);
				retVal += "entryAttribs["+lbuf1+"]["+lbuf2+"][0] = new Array();\n";
				string l3keys = "entryAttribs["+lbuf1+"]["+lbuf2+"][0] = new Array(";
				cout << "\t[ " << i2->first << " ]\n";
				for (l3=0,i3 = i2->second.begin(); i3 != i2->second.end(); ++i3,++l3) {
					cout << "\t\t" << i3->first << " = " << i3->second << "\n";
				}
			}
		}
	}
	return SOAP_OK;
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
	SWMgr library;
	SWModule *darby = library.getModule("Darby");
	darby->setKey("James 1:19");
	cout << darby->RenderText();

	return 0;
}
Exemplo n.º 8
0
int sword__Quick_getModuleRawEntry(xsd__string modName, xsd__string modKey, xsd__string &modText) {
	SWModule *mod = mgr->Modules[modName];
	if (mod) {
		mod->setKey(modKey);
		modText = mod->getRawEntry();
	}
	return SOAP_OK;
}
Exemplo n.º 9
0
int sword__Quick_getModuleRenderText(xsd__string modName, xsd__string modKey, xsd__string &modText) {
	SWModule *mod = mgr->Modules[modName];
	if (mod) {
		mod->setKey(modKey);
		modText = (char *)mod->RenderText();
	}
	return SOAP_OK;
}
Exemplo n.º 10
0
int sword__Quick_setModuleRawEntry(xsd__string modName, xsd__string modKey, xsd__string modText, xsd__int &noop) {
	SWModule *mod = mgr->Modules[modName];
	if (mod) {
		mod->setKey(modKey);
		(*mod) << modText;
	}
	return SOAP_OK;
}
Exemplo n.º 11
0
const char *SWModule_getFootnoteType(SWHANDLE hmodule, const char *key, const char *note) {
	SWModule *module = (SWModule *)hmodule;
	static SWBuf type;
	module->popError();
	module->setKey(key);
	module->renderText();	
	type = module->getEntryAttributes()["Footnote"][note]["type"].c_str();
	return (type) ? (const char*)type.c_str() : NULL;
}
Exemplo n.º 12
0
const char *SWModule_getFootnoteRefList(SWHANDLE hmodule, const char *key, const char *note) {
	SWModule *module = (SWModule *)hmodule;
	static SWBuf refList;
	module->popError();
	module->setKey(key);
	module->renderText();	
	refList = module->getEntryAttributes()["Footnote"][note]["refList"].c_str();
	return (refList) ? (const char*)refList.c_str() : NULL;
}
Exemplo n.º 13
0
const char *SWModule_getPreverseHeader(SWHANDLE hmodule, const char *key, int pvHeading) {
	SWModule *module = (SWModule *)hmodule;
	static SWBuf preverseHeading;
	char buf[12];	
	sprintf(buf, "%i", pvHeading);  
	module->setKey(key);	
	module->renderText();                 	
	preverseHeading = module->getEntryAttributes()["Heading"]["Preverse"][buf].c_str();
	return (preverseHeading.length()) ? (const char*)preverseHeading.c_str() : NULL;
}
Exemplo n.º 14
0
const char *SWModule_getFootnoteBody(SWHANDLE hmodule, const char *key, const char *note) {
	SWModule *module = (SWModule *)hmodule;
	static SWBuf body;
	module->popError();
	module->setKey(key);
	module->renderText();
	body = module->getEntryAttributes()["Footnote"][note]["body"].c_str();
	SWKey *keybuf = module->getKey();;
	module->renderFilter(body, keybuf);
	return (body) ? (const char*)body.c_str() : NULL;
}
Exemplo n.º 15
0
int main(int argc, char **argv) {
	SWMgr mymgr;

	SWModule *bbe = mymgr.Modules["BBE"];

	if (bbe) {
		VerseKey vk;
		vk.setPersist(true);
		bbe->setKey(vk);
		for (; !bbe->popError(); (*bbe)++ ) {
			std::cout << vk.getIndex() << std::endl; 
		}
	}
	return 0;
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{
	const char *range = (argc > 1) ? argv[1] : "Mat 2:10,12-15";

	VerseKey parser;
	ListKey result;

	result = parser.parseVerseList(range, parser, true);
	// let's iterate the key and display
	for (result = TOP; !result.popError(); result++) {
		cout << result << "\n";
	}
	cout << endl;

	// Now if we'd like persist this key for use inside of a book...
	result.setPersist(true);
	
	// Let's get a book;
	SWMgr library(new MarkupFilterMgr(FMT_PLAIN));	// render plain without fancy markup
	SWModule *book = library.getModule("KJV");

	// and set our limited key inside
	book->setKey(result);

	// now let's iterate the book and display
	for ((*book) = TOP; !book->popError(); (*book)++) {
		cout << "*** " << book->getKeyText() << ": " << book->renderText() << "\n";
	}

	// Since we've told our result key to persist in book, we can reuse our
	// setup by simply resetting result, e.g.
	//
	// result = parser.ParseVerseList(someNewRange, parser, true);
	//
	// Now an iteration of book will give us our new range.
	//
	// To stop persistence of our custom key, we'll need to set our book's key
	// to something simple:
	// 
	// book->setKey("gen.1.1");
	// 
	// Resetting our book object's key to something not persistent will revert our book object to using its default key for positioning
	//
	//

	return 0;
}
Exemplo n.º 17
0
std::string SwordPluginAPI::getStrong(const std::string& moduleName, const std::string& key) {
    std::stringstream out;

    SWModule *module = displayLibrary->getModule(moduleName.c_str());
    /* if (!module) {
        PDL_JSException(parms, "getStrong: You have to install the 'StrongsGreek' and 'StrongsHebrew' module to get Strong's Numbers!");
        return PDL_TRUE;
    } */

    module->setKey(key.c_str());

    if (strcmp(module->RenderText(), "") != 0) {
        out << convertString(module->RenderText());
    }

    return out.str();
}
Exemplo n.º 18
0
int main(int argc, char **argv) {
	std::cerr << "\n";
	SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG);
	SWConfig *sysConf = 0;
	if (argc > 1) {
		sysConf = new SWConfig(argv[1]);
	}
	SWMgr mymgr(0, sysConf);
	std::cerr << "\n\nprefixPath: " << mymgr.prefixPath;
	std::cerr << "\nconfigPath: " << mymgr.configPath << "\n\n";



	ModMap::iterator it;

	for (it = mymgr.Modules.begin(); it != mymgr.Modules.end(); it++) {
		std::cout << "[" << (*it).second->getName() << "] (Writable: " << (it->second->isWritable()?"Yes":"No") << ") [" << (*it).second->getDescription() << "]\n";
		std::cout << "AbsoluteDataPath = " << it->second->getConfigEntry("AbsoluteDataPath") << "\n";
		std::cout << "Has Feature HebrewDef = " << it->second->getConfig().has("Feature", "HebrewDef") << "\n";
		if ((!strcmp((*it).second->getType(), "Biblical Texts")) || (!strcmp((*it).second->getType(), "Commentaries"))) {
			it->second->setKey("James 1:19");
			std::cout << (const char *) *(*it).second << "\n\n";
		}
	}

	SWModule *mhc = mymgr.Modules["MHC"];

	if (mhc) {
		std::cout << "MHC, Lang = " << mhc->getLanguage() << "\n\n";
		for (mhc->setKey("Gen 1:1"); *mhc->getKey() < (VerseKey) "Gen 1:10"; (*mhc)++)
			std::cout << (const char *) *mhc << "\n";
	}

	if (sysConf)
		delete sysConf;

	return 0;
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	int action = 0;

	if ((argc < 4) || (argc > 6)) {
		cerr << "usage: " << argv[0] << " <mod_name> <key> <key|buf|""-delete> [0(deflt) - normal; 1 - link]\n";
		exit(-1);
	}

	if (argc > 4)
		action = atoi(argv[4]);

	SWMgr mgr;

	ModMap::iterator 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]);
		exit(-2);
	}

	SWModule *module = it->second;
	module->setKey(argv[2]);

	switch (action) {
	case 0:
		if (strlen(argv[3]))
			(*module) << argv[3];
		else module->deleteEntry();
		break;
	case 1:
		(*module) << (SWKey)argv[3];
		break;
	default:
		cerr << "Unknown action " << action << "\n";
		exit(-3);
	}
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
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;

}
Exemplo n.º 22
0
int main(int argc, char **argv) {

	const char * helptext ="imp2ld 1.0 Lexicon/Dictionary/Daily Devotional/Glossary module creation tool for the SWORD Project\n  usage:\n   %s <filename> [modname] [ 4 (default) | 2 | z - module driver]\n";

	signed long i = 0;
	string keybuffer;
	string entbuffer;
	string linebuffer;
	char modname[16];
	char links = 0;
	std::vector<string> linkbuffer;

	if (argc > 2) {
		strcpy (modname, argv[2]);
	}
	else if (argc > 1) {
		for (i = 0; (i < 16) && (argv[1][i]) && (argv[1][i] != '.'); i++) {
			modname[i] = argv[1][i];
		}
		modname[i] = 0;
	}
	else {
		fprintf(stderr, helptext, argv[0]);
		exit(-1);
	}

	std::ifstream infile(argv[1]);

	char mode = 1;
	if (argc > 3) {
		switch (*argv[3]) {
			case 'z': mode = 3; break;
			case '2': mode = 2; break;
			default: mode = 1;
		}
	}

	SWModule *mod = 0;
	SWKey *key, *linkKey;

	switch (mode) {
	case 3:
		zLD::createModule(modname);
		mod = new zLD(modname, 0, 0, 30, new ZipCompress());
		break;
	case 2:
		RawLD::createModule(modname);
		mod = new RawLD(modname);
		break;
	case 1:
		RawLD4::createModule(modname);
		mod = new RawLD4(modname);
		break;
	}

	key = mod->CreateKey();
	linkKey = mod->CreateKey();
	key->Persist(1);
	mod->setKey(key);

	while (!infile.eof()) {
		std::getline(infile, linebuffer);
		if (linebuffer.size() > 3 && linebuffer.substr(0,3) == "$$$") {
			if (keybuffer.size() && entbuffer.size()) {
				std::cout << keybuffer << std::endl;
				*key = keybuffer.c_str();

				mod->setEntry(entbuffer.c_str(), entbuffer.size());
				for (i = 0; i < links; i++) {
					std::cout << "Linking: " << linkbuffer[i] << std::endl;
					*linkKey = linkbuffer[i].c_str();
					mod->linkEntry(linkKey);
				}
			}
			if (linebuffer.size() > 3)
				keybuffer = linebuffer.substr(3,linebuffer.size());

			entbuffer.resize(0);
			linkbuffer.clear();
			links = 0;
		}
		else if (linebuffer.size() > 3 && linebuffer.substr(0,3) == "%%%") {
			linkbuffer.push_back(linebuffer.substr(3,linebuffer.size()));
			links++;
		}
		else {
			entbuffer += linebuffer;
		}
	}

	//handle final entry
	if (keybuffer.size() && entbuffer.size()) {
		std::cout << keybuffer << std::endl;
		*key = keybuffer.c_str();

		mod->setEntry(entbuffer.c_str(), entbuffer.size());
		for (i = 0; i < links; i++) {
			std::cout << "Linking: " << linkbuffer[i] << std::endl;
			*linkKey = linkbuffer[i].c_str();
			mod->linkEntry(linkKey);
		}
	}

	infile.close();

	delete linkKey;
	delete key;
	delete mod;

	return 0;
}
Exemplo n.º 23
0
int main(int argc, char **argv) {

    std::vector<string> linkbuffer;
    signed long i = 0;
    string keybuffer;
    string entbuffer;
    string linebuffer;
    char links = 0;
    string modname;
    SWBuf outPath          = "";
    bool append            = false;
    long blockCount = 30;
    bool caseSensitive = false;
    SWCompress *compressor = 0;
    SWBuf compType         = "";
    bool fourByteSize      = false;

    if (argc < 2) usage(*argv);

    const char *progName   = argv[0];
    const char *inFileName = argv[1];

    for (int i = 2; i < argc; i++) {
        if (!strcmp(argv[i], "-a")) {
            append = true;
        }
        else if (!strcmp(argv[i], "-z")) {
            if (compType.size()) usage(*argv, "Cannot specify both -z and -Z");
            if (fourByteSize) usage(*argv, "Cannot specify both -z and -4");
            compType = "ZIP";
        }
        else if (!strcmp(argv[i], "-Z")) {
            if (compType.size()) usage(*argv, "Cannot specify both -z and -Z");
            if (fourByteSize) usage(*argv, "Cannot specify both -Z and -4");
            compType = "LZSS";
        }
        else if (!strcmp(argv[i], "-4")) {
            fourByteSize = true;
        }
        else if (!strcmp(argv[i], "-b")) {
            if (i+1 < argc) {
                blockCount = atoi(argv[++i]);
                if (blockCount > 0) continue;
            }
            usage(*argv, "-b requires in entry count integer > 0");
        }
        else if (!strcmp(argv[i], "-o")) {
            if (i+1 < argc) outPath = argv[++i];
            else usage(progName, "-o requires <output_path>");
        }
        else if (!strcmp(argv[i], "-s")) {
            caseSensitive = true;
        }
        else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
    }



    if (outPath.size() < 1) {
        for (i = 0; (i < 16) && (inFileName[i]) && (inFileName[i] != '.'); i++) {
            outPath += inFileName[i];
        }
    }

    std::ifstream infile(inFileName);


    SWModule *mod = 0;
    SWKey *key, *linkKey;

    if (compType == "ZIP") {
#ifndef EXCLUDEZLIB
        compressor = new ZipCompress();
#else
        usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libzip is available when compiling SWORD library");
#endif
    }
    else if (compType == "LZSS") {
        compressor = new LZSSCompress();
    }

    // setup module
    if (!append) {
        if (compressor) {
            if (zLD::createModule(outPath)) {
                fprintf(stderr, "ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
                exit(-1);
            }
        }
        else {
            if (!fourByteSize)
                RawLD::createModule(outPath);
            else	RawLD4::createModule(outPath);
        }
    }

    if (compressor) {
        // Create a compressed text module allowing very large entries
        // Taking defaults except for first, fourth, fifth and last argument
        mod = new zLD(outPath, 0, 0, blockCount, compressor, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive);
    }
    else {
        mod = (!fourByteSize)
              ? (SWModule *)new RawLD (outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive)
              : (SWModule *)new RawLD4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, caseSensitive);
    }




    key = mod->createKey();
    linkKey = mod->createKey();
    key->setPersist(true);
    mod->setKey(key);

    while (!infile.eof()) {
        std::getline(infile, linebuffer);
        if (linebuffer.size() > 3 && linebuffer.substr(0,3) == "$$$") {
            if (keybuffer.size() && entbuffer.size()) {
                std::cout << keybuffer << std::endl;
                *key = keybuffer.c_str();

                mod->setEntry(entbuffer.c_str(), entbuffer.size());
                for (i = 0; i < links; i++) {
                    std::cout << "Linking: " << linkbuffer[i] << std::endl;
                    *linkKey = linkbuffer[i].c_str();
                    mod->linkEntry(linkKey);
                }
            }
            if (linebuffer.size() > 3)
                keybuffer = linebuffer.substr(3,linebuffer.size());

            entbuffer.resize(0);
            linkbuffer.clear();
            links = 0;
        }
        else if (linebuffer.size() > 3 && linebuffer.substr(0,3) == "%%%") {
            linkbuffer.push_back(linebuffer.substr(3,linebuffer.size()));
            links++;
        }
        else {
            entbuffer += linebuffer;
        }
    }

    //handle final entry
    if (keybuffer.size() && entbuffer.size()) {
        std::cout << keybuffer << std::endl;
        *key = keybuffer.c_str();

        mod->setEntry(entbuffer.c_str(), entbuffer.size());
        for (i = 0; i < links; i++) {
            std::cout << "Linking: " << linkbuffer[i] << std::endl;
            *linkKey = linkbuffer[i].c_str();
            mod->linkEntry(linkKey);
        }
    }

    infile.close();

    delete linkKey;
    delete key;
    delete mod;

    return 0;
}
Exemplo n.º 24
0
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;
}
Exemplo n.º 25
0
int main(int argc, char **argv) {


	// handle options
	if (argc < 2) usage(*argv);

	const char *progName   = argv[0];
	const char *inFileName = argv[1];
	SWBuf v11n	     = "KJV";
	SWBuf outPath	  = "./";
	SWBuf locale	       = "en";
	
	bool fourByteSize      = false;
	bool append	    = false;
	int iType	      = 4;
	SWBuf cipherKey        = "";
	SWCompress *compressor = 0;
	SWBuf compType	 = "";

	for (int i = 2; i < argc; i++) {
		if (!strcmp(argv[i], "-a")) {
			append = true;
		}
		else if (!strcmp(argv[i], "-z")) {
			if (fourByteSize) usage(*argv, "Cannot specify both -z and -4");
			compType = "ZIP";
			if (i+1 < argc && argv[i+1][0] != '-') {
				switch (argv[++i][0]) {
				case 'l': compType = "LZSS"; break;
				case 'z': compType = "ZIP"; break;
				case 'b': compType = "BZIP2"; break;
				case 'x': compType = "XZ"; break;
				}
			}
		}
		else if (!strcmp(argv[i], "-Z")) {
			if (compType.size()) usage(*argv, "Cannot specify both -z and -Z");
			if (fourByteSize) usage(*argv, "Cannot specify both -Z and -4");
			compType = "LZSS";
		}
		else if (!strcmp(argv[i], "-4")) {
			fourByteSize = true;
		}
		else if (!strcmp(argv[i], "-b")) {
			if (i+1 < argc) {
				iType = atoi(argv[++i]);
				if ((iType >= 2) && (iType <= 4)) continue;
			}
			usage(*argv, "-b requires one of <2|3|4>");
		}
		else if (!strcmp(argv[i], "-o")) {
			if (i+1 < argc) outPath = argv[++i];
			else usage(progName, "-o requires <output_path>");
		}
		else if (!strcmp(argv[i], "-v")) {
			if (i+1 < argc) v11n = argv[++i];
			else usage(progName, "-v requires <v11n>");
		}
		else if (!strcmp(argv[i], "-l")) {
			if (i+1 < argc) locale = argv[++i];
			else usage(progName, "-l requires <locale>");
		}
		else if (!strcmp(argv[i], "-c")) {
			if (i+1 < argc) cipherKey = argv[++i];
			else usage(*argv, "-c requires <cipher_key>");
		}
		else usage(progName, (((SWBuf)"Unknown argument: ")+ argv[i]).c_str());
	}
	// -----------------------------------------------------
	const VersificationMgr::System *v = VersificationMgr::getSystemVersificationMgr()->getVersificationSystem(v11n);
	if (!v) std::cout << "Warning: Versification " << v11n << " not found. Using KJV versification...\n";

	if (compType == "LZSS") {
		compressor = new LZSSCompress();
	}
	else if (compType == "ZIP") {
#ifndef EXCLUDEZLIB
		compressor = new ZipCompress();
#else
		usage(*argv, "ERROR: SWORD library not compiled with ZIP compression support.\n\tBe sure libz is available when compiling SWORD library");
#endif
	}
	else if (compType == "BZIP2") {
#ifndef EXCLUDEBZIP2
		compressor = new Bzip2Compress();
#else
		usage(*argv, "ERROR: SWORD library not compiled with bzip2 compression support.\n\tBe sure libbz2 is available when compiling SWORD library");
#endif
	}
	else if (compType == "XZ") {
#ifndef EXCLUDEXZ
		compressor = new XzCompress();
#else
		usage(*argv, "ERROR: SWORD library not compiled with xz compression support.\n\tBe sure liblzma is available when compiling SWORD library");
#endif		
	}


	// setup module
	if (!append) {
		if (compressor) {
			if (zText::createModule(outPath, iType, v11n)) {
				fprintf(stderr, "ERROR: %s: couldn't create module at path: %s \n", *argv, outPath.c_str());
				exit(-1);
			}
		}
		else {
			if (!fourByteSize)
				RawText::createModule(outPath, v11n);
			else	RawText4::createModule(outPath, v11n);
		}
	}

	SWModule *module = 0;
	if (compressor) {
		// Create a compressed text module allowing very large entries
		// Taking defaults except for first, fourth, fifth and last argument
		module = new zText(
				outPath,		// ipath
				0,		// iname
				0,		// idesc
				iType,		// iblockType
				compressor,	// icomp
				0,		// idisp
				ENC_UNKNOWN,	// enc
				DIRECTION_LTR,	// dir
				FMT_UNKNOWN,	// markup
				0,		// lang
				v11n		// versification
		       );
	}
	else {
		module = (!fourByteSize)
			? (SWModule *)new RawText(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n)
			: (SWModule *)new RawText4(outPath, 0, 0, 0, ENC_UNKNOWN, DIRECTION_LTR, FMT_UNKNOWN, 0, v11n);
	}

	SWFilter *cipherFilter = 0;

	if (cipherKey.length()) {
		fprintf(stderr, "Adding cipher filter with phrase: %s\n", cipherKey.c_str() );
		cipherFilter = new CipherFilter(cipherKey.c_str());
		module->addRawFilter(cipherFilter);
	}
	// -----------------------------------------------------
	
	// setup locale manager
	
	LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(locale);
			

	// setup module key to allow full range of possible values, and then some
	
	VerseKey *vkey = (VerseKey *)module->createKey();
	vkey->setIntros(true);
	vkey->setAutoNormalize(false);
	vkey->setPersist(true);
	module->setKey(*vkey);
	// -----------------------------------------------------


	// process input file
	FileDesc *fd = FileMgr::getSystemFileMgr()->open(inFileName, FileMgr::RDONLY);

	SWBuf lineBuffer;
	SWBuf keyBuffer;
	SWBuf entBuffer;

	bool more = true;
	do {
		more = FileMgr::getLine(fd, lineBuffer)!=0;
		if (lineBuffer.startsWith("$$$")) {
			if ((keyBuffer.size()) && (entBuffer.size())) {
				writeEntry(module, keyBuffer, entBuffer);
			}
			keyBuffer = lineBuffer;
			keyBuffer << 3;
			keyBuffer.trim();
			entBuffer.size(0);
		}
		else {
			if (keyBuffer.size()) {
				entBuffer += lineBuffer;
				entBuffer += "\n";
			}
		}
	} while (more);
	if ((keyBuffer.size()) && (entBuffer.size())) {
		writeEntry(module, keyBuffer, entBuffer);
	}

	delete module;
	if (cipherFilter)
		delete cipherFilter;
	delete vkey;

	FileMgr::getSystemFileMgr()->close(fd);

	return 0;
}
Exemplo n.º 26
0
void SWModule_setKeyText(SWHANDLE hmodule, const char *key) {
	SWModule *module = (SWModule *)hmodule;
	if (module)
		module->setKey(key);
}