aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/zverse_8cpp-source.html
blob: 737b9dbbfb4f18a7e454b1e6db3115234a5a4332 (plain) (tree)
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
















































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
<!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>zverse.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>zverse.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  zverse.h   - code for class 'zVerse'- a module that reads raw text</font>
00003 <font class="comment"> *                              files:  ot and nt using indexs ??.bks ??.cps ??.vss</font>
00004 <font class="comment"> *                              and provides lookup and parsing functions based on</font>
00005 <font class="comment"> *                              class VerseKey for compressed modules</font>
00006 <font class="comment"> */</font>
00007 
00008 
00009 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00010 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00011 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00012 <font class="preprocessor">#include &lt;errno.h&gt;</font>
00013 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00014 
00015 <font class="preprocessor">#ifndef __GNUC__</font>
00016 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00017 <font class="preprocessor">#else</font>
00018 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00019 <font class="preprocessor">#endif</font>
00020 <font class="preprocessor"></font>
00021 <font class="preprocessor">#include &lt;string.h&gt;</font>
00022 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00023 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00024 <font class="preprocessor">#include &lt;zverse.h&gt;</font>
00025 <font class="preprocessor">#include &lt;sysdata.h&gt;</font>
00026 
00027 
00028 <font class="preprocessor">#ifndef O_BINARY</font>
00029 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00030 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00031 <font class="preprocessor"></font>
00032 
00033 <font class="comment">/******************************************************************************</font>
00034 <font class="comment"> * zVerse Statics</font>
00035 <font class="comment"> */</font>
00036 
00037 <font class="keywordtype">int</font> zVerse::instance = 0;
00038 
00039 <font class="keyword">const</font> <font class="keywordtype">char</font> zVerse::uniqueIndexID[] = {<font class="charliteral">'X'</font>, <font class="charliteral">'r'</font>, <font class="charliteral">'v'</font>, <font class="charliteral">'c'</font>, <font class="charliteral">'b'</font>};
00040 
00041 <font class="comment">/******************************************************************************</font>
00042 <font class="comment"> * zVerse Constructor - Initializes data for instance of zVerse</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * ENT: ipath - path of the directory where data and index files are located.</font>
00045 <font class="comment"> *              be sure to include the trailing separator (e.g. '/' or '\')</font>
00046 <font class="comment"> *              (e.g. 'modules/texts/rawtext/webster/')</font>
00047 <font class="comment"> *              fileMode - open mode for the files (O_RDONLY, etc.)</font>
00048 <font class="comment"> *              blockType - verse, chapter, book, etc.</font>
00049 <font class="comment"> */</font>
00050 
00051 zVerse::zVerse(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keywordtype">int</font> fileMode, <font class="keywordtype">int</font> blockType, SWCompress *icomp)
00052 {
00053         <font class="keywordtype">char</font> buf[127];
00054 
00055         nl = <font class="charliteral">'\n'</font>;
00056         path = 0;
00057         cacheBufIdx = -1;
00058         cacheTestament = 0;
00059         cacheBuf = 0;
00060         dirtyCache = <font class="keyword">false</font>;
00061         stdstr(&amp;path, ipath);
00062 
00063         <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>))
00064                 path[strlen(path)-1] = 0;
00065 
00066         compressor = (icomp) ? icomp : <font class="keyword">new</font> SWCompress();
00067 
00068         <font class="keywordflow">if</font> (fileMode == -1) { <font class="comment">// try read/write if possible</font>
00069                 fileMode = O_RDWR;
00070         }
00071                 
00072         sprintf(buf, <font class="stringliteral">"%s/ot.%czs"</font>, path, uniqueIndexID[blockType]);
00073         idxfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00074 
00075         sprintf(buf, <font class="stringliteral">"%s/nt.%czs"</font>, path, uniqueIndexID[blockType]);
00076         idxfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00077 
00078         sprintf(buf, <font class="stringliteral">"%s/ot.%czz"</font>, path, uniqueIndexID[blockType]);
00079         textfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00080 
00081         sprintf(buf, <font class="stringliteral">"%s/nt.%czz"</font>, path, uniqueIndexID[blockType]);
00082         textfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00083 
00084         sprintf(buf, <font class="stringliteral">"%s/ot.%czv"</font>, path, uniqueIndexID[blockType]);
00085         compfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00086 
00087         sprintf(buf, <font class="stringliteral">"%s/nt.%czv"</font>, path, uniqueIndexID[blockType]);
00088         compfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00089         
00090         <a class="code" href="class_verse_key.html#r3">instance</a>++;
00091 }
00092 
00093 
00094 <font class="comment">/******************************************************************************</font>
00095 <font class="comment"> * zVerse Destructor - Cleans up instance of zVerse</font>
00096 <font class="comment"> */</font>
00097 
00098 zVerse::~zVerse()
00099 {
00100         <font class="keywordtype">int</font> loop1;
00101 
00102         <font class="keywordflow">if</font> (cacheBuf) {
00103                 flushCache();
00104                 free(cacheBuf);
00105         }
00106 
00107         <font class="keywordflow">if</font> (path)
00108                 <font class="keyword">delete</font> [] path;
00109 
00110         <font class="keywordflow">if</font> (compressor)
00111                 <font class="keyword">delete</font> compressor;
00112 
00113         --<a class="code" href="class_verse_key.html#r3">instance</a>;
00114 
00115         <font class="keywordflow">for</font> (loop1 = 0; loop1 &lt; 2; loop1++) {
00116                 FileMgr::systemFileMgr.close(idxfp[loop1]);
00117                 FileMgr::systemFileMgr.close(textfp[loop1]);
00118                 FileMgr::systemFileMgr.close(compfp[loop1]);
00119         }
00120 }
00121 
00122 
00123 <font class="comment">/******************************************************************************</font>
00124 <font class="comment"> * zVerse::findoffset   - Finds the offset of the key verse from the indexes</font>
00125 <font class="comment"> *</font>
00126 <font class="comment"> *</font>
00127 <font class="comment"> *</font>
00128 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00129 <font class="comment"> *      book    - book      to find (0 - testament    introduction)</font>
00130 <font class="comment"> *      chapter - chapter   to find (0 - book         introduction)</font>
00131 <font class="comment"> *      verse   - verse     to find (0 - chapter      introduction)</font>
00132 <font class="comment"> *      start   - address to store the starting offset</font>
00133 <font class="comment"> *      size    - address to store the size of the entry</font>
00134 <font class="comment"> */</font>
00135 
00136 <font class="keywordtype">void</font> zVerse::findoffset(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> idxoff, <font class="keywordtype">long</font> *start, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *size)
00137 {
00138         <font class="comment">// set start to offset in</font>
00139         <font class="comment">// set size to</font>
00140         <font class="comment">// set</font>
00141         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulBuffNum=0;                <font class="comment">// buffer number</font>
00142         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulVerseStart=0;          <font class="comment">// verse offset within buffer</font>
00143         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> usVerseSize=0;          <font class="comment">// verse size</font>
00144         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulCompOffset=0;          <font class="comment">// compressed buffer start</font>
00145         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulCompSize=0;                  <font class="comment">// buffer size compressed</font>
00146         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulUnCompSize=0;             <font class="comment">// buffer size uncompressed</font>
00147         <font class="keywordtype">char</font> *pcCompText=NULL;                                   <font class="comment">// compressed text</font>
00148 
00149         *start = *size = 0;
00150         <font class="comment">//printf ("Finding offset %ld\n", idxoff);</font>
00151         idxoff *= 10;
00152         <font class="keywordflow">if</font> (!testmt) {
00153                 testmt = ((idxfp[0]) ? 1:2);
00154         }
00155         
00156         <font class="comment">// assert we have and valid file descriptor</font>
00157         <font class="keywordflow">if</font> (compfp[testmt-1]-&gt;getFd() &lt; 1)
00158                 <font class="keywordflow">return</font>;
00159                 
00160         <font class="keywordtype">long</font> newOffset = lseek(compfp[testmt-1]-&gt;getFd(), idxoff, SEEK_SET);
00161         <font class="keywordflow">if</font> (newOffset == idxoff) {
00162                 <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;ulBuffNum, 4) != 4) {
00163                         printf (<font class="stringliteral">"Error reading ulBuffNum\n"</font>);
00164                         <font class="keywordflow">return</font>;
00165                 }
00166         }
00167         <font class="keywordflow">else</font> <font class="keywordflow">return</font>;
00168 
00169         ulBuffNum = swordtoarch32(ulBuffNum);
00170 
00171         <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;ulVerseStart, 4) &lt; 2)
00172         {
00173                 printf (<font class="stringliteral">"Error reading ulVerseStart\n"</font>);
00174                 <font class="keywordflow">return</font>;
00175         }
00176         <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;usVerseSize, 2) &lt; 2)
00177         {
00178                 printf (<font class="stringliteral">"Error reading usVerseSize\n"</font>);
00179                 <font class="keywordflow">return</font>;
00180         }
00181 
00182         *start = swordtoarch32(ulVerseStart);
00183         *size = swordtoarch16(usVerseSize);
00184 
00185         <font class="keywordflow">if</font> (*size) {
00186                 <font class="keywordflow">if</font> (((long) ulBuffNum == cacheBufIdx) &amp;&amp; (testmt == cacheTestament) &amp;&amp; (cacheBuf)) {
00187                         <font class="comment">// have the text buffered</font>
00188                         <font class="keywordflow">return</font>;
00189                 }
00190 
00191                 <font class="comment">//printf ("Got buffer number{%ld} versestart{%ld} versesize{%d}\n", ulBuffNum, ulVerseStart, usVerseSize);</font>
00192 
00193 
00194                 <font class="keywordflow">if</font> (lseek(idxfp[testmt-1]-&gt;getFd(), ulBuffNum*12, SEEK_SET)!=(long) ulBuffNum*12)
00195                 {
00196                         printf (<font class="stringliteral">"Error seeking compressed file index\n"</font>);
00197                         <font class="keywordflow">return</font>;
00198                 }
00199                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulCompOffset, 4)&lt;4)
00200                 {
00201                         printf (<font class="stringliteral">"Error reading ulCompOffset\n"</font>);
00202                         <font class="keywordflow">return</font>;
00203                 }
00204                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulCompSize, 4)&lt;4)
00205                 {
00206                         printf (<font class="stringliteral">"Error reading ulCompSize\n"</font>);
00207                         <font class="keywordflow">return</font>;
00208                 }
00209                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulUnCompSize, 4)&lt;4)
00210                 {
00211                         printf (<font class="stringliteral">"Error reading ulUnCompSize\n"</font>);
00212                         <font class="keywordflow">return</font>;
00213                 }
00214 
00215                 ulCompOffset  = swordtoarch32(ulCompOffset);
00216                 ulCompSize  = swordtoarch32(ulCompSize);
00217                 ulUnCompSize  = swordtoarch32(ulUnCompSize);
00218 
00219                 <font class="keywordflow">if</font> (lseek(textfp[testmt-1]-&gt;getFd(), ulCompOffset, SEEK_SET)!=(long)ulCompOffset)
00220                 {
00221                         printf (<font class="stringliteral">"Error: could not seek to right place in compressed text\n"</font>);
00222                         <font class="keywordflow">return</font>;
00223                 }
00224                 pcCompText = <font class="keyword">new</font> <font class="keywordtype">char</font>[ulCompSize];
00225 
00226                 <font class="keywordflow">if</font> (read(textfp[testmt-1]-&gt;getFd(), pcCompText, ulCompSize)&lt;(long)ulCompSize)
00227                 {
00228                         printf (<font class="stringliteral">"Error reading compressed text\n"</font>);
00229                         <font class="keywordflow">return</font>;
00230                 }
00231                 compressor-&gt;zBuf(&amp;ulCompSize, pcCompText);
00232 
00233                 <font class="keywordflow">if</font> (cacheBuf) {
00234                         flushCache();
00235                         free(cacheBuf);
00236                 }
00237                 
00238                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> len = 0;
00239                 compressor-&gt;Buf(0, &amp;len);
00240                 cacheBuf = (<font class="keywordtype">char</font> *)calloc(len + 1, 1);
00241                 memcpy(cacheBuf, compressor-&gt;Buf(), len);
00242 
00243                 cacheTestament = testmt;
00244                 cacheBufIdx = ulBuffNum;
00245         }
00246 }
00247 
00248 
00249 <font class="comment">/******************************************************************************</font>
00250 <font class="comment"> * zVerse::swgettext    - gets text at a given offset</font>
00251 <font class="comment"> *</font>
00252 <font class="comment"> * ENT: testmt  - testament file to search in (0 - Old; 1 - New)</font>
00253 <font class="comment"> *      start   - starting offset where the text is located in the file</font>
00254 <font class="comment"> *      size    - size of text entry + 1 (null)</font>
00255 <font class="comment"> *      buf     - buffer to store text</font>
00256 <font class="comment"> *</font>
00257 <font class="comment"> */</font>
00258 
00259 <font class="keywordtype">void</font> zVerse::swgettext(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> start, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size, <font class="keywordtype">char</font> *inbuf)
00260 {
00261         memset(inbuf, 0, size);
00262         <font class="keywordflow">if</font> (size &gt; 2) {
00263                 strncpy(inbuf, &amp;(cacheBuf[start]), size-2);
00264         }
00265 }
00266 
00267 
00268 <font class="comment">/******************************************************************************</font>
00269 <font class="comment"> * zVerse::settext      - Sets text for current offset</font>
00270 <font class="comment"> *</font>
00271 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00272 <font class="comment"> *      idxoff  - offset into .vss</font>
00273 <font class="comment"> *      buf     - buffer to store</font>
00274 <font class="comment"> *      len     - length of buffer (0 - null terminated)</font>
00275 <font class="comment"> */</font>
00276 
00277 <font class="keywordtype">void</font> zVerse::settext(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> idxoff, <font class="keyword">const</font> <font class="keywordtype">char</font> *buf, <font class="keywordtype">long</font> len)
00278 {
00279         <font class="keywordflow">if</font> (!testmt) 
00280                 testmt = ((idxfp[0]) ? 1:2);
00281         <font class="keywordflow">if</font> ((!dirtyCache) || (cacheBufIdx &lt; 0)) {
00282                 cacheBufIdx = lseek(idxfp[testmt-1]-&gt;getFd(), 0, SEEK_END) / 12;
00283                 cacheTestament = testmt;
00284                 <font class="keywordflow">if</font> (cacheBuf)
00285                         free(cacheBuf);
00286                 cacheBuf = (<font class="keywordtype">char</font> *)calloc(len ? len : strlen(buf)+1, 1);
00287         }
00288         <font class="keywordflow">else</font> cacheBuf = (<font class="keywordtype">char</font> *)((cacheBuf)?realloc(cacheBuf, strlen(cacheBuf)+(len ? len : strlen(buf)+1)):calloc((len ? len : strlen(buf)+1), 1));
00289 
00290         dirtyCache = <font class="keyword">true</font>;
00291 
00292         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> start, outstart;
00293         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> outBufIdx = cacheBufIdx;
00294         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00295         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> outsize;
00296 
00297         idxoff *= 10;
00298         size = outsize = len ? len : strlen(buf);
00299 
00300         start = strlen(cacheBuf);
00301 
00302         <font class="keywordflow">if</font> (!size)
00303                 start = outBufIdx = 0;
00304 
00305         outBufIdx = archtosword32(outBufIdx);
00306         outstart  = archtosword32(start);
00307         outsize   = archtosword16(size);
00308 
00309         lseek(compfp[testmt-1]-&gt;getFd(), idxoff, SEEK_SET);
00310         write(compfp[testmt-1]-&gt;getFd(), &amp;outBufIdx, 4);
00311         write(compfp[testmt-1]-&gt;getFd(), &amp;outstart, 4);
00312         write(compfp[testmt-1]-&gt;getFd(), &amp;outsize, 2);
00313         strcat(cacheBuf, buf);
00314 }
00315 
00316 
00317 <font class="keywordtype">void</font> zVerse::flushCache() {
00318         <font class="keywordflow">if</font> (dirtyCache) {
00319                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> idxoff;
00320                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> start, outstart;
00321                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> size, outsize;
00322                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> zsize, outzsize;
00323 
00324                 idxoff = cacheBufIdx * 12;
00325                 size = outsize = zsize = outzsize = strlen(cacheBuf);
00326                 <font class="keywordflow">if</font> (size) {
00327 <font class="comment">//                      if (compressor) {</font>
00328 <font class="comment">//                              delete compressor;</font>
00329 <font class="comment">//                              compressor = new LZSSCompress();</font>
00330 <font class="comment">//                      }</font>
00331                         compressor-&gt;Buf(cacheBuf);
00332                         compressor-&gt;zBuf(&amp;zsize);
00333                         outzsize = zsize;
00334 
00335                         start = outstart = lseek(textfp[cacheTestament-1]-&gt;getFd(), 0, SEEK_END);
00336 
00337                         outstart  = archtosword32(start);
00338                         outsize   = archtosword32(size);
00339                         outzsize  = archtosword32(zsize);
00340 
00341                         write(textfp[cacheTestament-1]-&gt;getFd(), compressor-&gt;zBuf(&amp;zsize), zsize);
00342 
00343                         lseek(idxfp[cacheTestament-1]-&gt;getFd(), idxoff, SEEK_SET);
00344                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outstart, 4);
00345                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outzsize, 4);
00346                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outsize, 4);
00347                 }
00348                 dirtyCache = <font class="keyword">false</font>;
00349         }
00350 }
00351 
00352 <font class="comment">/******************************************************************************</font>
00353 <font class="comment"> * RawVerse::linkentry  - links one entry to another</font>
00354 <font class="comment"> *</font>
00355 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00356 <font class="comment"> *      destidxoff      - dest offset into .vss</font>
00357 <font class="comment"> *      srcidxoff               - source offset into .vss</font>
00358 <font class="comment"> */</font>
00359 
00360 <font class="keywordtype">void</font> zVerse::linkentry(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> destidxoff, <font class="keywordtype">long</font> srcidxoff) {
00361         <font class="keywordtype">long</font> bufidx;
00362         <font class="keywordtype">long</font> start;
00363         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00364 
00365         destidxoff *= 10;
00366         srcidxoff  *= 10;
00367 
00368         <font class="keywordflow">if</font> (!testmt)
00369                 testmt = ((idxfp[1]) ? 1:2);
00370 
00371         <font class="comment">// get source</font>
00372         lseek(compfp[testmt-1]-&gt;getFd(), srcidxoff, SEEK_SET);
00373         read(compfp[testmt-1]-&gt;getFd(), &amp;bufidx, 4);
00374         read(compfp[testmt-1]-&gt;getFd(), &amp;start, 4);
00375         read(compfp[testmt-1]-&gt;getFd(), &amp;size, 2);
00376 
00377         <font class="comment">// write dest</font>
00378         lseek(compfp[testmt-1]-&gt;getFd(), destidxoff, SEEK_SET);
00379         write(compfp[testmt-1]-&gt;getFd(), &amp;bufidx, 4);
00380         write(compfp[testmt-1]-&gt;getFd(), &amp;start, 4);
00381         write(compfp[testmt-1]-&gt;getFd(), &amp;size, 2);
00382 }
00383 
00384 
00385 <font class="comment">/******************************************************************************</font>
00386 <font class="comment"> * RawVerse::CreateModule       - Creates new module files</font>
00387 <font class="comment"> *</font>
00388 <font class="comment"> * ENT: path    - directory to store module files</font>
00389 <font class="comment"> * RET: error status</font>
00390 <font class="comment"> */</font>
00391 
00392 <font class="keywordtype">char</font> zVerse::createModule(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keywordtype">int</font> blockBound)
00393 {
00394         <font class="keywordtype">char</font> *path = 0;
00395         <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ];
00396         FileDesc *fd, *fd2;
00397 
00398         stdstr(&amp;path, ipath);
00399 
00400         <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>))
00401                 path[strlen(path)-1] = 0;
00402 
00403         sprintf(buf, <font class="stringliteral">"%s/ot.%czs"</font>, path, uniqueIndexID[blockBound]);
00404         unlink(buf);
00405         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00406         fd-&gt;getFd();
00407         FileMgr::systemFileMgr.close(fd);
00408 
00409         sprintf(buf, <font class="stringliteral">"%s/nt.%czs"</font>, path, uniqueIndexID[blockBound]);
00410         unlink(buf);
00411         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00412         fd-&gt;getFd();
00413         FileMgr::systemFileMgr.close(fd);
00414 
00415         sprintf(buf, <font class="stringliteral">"%s/ot.%czz"</font>, path, uniqueIndexID[blockBound]);
00416         unlink(buf);
00417         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00418         fd-&gt;getFd();
00419         FileMgr::systemFileMgr.close(fd);
00420 
00421         sprintf(buf, <font class="stringliteral">"%s/nt.%czz"</font>, path, uniqueIndexID[blockBound]);
00422         unlink(buf);
00423         fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00424         fd2-&gt;getFd();
00425         FileMgr::systemFileMgr.close(fd);
00426 
00427         sprintf(buf, <font class="stringliteral">"%s/ot.%czv"</font>, path, uniqueIndexID[blockBound]);
00428         unlink(buf);
00429         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00430         fd-&gt;getFd();
00431 
00432         sprintf(buf, <font class="stringliteral">"%s/nt.%czv"</font>, path, uniqueIndexID[blockBound]);
00433         unlink(buf);
00434         fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00435         fd2-&gt;getFd();
00436 
00437         <a class="code" href="class_verse_key.html">VerseKey</a> vk;
00438         vk.<a class="code" href="class_verse_key.html#a32">Headings</a>(1);
00439         <font class="keywordtype">long</font> offset = 0;
00440         <font class="keywordtype">short</font> size = 0;
00441         <font class="keywordflow">for</font> (vk = TOP; !vk.<a class="code" href="class_s_w_key.html#a6">Error</a>(); vk++) {
00442                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;offset, 4);  <font class="comment">//compBufIdxOffset</font>
00443                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;offset, 4);
00444                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;size, 2);
00445         }
00446 
00447         FileMgr::systemFileMgr.close(fd);
00448         FileMgr::systemFileMgr.close(fd2);
00449 
00450         <font class="keyword">delete</font> [] path;
00451 <font class="comment">/*</font>
00452 <font class="comment">        RawVerse rv(path);</font>
00453 <font class="comment">        VerseKey mykey("Rev 22:21");</font>
00454 <font class="comment">*/</font>
00455         
00456         <font class="keywordflow">return</font> 0;
00457 }
00458 
00459 
00460 <font class="comment">/******************************************************************************</font>
00461 <font class="comment"> * zVerse::preptext     - Prepares the text before returning it to external</font>
00462 <font class="comment"> *                              objects</font>
00463 <font class="comment"> *</font>
00464 <font class="comment"> * ENT: buf     - buffer where text is stored and where to store the prep'd</font>
00465 <font class="comment"> *                      text.</font>
00466 <font class="comment"> */</font>
00467 
00468 <font class="keywordtype">void</font> zVerse::preptext(<font class="keywordtype">char</font> *buf)
00469 {
00470         <font class="keywordtype">char</font> *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
00471 
00472         <font class="keywordflow">for</font> (to = from = buf; *from; from++) {
00473                 <font class="keywordflow">switch</font> (*from) {
00474                 <font class="keywordflow">case</font> 10:
00475                         <font class="keywordflow">if</font> (!realdata)
00476                                 <font class="keywordflow">continue</font>;
00477                         space = (cr) ? 0 : 1;
00478                         cr = 0;
00479                         nlcnt++;
00480                         <font class="keywordflow">if</font> (nlcnt &gt; 1) {
00481 <font class="comment">//                              *to++ = nl;</font>
00482                                 *to++ = nl;
00483 <font class="comment">//                              nlcnt = 0;</font>
00484                         }
00485                         <font class="keywordflow">continue</font>;
00486                 <font class="keywordflow">case</font> 13:
00487                         <font class="keywordflow">if</font> (!realdata)
00488                                 <font class="keywordflow">continue</font>;
00489                         *to++ = nl;
00490                         space = 0;
00491                         cr = 1;
00492                         <font class="keywordflow">continue</font>;
00493                 }
00494                 realdata = 1;
00495                 nlcnt = 0;
00496                 <font class="keywordflow">if</font> (space) {
00497                         space = 0;
00498                         <font class="keywordflow">if</font> (*from != <font class="charliteral">' '</font>) {
00499                                 *to++ = <font class="charliteral">' '</font>;
00500                                 from--;
00501                                 <font class="keywordflow">continue</font>;
00502                         }
00503                 }
00504                 *to++ = *from;
00505         }
00506         *to = 0;
00507 
00508      <font class="keywordflow">if</font> (to &gt; buf) {
00509           <font class="keywordflow">for</font> (to--; to &gt; buf; to--) {                  <font class="comment">// remove trailing excess</font>
00510                <font class="keywordflow">if</font> ((*to == 10) || (*to == <font class="charliteral">' '</font>))
00511                     *to = 0;
00512                <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00513           }
00514      }
00515 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 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>