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

« back to all changes in this revision

Viewing changes to src/modules/comments/rawfiles/rawfilesgen.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
/*****************************************************************************
 
2
 *
 
3
 */
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include <string.h>
 
8
#include <ctype.h>
 
9
 
 
10
#ifndef __GNUC__
 
11
#include <io.h>
 
12
#else
 
13
#include <unistd.h>
 
14
#endif
 
15
 
 
16
#include <fcntl.h>
 
17
#include <versekey.h>
 
18
 
 
19
#ifndef O_BINARY
 
20
        #define O_BINARY 0
 
21
#endif
 
22
 
 
23
void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
 
24
char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
 
25
void openfiles();
 
26
void checkparams(int argc, char **argv);
 
27
void charsetconvert(char *data);
 
28
 
 
29
 
 
30
VerseKey key1, key2, key3;
 
31
int fp, vfp, cfp, bfp;
 
32
long chapoffset;
 
33
short chapsize;
 
34
char testmnt;
 
35
char startflag = 0;
 
36
 
 
37
 
 
38
main(int argc, char **argv)
 
39
{
 
40
        long pos, offset;
 
41
        int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
 
42
        char buf[127];
 
43
        short size, tmp;
 
44
        extern struct zonline online;
 
45
 
 
46
        checkparams(argc, argv);
 
47
 
 
48
        key1 = key2 = key3 = "Genesis 1:1";
 
49
 
 
50
        openfiles();
 
51
 
 
52
        num1    = key1.Chapter();
 
53
        num2    = key1.Verse();
 
54
 
 
55
        while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
 
56
                if (!startflag) {
 
57
                        startflag = 1;
 
58
                }
 
59
                else {
 
60
                        if (num2 < key2.Verse()) {            // new chapter
 
61
                                if (num1 <= key2.Chapter()) { // new book
 
62
                                        key2.Verse(1);
 
63
                                        key2.Chapter(1);
 
64
                                        key2.Book(key2.Book()+1);
 
65
                                }
 
66
                                printf("Created Empty Entry: %d ('%s')\n", num1, (const char *)key2);
 
67
                                chapoffset = offset;
 
68
                                chapsize = size;
 
69
//                              continue;
 
70
                        }
 
71
                }
 
72
                key2.Verse(1);
 
73
                key2.Chapter(num1);
 
74
                key2.Verse(num2);
 
75
 
 
76
                key3 = key2;
 
77
//              key3 += (rangemax - key3.Verse());
 
78
 
 
79
                writeidx(key1, key2, key3, offset, size);
 
80
        }
 
81
        close(vfp);
 
82
        close(cfp);
 
83
        close(bfp);
 
84
        close(fp);
 
85
}
 
86
 
 
87
 
 
88
/**************************************************************************
 
89
 * ENT: key1    - current location of index
 
90
 *      key2    - minimum keyval for which this offset is valid
 
91
 *      key3    - maximum keyval for which this offset is valid
 
92
 */
 
93
 
 
94
void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
 
95
{
 
96
        long pos;
 
97
        short tmp;
 
98
 
 
99
                if (key1.Verse() == 1) {        // new chapter
 
100
                        if (key1.Chapter() == 1) {      // new book
 
101
                                pos = lseek(cfp, 0, SEEK_CUR);
 
102
                                write(bfp, &pos, 4);
 
103
                                pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
 
104
                                write(cfp, &pos, 4);
 
105
                                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)*/
 
106
                                write(vfp, &chapsize, 2);
 
107
                        }
 
108
                        pos = lseek(vfp, 0, SEEK_CUR);
 
109
                        write(cfp, &pos, 4);
 
110
                        write(vfp, &chapoffset, 4);  /* Chapter intro */
 
111
                        write(vfp, &chapsize, 2);
 
112
                }
 
113
                if (key1 >= key2) {
 
114
                        write(vfp, &offset, 4);
 
115
                        size = 0;
 
116
                        write(vfp, &size, 2);
 
117
                }
 
