[sword-svn] r1994 - in trunk: . examples/cmdline src/keys src/modules src/modules/filters src/modules/genbook/rawgenbook tests utilities
scribe at www.crosswire.org
scribe at www.crosswire.org
Mon Nov 20 13:24:07 MST 2006
Author: scribe
Date: 2006-11-20 13:24:06 -0700 (Mon, 20 Nov 2006)
New Revision: 1994
Added:
trunk/utilities/genbookutil.cpp
trunk/utilities/treeidxutil.cpp
Removed:
trunk/tests/genbooktest.cpp
trunk/tests/treeidxtest.cpp
Modified:
trunk/ChangeLog
trunk/examples/cmdline/search.cpp
trunk/src/keys/treekey.cpp
trunk/src/keys/treekeyidx.cpp
trunk/src/modules/filters/utf8greekaccents.cpp
trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
trunk/src/modules/swmodule.cpp
trunk/tests/Makefile.am
trunk/utilities/Makefile.am
trunk/utilities/imp2gbs.cpp
Log:
Moved treekey and genbook tests to utilities
Finished first stable version of rewrite of imp2gbs
Fixed bug in treekey where didn't break on found sibling
Added .trim to localName segments of genbook path,
e.g. /this / is/a/test/ - all spaces will be removed.
Added recognition of additional greek accent ~
in UTF8GreekAccents filter
Fixed bug in RawGenBook::setText where default size
is < 0, not false.
Changed lucene indexing to actually index the key field. This
allows searching within key field (e.g. key:word)
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/ChangeLog 2006-11-20 20:24:06 UTC (rev 1994)
@@ -1,6 +1,20 @@
API ChangeLog (see the ChangeLog in each 'apps' directory for
app specific changes)
+20-Nov-2006 Troy A. Griffitts <scribe at crosswire.org>
+ Moved treekey and genbook tests to utilities
+ Finished first stable version of rewrite of imp2gbs
+ Fixed bug in treekey where didn't break on found sibling
+ Added .trim to localName segments of genbook path,
+ e.g. /this / is/a/test/ - all spaces will be removed.
+ Added recognition of additional greek accent ~
+ in UTF8GreekAccents filter
+ Fixed bug in RawGenBook::setText where default size
+ is < 0, not false.
+ Changed lucene indexing to actually index the key field. This
+ allows searching within key field (e.g. key:word)
+ Fixed divineName logic
+ Fixed & handling
* Release 1.5.9 *
Modified: trunk/examples/cmdline/search.cpp
===================================================================
--- trunk/examples/cmdline/search.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/examples/cmdline/search.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -75,7 +75,7 @@
* -3 - entryAttrib (eg. Word//Strongs/G1234/)
* -4 - Lucene
*/
- listkey = target->Search(searchTerm.c_str(), -2, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
+ listkey = target->Search(searchTerm.c_str(), -4, /*SEARCHFLAG_MATCHWHOLEENTRY*/ REG_ICASE, 0, 0, &percentUpdate, &lineLen);
std::cout << "\n";
listkey.sort();
while (!listkey.Error()) {
Modified: trunk/src/keys/treekey.cpp
===================================================================
--- trunk/src/keys/treekey.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/src/keys/treekey.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -50,19 +50,21 @@
root();
// TODO: change to NOT use strtok. strtok is dangerous.
- char *tok = strtok(keybuf, "/");
- while (tok) {
+ SWBuf tok = strtok(keybuf, "/");
+ tok.trim();
+ while (tok.size()) {
bool foundkey = false;
if (hasChildren()) {
firstChild();
- if (!strcmp(getLocalName(), tok)) {
+ if (tok == getLocalName()) {
foundkey = true;
}
else {
while (nextSibling()) {
if (getLocalName()) {
- if (!strcmp(getLocalName(), tok)) {
+ if (tok == getLocalName()) {
foundkey = true;
+ break;
}
}
}
@@ -83,7 +85,8 @@
// std::cout << getLocalName() << " : " << tok << std::endl;
#endif
- tok = strtok(NULL, "/");
+ tok = strtok(0, "/");
+ tok.trim();
}
delete [] keybuf;
Modified: trunk/src/keys/treekeyidx.cpp
===================================================================
--- trunk/src/keys/treekeyidx.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/src/keys/treekeyidx.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -459,26 +459,31 @@
void TreeKeyIdx::setText(const char *ikey) {
char *buf = 0;
stdstr(&buf, ikey);
- char *leaf = strtok(buf, "/");
+ SWBuf leaf = strtok(buf, "/");
+ leaf.trim();
root();
- while ((leaf) && (!Error())) {
+ while ((leaf.size()) && (!Error())) {
bool ok, inChild = false;
+ error = KEYERR_OUTOFBOUNDS;
for (ok = firstChild(); ok; ok = nextSibling()) {
inChild = true;
- if (!stricmp(leaf, getLocalName()))
+ if (leaf == getLocalName()) {
+ error = 0;
break;
+ }
}
leaf = strtok(0, "/");
+ leaf.trim();
if (!ok) {
if (inChild) { // if we didn't find a matching child node, default to first child
parent();
firstChild();
}
- if (leaf)
- error = KEYERR_OUTOFBOUNDS;
- break;
+ error = KEYERR_OUTOFBOUNDS;
}
}
+ if (leaf.size())
+ error = KEYERR_OUTOFBOUNDS;
delete [] buf;
unsnappedKeyText = ikey;
}
Modified: trunk/src/modules/filters/utf8greekaccents.cpp
===================================================================
--- trunk/src/modules/filters/utf8greekaccents.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/src/modules/filters/utf8greekaccents.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -52,7 +52,7 @@
from++;
}
}
- else if (*from == 0xCD && *(from + 1) == 0xBA) {
+ else if (*from == 0xCD && (*(from + 1) == 0xBA || *(from + 1) == 0x82)) {
from++;
}
//now converted pre-composed characters to their alphabetic bases, discarding the accents
Modified: trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp
===================================================================
--- trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/src/modules/genbook/rawgenbook/rawgenbook.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -141,7 +141,7 @@
char userData[8];
- if (!len)
+ if (len < 0)
len = strlen(inbuf);
bdtfd->write(inbuf, len);
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/src/modules/swmodule.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -1077,7 +1077,7 @@
}
lucene_utf8towcs(wcharBuffer, keyText, MAX_CONV_SIZE); //keyText must be utf8
- doc->add( *Field::UnIndexed(_T("key"), wcharBuffer ) );
+ doc->add( *Field::Text(_T("key"), wcharBuffer ) );
if (includeKeyInSearch) {
c = keyText;
Modified: trunk/tests/Makefile.am
===================================================================
--- trunk/tests/Makefile.am 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/tests/Makefile.am 2006-11-20 20:24:06 UTC (rev 1994)
@@ -7,7 +7,7 @@
noinst_PROGRAMS = ciphertest keytest mgrtest parsekey listtest casttest \
modtest compnone complzss localetest introtest indextest configtest keycast \
romantest testblocks filtertest rawldidxtest lextest swaptest \
-genbooktest treeidxtest swbuftest xmltest webiftest
+ swbuftest xmltest webiftest
if ICU
ICUPROG = icutest translittest tlitmgrtest
@@ -56,8 +56,6 @@
lextest_SOURCES = lextest.cpp
rawldidxtest_SOURCES = rawldidxtest.cpp
swaptest_SOURCES = swaptest.cpp
-treeidxtest_SOURCES = treeidxtest.cpp
-genbooktest_SOURCES = genbooktest.cpp
swbuftest_SOURCES = swbuftest.cpp
webiftest_SOURCES = webiftest.cpp
xmltest_SOURCES = xmltest.cpp
Deleted: trunk/tests/genbooktest.cpp
===================================================================
--- trunk/tests/genbooktest.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/tests/genbooktest.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -1,186 +0,0 @@
-#include <entriesblk.h>
-#include <iostream>
-#include <string>
-#include <stdio.h>
-#include <treekeyidx.h>
-#include <rawgenbook.h>
-#ifndef NO_SWORD_NAMESPACE
-using namespace sword;
-#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() << "/\n";
- if (treeKey.firstChild()) {
- printTree(treeKey, target, level+1);
- treeKey.parent();
- }
- if (treeKey.nextSibling())
- printTree(treeKey, target, level);
-
-}
-
-
-void printLocalName(TreeKeyIdx *treeKey) {
- std::cout << "locaName: " << treeKey->getLocalName() << "\n";
-}
-
-
-void setLocalName(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter New Node Name: ";
- gets(buf);
- treeKey->setLocalName(buf);
- treeKey->save();
-}
-
-
-void gotoPath(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter Path: ";
- gets(buf);
- (*treeKey) = buf;
-}
-
-
-void assurePath(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter Path: ";
- gets(buf);
- treeKey->assureKeyPath(buf);
-}
-
-
-void viewEntryText(RawGenBook *book) {
- std::cout << "\n";
- std::cout << book->RenderText();
- std::cout << "\n";
-}
-
-
-void setEntryText(RawGenBook *book) {
- std::string body;
- TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book);
- if (treeKey->getOffset()) {
- char buf[1023];
- std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n";
- do {
- gets(buf);
- if ((buf[0] == '.') && (buf[1] == 0))
- break;
- body += buf;
- body += "\n";
- } while (true);
-
- (*book) << body.c_str();
- }
- else std::cout << "Can't add entry text to root node\n";
-}
-
-
-void appendSibbling(TreeKeyIdx *treeKey) {
- if (treeKey->getOffset()) {
- char buf[1023];
- std::cout << "Enter New Sibbling Name: ";
- gets(buf);
- treeKey->append();
- treeKey->setLocalName(buf);
- treeKey->save();
- }
- else std::cout << "Can't add sibling to root node\n";
-}
-
-
-void appendChild(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter New Child Name: ";
- gets(buf);
- treeKey->appendChild();
- treeKey->setLocalName(buf);
- treeKey->save();
-}
-
-
-void removeEntry(EntriesBlock *eb, int index) {
- if (index < eb->getCount()) {
- std::cout << "Removing entry [" << index << "]\n";
- eb->removeEntry(index);
- }
- else std::cout << "Invalid entry number\n\n";
-}
-
-
-int main(int argc, char **argv) {
-
- if (argc != 2) {
- fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
- exit(-1);
- }
-
- TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
-
- if (treeKey->Error()) {
- RawGenBook::createModule(argv[1]);
- }
- delete treeKey;
-
- RawGenBook *book = new RawGenBook(argv[1]);
- TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
- treeKey = (TreeKeyIdx *)(SWKey *)(*book);
-
- std::string input;
- char line[1024];
-
- do {
- std::cout << "[" << treeKey->getText() << "] > ";
- gets(line);
- input = line;
- if (input.length() > 0) {
- switch (input[0]) {
- case 'n': printLocalName(treeKey); break;
- case 's': setLocalName(treeKey); break;
- case 'g': gotoPath(treeKey); break;
- case 'G': assurePath(treeKey); break;
- case 'p': root.root(); printTree(root, treeKey); break;
- case 'a': appendSibbling(treeKey); break;
- case 'c': appendChild(treeKey); break;
- case 'j': treeKey->nextSibling(); break;
- case 'k': treeKey->previousSibling(); break;
- case 'h': treeKey->parent(); break;
- case 'l': treeKey->firstChild(); break;
- case 'r': treeKey->root(); break;
- case 't': setEntryText(book); break;
- case 'v': viewEntryText(book); break;
- case 'q': break;
- case '?':
- default:
- std::cout << "\n p - print tree\n";
- std::cout << " n - get local name\n";
- std::cout << " s - set local name\n";
- std::cout << " j - next sibbling\n";
- std::cout << " k - previous sibbling\n";
- std::cout << " h - parent\n";
- std::cout << " l - first child\n";
- std::cout << " r - root\n";
- std::cout << " g - goto path\n";
- std::cout << " G goto path; create if it doesn't exist\n";
- std::cout << " a - append sibbling\n";
- std::cout << " c - append child\n";
- std::cout << " v - view entry text\n";
- std::cout << " t - set entry text\n";
- std::cout << " q - quit\n\n";
- break;
- }
- }
- }
- while (input.compare("q"));
-
- delete treeKey;
-
- return 0;
-}
Deleted: trunk/tests/treeidxtest.cpp
===================================================================
--- trunk/tests/treeidxtest.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/tests/treeidxtest.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -1,145 +0,0 @@
-#include <entriesblk.h>
-#include <iostream>
-#include <string>
-#include <stdio.h>
-#include <treekeyidx.h>
-
-#ifndef NO_SWORD_NAMESPACE
-using namespace sword;
-#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);
-
-}
-
-
-void printLocalName(TreeKeyIdx *treeKey) {
- std::cout << "locaName: " << treeKey->getLocalName() << std::endl;
-}
-
-
-void setLocalName(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter New Node Name: ";
- gets(buf);
- treeKey->setLocalName(buf);
- treeKey->save();
-}
-
-
-void assurePath(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter path: ";
- gets(buf);
- treeKey->assureKeyPath(buf);
-}
-
-
-void appendSibbling(TreeKeyIdx *treeKey) {
- if (treeKey->getOffset()) {
- char buf[1023];
- std::cout << "Enter New Sibbling Name: ";
- gets(buf);
- treeKey->append();
- treeKey->setLocalName(buf);
- treeKey->save();
- }
- else std::cout << "Can't add sibling to root node\n";
-}
-
-
-void appendChild(TreeKeyIdx *treeKey) {
- char buf[1023];
- std::cout << "Enter New Child Name: ";
- gets(buf);
- treeKey->appendChild();
- treeKey->setLocalName(buf);
- treeKey->save();
-}
-
-
-void removeEntry(EntriesBlock *eb, int index) {
- if (index < eb->getCount()) {
- std::cout << "Removing entry [" << index << "]\n";
- eb->removeEntry(index);
- }
- else std::cout << "Invalid entry number\n\n";
-}
-
-
-int main(int argc, char **argv) {
-
- if (argc != 2) {
- fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
- exit(-1);
- }
-
- TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
-
- if (treeKey->Error()) {
- treeKey->create(argv[1]);
- delete treeKey;
- treeKey = new TreeKeyIdx(argv[1]);
- }
- TreeKeyIdx root = *treeKey;
-
- std::string input;
- char line[1024];
-
- do {
- std::cout << "[" << treeKey->getText() << "] > ";
- gets(line);
- input = line;
- if (input.length() > 0) {
- switch (input[0]) {
- case 'n': printLocalName(treeKey); break;
- case 's': setLocalName(treeKey); break;
- case 'p': root.root(); printTree(root, treeKey); break;
- case 'a': appendSibbling(treeKey); break;
- case 'c': appendChild(treeKey); break;
- case 'j': treeKey->nextSibling(); break;
- case 'g': assurePath(treeKey); break;
- case 'k': treeKey->previousSibling(); break;
- case 'h': treeKey->parent(); break;
- case 'l': treeKey->firstChild(); break;
- case 'r': treeKey->root(); break;
- case 'q': break;
- case '?':
- default:
- std::cout << "\n p - print tree\n";
- std::cout << " n - get local name\n";
- std::cout << " s - set local name\n";
- std::cout << " j - next sibbling\n";
- std::cout << " k - previous sibbling\n";
- std::cout << " h - parent\n";
- std::cout << " l - first child\n";
- std::cout << " r - root\n";
- std::cout << " a - append sibbling\n";
- std::cout << " c - append child\n";
- std::cout << " u - get user data\n";
- std::cout << " d - set user data\n";
- std::cout << " g - goto path; create if it doesn't exist\n";
- std::cout << " q - quit\n\n";
- break;
- }
- }
- }
- while (input.compare("q"));
-
- delete treeKey;
-
- return 0;
-}
Modified: trunk/utilities/Makefile.am
===================================================================
--- trunk/utilities/Makefile.am 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/utilities/Makefile.am 2006-11-20 20:24:06 UTC (rev 1994)
@@ -4,7 +4,7 @@
LDADD = $(top_builddir)/lib/libsword.la
noinst_PROGRAMS = cipherraw lexdump \
stepdump step2vpl gbfidx modwrite addvs emptyvss \
-addgb
+addgb genbookutil treeidxutil
bin_PROGRAMS = mod2imp mod2osis osis2mod vs2osisref mod2vpl \
mkfastmod vpl2mod imp2vs installmgr xml2gbs imp2gbs
@@ -57,6 +57,8 @@
xml2gbs_SOURCES = xml2gbs.cpp
osis2mod_SOURCES = osis2mod.cpp
vs2osisref_SOURCES = vs2osisref.cpp
+genbookutil_SOURCES = genbookutil.cpp
+treeidxutil_SOURCES = treeidxutil.cpp
installmgr_SOURCES = installmgr.cpp
#installmgr_LDADD = -lcurl $(CURL_LIBS) $(LDADD)
Copied: trunk/utilities/genbookutil.cpp (from rev 1991, trunk/tests/genbooktest.cpp)
===================================================================
--- trunk/utilities/genbookutil.cpp (rev 0)
+++ trunk/utilities/genbookutil.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -0,0 +1,186 @@
+#include <entriesblk.h>
+#include <iostream>
+#include <string>
+#include <stdio.h>
+#include <treekeyidx.h>
+#include <rawgenbook.h>
+#ifndef NO_SWORD_NAMESPACE
+using namespace sword;
+#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() << "/\n";
+ if (treeKey.firstChild()) {
+ printTree(treeKey, target, level+1);
+ treeKey.parent();
+ }
+ if (treeKey.nextSibling())
+ printTree(treeKey, target, level);
+
+}
+
+
+void printLocalName(TreeKeyIdx *treeKey) {
+ std::cout << "locaName: " << treeKey->getLocalName() << "\n";
+}
+
+
+void setLocalName(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter New Node Name: ";
+ gets(buf);
+ treeKey->setLocalName(buf);
+ treeKey->save();
+}
+
+
+void gotoPath(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter Path: ";
+ gets(buf);
+ (*treeKey) = buf;
+}
+
+
+void assurePath(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter Path: ";
+ gets(buf);
+ treeKey->assureKeyPath(buf);
+}
+
+
+void viewEntryText(RawGenBook *book) {
+ std::cout << "\n";
+ std::cout << book->RenderText();
+ std::cout << "\n";
+}
+
+
+void setEntryText(RawGenBook *book) {
+ std::string body;
+ TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book);
+ if (treeKey->getOffset()) {
+ char buf[1023];
+ std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n";
+ do {
+ gets(buf);
+ if ((buf[0] == '.') && (buf[1] == 0))
+ break;
+ body += buf;
+ body += "\n";
+ } while (true);
+
+ (*book) << body.c_str();
+ }
+ else std::cout << "Can't add entry text to root node\n";
+}
+
+
+void appendSibbling(TreeKeyIdx *treeKey) {
+ if (treeKey->getOffset()) {
+ char buf[1023];
+ std::cout << "Enter New Sibbling Name: ";
+ gets(buf);
+ treeKey->append();
+ treeKey->setLocalName(buf);
+ treeKey->save();
+ }
+ else std::cout << "Can't add sibling to root node\n";
+}
+
+
+void appendChild(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter New Child Name: ";
+ gets(buf);
+ treeKey->appendChild();
+ treeKey->setLocalName(buf);
+ treeKey->save();
+}
+
+
+void removeEntry(EntriesBlock *eb, int index) {
+ if (index < eb->getCount()) {
+ std::cout << "Removing entry [" << index << "]\n";
+ eb->removeEntry(index);
+ }
+ else std::cout << "Invalid entry number\n\n";
+}
+
+
+int main(int argc, char **argv) {
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
+ exit(-1);
+ }
+
+ TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
+
+ if (treeKey->Error()) {
+ RawGenBook::createModule(argv[1]);
+ }
+ delete treeKey;
+
+ RawGenBook *book = new RawGenBook(argv[1]);
+ TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
+ treeKey = (TreeKeyIdx *)(SWKey *)(*book);
+
+ std::string input;
+ char line[1024];
+
+ do {
+ std::cout << "[" << treeKey->getText() << "] > ";
+ gets(line);
+ input = line;
+ if (input.length() > 0) {
+ switch (input[0]) {
+ case 'n': printLocalName(treeKey); break;
+ case 's': setLocalName(treeKey); break;
+ case 'g': gotoPath(treeKey); break;
+ case 'G': assurePath(treeKey); break;
+ case 'p': root.root(); printTree(root, treeKey); break;
+ case 'a': appendSibbling(treeKey); break;
+ case 'c': appendChild(treeKey); break;
+ case 'j': treeKey->nextSibling(); break;
+ case 'k': treeKey->previousSibling(); break;
+ case 'h': treeKey->parent(); break;
+ case 'l': treeKey->firstChild(); break;
+ case 'r': treeKey->root(); break;
+ case 't': setEntryText(book); break;
+ case 'v': viewEntryText(book); break;
+ case 'q': break;
+ case '?':
+ default:
+ std::cout << "\n p - print tree\n";
+ std::cout << " n - get local name\n";
+ std::cout << " s - set local name\n";
+ std::cout << " j - next sibbling\n";
+ std::cout << " k - previous sibbling\n";
+ std::cout << " h - parent\n";
+ std::cout << " l - first child\n";
+ std::cout << " r - root\n";
+ std::cout << " g - goto path\n";
+ std::cout << " G goto path; create if it doesn't exist\n";
+ std::cout << " a - append sibbling\n";
+ std::cout << " c - append child\n";
+ std::cout << " v - view entry text\n";
+ std::cout << " t - set entry text\n";
+ std::cout << " q - quit\n\n";
+ break;
+ }
+ }
+ }
+ while (input.compare("q"));
+
+ delete treeKey;
+
+ return 0;
+}
Modified: trunk/utilities/imp2gbs.cpp
===================================================================
--- trunk/utilities/imp2gbs.cpp 2006-11-15 03:13:45 UTC (rev 1993)
+++ trunk/utilities/imp2gbs.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -34,6 +34,8 @@
SWBuf inFile;
bool toUpper = false;
bool greekFilter = false;
+bool augMod = false;
+bool augEnt = true;
int lexLevels = 0;
UTF8GreekAccents greekAccentsFilter;
@@ -42,6 +44,8 @@
fprintf(stderr, "imp2gbs 1.0 General Book module creation tool for the SWORD Project\n\n");
fprintf(stderr, "usage: %s <inFile> [OPTIONS]\n", app);
fprintf(stderr, "\t-o <outPath>\n\t\tSpecify an output Path other than inFile location.\n");
+ fprintf(stderr, "\t-a\n\t\tAugment Module [default: create new]\n");
+ fprintf(stderr, "\t-O\n\t\tOverwrite entries of same key [default: append to]\n");
fprintf(stderr, "\t-U\n\t\tKey filter: Convert toUpper\n");
fprintf(stderr, "\t-g\n\t\tKey filter: Strip Greek diacritics\n");
fprintf(stderr, "\t-l <levels>\n\t\tKey filter: Pseudo-Lexicon n-level generation using first character\n");
@@ -79,6 +83,12 @@
else if (!strcmp(argv[i], "-g")) {
greekFilter = true;
}
+ else if (!strcmp(argv[i], "-O")) {
+ augEnt = false;
+ }
+ else if (!strcmp(argv[i], "-a")) {
+ augMod = true;
+ }
else if (!strcmp(argv[i], "-l")) {
if (i+1 < argc) {
lexLevels = atoi(argv[i+1]);
@@ -111,7 +121,8 @@
}
//#ifdef _ICU_
- if (lexLevels) {
+// if (lexLevels) {
+ if (lexLevels && !keyBuffer.startsWith("/Intro")) {
unsigned size = (keyBuffer.size()+(lexLevels*2));
keyBuffer.setFillByte(0);
keyBuffer.resize(size);
@@ -124,7 +135,29 @@
u_strFromUTF8(ubuffer, max+9, &len, keyBuffer.c_str(), -1, &err);
if (err == U_ZERO_ERROR) {
+ UChar *upper = new UChar[(lexLevels+1)*3];
+ memcpy(upper, ubuffer, lexLevels*sizeof(UChar));
+ upper[lexLevels] = 0;
+ len = u_strToUpper(upper, (lexLevels+1)*3, upper, -1, 0, &err);
+ memmove(ubuffer+len+1, ubuffer, (max-len)*sizeof(UChar));
+ memcpy(ubuffer, upper, len*sizeof(UChar));
+ ubuffer[len] = '/';
+ delete [] upper;
+
int totalShift = 0;
+ for (int i = lexLevels-1; i; i--) {
+ int shift = (i < len)? i : len;
+ memmove(ubuffer+(shift+1), ubuffer, (max-shift)*sizeof(UChar));
+ ubuffer[shift] = '/';
+ totalShift += (shift+1);
+ }
+ u_strToUTF8(keyBuffer.getRawData(), max, 0, ubuffer, -1, &err);
+ }
+
+/*
+ u_strFromUTF8(ubuffer, max+9, &len, keyBuffer.c_str(), -1, &err);
+ if (err == U_ZERO_ERROR) {
+ int totalShift = 0;
for (int i = lexLevels; i; i--) {
int shift = (i < len)? i : len;
memmove(ubuffer+(shift+1), ubuffer, (max-shift)*sizeof(UChar));
@@ -140,14 +173,25 @@
delete [] upper;
u_strToUTF8(keyBuffer.getRawData(), max, 0, ubuffer, -1, &err);
}
+*/
delete [] ubuffer;
}
//#endif
std::cout << keyBuffer << std::endl;
+
book->setKey(keyBuffer.c_str());
- book->setEntry(entBuffer, strlen(entBuffer));
+
+ // check to see if we already have an entry
+ for (int i = 2; book->getKey()->Error() != KEYERR_OUTOFBOUNDS; i++) {
+ SWBuf key;
+ key.setFormatted("%s {%d}", keyBuffer.c_str(), i);
+ std::cout << "dup key, trying: " << key << std::endl;
+ book->setKey(key.c_str());
+ }
+
+ book->setEntry(entBuffer);
}
@@ -165,7 +209,9 @@
RawGenBook *book;
// Do some initialization stuff
- RawGenBook::createModule(outPath);
+ if (!augMod) {
+ RawGenBook::createModule(outPath);
+ }
book = new RawGenBook(outPath);
SWBuf lineBuffer;
@@ -191,6 +237,9 @@
}
}
} while (more);
+ if ((keyBuffer.size()) && (entBuffer.size())) {
+ writeEntry(book, keyBuffer, entBuffer);
+ }
delete book;
Copied: trunk/utilities/treeidxutil.cpp (from rev 1991, trunk/tests/treeidxtest.cpp)
===================================================================
--- trunk/utilities/treeidxutil.cpp (rev 0)
+++ trunk/utilities/treeidxutil.cpp 2006-11-20 20:24:06 UTC (rev 1994)
@@ -0,0 +1,145 @@
+#include <entriesblk.h>
+#include <iostream>
+#include <string>
+#include <stdio.h>
+#include <treekeyidx.h>
+
+#ifndef NO_SWORD_NAMESPACE
+using namespace sword;
+#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);
+
+}
+
+
+void printLocalName(TreeKeyIdx *treeKey) {
+ std::cout << "locaName: " << treeKey->getLocalName() << std::endl;
+}
+
+
+void setLocalName(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter New Node Name: ";
+ gets(buf);
+ treeKey->setLocalName(buf);
+ treeKey->save();
+}
+
+
+void assurePath(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter path: ";
+ gets(buf);
+ treeKey->assureKeyPath(buf);
+}
+
+
+void appendSibbling(TreeKeyIdx *treeKey) {
+ if (treeKey->getOffset()) {
+ char buf[1023];
+ std::cout << "Enter New Sibbling Name: ";
+ gets(buf);
+ treeKey->append();
+ treeKey->setLocalName(buf);
+ treeKey->save();
+ }
+ else std::cout << "Can't add sibling to root node\n";
+}
+
+
+void appendChild(TreeKeyIdx *treeKey) {
+ char buf[1023];
+ std::cout << "Enter New Child Name: ";
+ gets(buf);
+ treeKey->appendChild();
+ treeKey->setLocalName(buf);
+ treeKey->save();
+}
+
+
+void removeEntry(EntriesBlock *eb, int index) {
+ if (index < eb->getCount()) {
+ std::cout << "Removing entry [" << index << "]\n";
+ eb->removeEntry(index);
+ }
+ else std::cout << "Invalid entry number\n\n";
+}
+
+
+int main(int argc, char **argv) {
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
+ exit(-1);
+ }
+
+ TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
+
+ if (treeKey->Error()) {
+ treeKey->create(argv[1]);
+ delete treeKey;
+ treeKey = new TreeKeyIdx(argv[1]);
+ }
+ TreeKeyIdx root = *treeKey;
+
+ std::string input;
+ char line[1024];
+
+ do {
+ std::cout << "[" << treeKey->getText() << "] > ";
+ gets(line);
+ input = line;
+ if (input.length() > 0) {
+ switch (input[0]) {
+ case 'n': printLocalName(treeKey); break;
+ case 's': setLocalName(treeKey); break;
+ case 'p': root.root(); printTree(root, treeKey); break;
+ case 'a': appendSibbling(treeKey); break;
+ case 'c': appendChild(treeKey); break;
+ case 'j': treeKey->nextSibling(); break;
+ case 'g': assurePath(treeKey); break;
+ case 'k': treeKey->previousSibling(); break;
+ case 'h': treeKey->parent(); break;
+ case 'l': treeKey->firstChild(); break;
+ case 'r': treeKey->root(); break;
+ case 'q': break;
+ case '?':
+ default:
+ std::cout << "\n p - print tree\n";
+ std::cout << " n - get local name\n";
+ std::cout << " s - set local name\n";
+ std::cout << " j - next sibbling\n";
+ std::cout << " k - previous sibbling\n";
+ std::cout << " h - parent\n";
+ std::cout << " l - first child\n";
+ std::cout << " r - root\n";
+ std::cout << " a - append sibbling\n";
+ std::cout << " c - append child\n";
+ std::cout << " u - get user data\n";
+ std::cout << " d - set user data\n";
+ std::cout << " g - goto path; create if it doesn't exist\n";
+ std::cout << " q - quit\n\n";
+ break;
+ }
+ }
+ }
+ while (input.compare("q"));
+
+ delete treeKey;
+
+ return 0;
+}
More information about the sword-cvs
mailing list