aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/texts_2ztext_2rawtxt2z_8cpp-source.html
blob: 824b8e4ed8e868ead166d92dc64dbd012d011867 (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






















































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
<!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>rawtxt2z.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>rawtxt2z.cpp</h1><div class="fragment"><pre>00001 <font class="comment">// Compression on variable granularity</font>
00002 
00003 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00004 <font class="preprocessor">#include &lt;iostream&gt;</font>
00005 <font class="preprocessor">#include &lt;fstream&gt;</font>
00006 <font class="preprocessor">#include &lt;string&gt;</font>
00007 
00008 <font class="preprocessor">#ifndef __GNUC__</font>
00009 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00010 <font class="preprocessor">#else</font>
00011 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00012 <font class="preprocessor">#endif</font>
00013 <font class="preprocessor"></font>
00014 <font class="preprocessor">#include &lt;zlib.h&gt;</font>
00015 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00016 
00017 <font class="keywordtype">int</font> iBufSize, ulBuffNum;
00018 ofstream cfile;
00019 ofstream cfile2;
00020 
00021 <font class="keywordtype">int</font> ofd[2], oxfd[2], ovxfd[2];
00022 <font class="keywordtype">int</font> ifd[2], ixfd[2];
00023 <font class="keywordtype">int</font> itestfd[2], itestxfd[2];
00024 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulIOff=0, ulCOff=0, ulFOff=0, ulNone=0;
00025 string currbuff=<font class="stringliteral">""</font>;
00026 
00027 
00028 <font class="keywordtype">int</font> openreadfile(<font class="keywordtype">char</font> *buffer, <font class="keywordtype">char</font> *path, <font class="keyword">const</font> <font class="keywordtype">char</font> *filename)
00029 {
00030         <font class="keywordtype">int</font> filenum;
00031         sprintf(buffer, <font class="stringliteral">"%s/%s"</font>, path, filename);
00032         cfile &lt;&lt; buffer &lt;&lt; <font class="stringliteral">"\n"</font>;
00033         filenum =  open(buffer, O_RDONLY|O_BINARY);
00034         <font class="keywordflow">if</font> (filenum &gt; 0)
00035         {
00036                 <font class="keywordflow">return</font> filenum;
00037         }
00038         <font class="keywordflow">else</font>
00039         {
00040                 cerr &lt;&lt; <font class="stringliteral">"failed to open file to read\n"</font>;
00041                 exit(-1);
00042         }
00043 }
00044 
00045 <font class="keywordtype">int</font> openwritefile(<font class="keywordtype">char</font> *buffer, <font class="keywordtype">char</font> *path, <font class="keyword">const</font> <font class="keywordtype">char</font> *filename)
00046 {
00047         <font class="keywordtype">int</font> filenum;
00048         sprintf(buffer, <font class="stringliteral">"%s/%s"</font>, path, filename);
00049         cfile &lt;&lt; buffer &lt;&lt; <font class="stringliteral">"\n"</font>;
00050         filenum =  open(buffer, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC);
00051         <font class="keywordflow">if</font> (filenum &gt; 0)
00052         {
00053                 <font class="keywordflow">return</font> filenum;
00054         }
00055         <font class="keywordflow">else</font>
00056         {
00057                 cerr &lt;&lt; <font class="stringliteral">"failed to open file to read\n"</font>;
00058                 exit(-1);
00059         }
00060 }
00061 
00062 <font class="keywordtype">int</font> bytebound(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;thekey)
00063 {
00064         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> bufferoff;
00065         cfile &lt;&lt; <font class="stringliteral">"byteboundtest "</font> &lt;&lt; thekey &lt;&lt; <font class="stringliteral">"\n"</font>;
00066         bufferoff = iBufSize * (ulBuffNum+1);
00067         <font class="keywordflow">if</font> (offset &gt; bufferoff)
00068         {
00069                 <font class="keywordflow">return</font> 1;
00070         }
00071         <font class="keywordflow">else</font>
00072         {
00073                 <font class="keywordflow">return</font> 0;
00074         }
00075 }
00076 
00077 <font class="keywordtype">int</font> versebound(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;thekey)
00078 {
00079         cfile &lt;&lt; <font class="stringliteral">"verseboundtest "</font> &lt;&lt; thekey &lt;&lt; <font class="stringliteral">"\n"</font>;
00080         <font class="keywordflow">return</font> 1;
00081 }
00082 
00083 <font class="keywordtype">int</font> chapterbound(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;thekey)
00084 {
00085         <a class="code" href="class_verse_key.html">VerseKey</a> testkey;
00086         testkey = thekey;
00087         testkey++;
00088         <font class="comment">//cfile &lt;&lt; "chapterboundtest " &lt;&lt; testkey;</font>
00089         <font class="keywordflow">if</font> (testkey.<a class="code" href="class_verse_key.html#a25">Verse</a>()==1 || (!thekey.<a class="code" href="class_verse_key.html#a38">compare</a>(<font class="stringliteral">"Revelation of John 22:21"</font>)))
00090         {
00091                 <font class="comment">//cfile &lt;&lt; " 1\n";</font>
00092                 <font class="keywordflow">return</font> 1;
00093         }
00094         <font class="keywordflow">else</font>
00095         {
00096                 <font class="comment">//cfile &lt;&lt; " 0\n";</font>
00097                 <font class="keywordflow">return</font> 0;
00098         }
00099 }
00100 
00101 <font class="keywordtype">int</font> bookbound(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;thekey)
00102 {
00103         <a class="code" href="class_verse_key.html">VerseKey</a> testkey;
00104         testkey = thekey;
00105         cfile &lt;&lt; <font class="stringliteral">"bookboundtest "</font> &lt;&lt; testkey &lt;&lt; <font class="stringliteral">"\n"</font>;
00106         testkey++;
00107         <font class="keywordflow">if</font> (testkey.<a class="code" href="class_verse_key.html#a24">Chapter</a>()==1 || (!thekey.<a class="code" href="class_verse_key.html#a38">compare</a>(<font class="stringliteral">"Revelation of John 22:21"</font>)))
00108         {
00109                 <font class="keywordflow">return</font> 1;
00110         }
00111         <font class="keywordflow">else</font>
00112         {
00113                 <font class="keywordflow">return</font> 0;
00114         }
00115 }
00116 
00117 
00118 <font class="keyword">typedef</font> int (*boundfunc)(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;thekey);
00119 
00120 <font class="keywordtype">int</font> writeblock(<font class="keywordtype">int</font> i)
00121 {
00122         <font class="keywordtype">char</font> *destbuff=NULL;
00123         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> compsize = 0, buffsize=0;
00124 
00125         cfile &lt;&lt; <font class="stringliteral">"compressing block\n"</font>;
00126         <font class="comment">// compress current buffer</font>
00127         buffsize = currbuff.length();
00128         write(itestfd[i], currbuff.c_str(), buffsize);
00129         compsize = (<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font>) (buffsize*1.01)+20;  <font class="comment">// at least 1% bigger than buffer + 12 bytes</font>
00130         <font class="comment">//cfile &lt;&lt; "{" &lt;&lt; compsize &lt;&lt; "}";</font>
00131         <font class="comment">//destbuff = (char *) calloc(compsize + 1, 1);</font>
00132         destbuff = <font class="keyword">new</font> <font class="keywordtype">char</font>[compsize];
00133         <font class="keywordflow">if</font> (compress((Bytef*)destbuff, &amp;compsize, (<font class="keyword">const</font> Bytef*)currbuff.c_str(), buffsize)!=Z_OK)
00134         {
00135                 cerr &lt;&lt; <font class="stringliteral">"Could not compress buffer: exiting\n"</font>;
00136                 <font class="keyword">delete</font>[] destbuff;
00137                 exit(-1);
00138         }
00139         <font class="comment">//cout &lt;&lt; "Compressed buffer{" &lt;&lt; compsize &lt;&lt; "}\n" &lt;&lt; destbuff &lt;&lt; "\n";</font>
00140         <font class="comment">//cout.flush();</font>
00141         <font class="comment">// write to compressed file index</font>
00142         ulCOff = lseek(ofd[i], 0, SEEK_END);
00143         write(oxfd[i], &amp;ulCOff, 4);    <font class="comment">// offset in compressed file</font>
00144         write(oxfd[i], &amp;compsize, 4);    <font class="comment">// compressed size</font>
00145         write(oxfd[i], &amp;buffsize, 4);    <font class="comment">// uncompressed size</font>
00146         cfile &lt;&lt; buffsize &lt;&lt; <font class="stringliteral">" -&gt; "</font> &lt;&lt; compsize &lt;&lt; <font class="stringliteral">"\n"</font>;
00147         cfile2 &lt;&lt; <font class="stringliteral">"Compressed{"</font> &lt;&lt; compsize &lt;&lt; <font class="stringliteral">"}\n"</font> &lt;&lt; destbuff &lt;&lt; <font class="stringliteral">"\n"</font>;
00148         cfile2.flush();
00149 
00150         <font class="comment">//write compressed buffer to file</font>
00151         write(ofd[i], destbuff, compsize);
00152 
00153         <font class="comment">//free(destbuff);</font>
00154         <font class="keyword">delete</font>[] destbuff;
00155 
00156         currbuff = <font class="stringliteral">""</font>;
00157         ulBuffNum++;
00158         ulIOff = 0;
00159         <font class="keywordflow">return</font> 1;
00160 }
00161 
00162 
00163 
00164 <font class="keywordtype">int</font> main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00165 {
00166         <a class="code" href="class_verse_key.html">VerseKey</a> key1, key2, key3;
00167         <font class="keywordtype">int</font> i;
00168         <font class="keywordtype">char</font> xbuff[64];
00169         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset;
00170         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size=0;
00171         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulsize=0;
00172         <font class="keywordtype">char</font> *tmpbuf=NULL;
00173         <font class="keywordtype">int</font> iType;
00174         boundfunc blockbound[4] = {bytebound, versebound, chapterbound, bookbound};
00175         <font class="keywordtype">bool</font> newbook=<font class="keyword">true</font>, newchapter=<font class="keyword">true</font>, newtestament = <font class="keyword">true</font>, newmodule = <font class="keyword">true</font>, lasttodo=<font class="keyword">true</font>;
00176 
00177         <font class="keywordflow">if</font> ((argc &lt; 2) || (argc &gt; 4)) {
00178                 cerr &lt;&lt; <font class="stringliteral">"usage: "</font> &lt;&lt; argv[0] &lt;&lt; <font class="stringliteral">" datapath [compression type [buffer size]]\n"</font>;
00179                 exit(1);
00180         }
00181 
00182         <font class="keywordflow">if</font> (argc&gt;2)
00183         {
00184                 iType = atoi(argv[2]);
00185                 <font class="keywordflow">if</font> (argc==4)
00186                 {
00187                         iBufSize = atoi(argv[3]);
00188                 }
00189                 <font class="keywordflow">else</font>
00190                 {
00191                         iBufSize = 1;
00192                 }
00193         }
00194         <font class="keywordflow">else</font>
00195         {
00196                 iType = 2;
00197                 iBufSize = 1;
00198         }
00199 
00200         cfile.open(<font class="stringliteral">"raw2z.log"</font>, ios::out);
00201         <font class="keywordflow">if</font> (!cfile.is_open())
00202         {
00203                 cerr &lt;&lt; <font class="stringliteral">"Failed to open log file\n"</font>;
00204                 exit(-1);
00205         }
00206         cfile2.open(<font class="stringliteral">"raw2z.lg2"</font>, ios::out);
00207         <font class="keywordflow">if</font> (!cfile2.is_open())
00208         {
00209                 cerr &lt;&lt; <font class="stringliteral">"Failed to open log file\n"</font>;
00210                 exit(-1);
00211         }
00212         cfile &lt;&lt; iType &lt;&lt; <font class="stringliteral">" "</font> &lt;&lt; iBufSize &lt;&lt; <font class="stringliteral">"\n"</font>;
00213 
00214         <font class="keywordflow">if</font> ((iType&lt;=0) || (iType &gt; 4) || !iBufSize || !strcmp(argv[1], <font class="stringliteral">"-h"</font>) || !strcmp(argv[1], <font class="stringliteral">"--help"</font>) || !strcmp(argv[1], <font class="stringliteral">"/?"</font>) || !strcmp(argv[1], <font class="stringliteral">"-help"</font>))
00215         {
00216                 cfile &lt;&lt; argv[0] &lt;&lt; <font class="stringliteral">" - a tool to create compressed Sword modules\n"</font>;
00217                 cfile &lt;&lt; <font class="stringliteral">"version 0.1\n\n"</font>;
00218                 cfile &lt;&lt; <font class="stringliteral">"usage: "</font>&lt;&lt; argv[0] &lt;&lt; <font class="stringliteral">" datapath [compression type [buffer size]]\n\n"</font>;
00219                 cfile &lt;&lt; <font class="stringliteral">"datapath: the directory in which to find the raw module\n"</font>;
00220                 cfile &lt;&lt; <font class="stringliteral">"compression type: (default 2)\n"</font> &lt;&lt; <font class="stringliteral">"   1 - bytes\n"</font> &lt;&lt; <font class="stringliteral">"   2 - verses\n"</font> &lt;&lt; <font class="stringliteral">"   3 - chapters\n"</font> &lt;&lt; <font class="stringliteral">"   4 - books\n"</font>;
00221                 cfile &lt;&lt; <font class="stringliteral">"buffer size (default 1): the number of the compression type in each block\n"</font>;
00222                 exit(1);
00223         }
00224 
00225         <font class="comment">//zobj = new SWCompress();</font>
00226         <font class="comment">//rawdrv = new RawVerse(argv[1]);</font>
00227 
00228 <font class="preprocessor">#ifndef O_BINARY</font>
00229 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00230 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00231 <font class="preprocessor"></font>        cfile &lt;&lt; <font class="stringliteral">"opening files\n"</font>;
00232 
00233         tmpbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(argv[1]) + 11 ];
00234 
00235         <font class="comment">//original files</font>
00236         ifd[0] = openreadfile(tmpbuf, argv[1], <font class="stringliteral">"ot"</font>);
00237         ixfd[0] = openreadfile(tmpbuf, argv[1], <font class="stringliteral">"ot.vss"</font>);
00238         ifd[1] = openreadfile(tmpbuf, argv[1], <font class="stringliteral">"nt"</font>);
00239         ixfd[1] = openreadfile(tmpbuf, argv[1], <font class="stringliteral">"nt.vss"</font>);
00240 
00241 <font class="keywordflow">switch</font> ( iType) {
00242         <font class="keywordflow">case</font> 1 :
00243                 ofd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.rzz"</font>);
00244                 oxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.rzs"</font>);
00245                 ovxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.rzv"</font>);
00246                 ofd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.rzz"</font>);
00247                 oxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.rzs"</font>);
00248                 ovxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.rzv"</font>);
00249                 <font class="comment">//boundfunc = bytebound;</font>
00250                 <font class="keywordflow">break</font>;
00251         <font class="keywordflow">case</font> 2 :
00252                 ofd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.vzz"</font>);
00253                 oxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.vzs"</font>);
00254                 ovxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.vzv"</font>);
00255                 ofd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.vzz"</font>);
00256                 oxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.vzs"</font>);
00257                 ovxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.vzv"</font>);
00258                 <font class="keywordflow">break</font>;
00259         <font class="keywordflow">case</font> 3 :
00260                 ofd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.czz"</font>);
00261                 oxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.czs"</font>);
00262                 ovxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.czv"</font>);
00263                 ofd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.czz"</font>);
00264                 oxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.czs"</font>);
00265                 ovxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.czv"</font>);
00266                 <font class="keywordflow">break</font>;
00267         <font class="keywordflow">case</font> 4 :
00268                 ofd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.bzz"</font>);
00269                 oxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.bzs"</font>);
00270                 ovxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.bzv"</font>);
00271                 ofd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.bzz"</font>);
00272                 oxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.bzs"</font>);
00273                 ovxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.bzv"</font>);
00274                 <font class="keywordflow">break</font>;
00275         <font class="keywordflow">default</font>:
00276                 cerr &lt;&lt; <font class="stringliteral">"Unknown compression type\n"</font>;
00277                 exit(-1);
00278 }
00279         itestfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.tst"</font>);
00280         itestfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.tst"</font>);
00281         itestxfd[0] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"ot.tdx"</font>);
00282         itestxfd[1] = openwritefile(tmpbuf, argv[1], <font class="stringliteral">"nt.tdx"</font>);
00283 
00284 
00285         <font class="keyword">delete</font> [] tmpbuf;
00286 
00287         <font class="comment">//cfile &lt;&lt; "about to start\n";</font>
00288 
00289 <font class="keywordflow">for</font> ( i=0; i&lt;2; i++)
00290 {
00291         ulIOff=0, ulBuffNum=0;
00292         currbuff = <font class="stringliteral">""</font>;
00293         key1 = (i == 1) ? <font class="stringliteral">"Matthew 1:1"</font> : <font class="stringliteral">"Genesis 1:1"</font>;
00294         key2 = key3 = key1;
00295         newtestament = <font class="keyword">true</font>;
00296 
00297         cfile &lt;&lt; <font class="stringliteral">"key: "</font> &lt;&lt; key1 &lt;&lt; <font class="stringliteral">" Testament {"</font> &lt;&lt; key1.<a class="code" href="class_verse_key.html#a22">Testament</a>()-1 &lt;&lt; <font class="stringliteral">"}\n"</font>;
00298         <font class="comment">//cfile &lt;&lt; "Chapter {" &lt;&lt; key.Chapter() &lt;&lt; "}\n";</font>
00299         <font class="comment">//cfile &lt;&lt; "Verse {" &lt;&lt; key.Verse() &lt;&lt; "}\n";</font>
00300         <font class="comment">//cfile &lt;&lt; key.compare("Revelation of John 22:21") &lt;&lt; "\n";</font>
00301         <font class="comment">//cfile &lt;&lt; key.compare("Genesis 1:1") &lt;&lt; "\n";</font>
00302         <font class="keywordflow">do</font>
00303         {
00304                 <font class="comment">//cfile &lt;&lt; "ok";</font>
00305                 <font class="comment">// read current verse offset</font>
00306                 <font class="keywordflow">if</font> (read(ixfd[i], &amp;offset, 4) != 4)
00307                 {
00308                         cfile &lt;&lt; <font class="stringliteral">"Failed to read input verse offsets?\n"</font>;
00309                         <font class="keywordflow">break</font>;
00310                 }
00311                 <font class="keywordflow">if</font> (read(ixfd[i], &amp;size, 2) != 2)
00312                 {
00313                         cfile &lt;&lt; <font class="stringliteral">"Failed to read input verse sizes?\n"</font>;
00314                         <font class="keywordflow">break</font>;
00315                 }
00316                 cfile &lt;&lt; <font class="stringliteral">"key:"</font> &lt;&lt; key1 &lt;&lt; <font class="stringliteral">" offset:"</font> &lt;&lt; offset &lt;&lt; <font class="stringliteral">" size:"</font> &lt;&lt; size &lt;&lt; <font class="stringliteral">"\n"</font>;
00317                 sprintf(xbuff, <font class="stringliteral">"key{%s} offset{%ld} size{%d}\n"</font>, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key1, offset, size);
00318                 write(itestxfd[i], &amp;xbuff, strlen(xbuff));
00319                 ulsize = size;
00320                 <font class="keywordflow">if</font> (!offset &amp;&amp; !size)
00321                 {
00322                         <font class="comment">//Check for module header</font>
00323                         <font class="keywordflow">if</font> (read(ixfd[i], &amp;ulIOff, 4) != 4)
00324                         {
00325                                 cfile &lt;&lt; <font class="stringliteral">"Failed to read input verse offsets?\n"</font>;
00326                                 <font class="keywordflow">break</font>;
00327                         }
00328                         ulsize = ulIOff;
00329                         ulIOff = 0;
00330                         lseek(ixfd[i], 6, SEEK_SET);
00331                 }
00332 
00333                 <font class="keywordflow">if</font> (ulsize)
00334                 {
00335                         <font class="comment">// read current verse and add to current buffer</font>
00336                         tmpbuf = (<font class="keywordtype">char</font> *) calloc(ulsize + 1, 1);
00337                         lseek(ifd[i], offset, SEEK_SET);
00338                         read(ifd[i], tmpbuf, ulsize);
00339                         currbuff += tmpbuf;
00340                         <font class="comment">//cfile &lt;&lt; currbuff &lt;&lt; "\n";</font>
00341 
00342                         <font class="comment">// write to verse index into compressed</font>
00343                         write(ovxfd[i], &amp;ulBuffNum, 4);    <font class="comment">// current buffer number</font>
00344                         write(ovxfd[i], &amp;ulIOff, 4);    <font class="comment">// offset within the buffer</font>
00345                         write(ovxfd[i], &amp;size, 2);    <font class="comment">// verse size</font>
00346 
00347                         ulFOff = lseek(ofd[i], 0, SEEK_CUR) + size;
00348                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a38">compare</a>(<font class="stringliteral">"Revelation of John 22:21"</font>)!=-1)
00349                         {
00350                                 lasttodo = <font class="keyword">false</font>;
00351                         }
00352                         <font class="keywordflow">if</font> (blockbound[iType-1](ulFOff, key1)<font class="comment">/*at block boudary*/</font>)
00353                         {
00354                                 writeblock(i);
00355                                 <font class="comment">/*</font>
00356 <font class="comment">                                cfile &lt;&lt; "compressing block\n";</font>
00357 <font class="comment">                                // compress current buffer</font>
00358 <font class="comment">                                buffsize = currbuff.length();</font>
00359 <font class="comment">                                write(itestfd[i], currbuff.c_str(), buffsize);</font>
00360 <font class="comment">                                compsize = (unsigned long) (buffsize*1.01)+20;  // at least 1% bigger than buffer + 12 bytes</font>
00361 <font class="comment">                                //cfile &lt;&lt; "{" &lt;&lt; compsize &lt;&lt; "}";</font>
00362 <font class="comment">                                //destbuff = (char *) calloc(compsize + 1, 1);</font>
00363 <font class="comment">                                destbuff = new char[compsize];</font>
00364 <font class="comment">                                if (compress((Bytef*)destbuff, &amp;compsize, (const Bytef*)currbuff.c_str(), buffsize)!=Z_OK)</font>
00365 <font class="comment">                                {</font>
00366 <font class="comment">                                        cerr &lt;&lt; "Could not compress buffer: exiting\n";</font>
00367 <font class="comment">                                        delete[] destbuff;</font>
00368 <font class="comment">                                        exit(-1);</font>
00369 <font class="comment">                                }</font>
00370 <font class="comment">                                //cout &lt;&lt; "Compressed buffer{" &lt;&lt; compsize &lt;&lt; "}\n" &lt;&lt; destbuff &lt;&lt; "\n";</font>
00371 <font class="comment">                                //cout.flush();</font>
00372 <font class="comment">                                // write to compressed file index</font>
00373 <font class="comment">                                ulCOff = lseek(ofd[i], 0, SEEK_END);</font>
00374 <font class="comment">                                write(oxfd[i], &amp;ulCOff, 4);    // offset in compressed file</font>
00375 <font class="comment">                                write(oxfd[i], &amp;compsize, 4);    // compressed size</font>
00376 <font class="comment">                                write(oxfd[i], &amp;buffsize, 4);    // uncompressed size</font>
00377 <font class="comment">                                cfile &lt;&lt; buffsize &lt;&lt; " -&gt; " &lt;&lt; compsize &lt;&lt; "\n";</font>
00378 <font class="comment">                                cfile2 &lt;&lt; "Compressed{" &lt;&lt; compsize &lt;&lt; "}\n" &lt;&lt; destbuff &lt;&lt; "\n";</font>
00379 <font class="comment">                                cfile2.flush();</font>
00380 <font class="comment"></font>
00381 <font class="comment">                                //write compressed buffer to file</font>
00382 <font class="comment">                                write(ofd[i], destbuff, compsize);</font>
00383 <font class="comment"></font>
00384 <font class="comment">                                //free(destbuff);</font>
00385 <font class="comment">                                delete[] destbuff;</font>
00386 <font class="comment"></font>
00387 <font class="comment">                                currbuff = "";</font>
00388 <font class="comment">                                ulBuffNum++;</font>
00389 <font class="comment">                                ulIOff = 0;</font>
00390 <font class="comment">                                */</font>
00391                         }
00392                         <font class="keywordflow">else</font>
00393                         {
00394                                 ulIOff += ulsize;
00395                         }
00396                         free(tmpbuf);
00397 
00398                         <font class="keywordflow">if</font> (newmodule)
00399                         {
00400                                 newmodule = <font class="keyword">false</font>;
00401                                 cfile &lt;&lt; <font class="stringliteral">"had a new module "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"{"</font> &lt;&lt; offset &lt;&lt; <font class="stringliteral">"}\n"</font>;
00402                                 writeblock(i);
00403                         }
00404                         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (newtestament)
00405                         {
00406                                 newtestament = <font class="keyword">false</font>;
00407                                 cfile &lt;&lt; <font class="stringliteral">"had a new testament "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"{"</font> &lt;&lt; offset &lt;&lt; <font class="stringliteral">"}\n"</font>;
00408                         }
00409                         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (newbook)
00410                         {
00411                                 newbook = <font class="keyword">false</font>;
00412                                 cfile &lt;&lt; <font class="stringliteral">"had a new book "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"{"</font> &lt;&lt; offset &lt;&lt; <font class="stringliteral">"}\n"</font>;
00413                         }
00414                         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (newchapter)
00415                         {
00416                                 newchapter = <font class="keyword">false</font>;
00417                                 cfile &lt;&lt; <font class="stringliteral">"had a new chapter "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"{"</font> &lt;&lt; offset &lt;&lt; <font class="stringliteral">"}\n"</font>;
00418                         }
00419                         <font class="keywordflow">else</font>
00420                         {
00421                                 key1++;
00422                         }
00423 
00424                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>()!=key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>() || (key1.<a class="code" href="class_verse_key.html#a23">Book</a>()!=key2.<a class="code" href="class_verse_key.html#a23">Book</a>()))
00425                         {
00426                                 newchapter = <font class="keyword">true</font>;
00427                                 cfile &lt;&lt; <font class="stringliteral">"got a new chapter "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"\n"</font>;
00428                         }
00429                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a23">Book</a>()!=key2.<a class="code" href="class_verse_key.html#a23">Book</a>())
00430                         {
00431                                 newbook = <font class="keyword">true</font>;
00432                                 cfile &lt;&lt; <font class="stringliteral">"got a new book "</font> &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 &lt;&lt; <font class="stringliteral">"\n"</font>;
00433                         }
00434                         key2 = key1;
00435 
00436                 }
00437                 <font class="keywordflow">else</font>
00438                 {
00439                         cfile &lt;&lt; <font class="stringliteral">"empty offset\n"</font>;
00440                         <font class="comment">// write to verse index into compressed</font>
00441                         write(ovxfd[i], &amp;ulNone, 4);    <font class="comment">// current buffer number</font>
00442                         write(ovxfd[i], &amp;size, 2);    <font class="comment">// verse size</font>
00443                         write(ovxfd[i], &amp;ulNone, 4);    <font class="comment">// offset within the buffer</font>
00444                 }
00445         }
00446         <font class="keywordflow">while</font> ( (key1.<a class="code" href="class_verse_key.html#a22">Testament</a>()==i+1) &amp;&amp; ((key1.<a class="code" href="class_verse_key.html#a38">compare</a>(<font class="stringliteral">"Revelation of John 22:21"</font>)==-1) || (lasttodo)));
00447 
00448         close(ifd[i]);
00449         close(ofd[i]);
00450         close(ixfd[i]);
00451         close(oxfd[i]);
00452         close(ovxfd[i]);
00453         close(itestfd[i]);
00454         close(itestxfd[i]);
00455 }
00456         <font class="keywordflow">return</font> 1;
00457 }
</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>