6
char findbreak(int fp, int *offset, int *num1, int *num2, short *size);
9
main(int argc, char **argv)
11
int fp, vfp, cfp, bfp;
14
int num1, num2, offset, curbook = 0, curchap = 0, curverse = 0;
18
if ((argc < 2) || (argc > 3)) {
19
fprintf(stderr, "usage: %s <file to process> [nt]\n", argv[0]);
23
if ((fp = open(argv[1], O_RDONLY)) == -1) {
24
fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
28
sprintf(buf, "%s.vss", argv[1]);
29
if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
30
fprintf(stderr, "Couldn't open file: %s\n", buf);
34
sprintf(buf, "%s.cps", argv[1]);
35
if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
36
fprintf(stderr, "Couldn't open file: %s\n", buf);
40
sprintf(buf, "%s.bks", argv[1]);
41
if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
42
fprintf(stderr, "Couldn't open file: %s\n", buf);
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
mykey = (argc == 3) ? "Matthew 1:1" : "Genesis 1:1";
62
while (!findbreak(fp, &offset, &num1, &num2, &size)) {
63
num1 = mykey.Chapter();
65
if (num2 == 1) { /* if we're at a new chapter */
66
if (num1 == 1) { /* if we're at a new book */
67
pos = lseek(cfp, 0, SEEK_CUR);
69
pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
73
write(vfp, &pos, 4); /* Book intro (vss) */
78
pos = lseek(vfp, 0, SEEK_CUR);
83
write(vfp, &pos, 4); /* Chapter intro */
89
printf("%2d:%3d:%3d found at offset: %7d\n", curbook, num1, num2, offset);
91
if (num1 != curchap) {
92
fprintf(stderr, "Error: Found chaptures out of sequence\n");
95
if (num2 != curverse) {
96
fprintf(stderr, "Error: Found verses out of sequence\n");
99
write(vfp, &offset, 4);
100
write(vfp, &size, 2);
111
char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
116
char offadj, inquotes, sizeadj;
117
int offset2, ch2, vs2;
119
memset(buf, ' ', 17);
125
if ((!memcmp(buf, "\\widctlpar {\\b\\f0\\cf2 ", 16)) && (!size)) {
130
if (!memcmp(&buf[1], "\\f0\\fs16\\cf2\\up6", 15)) {
133
sizeadj = (*buf == 10) ? -18:-17;
135
if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
141
*offset = lseek(fp, 0, SEEK_CUR) + offadj;
145
while (read(fp, buf2, 1) == 1) {
152
if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
153
*size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
156
sprintf(buf2, "%d:%d", ch2, vs2);
157
*size = (offset2 - (*offset));
159
lseek(fp, *offset+17, SEEK_SET);
161
else (*offset) += sizeadj;
164
memmove(buf, &buf[1], 16);
165
if (read(fp, &buf[16], 1) != 1)