aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/rwpidx_8cpp-source.html
blob: 772691b025180db28dfd32386482e2edadbd561f (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
<!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>rwpidx.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>rwpidx.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 RWP).  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 = 0, num2 = 0, 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         pos  = 0;
00047         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00048         pos = 4;
00049         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00050 
00051 
00052 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00053         pos = 0;
00054         size = 0;
00055         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00056         write(vfp, &amp;size, 2);
00057         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00058         write(vfp, &amp;size, 2);
00059 
00060         <font class="keywordflow">while</font>(!findbreak(fp, &amp;offset, &amp;num1, &amp;num2, &amp;rangemax, &amp;size)) {
00061                 <font class="keywordflow">if</font> (num2) {                             
00062                         key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00063                         key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00064                         key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(num2);
00065                 }
00066                 <font class="keywordflow">else</font> {
00067                         key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00068                         <font class="keywordflow">if</font> (!startflag) {
00069                                 startflag = 1;
00070                         }
00071                         <font class="keywordflow">else</font> {
00072                                 <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>
00073                                         key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00074                                         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);
00075                                 }
00076                         }
00077                         key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00078                         printf(<font class="stringliteral">"Found Chapter Break: %d ('%s')\n"</font>, num1, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00079                         chapoffset = offset;
00080                         chapsize = size;
00081                         <font class="keywordflow">continue</font>;
00082                 }
00083 
00084                 key3 = key2;
00085                 key3 += (rangemax - key3.<a class="code" href="class_verse_key.html#a25">Verse</a>());
00086 
00087                 printf(<font class="stringliteral">"Found verse Break: ('%s')\n"</font>, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00088                 writeidx(key1, key2, key3, offset, size);
00089         }
00090         close(vfp);
00091         close(cfp);
00092         close(bfp);
00093         close(fp);
00094 }
00095 
00096 
00097 <font class="comment">/**************************************************************************</font>
00098 <font class="comment"> * ENT: key1    - current location of index</font>
00099 <font class="comment"> *      key2    - minimum keyval for which this offset is valid</font>
00100 <font class="comment"> *      key3    - maximum keyval for which this offset is valid</font>
00101 <font class="comment"> */</font>
00102 
00103 <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)
00104 {
00105         <font class="keywordtype">long</font> pos;
00106         <font class="keywordtype">short</font> tmp;
00107 
00108         <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) {
00109                 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) {        <font class="comment">// new chapter</font>
00110                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) {      <font class="comment">// new book</font>
00111                                 pos = lseek(cfp, 0, SEEK_CUR);
00112                                 write(bfp, &amp;pos, 4);
00113                                 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00114                                 write(cfp, &amp;pos, 4);
00115                                 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>
00116                                 write(vfp, &amp;chapsize, 2);
00117                         }
00118                         pos = lseek(vfp, 0, SEEK_CUR);
00119                         write(cfp, &amp;pos, 4);
00120                         write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Chapter intro */</font>
00121                         write(vfp, &amp;chapsize, 2);
00122                 }
00123                 <font class="keywordflow">if</font> (key1 &gt;= key2) {
00124                         write(vfp, &amp;offset, 4);
00125                         write(vfp, &amp;size, 2);
00126                 }
00127                 <font class="keywordflow">else</font>    {
00128                         pos = 0;
00129                         tmp = 0;
00130                         write(vfp, &amp;pos, 4);
00131                         write(vfp, &amp;tmp, 2);
00132                 }
00133         }
00134 }
00135 
00136 
00137 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf)
00138 {
00139         <font class="keywordtype">char</font> colon = 0;
00140 
00141         <font class="keywordflow">if</font> (buf[0] != 10)
00142                 <font class="keywordflow">return</font> 0;
00143         <font class="keywordflow">if</font> (buf[1] != 10)
00144                 <font class="keywordflow">return</font> 0;
00145         <font class="keywordflow">if</font> (!isdigit(buf[2]))
00146                 <font class="keywordflow">return</font> 0;
00147         <font class="keywordflow">if</font> (!isdigit(buf[3])) {
00148                 <font class="keywordflow">if</font> (buf[3]!= <font class="charliteral">':'</font>)
00149                         <font class="keywordflow">return</font> 0;
00150                 <font class="keywordflow">else</font>    colon++;
00151         }
00152         <font class="keywordflow">if</font> (!isdigit(buf[4])) {
00153                 <font class="keywordflow">if</font> (buf[4]!= <font class="charliteral">':'</font>)
00154                         <font class="keywordflow">return</font> 0;
00155                 <font class="keywordflow">else</font>    colon++;
00156         }
00157         <font class="keywordflow">if</font> (colon != 1)
00158                 <font class="keywordflow">return</font> 0;
00159         <font class="keywordflow">return</font> 1;
00160 }
00161 
00162 
00163 <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)
00164 {
00165         <font class="keywordtype">char</font> buf[7];
00166         <font class="keywordtype">char</font> buf2[20];
00167         <font class="keywordtype">char</font> ch;
00168         <font class="keywordtype">char</font> loop;
00169         <font class="keywordtype">long</font> offset2;
00170         <font class="keywordtype">int</font> ch2, vs2, rm2;
00171         
00172         memset(buf, <font class="charliteral">' '</font>, 7);
00173 
00174         <font class="keywordflow">while</font> (1) {
00175                 <font class="keywordflow">if</font> (startentry(buf)) {
00176                         buf[0] = <font class="charliteral">' '</font>;
00177                         buf[1] = <font class="charliteral">' '</font>;
00178                         sscanf(buf, <font class="stringliteral">"%d:%d"</font>, num1, num2);
00179                         *rangemax = *num2;
00180                         *offset = lseek(fp, 0, SEEK_CUR) - 5;
00181                         <font class="keywordflow">if</font> (size) {
00182                                 <font class="keywordflow">if</font> (findbreak(fp, &amp;offset2, &amp;ch2, &amp;vs2, &amp;rm2, 0)) {
00183                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00184                                 }
00185                                 <font class="keywordflow">else</font> {
00186                                         <font class="keywordflow">if</font> (vs2) {
00187                                                 *size = (offset2 - (*offset)) - 2;
00188                                         }
00189                                         <font class="keywordflow">else</font> {
00190                                                 *size = (offset2 - (*offset)) - 6;
00191                                         }
00192                                 }
00193                                 lseek(fp, *offset, SEEK_SET);
00194                         }
00195                         <font class="keywordflow">return</font> 0;
00196                 }
00197                                         
00198                 <font class="keywordflow">if</font> (!strncmp(buf, <font class="stringliteral">"$-$-$-"</font>, 6)) {
00199                         *offset = lseek(fp, 0, SEEK_CUR) - 1;
00200                         *num2 = 0;
00201                         (*num1)++;
00202                         printf(<font class="stringliteral">"Book marker: %s\n"</font>, buf2);
00203                         <font class="keywordflow">if</font> (size) {
00204                                 <font class="keywordflow">if</font> (findbreak(fp, &amp;offset2, &amp;ch2, &amp;vs2, &amp;rm2, 0)) {
00205                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00206                                 }
00207                                 <font class="keywordflow">else</font> {
00208                                         <font class="keywordflow">if</font> (vs2) {
00209                                                 *size = (offset2 - (*offset)) - 2;
00210                                         }
00211                                         <font class="keywordflow">else</font> {
00212                                                 *size = (offset2 - (*offset)) - 6;
00213                                         }
00214                                 }
00215                                 lseek(fp, *offset, SEEK_SET);
00216                         }
00217                         <font class="keywordflow">return</font> 0;
00218                 }
00219                                  
00220                                 
00221                 memmove(buf, &amp;buf[1], 6);
00222                 <font class="keywordflow">if</font> (read(fp, &amp;buf[6], 1) != 1)
00223                         <font class="keywordflow">return</font> 1;
00224         }
00225 }
00226 
00227 
00228 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname)
00229 {
00230         <font class="keywordtype">char</font> buf[255];
00231 
00232         <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY)) == -1) {
00233                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00234                 exit(1);
00235         }
00236 
00237         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00238         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00239                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00240                 exit(1);
00241         }
00242 
00243         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00244         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00245                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00246                 exit(1);
00247         }
00248 
00249         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00250         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00251                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00252                 exit(1);
00253         }
00254 }
00255 
00256 
00257 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00258 {
00259         <font class="keywordflow">if</font> (argc &lt; 2) {
00260                 fprintf(stderr, <font class="stringliteral">"usage: %s &lt;file to process&gt; [nt - for new testmt file]\n"</font>, argv[0]);
00261                 exit(1);
00262         }
00263         <font class="keywordflow">if</font> (argc == 3)
00264                 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>;
00265         <font class="keywordflow">else</font>    key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00266 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 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>