~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/modules/texts/rawtext/kjvidx.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <fcntl.h>
 
3
#include <versekey.h>
 
4
 
 
5
 
 
6
char findbreak(int fp, int *offset, int *num1, int *num2, short *size);
 
7
 
 
8
 
 
9
main(int argc, char **argv)
 
10
{
 
11
        int fp, vfp, cfp, bfp;
 
12
        long pos;
 
13
        short size, tmp;
 
14
        int num1, num2, offset, curbook = 0, curchap = 0, curverse = 0;
 
15
        char buf[127];
 
16
        VerseKey mykey;
 
17
 
 
18
        if ((argc < 2) || (argc > 3)) {
 
19
                fprintf(stderr, "usage: %s <file to process> [nt]\n", argv[0]);
 
20
                exit(1);
 
21
        }
 
22
 
 
23
        if ((fp = open(argv[1], O_RDONLY)) == -1) {
 
24
                fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
 
25
                exit(1);
 
26
        }
 
27
 
 
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);
 
31
                exit(1);
 
32
        }
 
33
 
 
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);
 
37
                exit(1);
 
38
        }
 
39
 
 
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);
 
43
                exit(1);
 
44
        }
 
45
 
 
46
        pos  = 0;
 
47
        write(bfp, &pos, 4);  /* Book    offset for testament intros */
 
48
        pos = 4;
 
49
        write(cfp, &pos, 4);  /* Chapter offset for testament intro */
 
50
 
 
51
 
 
52
/*      Right now just zero out intros until parsing correctly */
 
53
        pos = 0;
 
54
        size = 0;
 
55
        write(vfp, &pos, 4);  /* Module intro */
 
56
        write(vfp, &size, 2);
 
57
        write(vfp, &pos, 4);  /* Testament intro */
 
58
        write(vfp, &size, 2);
 
59
 
 
60
        mykey = (argc == 3) ? "Matthew 1:1" : "Genesis 1:1";
 
61
 
 
62
        while (!findbreak(fp, &offset, &num1, &num2, &size)) {
 
63
                num1 = mykey.Chapter();
 
64
                num2 = mykey.Verse();
 
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);
 
68
                                write(bfp, &pos, 4);
 
69
                                pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
 
70
                                write(cfp, &pos, 4);
 
71
                                pos  = 0;
 
72
                                tmp = 0;
 
73
                                write(vfp, &pos, 4);  /* Book intro (vss) */
 
74
                                write(vfp, &tmp, 2);
 
75
                                curbook++;
 
76
                                curchap = 0;
 
77
                        }
 
78
                        pos = lseek(vfp, 0, SEEK_CUR);
 
79
                        write(cfp, &pos, 4);
 
80
                        curverse = 1;
 
81
                        pos  = 0;
 
82
                        tmp = 0;
 
83
                        write(vfp, &pos, 4);  /* Chapter intro */
 
84
                        write(vfp, &tmp, 2);
 
85
                        curchap++;
 
86
                }
 
87
                else curverse++;
 
88
        
 
89
                printf("%2d:%3d:%3d found at offset: %7d\n", curbook, num1, num2, offset);
 
90
 
 
91
                if (num1 != curchap) {
 
92
                        fprintf(stderr, "Error: Found chaptures out of sequence\n");
 
93
                        break;
 
94
                }
 
95
                if (num2 != curverse) {
 
96
                        fprintf(stderr, "Error: Found verses out of sequence\n");
 
97
                        break;
 
98
                }
 
99
                write(vfp, &offset, 4);
 
100
                write(vfp, &size, 2);
 
101
                mykey++;
 
102
        }
 
103
        
 
104
        close(vfp);
 
105
        close(cfp);
 
106
        close(bfp);
 
107
        close(fp);
 
108
}
 
109
 
 
110
 
 
111
char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
 
112
{
 
113
        char buf[17];
 
114
        char buf2[7];
 
115
        char loop;
 
116
        char offadj, inquotes, sizeadj;
 
117
        int offset2, ch2, vs2;
 
118
        
 
119
        memset(buf, ' ', 17);
 
120
 
 
121
        while (1) {
 
122
                offadj = -10;
 
123
                inquotes = 0;
 
124
                sizeadj = 0;
 
125
                if ((!memcmp(buf, "\\widctlpar {\\b\\f0\\cf2 ", 16)) && (!size)) {
 
126
                        offadj = -1;
 
127
//                      inquotes = 1;
 
128
                        sizeadj = -18;
 
129
                }
 
130
                if (!memcmp(&buf[1], "\\f0\\fs16\\cf2\\up6", 15)) {
 
131
                        offadj = 0;
 
132
                        inquotes = 1;
 
133
                        sizeadj = (*buf == 10) ? -18:-17;
 
134
                }
 
135
                if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
 
136
                        offadj = -1;
 
137
//                      inquotes = 1;
 
138
                        sizeadj = -18;
 
139
                }
 
140
                if (offadj > -10) {
 
141
                        *offset = lseek(fp, 0, SEEK_CUR) + offadj;
 
142
                        if (size) {
 
143
                                (*offset)++;
 
144
                                while (inquotes) {
 
145
                                        while (read(fp, buf2, 1) == 1) {
 
146
                                                if (*buf2 == '}')
 
147
                                                        break;
 
148
                                                (*offset)++;
 
149
                                        }
 
150
                                        inquotes--;
 
151
                                }
 
152
                                if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
 
153
                                        *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
 
154
                                }
 
155
                                else {
 
156
                                        sprintf(buf2, "%d:%d", ch2, vs2);
 
157
                                        *size = (offset2 - (*offset));
 
158
                                }
 
159
                                lseek(fp, *offset+17, SEEK_SET);
 
160
                        }
 
161
                        else (*offset) += sizeadj;
 
162
                        return 0;
 
163
                }
 
164
                memmove(buf, &buf[1], 16);
 
165
                if (read(fp, &buf[16], 1) != 1)
 
166
                        return 1;
 
167
        }
 
168
}
 
169