1
/*****************************************************************************
3
* This code wreaks but works (at least for MHC). Good luck!
21
void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
22
char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
23
void openfiles(char *fname);
24
void checkparams(int argc, char **argv);
27
VerseKey key1, key2, key3;
28
int fp, vfp, cfp, bfp;
34
main(int argc, char **argv)
37
int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
38
char buf[127], startflag = 0;
41
checkparams(argc, argv);
45
testmnt = key1.Testament();
47
write(bfp, &pos, 4); /* Book offset for testament intros */
49
write(cfp, &pos, 4); /* Chapter offset for testament intro */
52
/* Right now just zero out intros until parsing correctly */
55
write(vfp, &pos, 4); /* Module intro */
57
write(vfp, &pos, 4); /* Testament intro */
60
while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
72
if (num1 <= key2.Chapter()) { // new book
74
key2.Book(key2.Book()+1);
78
printf("Found Chapter Break: %d ('%s')\n", num1, (const char *)key2);
85
key3 += (rangemax - key3.Verse());
87
writeidx(key1, key2, key3, offset, size);
96
/**************************************************************************
97
* ENT: key1 - current location of index
98
* key2 - minimum keyval for which this offset is valid
99
* key3 - maximum keyval for which this offset is valid
102
void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
107
for (; ((key1 <= key3) && (key1.Error() != KEYERR_OUTOFBOUNDS) && (key1.Testament() == testmnt)); key1+=1) {
108
if (key1.Verse() == 1) { // new chapter
109
if (key1.Chapter() == 1) { // new book
110
pos = lseek(cfp, 0, SEEK_CUR);
112
pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
114
write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
115
write(vfp, &chapsize, 2);
117
pos = lseek(vfp, 0, SEEK_CUR);
119
write(vfp, &chapoffset, 4); /* Chapter intro */
120
write(vfp, &chapsize, 2);
123
write(vfp, &offset, 4);
124
write(vfp, &size, 2);
136
char startentry(char *buf)
144
if (!isdigit(buf[2]))
146
for (loop = 3; loop < 7; loop++) {
147
if (buf[loop] == ' ')
149
if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))
156
char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
168
if (startentry(buf)) {
170
for (loop = 2; loop < 7; loop++) {
171
if ((buf[loop] == '-') || (buf[loop] == ',') || (buf[loop] == ' ')) {
177
for (ch = loop + 1; ch < 7; ch++) {
178
if (buf[ch] == ' ') {
183
*rangemax = atoi(&buf[loop+1]);
186
*offset = lseek(fp, 0, SEEK_CUR) - 5;
188
if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
189
*size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
193
*size = (offset2 - (*offset)) - 3;
196
sprintf(buf2, "$-$-$- XX:%d", ch2);
197
*size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
200
lseek(fp, *offset, SEEK_SET);
205
if (!strncmp(buf, "$-$-$-", 6)) {
208
while ((read(fp, &buf2[loop], 1) == 1) && (loop < 7)) {
209
if ((buf2[loop] == 10) || (buf2[loop] == 13)) {
215
while (read(fp, &ch, 1) == 1) {
220
*offset = lseek(fp, 0, SEEK_CUR) - 1;
222
for (loop = strlen(buf2) - 1; loop; loop--) {
223
if (buf2[loop] == ':')
226
*num1 = atoi(&buf2[loop+1]);
227
printf("Chapter marker: %s\n", buf2);
229
if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
230
*size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
234
*size = (offset2 - (*offset)) - 3;
237
sprintf(buf2, "$-$-$- XX:%d", ch2);
238
*size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
241
lseek(fp, *offset, SEEK_SET);
247
memmove(buf, &buf[1], 6);
248
if (read(fp, &buf[6], 1) != 1)
254
void openfiles(char *fname)
258
if ((fp = open(fname, O_RDONLY)) == -1) {
259
fprintf(stderr, "Couldn't open file: %s\n", fname);
263
sprintf(buf, "%s.vss", fname);
264
if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
265
fprintf(stderr, "Couldn't open file: %s\n", buf);
269
sprintf(buf, "%s.cps", fname);
270
if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
271
fprintf(stderr, "Couldn't open file: %s\n", buf);
275
sprintf(buf, "%s.bks", fname);
276
if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
277
fprintf(stderr, "Couldn't open file: %s\n", buf);
283
void checkparams(int argc, char **argv)
286
fprintf(stderr, "usage: %s <file to process> [nt - for new testmt file]\n", argv[0]);
290
key1 = key2 = key3 = "Matthew 1:1";
291
else key1 = key2 = key3 = "Genesis 1:1";