24 #pragma warning( disable: 4251 )
33 #ifndef NO_SWORD_NAMESPACE
34 using namespace sword;
37 void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target = 0,
int level = 1) {
41 unsigned long currentOffset = target->getOffset();
42 std::cout << ((currentOffset == treeKey.getOffset()) ?
"==>" :
"");
43 for (
int i = 0; i < level; i++) std::cout <<
"\t";
44 std::cout << treeKey.getLocalName() <<
"/\n";
45 if (treeKey.firstChild()) {
49 if (treeKey.nextSibling())
56 std::cout <<
"locaName: " << treeKey->getLocalName() <<
"\n";
62 std::cout <<
"Enter New Node Name: ";
63 fgets(buf, 1000, stdin);
65 treeKey->setLocalName(name.trim());
72 std::cout <<
"Enter Path: ";
73 fgets(buf, 1000, stdin);
75 (*treeKey) = path.trim();
81 std::cout <<
"Enter Path: ";
82 fgets(buf, 1000, stdin);
84 treeKey->assureKeyPath(path.trim());
90 std::cout << book->renderText();
97 TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book);
98 if (treeKey->getOffset()) {
100 std::cout <<
"Enter New Entry Text ('.' on a line by itself to end): \n";
102 fgets(buf, 1000, stdin);
105 if ((text[0] ==
'.') && (text[1] == 0))
111 (*book) << body.c_str();
113 else std::cout <<
"Can't add entry text to root node\n";
118 if (treeKey->getOffset()) {
120 std::cout <<
"Enter New Sibbling Name: ";
121 fgets(buf, 1000, stdin);
124 treeKey->setLocalName(name.trim());
127 else std::cout <<
"Can't add sibling to root node\n";
133 std::cout <<
"Enter New Child Name: ";
134 fgets(buf, 1000, stdin);
136 treeKey->appendChild();
137 treeKey->setLocalName(name.trim());
143 std::cout <<
"Removing entry [" << treeKey->getText() <<
"]\n";
149 if (index < eb->getCount()) {
150 std::cout <<
"Removing entry [" << index <<
"]\n";
153 else std::cout <<
"Invalid entry number\n\n";
157 int main(
int argc,
char **argv) {
160 fprintf(stderr,
"usage: %s <tree/key/data/path>\n", *argv);
164 TreeKeyIdx *treeKey =
new TreeKeyIdx(argv[1]);
166 if (treeKey->popError()) {
171 RawGenBook *book =
new RawGenBook(argv[1]);
172 TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
173 treeKey = (TreeKeyIdx *)(SWKey *)(*book);
179 std::cout <<
"[" << treeKey->getText() <<
"] > ";
180 fgets(line, 1000, stdin);
183 if (input.length() > 0) {
189 case 'p': root.root();
printTree(root, treeKey);
break;
193 case 'j': treeKey->nextSibling();
break;
194 case 'k': treeKey->previousSibling();
break;
195 case 'h': treeKey->parent();
break;
196 case 'l': treeKey->firstChild();
break;
197 case 'r': treeKey->root();
break;
203 std::cout <<
"\n p - print tree\n";
204 std::cout <<
" n - get local name\n";
205 std::cout <<
" s - set local name\n";
206 std::cout <<
" j - next sibbling\n";
207 std::cout <<
" k - previous sibbling\n";
208 std::cout <<
" h - parent\n";
209 std::cout <<
" l - first child\n";
210 std::cout <<
" r - root\n";
211 std::cout <<
" g - goto path\n";
212 std::cout <<
" G goto path; create if it doesn't exist\n";
213 std::cout <<
" a - append sibbling\n";
214 std::cout <<
" c - append child\n";
215 std::cout <<
" d - delete node\n";
216 std::cout <<
" v - view entry text\n";
217 std::cout <<
" t - set entry text\n";
218 std::cout <<
" q - quit\n\n";
223 while (input.compare(
"q"));
void appendSibbling(TreeKeyIdx *treeKey)
void removeEntry(EntriesBlock *eb, int index)
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
void deleteNode(TreeKeyIdx *treeKey)
static char createModule(const char *ipath)
void setLocalName(TreeKeyIdx *treeKey)
void viewEntryText(RawGenBook *book)
void printLocalName(TreeKeyIdx *treeKey)
void removeEntry(int entryIndex)
void assurePath(TreeKeyIdx *treeKey)
void gotoPath(TreeKeyIdx *treeKey)
void appendChild(TreeKeyIdx *treeKey)
void setEntryText(RawGenBook *book)