[sword-svn] r1844 - in trunk: bindings/corba
bindings/corba/orbitcpp examples/cmdline include src/mgr
src/modules/filters tests utilities
scribe at crosswire.org
scribe at crosswire.org
Wed Aug 3 18:12:34 MST 2005
Author: scribe
Date: 2005-08-03 18:12:33 -0700 (Wed, 03 Aug 2005)
New Revision: 1844
Added:
trunk/include/papyriplain.h
trunk/src/modules/filters/papyriplain.cpp
Modified:
trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
trunk/bindings/corba/orbitcpp/swordorb-impl.hpp
trunk/bindings/corba/swordorb.idl
trunk/examples/cmdline/lookup.cpp
trunk/examples/cmdline/search.cpp
trunk/include/Makefile.am
trunk/include/swmgr.h
trunk/src/mgr/swmgr.cpp
trunk/src/modules/filters/Makefile.am
trunk/src/modules/filters/utf8greekaccents.cpp
trunk/src/modules/filters/utf8nfkd.cpp
trunk/tests/filtertest.cpp
trunk/utilities/imp2gbs.cpp
Log:
Added features to help with sans accent and papyri tag searching
Modified: trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
===================================================================
--- trunk/bindings/corba/orbitcpp/swordorb-impl.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/bindings/corba/orbitcpp/swordorb-impl.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -110,6 +110,12 @@
delegate->setJavascript(val);
}
+char *SWMgr_impl::filterText(const char *filterName, const char *text) throw(CORBA::SystemException) {
+ SWBuf buf = text;
+ SWBuf retVal = delegate->filterText(filterName, buf);
+ return CORBA::string_dup((char *)retVal.c_str());
+}
+
char *SWModule_impl::getCategory() throw(CORBA::SystemException) {
SWBuf type = delegate->Type();
SWBuf cat = delegate->getConfigEntry("Category");
Modified: trunk/bindings/corba/orbitcpp/swordorb-impl.hpp
===================================================================
--- trunk/bindings/corba/orbitcpp/swordorb-impl.hpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/bindings/corba/orbitcpp/swordorb-impl.hpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -55,6 +55,7 @@
ModInfoList *getModInfoList() throw(CORBA::SystemException);
SWModule_ptr getModuleByName(const char *name) throw(CORBA::SystemException);
+ char *filterText(const char *filterName, const char *text) throw(CORBA::SystemException);
char *getPrefixPath() throw(CORBA::SystemException) { return CORBA::string_dup(delegate->prefixPath); }
char *getConfigPath() throw(CORBA::SystemException) { return CORBA::string_dup(delegate->configPath); }
void setGlobalOption(const char *option, const char *value) throw(CORBA::SystemException) { delegate->setGlobalOption(option, value); }
Modified: trunk/bindings/corba/swordorb.idl
===================================================================
--- trunk/bindings/corba/swordorb.idl 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/bindings/corba/swordorb.idl 2005-08-04 01:12:33 UTC (rev 1844)
@@ -74,6 +74,7 @@
void setGlobalOption(in string option, in string value);
string getGlobalOption(in string option);
string getGlobalOptionTip(in string option);
+ string filterText(in string filterName, in string text);
StringList getGlobalOptions();
StringList getGlobalOptionValues(in string option);
void setCipherKey(in string modName, in string key);
Modified: trunk/examples/cmdline/lookup.cpp
===================================================================
--- trunk/examples/cmdline/lookup.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/examples/cmdline/lookup.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -36,6 +36,7 @@
}
manager.setGlobalOption("Headings", "On");
+ manager.setGlobalOption("Greek Accents", "Off");
target = (*it).second;
Modified: trunk/examples/cmdline/search.cpp
===================================================================
--- trunk/examples/cmdline/search.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/examples/cmdline/search.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -42,6 +42,11 @@
exit(-1);
}
+
+ SWBuf searchTerm = argv[2];
+ manager.setGlobalOption("Greek Accents", "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]);
@@ -68,7 +73,7 @@
* -3 - entryAttrib (eg. Word//Strongs/G1234/)
* -4 - Lucene
*/
- listkey = target->Search(argv[2], -2, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
+ listkey = target->Search(searchTerm.c_str(), -1, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
std::cout << "\n";
while (!listkey.Error()) {
std::cout << (const char *)listkey << std::endl;
Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/include/Makefile.am 2005-08-04 01:12:33 UTC (rev 1844)
@@ -57,6 +57,7 @@
pkginclude_HEADERS += $(swincludedir)/osisscripref.h
pkginclude_HEADERS += $(swincludedir)/osiswordjs.h
+pkginclude_HEADERS += $(swincludedir)/papyriplain.h
pkginclude_HEADERS += $(swincludedir)/plainfootnotes.h
pkginclude_HEADERS += $(swincludedir)/plainfootnotes.h
pkginclude_HEADERS += $(swincludedir)/plainhtml.h
Added: trunk/include/papyriplain.h
===================================================================
--- trunk/include/papyriplain.h 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/include/papyriplain.h 2005-08-04 01:12:33 UTC (rev 1844)
@@ -0,0 +1,37 @@
+/***************************************************************************
+ *
+ * $Id: papyriplain.h 1688 2005-01-01 04:42:26Z scribe $
+ *
+ * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#ifndef PapyriPLAIN_H
+#define PapyriPLAIN_H
+
+#include <swfilter.h>
+
+SWORD_NAMESPACE_START
+
+ /** This filter converts Papyri text to plain text
+ */
+class SWDLLEXPORT PapyriPlain : public SWFilter {
+public:
+ PapyriPlain();
+ virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+};
+
+SWORD_NAMESPACE_END
+#endif
Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/include/swmgr.h 2005-08-04 01:12:33 UTC (rev 1844)
@@ -132,6 +132,9 @@
*/
virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion);
+ // ones manually specified in .conf file
+ virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
+
/**
* Called to add appropriate Raw Filters to a module. Override to do special actions,
* if desired. See the module.conf CipherKey= entry.
@@ -289,6 +292,15 @@
*/
virtual StringList getGlobalOptionValues(const char *option);
+ /** Filters a buffer thru a named filter
+ * @param filterName
+ * @param text buffer to filter
+ * @param key context key if filter needs this for processing
+ * @param module context module if filter needs this for processing
+ * @return error status
+ */
+ virtual char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+
/**
* Sets the cipher key for the given module. This function updates the key
* at runtime, but it does not write to the config file.
Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/src/mgr/swmgr.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -41,6 +41,7 @@
#include <gbfplain.h>
#include <thmlplain.h>
#include <osisplain.h>
+#include <papyriplain.h>
#include <gbfstrongs.h>
#include <gbffootnotes.h>
#include <gbfheadings.h>
@@ -213,6 +214,10 @@
optionFilters.insert(FilterMap::value_type("GreekLexAttribs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
+ tmpFilter = new PapyriPlain();
+ optionFilters.insert(FilterMap::value_type("PapyriPlain", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
// UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
#ifdef _ICU_
transliterator = new UTF8Transliterator();
@@ -851,6 +856,17 @@
}
+char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key, const SWModule *module)
+ {
+ char retVal = -1;
+ FilterMap::iterator it = optionFilters.find(filterName);
+ if (it != optionFilters.end()) {
+ retVal = it->second->processText(text, key, module); // add filter to module
+ }
+ return retVal;
+}
+
+
void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
{
for (;start != end; start++) {
@@ -866,6 +882,19 @@
}
+// manually specified StripFilters for special cases, like Papyri marks and such
+void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
+{
+ for (;start != end; start++) {
+ FilterMap::iterator it;
+ it = optionFilters.find((*start).second);
+ if (it != optionFilters.end()) {
+ module->AddStripFilter((*it).second); // add filter to module
+ }
+ }
+}
+
+
void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap §ion) {
SWBuf sourceformat, cipherKey;
ConfigEntMap::iterator entry;
@@ -960,16 +989,31 @@
if (driver.length()) {
newmod = CreateMod((*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);
- AddStripFilters(newmod, section);
AddRenderFilters(newmod, section);
AddEncodingFilters(newmod, section);
Modified: trunk/src/modules/filters/Makefile.am
===================================================================
--- trunk/src/modules/filters/Makefile.am 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/src/modules/filters/Makefile.am 2005-08-04 01:12:33 UTC (rev 1844)
@@ -66,6 +66,7 @@
PLFIL += $(filtersdir)/plainhtml.cpp
PLFIL += $(filtersdir)/greeklexattribs.cpp
PLFIL += $(filtersdir)/unicodertf.cpp
+PLFIL += $(filtersdir)/papyriplain.cpp
SWICUSRC = $(filtersdir)/utf8transliterator.cpp
Added: trunk/src/modules/filters/papyriplain.cpp
===================================================================
--- trunk/src/modules/filters/papyriplain.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/src/modules/filters/papyriplain.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ *
+ * papyriplain - SWFilter descendant to strip out all Papyri tags
+ */
+
+
+#include <stdlib.h>
+#include <papyriplain.h>
+
+SWORD_NAMESPACE_START
+
+PapyriPlain::PapyriPlain() {
+}
+
+
+char PapyriPlain::processText (SWBuf &text, const SWKey *key, const SWModule *module)
+{
+ SWBuf orig = text;
+ const char *from = orig.c_str();
+
+ for (text = ""; *from; ++from) {
+
+ // remove hyphen and whitespace if that is all that separates words
+ // also be sure we're not a double hyphen '--'
+ if ((*from == '-') && (text.length() > 0) && (text[text.length()-1] != '-')) {
+ char remove = 0;
+ const char *c;
+ for (c = from+1; *c; c++) {
+ if ((*c == 10) || (*c == 13)) {
+ remove = 1;
+ }
+ if (!strchr(" \t\n", *c)) {
+ if (remove) remove++;
+ break;
+ }
+ }
+ if (remove > 1) {
+ from = c-1;
+ continue;
+ }
+ }
+
+ // remove all newlines
+ if ((*from == 10) || (*from == 13)) {
+ if ((text.length()>1) && (text[text.length()-2] != ' ') && (*(from+1) != ' '))
+ text.append(' ');
+ continue;
+ }
+
+
+ // strip odd characters
+ switch (*from) {
+ case '(':
+ case ')':
+ case '[':
+ case ']':
+ case '{':
+ case '}':
+ case '<':
+ case '>':
+ continue;
+ }
+
+ // if we've made it this far
+ text.append(*from);
+
+ }
+ return 0;
+}
+
+SWORD_NAMESPACE_END
Modified: trunk/src/modules/filters/utf8greekaccents.cpp
===================================================================
--- trunk/src/modules/filters/utf8greekaccents.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/src/modules/filters/utf8greekaccents.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -9,6 +9,12 @@
#include <stdio.h>
#include <utf8greekaccents.h>
+
+#ifdef _ICU_
+#include <utf8nfkd.h>
+sword::UTF8NFKD decompose;
+#endif
+
SWORD_NAMESPACE_START
const char oName[] = "Greek Accents";
@@ -30,6 +36,9 @@
//unsigned char *to, *from;
//to = (unsigned char*)text;
//for (from = (unsigned char*)text; *from; from++) {
+#ifdef _ICU_
+ decompose.processText(text, (SWKey *)2); // note the hack of 2 to mimic a real key. TODO: remove all hacks
+#endif
SWBuf orig = text;
const unsigned char* from = (unsigned char*)orig.c_str();
Modified: trunk/src/modules/filters/utf8nfkd.cpp
===================================================================
--- trunk/src/modules/filters/utf8nfkd.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/src/modules/filters/utf8nfkd.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -27,19 +27,19 @@
if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
return -1;
- int32_t len = text.length() * 2;
+ int32_t len = 5 + text.length() * 5;
source = new UChar[len + 1]; //each char could become a surrogate pair
// Convert UTF-8 string to UTF-16 (UChars)
- len = ucnv_toUChars(conv, source, len, text.c_str(), -1, &err);
+ int32_t ulen = ucnv_toUChars(conv, source, len, text.c_str(), -1, &err);
target = new UChar[len + 1];
//compatability decomposition
- unorm_normalize(source, len, UNORM_NFKD, 0, target, len, &err);
+ ulen = unorm_normalize(source, ulen, UNORM_NFKD, 0, target, len, &err);
- text.setSize(text.size()*2);
- len = ucnv_fromUChars(conv, text.getRawData(), text.size(), target, -1, &err);
text.setSize(len);
+ len = ucnv_fromUChars(conv, text.getRawData(), len, target, ulen, &err);
+ text.setSize(len);
delete [] source;
delete [] target;
Modified: trunk/tests/filtertest.cpp
===================================================================
--- trunk/tests/filtertest.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/tests/filtertest.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -1,6 +1,6 @@
#include <iostream>
#include <swbuf.h>
-#include <osishtmlhref.h>
+#include <papyriplain.h>
//#include <swmgr.h>
#ifndef NO_SWORD_NAMESPACE
using namespace sword;
@@ -11,9 +11,9 @@
int main(int argc, char **argv) {
// SWMgr mgr;
// SWModule *module = mgr.getModule("KJV");
- OSISHTMLHREF filter;
+ PapyriPlain filter;
SWBuf buf;
- buf = "This is OSIS text with a <figure src=\"images/scroll.png\"/>";
+ buf = "This is t<e>xt which has papy-\nri markings in it.\n L[et's be] sure it gets--\n cleaned up well for s(earching)";
std::cout << "Original:\n\n" << buf << "\n\n-------\n\n";
filter.processText(buf);
// filter.processText(buf, module->getKey(), module);
Modified: trunk/utilities/imp2gbs.cpp
===================================================================
--- trunk/utilities/imp2gbs.cpp 2005-08-02 09:59:53 UTC (rev 1843)
+++ trunk/utilities/imp2gbs.cpp 2005-08-04 01:12:33 UTC (rev 1844)
@@ -12,130 +12,166 @@
using sword::SWKey;
#endif
+
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target = 0, int level = 1) {
- if (!target)
- target = &treeKey;
-
- unsigned long currentOffset = target->getOffset();
- std::cout << ((currentOffset == treeKey.getOffset()) ? "==>" : "");
- for (int i = 0; i < level; i++) std::cout << "\t";
- std::cout << treeKey.getLocalName() << std::endl;
- if (treeKey.firstChild()) {
- printTree(treeKey, target, level+1);
- treeKey.parent();
- }
- if (treeKey.nextSibling())
- printTree(treeKey, target, level);
+ if (!target)
+ target = &treeKey;
+
+ unsigned long currentOffset = target->getOffset();
+ std::cout << ((currentOffset == treeKey.getOffset()) ? "==>" : "");
+ for (int i = 0; i < level; i++) std::cout << "\t";
+ std::cout << treeKey.getLocalName() << std::endl;
+ if (treeKey.firstChild()) {
+ printTree(treeKey, target, level+1);
+ treeKey.parent();
+ }
+ if (treeKey.nextSibling())
+ printTree(treeKey, target, level);
}
+
void setkey (TreeKeyIdx * treeKey, const char* keybuffer) {
- char *keybuf = strdup(keybuffer);
- char* tok = strtok(keybuf, "/");
- while (tok) {
- bool foundkey = false;
- if (treeKey->hasChildren()) {
- treeKey->firstChild();
- if (!strcmp(treeKey->getLocalName(), tok)) {
- foundkey = true;
- } else {
- while (treeKey->nextSibling()) {
- if (treeKey->getLocalName()) {
- if (!strcmp(treeKey->getLocalName(), tok)) {
- foundkey = true;
- }
- }
+ char *keybuf = strdup(keybuffer);
+ char* tok = strtok(keybuf, "/");
+ while (tok) {
+ bool foundkey = false;
+ if (treeKey->hasChildren()) {
+ treeKey->firstChild();
+ if (!strcmp(treeKey->getLocalName(), tok)) {
+ foundkey = true;
+ }
+ else {
+ while (treeKey->nextSibling()) {
+ if (treeKey->getLocalName()) {
+ if (!strcmp(treeKey->getLocalName(), tok)) {
+ foundkey = true;
+ }
+ }
+ }
+ }
+ if (!foundkey) {
+ treeKey->append();
+ treeKey->setLocalName(tok);
+ treeKey->save();
+ }
+ }
+ else {
+ treeKey->appendChild();
+ treeKey->setLocalName(tok);
+ treeKey->save();
+ }
+
+//DEBUG std::cout << treeKey->getLocalName() << " : " << tok << std::endl;
+
+ tok = strtok(NULL, "/");
+
}
- }
- if (!foundkey) {
- treeKey->append();
- treeKey->setLocalName(tok);
- treeKey->save();
- }
- }
- else {
- treeKey->appendChild();
- treeKey->setLocalName(tok);
- treeKey->save();
- }
-
- //DEBUG std::cout << treeKey->getLocalName() << " : " << tok << std::endl;
-
- tok = strtok(NULL, "/");
-
- }
- free(keybuf);
+ free(keybuf);
}
+void usage_info(const char *appName) {
+ const char * helptext ="imp2gbs 1.0 General Book module creation tool for the SWORD Project\n usage:\n %s [options] <filename> [modname]\n";
+ fprintf(stderr, helptext, appName);
+ fprintf(stderr, "\t -a -- append to module [default: remove any existing modules files]");
+ fprintf(stderr, "\t -c -- concat text of dup key entries [default: replace]");
+ fprintf(stderr, "\n\n");
+}
+
+
int main(int argc, char **argv) {
-
- const char * helptext ="imp2gbs 1.0 General Book module creation tool for the SWORD Project\n usage:\n %s <filename> [modname]\n";
-
- signed long i = 0;
- string keybuffer;
- string entbuffer;
- string linebuffer;
- char modname[16];
-
- 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]);
-
- TreeKeyIdx * treeKey;
- RawGenBook *book;
-
- // Do some initialization stuff
- TreeKeyIdx::create(modname);
- treeKey = new TreeKeyIdx(modname);
- RawGenBook::createModule(modname);
- delete treeKey;
- book = new RawGenBook(modname);
- //DEBUG TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
- treeKey = ((TreeKeyIdx *)((SWKey *)(*book)));
-
- 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;
- treeKey->root();
- setkey(treeKey, keybuffer.c_str());
- book->setEntry(entbuffer.c_str(), entbuffer.size());
- }
- keybuffer = linebuffer.substr(3,linebuffer.size()) ;
- entbuffer.resize(0);
- }
- else {
- entbuffer += linebuffer;
- }
- }
- //handle final entry
- if (keybuffer.size() && entbuffer.size()) {
- std::cout << keybuffer << std::endl;
- treeKey->root();
- setkey(treeKey, keybuffer.c_str());
- book->setEntry(entbuffer.c_str(), entbuffer.size());
- }
-
- //DEBUG printTree(root, treeKey);
-
- delete book;
- infile.close();
+ signed long i = 0;
+ string keybuffer;
+ string entbuffer;
+ string linebuffer;
+ char modname[16];
+ bool opt_append_mod = false;
+ bool opt_cat_dups = false;
+ const char *app_name = *argv;
- return 0;
+ --argc ;
+ ++argv ;
+
+ while(argc > 2 && argv[0][0] == '-') {
+ switch(argv[0][1]) {
+ case 'a': opt_append_mod = true; break ;
+ case 'c': opt_cat_dups = true; break ;
+ default: usage_info(app_name) ; exit(-1) ;
+ }
+ argc-- ;
+ argv++ ;
+ }
+
+ 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 {
+ usage_info(app_name);
+ exit(-1);
+ }
+
+
+ std::ifstream infile(argv[1]);
+
+ TreeKeyIdx * treeKey;
+ RawGenBook *book;
+
+ // Do some initialization stuff
+ if (opt_append_mod) {
+ TreeKeyIdx::create(modname);
+ treeKey = new TreeKeyIdx(modname);
+ RawGenBook::createModule(modname);
+ delete treeKey;
+ }
+
+ book = new RawGenBook(modname);
+ //DEBUG TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
+ treeKey = ((TreeKeyIdx *)((SWKey *)(*book)));
+
+ 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;
+ treeKey->root();
+ setkey(treeKey, keybuffer.c_str());
+ if (opt_cat_dups) {
+ entbuffer = ((string)book->getRawEntry()) + (string)"\n" + entbuffer;
+ }
+ book->setEntry(entbuffer.c_str(), entbuffer.size());
+ }
+ keybuffer = linebuffer.substr(3,linebuffer.size()) ;
+ entbuffer.resize(0);
+ }
+ else {
+ entbuffer += linebuffer;
+ }
+ }
+
+ //handle final entry
+ if (keybuffer.size() && entbuffer.size()) {
+ std::cout << keybuffer << std::endl;
+ treeKey->root();
+ setkey(treeKey, keybuffer.c_str());
+ if (opt_cat_dups) {
+ entbuffer = ((string)book->getRawEntry()) + (string)"\n" + entbuffer;
+ }
+ book->setEntry(entbuffer.c_str(), entbuffer.size());
+ }
+
+ //DEBUG printTree(root, treeKey);
+
+ delete book;
+ infile.close();
+
+ return 0;
}
More information about the sword-cvs
mailing list