2
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
3
* CrossWire Bible Society
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation version 2.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
35
#ifndef NO_SWORD_NAMESPACE
39
using sword::VerseKey;
41
using sword::SWModule;
44
int main(int argc, char **argv) {
46
const char * helptext = "addvs 1.1 Bible & Commentary module creation tool for the SWORD Project\nUse -a to add a new verse from standard input or a file, -d to delete a verse,\n-l to link two verses, -c to create a new module.\n usage:\n %s -a </path/to/module> <verse> [</path/to/file/with/verse>]\n %s -d </path/to/module> <key>\n %s -l </path/to/module> <first verse (already assigned)> <second verse>\n %s -c </path/to/module>\n";
50
fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);
53
if (!strcmp(argv[1], "-a") && (argc == 4 || argc == 5)) {
55
// Do some initialization stuff
56
char buffer[65536]; //this is the max size of any entry
57
RawText * mod = new RawText(argv[2]); // open our datapath with our RawText driver.
58
VerseKey *vkey = new VerseKey;
60
vkey->AutoNormalize(0);
61
vkey->Persist(1); // the magical setting
65
if (!vkey->Chapter()) {
68
// (chapter):0 is Chapter intro
70
// 0:2 is Module intro
71
// 0:1 is Testament intro
72
int backstep = vkey->Verse();
78
// case: add from text file
79
//Open our data file and read its contents into the buffer
80
if (argc == 5) infile = fopen(argv[4], "r");
81
// case: add from stdin
84
entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
86
mod->setEntry(buffer, entrysize); // save text to module at current position
89
ListKey listkey = vkey->ParseVerseList(argv[3], "Gen1:1", true);
91
bool havefirst = false;
93
for (i = 0; i < listkey.Count(); i++) {
94
VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i));
96
mod->Key(element->LowerBound());
97
VerseKey finalkey = element->UpperBound();
98
std::cout << (const char*)mod->Key() << "-" << (const char*)finalkey << std::endl;
101
firstverse = mod->Key();
103
// case: add from text file
104
//Open our data file and read its contents into the buffer
105
if (argc == 5) infile = fopen(argv[4], "r");
106
// case: add from stdin
109
entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
111
mod->setEntry(buffer, entrysize); // save text to module at current position
112
std::cout << "f" << (const char*)firstverse << std::endl;
115
while (mod->Key() <= finalkey) {
116
std::cout << (const char*)mod->Key() << std::endl;
117
*(SWModule*)mod << &firstverse;
123
mod->Key(*listkey.GetElement(i));
124
*(SWModule*)mod << &firstverse;
125
std::cout << (const char*)mod->Key() << std::endl;
128
mod->Key(*listkey.GetElement(i));
130
firstverse = mod->Key();
132
// case: add from text file
133
//Open our data file and read its contents into the buffer
134
if (argc == 5) infile = fopen(argv[4], "r");
135
// case: add from stdin
138
entrysize = fread(buffer, sizeof(char), sizeof(buffer), infile);
140
mod->setEntry(buffer, entrysize); // save text to module at current position
141
std::cout << "f" << (const char*)firstverse << std::endl;
149
else if (!strcmp(argv[1], "-l") && argc == 5) {
150
// Do some initialization stuff
151
RawText *mod = new RawText(argv[2]); // open our datapath with our RawText driver.
153
mod->setKey(argv[4]); // set key from argument
154
SWKey tmpkey = (SWKey) argv[3];
155
*(SWModule*)mod << &(tmpkey);
159
else if (!strcmp(argv[1], "-d") && argc == 4) {
160
RawText mod(argv[2]); // open our datapath with our RawText driver.
161
VerseKey *vkey = new VerseKey;
163
vkey->AutoNormalize(0);
164
vkey->Persist(1); // the magical setting
170
if (!vkey->Chapter())
174
// (chapter):0 is Chapter intro
176
// 0:2 is Module intro
177
// 0:1 is Testament intro
178
int backstep = vkey->Verse();
189
else if (!strcmp(argv[1], "-c") && argc == 3) {
190
// Try to initialize a default set of datafiles and indicies at our
191
// datapath location passed to us from the user.
192
if (RawText::createModule(argv[2])) {
193
fprintf(stderr, "error: %s: couldn't create module at path: %s \n", argv[0], argv[2]);
198
// Bad arguments, print usage
200
fprintf(stderr, helptext, argv[0], argv[0], argv[0], argv[0]);