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

Go to the source code of this file.

Functions

void appendChild (TreeKeyIdx *treeKey)
 
void appendSibbling (TreeKeyIdx *treeKey)
 
void assurePath (TreeKeyIdx *treeKey)
 
void deleteNode (TreeKeyIdx *treeKey)
 
void gotoPath (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 setEntryText (RawGenBook *book)
 
void setLocalName (TreeKeyIdx *treeKey)
 
void viewEntryText (RawGenBook *book)
 

Function Documentation

void appendChild ( TreeKeyIdx treeKey)

Definition at line 131 of file genbookutil.cpp.

131  {
132  char buf[1023];
133  std::cout << "Enter New Child Name: ";
134  fgets(buf, 1000, stdin);
135  SWBuf name = buf;
136  treeKey->appendChild();
137  treeKey->setLocalName(name.trim());
138  treeKey->save();
139 }
void appendSibbling ( TreeKeyIdx treeKey)

Definition at line 117 of file genbookutil.cpp.

117  {
118  if (treeKey->getOffset()) {
119  char buf[1023];
120  std::cout << "Enter New Sibbling Name: ";
121  fgets(buf, 1000, stdin);
122  SWBuf name = buf;
123  treeKey->append();
124  treeKey->setLocalName(name.trim());
125  treeKey->save();
126  }
127  else std::cout << "Can't add sibling to root node\n";
128 }
void assurePath ( TreeKeyIdx treeKey)

Definition at line 79 of file genbookutil.cpp.

79  {
80  char buf[1023];
81  std::cout << "Enter Path: ";
82  fgets(buf, 1000, stdin);
83  SWBuf path = buf;
84  treeKey->assureKeyPath(path.trim());
85 }
void deleteNode ( TreeKeyIdx treeKey)

Definition at line 142 of file genbookutil.cpp.

142  {
143  std::cout << "Removing entry [" << treeKey->getText() << "]\n";
144  treeKey->remove();
145 }
void gotoPath ( TreeKeyIdx treeKey)

Definition at line 70 of file genbookutil.cpp.

70  {
71  char buf[1023];
72  std::cout << "Enter Path: ";
73  fgets(buf, 1000, stdin);
74  SWBuf path = buf;
75  (*treeKey) = path.trim();
76 }
int main ( int  argc,
char **  argv 
)

Definition at line 157 of file genbookutil.cpp.

157  {
158 
159  if (argc != 2) {
160  fprintf(stderr, "usage: %s <tree/key/data/path>\n", *argv);
161  exit(-1);
162  }
163 
164  TreeKeyIdx *treeKey = new TreeKeyIdx(argv[1]);
165 
166  if (treeKey->popError()) {
167  RawGenBook::createModule(argv[1]);
168  }
169  delete treeKey;
170 
171  RawGenBook *book = new RawGenBook(argv[1]);
172  TreeKeyIdx root = *((TreeKeyIdx *)((SWKey *)(*book)));
173  treeKey = (TreeKeyIdx *)(SWKey *)(*book);
174 
175  SWBuf input;
176  char line[1024];
177 
178  do {
179  std::cout << "[" << treeKey->getText() << "] > ";
180  fgets(line, 1000, stdin);
181  input = line;
182  input.trim();
183  if (input.length() > 0) {
184  switch (input[0]) {
185  case 'n': printLocalName(treeKey); break;
186  case 's': setLocalName(treeKey); break;
187  case 'g': gotoPath(treeKey); break;
188  case 'G': assurePath(treeKey); break;
189  case 'p': root.root(); printTree(root, treeKey); break;
190  case 'a': appendSibbling(treeKey); break;
191  case 'c': appendChild(treeKey); break;
192  case 'd': deleteNode(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;
198  case 't': setEntryText(book); break;
199  case 'v': viewEntryText(book); break;
200  case 'q': break;
201  case '?':
202  default:
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";
219  break;
220  }
221  }
222  }
223  while (input.compare("q"));
224 
225  delete treeKey;
226 
227  return 0;
228 }
void appendSibbling(TreeKeyIdx *treeKey)
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
Definition: addgb.cpp:54
void deleteNode(TreeKeyIdx *treeKey)
static char createModule(const char *ipath)
Definition: rawgenbook.cpp:191
void setLocalName(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:60
void viewEntryText(RawGenBook *book)
Definition: genbookutil.cpp:88
void printLocalName(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:55
void assurePath(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:79
void gotoPath(TreeKeyIdx *treeKey)
Definition: genbookutil.cpp:70
void appendChild(TreeKeyIdx *treeKey)
void setEntryText(RawGenBook *book)
Definition: genbookutil.cpp:95
void printLocalName ( TreeKeyIdx treeKey)

Definition at line 55 of file genbookutil.cpp.

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

Definition at line 37 of file genbookutil.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() << "/\n";
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 148 of file genbookutil.cpp.

148  {
149  if (index < eb->getCount()) {
150  std::cout << "Removing entry [" << index << "]\n";
151  eb->removeEntry(index);
152  }
153  else std::cout << "Invalid entry number\n\n";
154 }
void removeEntry(int entryIndex)
Definition: entriesblk.cpp:166
void setEntryText ( RawGenBook book)

Definition at line 95 of file genbookutil.cpp.

95  {
96  SWBuf body;
97  TreeKeyIdx *treeKey = (TreeKeyIdx *)(SWKey *)(*book);
98  if (treeKey->getOffset()) {
99  char buf[1023];
100  std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n";
101  do {
102  fgets(buf, 1000, stdin);
103  SWBuf text = buf;
104  text.trim();
105  if ((text[0] == '.') && (text[1] == 0))
106  break;
107  body += text;
108  body += "\n";
109  } while (true);
110 
111  (*book) << body.c_str();
112  }
113  else std::cout << "Can't add entry text to root node\n";
114 }
void setLocalName ( TreeKeyIdx treeKey)

Definition at line 60 of file genbookutil.cpp.

60  {
61  char buf[1023];
62  std::cout << "Enter New Node Name: ";
63  fgets(buf, 1000, stdin);
64  SWBuf name = buf;
65  treeKey->setLocalName(name.trim());
66  treeKey->save();
67 }
void viewEntryText ( RawGenBook book)

Definition at line 88 of file genbookutil.cpp.

88  {
89  std::cout << "\n";
90  std::cout << book->renderText();
91  std::cout << "\n";
92 }