118
                else    {
 
119
                        pos = 0;
 
120
                        tmp = 0;
 
121
                        write(vfp, &pos, 4);
 
122
                        write(vfp, &tmp, 2);
 
123
                }
 
124
                key1++;
 
125
}
 
126
 
 
127
 
 
128
static VerseKey inckey = "Genesis 1:1";
 
129
 
 
130
char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
 
131
{
 
132
        char buf[7];
 
133
        char buf2[20];
 
134
        char ch;
 
135
        char loop;
 
136
        long offset2;
 
137
        int ch2, vs2, rm2;
 
138
        bool flag;
 
139
        long chapstart = 0; 
 
140
        static int olbvnum = 0;
 
141
        char data[16];
 
142
 
 
143
        memset (data,0,16);
 
144
 
 
145
        if (++olbvnum <= 31102) {
 
146
 
 
147
                if (olbvnum == 23146) { // "Matthew 1:1"        
 
148
                        close(vfp);
 
149
                        close(cfp);
 
150
                        close(bfp);
 
151
                        close(fp);
 
152
                        key1 = key2 = key3 = inckey = "Matthew 1:1";
 
153
                        openfiles();
 
154
                        startflag = 0;
 
155
                }
 
156
 
 
157
 
 
158
                *offset = lseek(fp, 0, SEEK_CUR);
 
159
 
 
160
                if ((olbvnum!=1) && (olbvnum != 23146))
 
161
                        inckey++;
 
162
                        
 
163
                *num1 = inckey.Chapter();
 
164
                *num2 = inckey.Verse();
 
165
        
 
166
                
 
167
                write(fp, data, 16);
 
168
 
 
169
                *size = lseek(fp, 0, SEEK_CUR) - *offset;
 
170
                return 0;
 
171
        }
 
172
        return 1;
 
173
}
 
174
 
 
175
 
 
176
void openfiles()
 
177
{
 
178
        char buf[255];
 
179
        char fname[5];
 
180
        long pos;
 
181
        short size;
 
182
        
 
183
        testmnt = key1.Testament();
 
184
 
 
185
        strcpy(fname, (testmnt==2) ? "nt" : "ot");
 
186
        unlink(fname);
 
187
        if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
 
188
                fprintf(stderr, "Couldn't open file: %s\n", fname);
 
189
                exit(1);
 
190
        }
 
191
 
 
192
        sprintf(buf, "%s.vss", fname);
 
193
        unlink(buf);
 
194
        if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
 
195
                fprintf(stderr, "Couldn't open file: %s\n", buf);
 
196
                exit(1);
 
197
        }
 
198
 
 
199
        sprintf(buf, "%s.cps", fname);
 
200
        unlink(buf);
 
201
        if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
 
202
                fprintf(stderr, "Couldn't open file: %s\n", buf);
 
203
                exit(1);
 
204
        }
 
205
 
 
206
        sprintf(buf, "%s.bks", fname);
 
207
        unlink(buf);
 
208
        if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
 
209
                fprintf(stderr, "Couldn't open file: %s\n", buf);
 
210
                exit(1);
 
211
        }
 
212
 
 
213
        pos  = 0;
 
214
        write(bfp, &pos, 4);  /* Book    offset for testament intros */
 
215
        pos = 4;
 
216
        write(cfp, &pos, 4);  /* Chapter offset for testament intro */
 
217
 
 
218
 
 
219
/*      Right now just zero out intros until parsing correctly */
 
220
        pos = 0;
 
221
        size = 0;
 
222
        write(vfp, &pos, 4);  /* Module intro */
 
223
        write(vfp, &size, 2);
 
224
        write(vfp, &pos, 4);  /* Testament intro */
 
225
        write(vfp, &size, 2);
 
226
 
 
227
}
 
228
 
 
229
 
 
230
void checkparams(int argc, char **argv)
 
231
{
 
232
        if (argc !=1) {
 
233
                fprintf(stderr, "usage: %s\n", argv[0]);
 
234
                exit(1);
 
235
        }
 
236
}