[sword-svn] r2147 - in trunk: . src/keys utilities

scribe at www.crosswire.org scribe at www.crosswire.org
Thu Mar 13 23:54:19 MST 2008


Author: scribe
Date: 2008-03-13 23:54:18 -0700 (Thu, 13 Mar 2008)
New Revision: 2147

Modified:
   trunk/ChangeLog
   trunk/src/keys/treekeyidx.cpp
   trunk/src/keys/versekey.cpp
   trunk/utilities/genbookutil.cpp
Log:
	Implemented a basic TreeKeyIdx::remove() method


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-03-04 22:49:30 UTC (rev 2146)
+++ trunk/ChangeLog	2008-03-14 06:54:18 UTC (rev 2147)
@@ -1,5 +1,8 @@
 API ChangeLog 
 
+16-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
+	Implemented a basic TreeKeyIdx::remove() method
+
 * Release 1.5.10 *
 
 16-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
@@ -8,7 +11,7 @@
 
 11-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
 	Added new FileMgr::openFileReadOnly to help centralize
-		all file io details.
+		all file io details
 
 11-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
 	Added new RawText4 and RawCom4 drivers which allow

Modified: trunk/src/keys/treekeyidx.cpp
===================================================================
--- trunk/src/keys/treekeyidx.cpp	2008-03-04 22:49:30 UTC (rev 2146)
+++ trunk/src/keys/treekeyidx.cpp	2008-03-14 06:54:18 UTC (rev 2147)
@@ -220,6 +220,40 @@
 
 
 void TreeKeyIdx::remove() {
+	TreeNode node;
+	bool done = false;
+	if (currentNode.offset) {
+		getTreeNodeFromIdxOffset(currentNode.offset, &node);
+		if (node.parent > -1) {
+			TreeNode parent;
+			getTreeNodeFromIdxOffset(node.parent, &parent);
+			if (parent.firstChild == node.offset) {
+				parent.firstChild = node.next;
+				saveTreeNodeOffsets(&parent);
+				getTreeNodeFromIdxOffset(parent.offset, &currentNode);
+				done = true;
+			}
+		}
+		if (!done) {
+			TreeNode iterator;
+			__s32 target = currentNode.offset;
+			if (currentNode.parent > -1) {
+				getTreeNodeFromIdxOffset(currentNode.parent, &iterator);
+				getTreeNodeFromIdxOffset(iterator.firstChild, &iterator);
+				if (iterator.offset != target) {
+					while ((iterator.next != target) && (iterator.next > -1))
+						getTreeNodeFromIdxOffset(iterator.next, &iterator);
+						if (iterator.next > -1) {
+							TreeNode prev;
+							getTreeNodeFromIdxOffset(iterator.offset, &prev);
+							prev.next = node.next;
+							saveTreeNodeOffsets(&prev);
+							getTreeNodeFromIdxOffset(prev.offset, &currentNode);
+					}
+				}
+			}
+		}
+	}
 }
 
 

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2008-03-04 22:49:30 UTC (rev 2146)
+++ trunk/src/keys/versekey.cpp	2008-03-14 06:54:18 UTC (rev 2147)
@@ -631,13 +631,7 @@
 								curKey = MAXCHAPTER;
 							if (partial > 0)
 								curKey = MAXVERSE;
-							if (newElement->LowerBound() > curKey) {
-								newElement->UpperBound(newElement->LowerBound());
-								newElement->LowerBound(curKey);
-							}
-							else {
-								newElement->UpperBound(curKey);
-							}
+							newElement->UpperBound(curKey);
 							*newElement = TOP;
 							tmpListKey.GetElement()->userData = (void *)buf;
 						}
@@ -822,13 +816,7 @@
 						curKey = MAXCHAPTER;
 					if (partial > 0)
 						curKey = MAXVERSE;
-					if (newElement->LowerBound() > curKey) {
-						newElement->UpperBound(newElement->LowerBound());
-						newElement->LowerBound(curKey);
-					}
-					else {
 						newElement->UpperBound(curKey);
-					}
 					*newElement = TOP;
 					tmpListKey.GetElement()->userData = (void *)buf;
 				}

