The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
treeidxutil.cpp File Reference
#include <entriesblk.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <treekeyidx.h>
+ Include dependency graph for treeidxutil.cpp:

Go to the source code of this file.

Functions

void appendChild (TreeKeyIdx *treeKey)
 
void appendSibbling (TreeKeyIdx *treeKey)
 
void assurePath (TreeKeyIdx *treeKey)
 
int main (int argc, char **argv)
 
void printLocalName (TreeKeyIdx *treeKey)
 
void printTree (TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
 
void removeEntry (EntriesBlock *eb, int index)
 
void setLocalName (TreeKeyIdx *treeKey)
 

Function Documentation

void appendChild ( TreeKeyIdx treeKey)

Definition at line 90 of file treeidxutil.cpp.

90  {
91  char buf[1023];
92  std::cout << "Enter New Child Name: ";
93  fgets(buf, 1000, stdin);
94  treeKey->appendChild();
95  treeKey->setLocalName(buf);
96  treeKey->save();
97 }
void appendSibbling ( TreeKeyIdx treeKey)

Definition at line 77 of file treeidxutil.cpp.

77  {
78  if (treeKey->getOffset()) {
79  char buf[1023];
80  std::cout << "Enter New Sibbling Name: ";
81  fgets(buf, 1000, stdin);
82  treeKey->append();
83  treeKey->setLocalName(buf);
84  treeKey->save();
85  }
86  else std::cout << "Can't add sibling to root node\n";
87 }
void assurePath ( TreeKeyIdx treeKey)

Definition at line 69 of file treeidxutil.cpp.

69  {
70  char buf[1023];
71  std::cout << "Enter path: ";
72  fgets(buf, 1000, stdin);
73  treeKey->assureKeyPath(buf);
74 }
int main ( int  argc,
char **  argv 
)

Definition at line 109 of file treeidxutil.cpp.

109  {
110 
111  if (argc != 2) {
112  fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
113  exit(-1);
114  }
115 
116  TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
117 
118  if (treeKey->popError()) {
119  treeKey->create(argv[1]);
120  delete treeKey;
121  treeKey = new TreeKeyIdx(argv[1]);
122  }
123  TreeKeyIdx root = *treeKey;
124 
125  std::string input;
126  char line[1024];
127 
128  do {
129  std::cout << "[" << treeKey->getText() << "] > ";
130  fgets(line, 1000, stdin);
131  input = line;
132  if (input.length() > 0) {
133  switch (input[0]) {
134  case 'n': printLocalName(treeKey); break;
135  case 's': setLocalName(treeKey); break;
136  case 'p': root.root(); printTree(root, treeKey); break;
137  case 'a': appendSibbling(treeKey); break;
138  case 'c': appendChild(treeKey); break;
139  case 'j': treeKey->nextSibling(); break;
140  case 'g': assurePath(treeKey); 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;
145  case 'q': break;
146  case '?':
147  default:
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";
162  break;
163  }
164  }
165  }
166  while (input.compare("q"));
167 
168  delete treeKey;
169 
170  return 0;
171 }
void appendSibbling(TreeKeyIdx *treeKey)
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
Definition: addgb.cpp:54
void setLocalName(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:60
void printLocalName(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:55
void assurePath(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:79
void appendChild(TreeKeyIdx *treeKey)
const char * string
Definition: regex.c:5014
void printLocalName ( TreeKeyIdx treeKey)

Definition at line 55 of file treeidxutil.cpp.

55  {
56  std::cout << "locaName: " << treeKey->getLocalName() << std::endl;
57 }
void printTree ( TreeKeyIdx  treeKey,
TreeKeyIdx target = 0,
int  level = 1 
)

Definition at line 37 of file treeidxutil.cpp.

37  {
38  if (!target)
39  target = &treeKey;
40 
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()) {
46  printTree(treeKey, target, level+1);
47  treeKey.parent();
48  }
49  if (treeKey.nextSibling())
50  printTree(treeKey, target, level);
51 
52 }
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
Definition: addgb.cpp:54
void removeEntry ( EntriesBlock eb,
int  index 
)

Definition at line 100 of file treeidxutil.cpp.

100  {
101  if (index < eb->getCount()) {
102  std::cout << "Removing entry [" << index << "]\n";
103  eb->removeEntry(index);
104  }
105  else std::cout << "Invalid entry number\n\n";
106 }
void removeEntry(int entryIndex)
Definition: entriesblk.cpp:166
void setLocalName ( TreeKeyIdx treeKey)

Definition at line 60 of file treeidxutil.cpp.

60  {
61  char buf[1023];
62  std::cout << "Enter New Node Name: ";
63  fgets(buf, 1000, stdin);
64  treeKey->setLocalName(buf);
65  treeKey->save();
66 }