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() << std::endl;
45 if (treeKey.firstChild()) {
49 if (treeKey.nextSibling())
56 std::cout <<
"locaName: " << treeKey->getLocalName() << std::endl;
62 std::cout <<
"Enter New Node Name: ";
63 fgets(buf, 1000, stdin);
64 treeKey->setLocalName(buf);
71 std::cout <<
"Enter path: ";
72 fgets(buf, 1000, stdin);
73 treeKey->assureKeyPath(buf);
78 if (treeKey->getOffset()) {
80 std::cout <<
"Enter New Sibbling Name: ";
81 fgets(buf, 1000, stdin);
83 treeKey->setLocalName(buf);
86 else std::cout <<
"Can't add sibling to root node\n";
92 std::cout <<
"Enter New Child Name: ";
93 fgets(buf, 1000, stdin);
94 treeKey->appendChild();
95 treeKey->setLocalName(buf);
101 if (index < eb->getCount()) {
102 std::cout <<
"Removing entry [" << index <<
"]\n";
105 else std::cout <<
"Invalid entry number\n\n";
109 int main(
int argc,
char **argv) {
112 fprintf(stderr,
"usage: %s <tree/key/data/path>\n", *argv);
116 TreeKeyIdx *treeKey =
new TreeKeyIdx(argv[1]);
118 if (treeKey->popError()) {
119 treeKey->create(argv[1]);
121 treeKey =
new TreeKeyIdx(argv[1]);
123 TreeKeyIdx root = *treeKey;
129 std::cout <<
"[" << treeKey->getText() <<
"] > ";
130 fgets(line, 1000, stdin);
132 if (input.length() > 0) {
136 case 'p': root.root();
printTree(root, treeKey);
break;
139 case 'j': treeKey->nextSibling();
break;
141 case 'k': treeKey->previousSibling();
break;
142 case 'h': treeKey->parent();
break;
143 case 'l': treeKey->firstChild();
break;
144 case 'r': treeKey->root();
break;
148 std::cout <<
"\n p - print tree\n";
149 std::cout <<
" n - get local name\n";
150 std::cout <<
" s - set local name\n";
151 std::cout <<
" j - next sibbling\n";
152 std::cout <<
" k - previous sibbling\n";
153 std::cout <<
" h - parent\n";
154 std::cout <<
" l - first child\n";
155 std::cout <<
" r - root\n";
156 std::cout <<
" a - append sibbling\n";
157 std::cout <<
" c - append child\n";
158 std::cout <<
" u - get user data\n";
159 std::cout <<
" d - set user data\n";
160 std::cout <<
" g - goto path; create if it doesn't exist\n";
161 std::cout <<
" q - quit\n\n";
166 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 setLocalName(TreeKeyIdx *treeKey)
void printLocalName(TreeKeyIdx *treeKey)
void removeEntry(int entryIndex)
void assurePath(TreeKeyIdx *treeKey)
void appendChild(TreeKeyIdx *treeKey)