<!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> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </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 <fcntl.h></font>
00004 <font class="preprocessor">#include <iostream></font>
00005 <font class="preprocessor">#include <fstream></font>
00006 <font class="preprocessor">#include <string></font>
00007
00008 <font class="preprocessor">#ifndef __GNUC__</font>
00009 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00010 <font class="preprocessor">#else</font>
00011 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00012 <font class="preprocessor">#endif</font>
00013 <font class="preprocessor"></font>
00014 <font class="preprocessor">#include <zlib.h></font>
00015 <font class="preprocessor">#include <versekey.h></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 << buffer << <font class="stringliteral">"\n"</font>;
00033 filenum = open(buffer, O_RDONLY|O_BINARY);
00034 <font class="keywordflow">if</font> (filenum > 0)
00035 {
00036 <font class="keywordflow">return</font> filenum;
00037 }
00038 <font class="keywordflow">else</font>
00039 {
00040 cerr << <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 << buffer << <font class="stringliteral">"\n"</font>;
00050 filenum = open(buffer, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC);
00051 <font class="keywordflow">if</font> (filenum > 0)
00052 {
00053 <font class="keywordflow">return</font> filenum;
00054 }
00055 <font class="keywordflow">else</font>
00056 {
00057 cerr << <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> &thekey)
00063 {
00064 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> bufferoff;
00065 cfile << <font class="stringliteral">"byteboundtest "</font> << thekey << <font class="stringliteral">"\n"</font>;
00066 bufferoff = iBufSize * (ulBuffNum+1);
00067 <font class="keywordflow">if</font> (offset > 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> &thekey)
00078 {
00079 cfile << <font class="stringliteral">"verseboundtest "</font> << thekey << <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> &thekey)
00084 {
00085 <a class="code" href="class_verse_key.html">VerseKey</a> testkey;
00086 testkey = thekey;
00087 testkey++;
00088 <font class="comment">//cfile << "chapterboundtest " << 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 << " 1\n";</font>
00092 <font class="keywordflow">return</font> 1;
00093 }
00094 <font class="keywordflow">else</font>
00095 {
00096 <font class="comment">//cfile << " 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> &thekey)
00102 {
00103 <a class="code" href="class_verse_key.html">VerseKey</a> testkey;
00104 testkey = thekey;
00105 cfile << <font class="stringliteral">"bookboundtest "</font> << testkey << <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> &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 << <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 << "{" << compsize << "}";</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, &compsize, (<font class="keyword">const</font> Bytef*)currbuff.c_str(), buffsize)!=Z_OK)
00134 {
00135 cerr << <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 << "Compressed buffer{" << compsize << "}\n" << destbuff << "\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], &ulCOff, 4); <font class="comment">// offset in compressed file</font>
00144 write(oxfd[i], &compsize, 4); <font class="comment">// compressed size</font>
00145 write(oxfd[i], &buffsize, 4); <font class="comment">// uncompressed size</font>
00146 cfile << buffsize << <font class="stringliteral">" -> "</font> << compsize << <font class="stringliteral">"\n"</font>;
00147 cfile2 << <font class="stringliteral">"Compressed{"</font> << compsize << <font class="stringliteral">"}\n"</font> << destbuff << <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 < 2) || (argc > 4)) {
00178 cerr << <font class="stringliteral">"usage: "</font> << argv[0] << <font class="stringliteral">" datapath [compression type [buffer size]]\n"</font>;
00179 exit(1);
00180 }
00181
00182 <font class="keywordflow">if</font> (argc>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 << <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 << <font class="stringliteral">"Failed to open log file\n"</font>;
00210 exit(-1);
00211 }
00212 cfile << iType << <font class="stringliteral">" "</font> << iBufSize << <font class="stringliteral">"\n"</font>;
00213
00214 <font class="keywordflow">if</font> ((iType<=0) || (iType > 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 << argv[0] << <font class="stringliteral">" - a tool to create compressed Sword modules\n"</font>;
00217 cfile << <font class="stringliteral">"version 0.1\n\n"</font>;
00218 cfile << <font class="stringliteral">"usage: "</font><< argv[0] << <font class="stringliteral">" datapath [compression type [buffer size]]\n\n"</font>;
00219 cfile << <font class="stringliteral">"datapath: the directory in which to find the raw module\n"</font>;
00220 cfile << <font class="stringliteral">"compression type: (default 2)\n"</font> << <font class="stringliteral">" 1 - bytes\n"</font> << <font class="stringliteral">" 2 - verses\n"</font> << <font class="stringliteral">" 3 - chapters\n"</font> << <font class="stringliteral">" 4 - books\n"</font>;
00221 cfile << <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 << <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 << <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 << "about to start\n";</font>
00288
00289 <font class="keywordflow">for</font> ( i=0; i<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 << <font class="stringliteral">"key: "</font> << key1 << <font class="stringliteral">" Testament {"</font> << key1.<a class="code" href="class_verse_key.html#a22">Testament</a>()-1 << <font class="stringliteral">"}\n"</font>;
00298 <font class="comment">//cfile << "Chapter {" << key.Chapter() << "}\n";</font>
00299 <font class="comment">//cfile << "Verse {" << key.Verse() << "}\n";</font>
00300 <font class="comment">//cfile << key.compare("Revelation of John 22:21") << "\n";</font>
00301 <font class="comment">//cfile << key.compare("Genesis 1:1") << "\n";</font>
00302 <font class="keywordflow">do</font>
00303 {
00304 <font class="comment">//cfile << "ok";</font>
00305 <font class="comment">// read current verse offset</font>
00306 <font class="keywordflow">if</font> (read(ixfd[i], &offset, 4) != 4)
00307 {
00308 cfile << <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], &size, 2) != 2)
00312 {
00313 cfile << <font class="stringliteral">"Failed to read input verse sizes?\n"</font>;
00314 <font class="keywordflow">break</font>;
00315 }
00316 cfile << <font class="stringliteral">"key:"</font> << key1 << <font class="stringliteral">" offset:"</font> << offset << <font class="stringliteral">" size:"</font> << size << <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], &xbuff, strlen(xbuff));
00319 ulsize = size;
00320 <font class="keywordflow">if</font> (!offset && !size)
00321 {
00322 <font class="comment">//Check for module header</font>
00323 <font class="keywordflow">if</font> (read(ixfd[i], &ulIOff, 4) != 4)
00324 {
00325 cfile << <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 << currbuff << "\n";</font>
00341
00342 <font class="comment">// write to verse index into compressed</font>
00343 write(ovxfd[i], &ulBuffNum, 4); <font class="comment">// current buffer number</font>
00344 write(ovxfd[i], &ulIOff, 4); <font class="comment">// offset within the buffer</font>
00345 write(ovxfd[i], &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 << "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 << "{" << compsize << "}";</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, &compsize, (const Bytef*)currbuff.c_str(), buffsize)!=Z_OK)</font>
00365 <font class="comment"> {</font>
00366 <font class="comment"> cerr << "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 << "Compressed buffer{" << compsize << "}\n" << destbuff << "\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], &ulCOff, 4); // offset in compressed file</font>
00375 <font class="comment"> write(oxfd[i], &compsize, 4); // compressed size</font>
00376 <font class="comment"> write(oxfd[i], &buffsize, 4); // uncompressed size</font>
00377 <font class="comment"> cfile << buffsize << " -> " << compsize << "\n";</font>
00378 <font class="comment"> cfile2 << "Compressed{" << compsize << "}\n" << destbuff << "\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 << <font class="stringliteral">"had a new module "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <font class="stringliteral">"{"</font> << offset << <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 << <font class="stringliteral">"had a new testament "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <font class="stringliteral">"{"</font> << offset << <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 << <font class="stringliteral">"had a new book "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <font class="stringliteral">"{"</font> << offset << <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 << <font class="stringliteral">"had a new chapter "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <font class="stringliteral">"{"</font> << offset << <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 << <font class="stringliteral">"got a new chapter "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <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 << <font class="stringliteral">"got a new book "</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *) key1 << <font class="stringliteral">"\n"</font>;
00433 }
00434 key2 = key1;
00435
00436 }
00437 <font class="keywordflow">else</font>
00438 {
00439 cfile << <font class="stringliteral">"empty offset\n"</font>;
00440 <font class="comment">// write to verse index into compressed</font>
00441 write(ovxfd[i], &ulNone, 4); <font class="comment">// current buffer number</font>
00442 write(ovxfd[i], &size, 2); <font class="comment">// verse size</font>
00443 write(ovxfd[i], &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) && ((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>