Modified: trunk/utilities/genbookutil.cpp
===================================================================
--- trunk/utilities/genbookutil.cpp	2008-03-04 22:49:30 UTC (rev 2146)
+++ trunk/utilities/genbookutil.cpp	2008-03-14 06:54:18 UTC (rev 2147)
@@ -1,6 +1,5 @@
 #include <entriesblk.h>
 #include <iostream>
-#include <string>
 #include <stdio.h>
 #include <treekeyidx.h>
 #include <rawgenbook.h>
@@ -35,7 +34,8 @@
 	char buf[1023];
 	std::cout << "Enter New Node Name: ";
 	fgets(buf, 1000, stdin);
-	treeKey->setLocalName(buf);
+	SWBuf name = buf;
+	treeKey->setLocalName(name.trim());
 	treeKey->save();
 }
 
@@ -44,7 +44,8 @@
 	char buf[1023];
 	std::cout << "Enter Path: ";
 	fgets(buf, 1000, stdin);
-	(*treeKey) = buf;
+	SWBuf path = buf;
+	(*treeKey) = path.trim();
 }
 
 
@@ -52,7 +53,8 @@
 	char buf[1023];
 	std::cout << "Enter Path: ";
 	fgets(buf, 1000, stdin);
-	treeKey->assureKeyPath(buf);
+	SWBuf path = buf;
+	treeKey->assureKeyPath(path.trim());
 }
 
 
@@ -64,16 +66,18 @@
 
 
 void setEntryText(RawGenBook *book) {
-	std::string body;
+	SWBuf 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 {
 			fgets(buf, 1000, stdin);
-			if ((buf[0] == '.') && (buf[1] == 0))
+			SWBuf text = buf;
+			text.trim();
+			if ((text[0] == '.') && (text[1] == 0))
 				break;
-			body += buf;
+			body += text;
 			body += "\n";
 		} while (true);
 
@@ -88,8 +92,9 @@
 		char buf[1023];
 		std::cout << "Enter New Sibbling Name: ";
 		fgets(buf, 1000, stdin);
+		SWBuf name = buf;
 		treeKey->append();
-		treeKey->setLocalName(buf);
+		treeKey->setLocalName(name.trim());
 		treeKey->save();
 	}
 	else	std::cout << "Can't add sibling to root node\n";
@@ -100,12 +105,19 @@
 	char buf[1023];
 	std::cout << "Enter New Child Name: ";
 	fgets(buf, 1000, stdin);
+	SWBuf name = buf;
 	treeKey->appendChild();
-	treeKey->setLocalName(buf);
+	treeKey->setLocalName(name.trim());
 	treeKey->save();
 }
 
 
+void deleteNode(TreeKeyIdx *treeKey) {
+	std::cout << "Removing entry [" << treeKey->getText() << "]\n";
+	treeKey->remove();
+}
+
+
 void removeEntry(EntriesBlock *eb, int index) {
 	if (index < eb->getCount()) {
 		std::cout << "Removing entry [" << index << "]\n";
@@ -133,13 +145,14 @@
 	TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
 	treeKey = (TreeKeyIdx *)(SWKey *)(*book);
 
-	std::string input;
+	SWBuf input;
 	char line[1024];
 
 	do {
 		std::cout << "[" << treeKey->getText() << "] > ";
 		fgets(line, 1000, stdin);
 		input = line;
+		input.trim();
 		if (input.length() > 0) {
 			switch (input[0]) {
 				case 'n': printLocalName(treeKey); break;
@@ -149,6 +162,7 @@
 				case 'p':	root.root(); printTree(root, treeKey); break;
 				case 'a':	appendSibbling(treeKey); break;
 				case 'c':	appendChild(treeKey); break;
+				case 'd':	deleteNode(treeKey); break;
 				case 'j':	treeKey->nextSibling(); break;
 				case 'k':	treeKey->previousSibling(); break;
 				case 'h':	treeKey->parent(); break;
@@ -171,6 +185,7 @@
 					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 << " d - delete node\n";
 					std::cout << " v - view entry text\n";
 					std::cout << " t - set entry text\n";
 					std::cout << " q - quit\n\n";




More information about the sword-cvs mailing list