aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/rawgbf_2gbfidx_8cpp-source.html
blob: 2c61994a64bba33f7b22c42ce80b5cf6f9e4c1af (plain) (blame)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gbfidx.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>gbfidx.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/*****************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> *      This code wreaks but works (at least for WEB).  Good luck!</font>
00004 <font class="comment"> */</font>
00005 
00006 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00007 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00008 <font class="preprocessor">#include &lt;string.h&gt;</font>
00009 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00010 
00011 <font class="preprocessor">#ifndef __GNUC__</font>
00012 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00013 <font class="preprocessor">#else</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00015 <font class="preprocessor">#endif</font>
00016 <font class="preprocessor"></font>
00017 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00018 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00019 
00020 
00021 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size);
00022 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size);
00023 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname);
00024 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv);
00025 
00026 
00027 <a class="code" href="class_verse_key.html">VerseKey</a> key1, key2, key3;
00028 <font class="keywordtype">int</font> fp, vfp, cfp, bfp;
00029 <font class="keywordtype">long</font> chapoffset;
00030 <font class="keywordtype">short</font> chapsize;
00031 <font class="keywordtype">char</font> testmnt;
00032 
00033 
00034 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00035 {
00036         <font class="keywordtype">long</font> pos, offset;
00037         <font class="keywordtype">int</font> num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
00038         <font class="keywordtype">char</font> buf[127], startflag = 0;
00039         <font class="keywordtype">short</font> size, tmp;
00040 
00041         checkparams(argc, argv);
00042 
00043         openfiles(argv[1]);
00044 
00045         testmnt = key1.<a class="code" href="class_verse_key.html#a22">Testament</a>();
00046         num1 = key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00047         num2 = key1.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00048         pos  = 0;
00049         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00050         pos = 4;
00051         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00052 
00053 
00054 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00055         pos = 0;
00056         size = 0;
00057         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00058         write(vfp, &amp;size, 2);
00059         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00060         write(vfp, &amp;size, 2);
00061 
00062         <font class="keywordflow">while</font>(!findbreak(fp, &amp;offset, &amp;num1, &amp;num2, &amp;rangemax, &amp;size)) {
00063                 <font class="keywordflow">if</font> (!startflag) {
00064                         startflag = 1;
00065                 }
00066                 <font class="keywordflow">else</font> {
00067                         <font class="keywordflow">if</font> (num2 &lt; key2.<a class="code" href="class_verse_key.html#a25">Verse</a>()) {            <font class="comment">// new chapter</font>
00068                                 <font class="keywordflow">if</font> (num1 &lt;= key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>()) { <font class="comment">// new book</font>
00069                                         key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00070                                         key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00071                                         key2.<a class="code" href="class_verse_key.html#a23">Book</a>(key2.<a class="code" href="class_verse_key.html#a23">Book</a>()+1);
00072                                 }
00073                                 printf(<font class="stringliteral">"Found Chapter Break: %d ('%s')\n"</font>, num1, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00074                                 chapoffset = offset;
00075                                 chapsize = size;
00076 <font class="comment">//                              continue;</font>
00077                         }
00078                 }
00079                 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00080                 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00081                 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(num2);
00082 
00083                 key3 = key2;
00084 <font class="comment">//              key3 += (rangemax - key3.Verse());</font>
00085 
00086                 writeidx(key1, key2, key3, offset, size);
00087         }
00088         close(vfp);
00089         close(cfp);
00090         close(bfp);
00091         close(fp);
00092 }
00093 
00094 
00095 <font class="comment">/**************************************************************************</font>
00096 <font class="comment"> * ENT: key1    - current location of index</font>
00097 <font class="comment"> *      key2    - minimum keyval for which this offset is valid</font>
00098 <font class="comment"> *      key3    - maximum keyval for which this offset is valid</font>
00099 <font class="comment"> */</font>
00100 
00101 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size)
00102 {
00103         <font class="keywordtype">long</font> pos;
00104         <font class="keywordtype">short</font> tmp;
00105 
00106         <font class="keywordflow">for</font> (; ((key1 &lt;= key3) &amp;&amp; (key1.<a class="code" href="class_s_w_key.html#a6">Error</a>() != KEYERR_OUTOFBOUNDS) &amp;&amp; (key1.<a class="code" href="class_verse_key.html#a22">Testament</a>() == testmnt)); key1+=1) {
00107                 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) {        <font class="comment">// new chapter</font>
00108                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) {      <font class="comment">// new book</font>
00109                                 pos = lseek(cfp, 0, SEEK_CUR);
00110                                 write(bfp, &amp;pos, 4);
00111                                 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00112                                 write(cfp, &amp;pos, 4);
00113                                 write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Book intro (vss)  set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/</font>
00114                                 write(vfp, &amp;chapsize, 2);
00115                         }
00116                         pos = lseek(vfp, 0, SEEK_CUR);
00117                         write(cfp, &amp;pos, 4);
00118                         write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Chapter intro */</font>
00119                         write(vfp, &amp;chapsize, 2);
00120                 }
00121                 <font class="keywordflow">if</font> (key1 &gt;= key2) {
00122                         write(vfp, &amp;offset, 4);
00123                         write(vfp, &amp;size, 2);
00124                 }
00125                 <font class="keywordflow">else</font>    {
00126                         pos = 0;
00127                         tmp = 0;
00128                         write(vfp, &amp;pos, 4);
00129                         write(vfp, &amp;tmp, 2);
00130                 }
00131         }
00132 }
00133 
00134 
00135 <font class="keywordtype">char</font> startchap(<font class="keywordtype">char</font> *buf)
00136 {
00137         <font class="keywordtype">char</font> loop;
00138 
00139         <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'&lt;'</font>)
00140                 <font class="keywordflow">return</font> 0;
00141         <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>)
00142                 <font class="keywordflow">return</font> 0;
00143         <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'C'</font>)
00144                 <font class="keywordflow">return</font> 0;
00145 <font class="comment">/*</font>
00146 <font class="comment">        if (!isdigit(buf[2]))</font>
00147 <font class="comment">                return 0;</font>
00148 <font class="comment">        for (loop = 3; loop &lt; 7; loop++) {</font>
00149 <font class="comment">                if (buf[loop] == ' ')</font>
00150 <font class="comment">                        break;</font>
00151 <font class="comment">                if ((!isdigit(buf[loop])) &amp;&amp; (buf[loop] != ',') &amp;&amp; (buf[loop] != '-'))</font>
00152 <font class="comment">                        return 0;</font>
00153 <font class="comment">        }</font>
00154 <font class="comment">*/</font>
00155         <font class="keywordflow">return</font> 1;
00156 }
00157 
00158 
00159 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf)
00160 {
00161         <font class="keywordtype">char</font> loop;
00162 
00163         <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'&lt;'</font>)
00164                 <font class="keywordflow">return</font> 0;
00165         <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>)
00166                 <font class="keywordflow">return</font> 0;
00167         <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'V'</font>)
00168                 <font class="keywordflow">return</font> 0;
00169 <font class="comment">/*</font>
00170 <font class="comment">        if (!isdigit(buf[2]))</font>
00171 <font class="comment">                return 0;</font>
00172 <font class="comment">        for (loop = 3; loop &lt; 7; loop++) {</font>
00173 <font class="comment">                if (buf[loop] == ' ')</font>
00174 <font class="comment">                        break;</font>
00175 <font class="comment">                if ((!isdigit(buf[loop])) &amp;&amp; (buf[loop] != ',') &amp;&amp; (buf[loop] != '-'))</font>
00176 <font class="comment">                        return 0;</font>
00177 <font class="comment">        }</font>
00178 <font class="comment">*/</font>
00179         <font class="keywordflow">return</font> 1;
00180 }
00181 
00182 
00183 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size)
00184 {
00185         <font class="keywordtype">char</font> buf[7];
00186         <font class="keywordtype">char</font> buf2[20];
00187         <font class="keywordtype">char</font> ch;
00188         <font class="keywordtype">char</font> loop;
00189         <font class="keywordtype">long</font> offset2;
00190         <font class="keywordtype">int</font> ch2, vs2, rm2;
00191         <font class="keywordtype">bool</font> flag;
00192         <font class="keywordtype">long</font> chapstart = 0; 
00193         
00194         memset(buf, <font class="charliteral">' '</font>, 7);
00195 
00196         <font class="keywordflow">while</font> (1) {
00197                 <font class="keywordflow">if</font> (startchap(buf)) {
00198                         chapstart = lseek(fp, 0, SEEK_CUR) - 7;
00199                         memset(buf, <font class="charliteral">' '</font>, 3);
00200                         flag = <font class="keyword">false</font>;
00201                         <font class="keywordflow">for</font> (loop = 3; loop &lt; 6; loop++) {
00202                                 <font class="keywordflow">if</font> (isdigit(buf[loop]))
00203                                         flag = <font class="keyword">true</font>;
00204                                 <font class="keywordflow">else</font> {
00205                                         buf[loop] = 0;
00206                                         <font class="keywordflow">break</font>;
00207                                 }
00208                         }
00209                         <font class="keywordflow">if</font> (flag) 
00210                                 *num1 = atoi(buf);
00211                         <font class="keywordflow">else</font>    (*num1)++;
00212                 }
00213                 <font class="keywordflow">if</font> (startentry(buf)) {
00214                         memset(buf, <font class="charliteral">' '</font>, 3);
00215                         flag = <font class="keyword">false</font>;
00216                         <font class="keywordflow">for</font> (loop = 3; loop &lt; 6; loop++) {
00217                                 <font class="keywordflow">if</font> (isdigit(buf[loop]))
00218                                         flag = <font class="keyword">true</font>;
00219                                 <font class="keywordflow">else</font> {
00220                                         buf[loop] = 0;
00221                                         <font class="keywordflow">break</font>;
00222                                 }
00223                         <font class="keywordflow">if</font> (flag)
00224                                 *num2 = atoi(buf);
00225                         <font class="keywordflow">else</font>    (*num2)++;
00226                         }
00227                         loop++;
00228                         <font class="keywordflow">if</font> (size)
00229                                 *offset = lseek(fp, 0, SEEK_CUR) - (7 - loop);
00230                         <font class="keywordflow">else</font>    *offset = (chapstart) ? chapstart : lseek(fp, 0, SEEK_CUR) - 7;
00231                         <font class="keywordflow">if</font> (size) {
00232                                 ch2 = *num1;
00233                                 vs2 = *num2;
00234                                 <font class="keywordflow">if</font> (findbreak(fp, &amp;offset2, &amp;ch2, &amp;vs2, &amp;rm2, 0)) {
00235                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00236                                 }
00237                                 <font class="keywordflow">else</font> {
00238                                         <font class="keywordflow">if</font> (vs2) {
00239                                                 *size = (offset2 - (*offset));
00240                                         }
00241                                 }
00242                                 lseek(fp, *offset, SEEK_SET);
00243                         }
00244                         <font class="keywordflow">return</font> 0;
00245                 }
00246                 memmove(buf, &amp;buf[1], 6);
00247                 <font class="keywordflow">if</font> (read(fp, &amp;buf[6], 1) != 1)
00248                         <font class="keywordflow">return</font> 1;
00249         }
00250 }
00251 
00252 
00253 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname)
00254 {
00255 <font class="preprocessor">#ifndef O_BINARY                // O_BINARY is needed in Borland C++ 4.53</font>
00256 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0              // If it hasn't been defined than we probably</font>
00257 <font class="preprocessor"></font><font class="preprocessor">#endif                          // don't need it.</font>
00258 <font class="preprocessor"></font>        <font class="keywordtype">char</font> buf[255];
00259 
00260         <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY|O_BINARY)) == -1) {
00261                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00262                 exit(1);
00263         }
00264 
00265         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00266         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00267                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00268                 exit(1);
00269         }
00270 
00271         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00272         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00273                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00274                 exit(1);
00275         }
00276 
00277         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00278         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00279                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00280                 exit(1);
00281         }
00282 }
00283 
00284 
00285 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00286 {
00287         <font class="keywordflow">if</font> (argc &lt; 2) {
00288                 fprintf(stderr, <font class="stringliteral">"usage: %s &lt;file to process&gt; [nt - for new testmt file]\n"</font>, argv[0]);
00289                 exit(1);
00290         }
00291         <font class="keywordflow">if</font> (argc == 3)
00292                 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>;
00293         <font class="keywordflow">else</font>    key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00294 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>