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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 
void printTree (TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 72 of file addgb.cpp.

72  {
73 
74  const char * helptext ="addgb 1.0 General Book module creation tool for the SWORD Project\nUse -a to add a new leaf entry from standard input or a file\n usage:\n %s -a <filename> <key> [</path/to/file/with/entry>]\n";
75 
76  // const char * helptext ="addgb 1.0 General Book module creation tool for the SWORD Project\nUse -a to add a new leaf entry from standard input or a file, -d to delete an\nentry, -l to link two leaf entries.\n usage:\n %s -a <filename> <key> [</path/to/file/with/entry>]\n %s -d <filename> <key>\n %s -l <filename> <first key (already assigned)> <second key>\n";
77 
78  char mode;
79  unsigned long entrysize;
80 
81  if (argc < 3) {
82  fprintf(stderr, helptext, argv[0]);
83  exit(-1);
84  }
85 
86  mode = argv[1][1];
87 
88  // Do some initialization stuff
89  TreeKeyIdx *treeKey = new TreeKeyIdx(argv[2]);
90  if (treeKey->popError()) {
91  treeKey->create(argv[2]);
92  delete treeKey;
93  treeKey = new TreeKeyIdx(argv[2]);
94  RawGenBook::createModule(argv[2]);
95  }
96  delete treeKey;
97  RawGenBook *book = new RawGenBook(argv[2]);
98 
99  if ((mode == 'a') && (argc == 4 || argc == 5)) {
100  char buffer[1048576]; //this is the max size of any entry
101 
102 
103  FILE *infile;
104  // case: add from text file
105  //Open our data file and read its contents into the buffer
106  if (argc == 5) infile = fopen(argv[4], "r");
107  // case: add from stdin
108  else infile = stdin;
109 
110  entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
111  book->setKey(argv[3]);
112  book->setEntry(buffer, entrysize); // save text to module at current position
113  }
114 
115  /*
116  // let's pretend these don't exist for the time being
117 
118  // Link 2 verses
119  else if ((mode == 'l') && argc == 5) {
120  *key = argv[3];
121  mod.setKey(*key);
122 
123  SWKey tmpkey = argv[4];
124  mod << &(tmpkey);
125  }
126 
127  // Delete an entry
128  else if ((mode == 'd') && argc == 4) {
129  mod.setKey(argv[3]);
130  mod.deleteEntry();
131  }
132  */
133  // Bad arguments, print usage
134  else {
135  fprintf(stderr, helptext, argv[0]);
136  exit(-1);
137  }
138 
139  //DEBUG printTree(root, treeKey);
140 
141  delete treeKey;
142  delete book;
143  return 0;
144 }
static char createModule(const char *ipath)
Definition: rawgenbook.cpp:191
preg buffer
Definition: regex.c:8089
virtual char setKey(const SWKey *ikey)
Definition: swmodule.cpp:298
static signed char create(const char *path)
Definition: treekeyidx.cpp:290
virtual void setEntry(const char *inbuf, long len=-1)
Definition: rawgenbook.cpp:134
virtual char popError()
Definition: swkey.cpp:147
void printTree ( TreeKeyIdx  treeKey,
TreeKeyIdx target = 0,
int  level = 1 
)

Definition at line 54 of file addgb.cpp.

54  {
55  if (!target)
56  target = &treeKey;
57 
58  unsigned long currentOffset = target->getOffset();
59  std::cout << ((currentOffset == treeKey.getOffset()) ? "==>" : "");
60  for (int i = 0; i < level; i++) std::cout << "\t";
61  std::cout << treeKey.getLocalName() << "/\n";
62  if (treeKey.firstChild()) {
63  printTree(treeKey, target, level+1);
64  treeKey.parent();
65  }
66  if (treeKey.nextSibling())
67  printTree(treeKey, target, level);
68 
69 }
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target=0, int level=1)
Definition: addgb.cpp:54
virtual const char * getLocalName()
Definition: treekeyidx.cpp:91
virtual bool nextSibling()
Definition: treekeyidx.cpp:168
virtual bool parent()
Definition: treekeyidx.cpp:148
unsigned long getOffset() const
Definition: treekeyidx.cpp:410
virtual bool firstChild()
Definition: treekeyidx.cpp:158