1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#ifndef __GNUC__
#include <io.h>
#else
#include <unistd.h>
#endif
#include <iostream>
#include <string>
#include <rawtext.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
int readline(FILE* infile, char* linebuffer) {
signed char c;
char* lbPtr = linebuffer;
while ((c = fgetc(infile)) != EOF) {
*lbPtr++ = c;
if (c == 10) {
*lbPtr = 0;
return (strlen(linebuffer));
}
}
return 0;
}
int main(int argc, char **argv) {
const char * helptext ="imp2vs 1.0 Bible/Commentary module creation tool for the SWORD Project\n usage:\n %s <filename> [output dir] \n";
signed long i = 0;
char* keybuffer = new char[2048];
char* entbuffer = new char[1048576];
char* linebuffer = new char[1048576];
char modname[16];
if (argc > 2) {
strcpy (modname, argv[2]);
}
else if (argc > 1) {
strcpy (modname, "./");
}
else {
fprintf(stderr, helptext, argv[0]);
exit(-1);
}
FILE *infile;
infile = fopen(argv[1], "r");
SWText* mod;
RawText::createModule(modname);
RawText modRaw(modname);
mod = &modRaw;
VerseKey* vkey = new VerseKey;
vkey->Headings(1);
vkey->AutoNormalize(0);
vkey->Persist(1);
while (readline(infile, linebuffer)) {
if (!strncmp(linebuffer, "$$$", 3)) {
if (strlen(keybuffer) && strlen(entbuffer)) {
std::cout << keybuffer << std::endl;
*vkey = keybuffer;
mod->SetKey(*vkey);
if (!vkey->Chapter()) {
// bad hack: 0:0 is Book intro; (chapter):0 is Chapter intro; 0:2 is Module intro; 0:1 is Testament intro
int backstep = vkey->Verse();
vkey->Verse(0);
*mod -= backstep;
mod->setEntry(entbuffer, strlen(entbuffer));
}
else {
ListKey listkey = vkey->ParseVerseList(keybuffer, "Gen1:1", true);
int i;
bool havefirst = false;
VerseKey firstverse;
for (i = 0; i < listkey.Count(); i++) {
VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i));
if (element) {
mod->Key(element->LowerBound());
VerseKey finalkey = element->UpperBound();
std::cout << (const char*)mod->Key() << "-" << (const char*)finalkey << std::endl;
if (!havefirst) {
havefirst = true;
firstverse = mod->Key();
mod->setEntry(entbuffer, strlen(entbuffer));
std::cout << "f" << (const char*)firstverse << std::endl;
(mod->Key())++;
}
while (mod->Key() <= finalkey) {
std::cout << (const char*)mod->Key() << std::endl;
*(SWModule*)mod << &firstverse;
(mod->Key())++;
}
}
else {
if (havefirst) {
mod->Key(*listkey.GetElement(i));
*(SWModule*)mod << &firstverse;
std::cout << (const char*)mod->Key() << std::endl;
}
else {
mod->Key(*listkey.GetElement(i));
havefirst = true;
firstverse = mod->Key();
mod->setEntry(entbuffer, strlen(entbuffer));
std::cout << "f" << (const char*)firstverse << std::endl;
}
}
}
}
}
linebuffer[strlen(linebuffer) - 1] = 0;
strcpy (keybuffer, linebuffer + 3);
*entbuffer = 0;
}
else {
strcat (entbuffer, linebuffer);
}
}
//handle final entry
if (strlen(keybuffer) && strlen(entbuffer)) {
std::cout << keybuffer << std::endl;
*vkey = keybuffer;
mod->SetKey(*vkey);
if (!vkey->Chapter()) {
// bad hack: 0:0 is Book intro; (chapter):0 is Chapter intro; 0:2 is Module intro; 0:1 is Testament intro
int backstep = vkey->Verse();
vkey->Verse(0);
*mod -= backstep;
mod->setEntry(entbuffer, strlen(entbuffer));
}
else {
ListKey listkey = vkey->ParseVerseList(keybuffer, "Gen1:1", true);
int i;
bool havefirst = false;
VerseKey firstverse;
for (i = 0; i < listkey.Count(); i++) {
VerseKey *element = SWDYNAMIC_CAST(VerseKey, listkey.GetElement(i));
if (element) {
mod->Key(element->LowerBound());
VerseKey finalkey = element->UpperBound();
std::cout << (const char*)mod->Key() << "-" << (const char*)finalkey << std::endl;
if (!havefirst) {
havefirst = true;
firstverse = mod->Key();
((SWModule*)mod)->setEntry(entbuffer, strlen(entbuffer));
std::cout << "f" << (const char*)firstverse << std::endl;
(mod->Key())++;
}
while (mod->Key() <= finalkey) {
std::cout << (const char*)mod->Key() << std::endl;
*(SWModule*)mod << &firstverse;
(mod->Key())++;
}
}
else {
if (havefirst) {
mod->Key(*listkey.GetElement(i));
*mod << &firstverse;
std::cout << (const char*)mod->Key() << std::endl;
}
else {
mod->Key(*listkey.GetElement(i));
havefirst = true;
firstverse = mod->Key();
mod->setEntry(entbuffer, strlen(entbuffer));
std::cout << "f" << (const char*)firstverse << std::endl;
}
}
}
}
}
//DEBUG printTree(root, treeKey);
delete entbuffer;
delete linebuffer;
delete keybuffer;
return 0;
}
|