<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>gbfidx.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <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>gbfidx.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/*****************************************************************************</font> 00002 <font class="comment"> *</font> 00003 <font class="comment"> * This code reeks but works (sometimes). Good luck!</font> 00004 <font class="comment"> * Modified for zText purposes</font> 00005 <font class="comment"> */</font> 00006 00007 <font class="comment">//#include <stdio.h></font> 00008 <font class="preprocessor">#include <iostream></font> 00009 <font class="preprocessor">#include <fstream></font> 00010 <font class="preprocessor">#include <stdlib.h></font> 00011 <font class="preprocessor">#include <string.h></font> 00012 <font class="preprocessor">#include <ctype.h></font> 00013 <font class="preprocessor">#include <assert.h></font> 00014 00015 <font class="comment">//#ifndef __GNUC__</font> 00016 <font class="preprocessor">#include <io.h></font> 00017 <font class="comment">//#else</font> 00018 <font class="comment">//#include <unistd.h></font> 00019 <font class="comment">//#endif</font> 00020 00021 <font class="preprocessor">#include <fcntl.h></font> 00022 <font class="preprocessor">#include <versekey.h></font> 00023 00024 00025 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &key1, <a class="code" href="class_verse_key.html">VerseKey</a> &key2, <a class="code" href="class_verse_key.html">VerseKey</a> &key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size); 00026 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *size); 00027 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname); 00028 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv); 00029 00030 00031 <a class="code" href="class_verse_key.html">VerseKey</a> key1, key2, key3; 00032 <font class="keywordtype">int</font> fp=0, vfp=0, cfp=0, bfp=0; 00033 <font class="keywordtype">long</font> chapoffset=0; 00034 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> chapsize=0; 00035 <font class="keywordtype">long</font> bookoffset=0; 00036 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> booksize=0; 00037 <font class="keywordtype">long</font> testoffset=0; 00038 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> testsize=0; 00039 <font class="keywordtype">long</font> verseoffset=0; 00040 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> versesize=0; 00041 <font class="keywordtype">long</font> nextoffset=0; 00042 <font class="keywordtype">char</font> testmnt=0; 00043 <font class="keywordtype">int</font> deadcount = 0; 00044 <font class="keywordtype">int</font> chapmark=-4, bookmark=-1; 00045 ofstream cfile; 00046 00047 00048 <font class="keywordtype">int</font> main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv) 00049 { 00050 <font class="keywordtype">long</font> pos, offset; 00051 <font class="keywordtype">int</font> num1, num2, rangemax;<font class="comment">//, curbook = 0, curchap = 0, curverse = 0;</font> 00052 <font class="comment">//char buf[127],</font> 00053 <font class="keywordtype">char</font> startflag = 0; 00054 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;<font class="comment">//, tmp;</font> 00055 00056 checkparams(argc, argv); 00057 00058 openfiles(argv[1]); 00059 <font class="comment">//key1 = "Matthew 1:1";</font> 00060 <font class="comment">//key2 = "Matthew 1:1";</font> 00061 <font class="comment">//key3 = "Matthew 1:1";</font> 00062 00063 testmnt = key1.<a class="code" href="class_verse_key.html#a22">Testament</a>(); 00064 cfile << <font class="stringliteral">"testament"</font> << (int) testmnt << <font class="stringliteral">"\n"</font>; 00065 num1 = key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>(); 00066 num2 = key1.<a class="code" href="class_verse_key.html#a25">Verse</a>(); 00067 pos = 0; 00068 write(bfp, &pos, 4); <font class="comment">/* Book offset for testament intros */</font> 00069 pos = 4; 00070 write(cfp, &pos, 4); <font class="comment">/* Chapter offset for testament intro */</font> 00071 00072 00073 <font class="comment">/* Right now just zero out intros until parsing correctly */</font> 00074 <font class="comment">/*pos = 0;</font> 00075 <font class="comment"> size = 0;</font> 00076 <font class="comment"> write(vfp, &pos, 4); // Module intro</font> 00077 <font class="comment"> write(vfp, &size, 2);</font> 00078 <font class="comment"> cfile << "modintro pos{" << pos << "} size{" << size << "}\n";</font> 00079 <font class="comment"> write(vfp, &pos, 4); // Testament intro</font> 00080 <font class="comment"> write(vfp, &size, 2);</font> 00081 <font class="comment"> cfile << "test intro pos{" << pos << "} size{" << size << "}\n";</font> 00082 <font class="comment"> */</font> 00083 cout << <font class="stringliteral">"GBFIDX Running\n"</font>; 00084 cout.flush(); 00085 <font class="keywordflow">while</font>(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) { 00086 <font class="keywordflow">if</font> (!startflag) { 00087 startflag = 1; 00088 } 00089 <font class="keywordflow">else</font> { 00090 <font class="keywordflow">if</font> (num2 < key2.<a class="code" href="class_verse_key.html#a25">Verse</a>()) { <font class="comment">// new chapter</font> 00091 <font class="keywordflow">if</font> (num1 <= key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>()) { <font class="comment">// new book</font> 00092 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1); 00093 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1); 00094 key2.<a class="code" href="class_verse_key.html#a23">Book</a>(key2.<a class="code" href="class_verse_key.html#a23">Book</a>()+1); 00095 } 00096 cfile << <font class="stringliteral">"Found Chapter Break: "</font> << num1 << <font class="stringliteral">" ('"</font> << (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2 << <font class="stringliteral">"')\n"</font>; 00097 <font class="comment">//chapoffset = offset;</font> 00098 <font class="comment">//chapsize = chapsize - size;</font> 00099 <font class="comment">// continue;</font> 00100 } 00101 } 00102 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1); 00103 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1); 00104 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(num2); 00105 00106 key3 = key2; 00107 <font class="comment">// key3 += (rangemax - key3.Verse());</font> 00108 00109 writeidx(key1, key2, key3, offset, size); 00110 } 00111 close(vfp); 00112 close(cfp); 00113 close(bfp); 00114 close(fp); 00115 00116 <font class="keywordflow">return</font> 1; 00117 } 00118 00119 00120 <font class="comment">/**************************************************************************</font> 00121 <font class="comment"> * writeidx: key1 - current location of index</font> 00122 <font class="comment"> * key2 - minimum keyval for which this offset is valid</font> 00123 <font class="comment"> * key3 - maximum keyval for which this offset is valid</font> 00124 <font class="comment"> */</font> 00125 00126 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &key1, <a class="code" href="class_verse_key.html">VerseKey</a> &key2, <a class="code" href="class_verse_key.html">VerseKey</a> &key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size) 00127 { 00128 <font class="keywordtype">long</font> pos; 00129 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> tmp; 00130 00131 <font class="keywordflow">for</font> (; ((key1 <= key3) && (key1.<a class="code" href="class_s_w_key.html#a6">Error</a>() != KEYERR_OUTOFBOUNDS) && (key1.<a class="code" href="class_verse_key.html#a22">Testament</a>() == testmnt)); key1+=1) { 00132 <font class="keywordflow">if</font> (chapmark>=2) 00133 { 00134 <font class="keywordflow">if</font> (bookmark==2) 00135 { 00136 <font class="comment">//booksize = booksize - chapsize + 7;</font> 00137 cfile << <font class="stringliteral">"versesize "</font> << versesize << <font class="stringliteral">" booksize "</font> << booksize << <font class="stringliteral">" chapsize "</font> << chapsize << <font class="stringliteral">" size "</font> << size << <font class="stringliteral">"\n"</font>; 00138 <font class="comment">//cfile.flush();</font> 00139 <font class="comment">//assert(chapsize < size);</font> 00140 <font class="comment">//if (chapsize > size) // At start of Psalms gets chapsize rather than chapsize+size ???</font> 00141 <font class="comment">//{</font> 00142 <font class="comment">// versesize = versesize - (booksize - (chapsize - size) + 7);</font> 00143 <font class="comment">//}</font> 00144 <font class="comment">//else</font> 00145 <font class="comment">//{</font> 00146 versesize = versesize - (booksize - (chapsize) + 7); 00147 <font class="comment">//}</font> 00148 cfile << <font class="stringliteral">"Last verse in book\n"</font>; 00149 } 00150 <font class="comment">//chapsize = chapsize - size;</font> 00151 cfile << <font class="stringliteral">"versesize "</font> << versesize << <font class="stringliteral">" chapsize "</font> << chapsize << <font class="stringliteral">" size "</font> << size<< <font class="stringliteral">"\n"</font>; 00152 cfile.flush(); 00153 <font class="comment">//assert(chapsize > size);</font> 00154 <font class="comment">//if (chapsize > size) // At start of Psalms gets chapsize rather than chapsize+size ???</font> 00155 <font class="comment">//{</font> 00156 <font class="comment">// versesize = versesize - (chapsize - size);</font> 00157 <font class="comment">//}</font> 00158 <font class="comment">//else</font> 00159 <font class="comment">//{</font> 00160 versesize = versesize - (chapsize); 00161 <font class="comment">//}</font> 00162 cfile << <font class="stringliteral">"Last verse in chapter\n"</font>; 00163 } 00164 <font class="keywordflow">if</font> (chapmark>=2 && bookmark!=1) 00165 { 00166 cfile << <font class="stringliteral">"prev verse pos{"</font> << verseoffset << <font class="stringliteral">"} size{"</font> << versesize << <font class="stringliteral">"} nextoffset{"</font> << nextoffset << <font class="stringliteral">"}\n"</font>; 00167 cfile.flush(); 00168 assert(verseoffset==nextoffset); 00169 write(vfp, &verseoffset, 4); 00170 write(vfp, &versesize, 2); 00171 nextoffset = verseoffset+versesize; 00172 bookmark = 0; 00173 chapmark = 0; 00174 } 00175 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) { <font class="comment">// new chapter</font> 00176 cfile << <font class="stringliteral">"size??? "</font> << size << <font class="stringliteral">"\n"</font>; 00177 cfile.flush(); 00178 <font class="comment">//assert(chapsize > size || key1.Chapter()==1);</font> 00179 <font class="comment">//assert(chapsize > size);</font> 00180 <font class="comment">//if (chapsize > size) // At start of books gets chapsize rather than chapsize+size</font> 00181 <font class="comment">//{</font> 00182 <font class="comment">// chapsize = chapsize - size;</font> 00183 <font class="comment">//}</font> 00184 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) { <font class="comment">// new book</font> 00185 booksize = booksize - chapsize + 7; 00186 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a23">Book</a>() == 1) 00187 { 00188 pos = 0; 00189 <font class="comment">//tmp = testoffset;</font> 00190 tmp = 0; <font class="comment">// better just remember that it goes up to the testament intro to avoid 64k limit</font> 00191 <font class="comment">// AV exceeds that anyway!</font> 00192 write(vfp, &pos, 4); <font class="comment">/* Module intro */</font> 00193 write(vfp, &tmp, 2); 00194 assert(nextoffset==0); 00195 cfile << <font class="stringliteral">"modintro pos{"</font> << pos << <font class="stringliteral">"} size{"</font> << tmp << <font class="stringliteral">"}\n"</font>; 00196 testsize = testsize - booksize - chapsize + 7; 00197 <font class="keywordflow">if</font> (testsize > 10000) 00198 { 00199 cerr << <font class="stringliteral">"Error: testament too big "</font> << testsize << <font class="stringliteral">"\n"</font>; 00200 exit(-1); 00201 } 00202 <font class="comment">//assert(testoffset==nextoffset);</font> 00203 write(vfp, &testoffset, 4); <font class="comment">/* Testament intro (vss) */</font> 00204 write(vfp, &testsize, 2); 00205 nextoffset = testoffset+testsize; 00206 cfile << <font class="stringliteral">"test intro pos{"</font> << testoffset << <font class="stringliteral">"} size{"</font> << testsize << <font class="stringliteral">"}\n"</font>; 00207 } 00208 pos = lseek(cfp, 0, SEEK_CUR); 00209 write(bfp, &pos, 4); 00210 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font> 00211 write(cfp, &pos, 4); 00212 <font class="keywordflow">if</font> (booksize > 10000) 00213 { 00214 cerr << <font class="stringliteral">"Error: book too big "</font> << booksize << <font class="stringliteral">"\n"</font>; 00215 exit(-1); 00216 } 00217 assert(bookoffset==nextoffset); 00218 write(vfp, &bookoffset, 4); <font class="comment">/* Book intro (vss) */</font> 00219 write(vfp, &booksize, 2); 00220 nextoffset = bookoffset+booksize; 00221 cfile << <font class="stringliteral">"book intro pos{"</font> << bookoffset << <font class="stringliteral">"} size{"</font> << booksize << <font class="stringliteral">"}\n"</font>; 00222 <font class="comment">//offset += booksize;</font> 00223 <font class="comment">//bookmark = false;</font> 00224 } 00225 pos = lseek(vfp, 0, SEEK_CUR); 00226 write(cfp, &pos, 4); 00227 assert(chapsize < 10000); 00228 write(vfp, &chapoffset, 4); <font class="comment">/* Chapter intro */</font> 00229 write(vfp, &chapsize, 2); 00230 nextoffset = chapoffset+chapsize; 00231 cfile << <font class="stringliteral">"chapter intro pos{"</font> << chapoffset << <font class="stringliteral">"} size{"</font> << chapsize << <font class="stringliteral">"}\n"</font>; 00232 <font class="comment">//offset += chapsize;</font> 00233 <font class="comment">//size -= chapsize;</font> 00234 <font class="comment">//chapmark = false;</font> 00235 } 00236 <font class="keywordflow">if</font> (key1 >= key2) { 00237 <font class="keywordflow">if</font> (size > 10000) 00238 { 00239 cerr << <font class="stringliteral">"Error: verse too big "</font> << size << <font class="stringliteral">"\n"</font>; 00240 exit(-1); 00241 } 00242 <font class="keywordflow">if</font> (!chapmark && !bookmark) 00243 { 00244 write(vfp, &offset, 4); 00245 write(vfp, &size, 2); 00246 cfile << <font class="stringliteral">"verse pos{"</font> << offset << <font class="stringliteral">"} size{"</font> << size << <font class="stringliteral">"}\n"</font>; 00247 cfile.flush(); 00248 assert(offset==nextoffset); 00249 nextoffset = offset+size; 00250 <font class="comment">//cfile << "bookmark " << bookmark << " chapmark " << chapmark << "\n";</font> 00251 } 00252 <font class="keywordflow">else</font> 00253 { 00254 verseoffset = offset; 00255 versesize = size; 00256 cfile << <font class="stringliteral">"saving verse pos{"</font> << offset << <font class="stringliteral">"} size{"</font> << size << <font class="stringliteral">"}\n"</font>; 00257 cfile << <font class="stringliteral">"bookmark "</font> << bookmark << <font class="stringliteral">" chapmark "</font> << chapmark << <font class="stringliteral">"\n"</font>; 00258 } 00259 } 00260 <font class="keywordflow">else</font> { 00261 pos = 0; 00262 tmp = 0; 00263 write(vfp, &pos, 4); 00264 write(vfp, &tmp, 2); 00265 cfile << <font class="stringliteral">"blank pos{"</font> << pos << <font class="stringliteral">"} size{"</font> << tmp << <font class="stringliteral">"}\n"</font>; 00266 } 00267 } 00268 } 00269 00270 <font class="keywordtype">char</font> startmod(<font class="keywordtype">char</font> *buf) 00271 { 00272 <font class="comment">//char loop;</font> 00273 00274 <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'<'</font>) 00275 <font class="keywordflow">return</font> 0; 00276 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'H'</font>) 00277 <font class="keywordflow">return</font> 0; 00278 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'0'</font>) 00279 <font class="keywordflow">return</font> 0; 00280 <font class="comment">/*</font> 00281 <font class="comment"> if (!isdigit(buf[2]))</font> 00282 <font class="comment"> return 0;</font> 00283 <font class="comment"> for (loop = 3; loop < 7; loop++) {</font> 00284 <font class="comment"> if (buf[loop] == ' ')</font> 00285 <font class="comment"> break;</font> 00286 <font class="comment"> if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))</font> 00287 <font class="comment"> return 0;</font> 00288 <font class="comment"> }</font> 00289 <font class="comment">*/</font> 00290 <font class="keywordflow">return</font> 1; 00291 } 00292 00293 00294 <font class="keywordtype">char</font> starttest(<font class="keywordtype">char</font> *buf) 00295 { 00296 <font class="comment">//char loop;</font> 00297 00298 <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'<'</font>) 00299 <font class="keywordflow">return</font> 0; 00300 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'B'</font>) 00301 <font class="keywordflow">return</font> 0; 00302 <font class="keywordflow">if</font> (testmnt==2) 00303 { 00304 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'N'</font>) 00305 <font class="keywordflow">return</font> 0; 00306 } 00307 <font class="keywordflow">else</font> 00308 { 00309 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'O'</font>) 00310 <font class="keywordflow">return</font> 0; 00311 } 00312 <font class="comment">//if (buf[3] != '>')</font> 00313 <font class="comment">// return 0;</font> 00314 <font class="comment">/*</font> 00315 <font class="comment"> if (!isdigit(buf[2]))</font> 00316 <font class="comment"> return 0;</font> 00317 <font class="comment"> for (loop = 3; loop < 7; loop++) {</font> 00318 <font class="comment"> if (buf[loop] == ' ')</font> 00319 <font class="comment"> break;</font> 00320 <font class="comment"> if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))</font> 00321 <font class="comment"> return 0;</font> 00322 <font class="comment"> }</font> 00323 <font class="comment">*/</font> 00324 <font class="keywordflow">return</font> 1; 00325 } 00326 00327 00328 <font class="keywordtype">char</font> startbook(<font class="keywordtype">char</font> *buf) 00329 { 00330 <font class="comment">//char loop;</font> 00331 00332 <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'<'</font>) 00333 <font class="keywordflow">return</font> 0; 00334 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>) 00335 <font class="keywordflow">return</font> 0; 00336 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'B'</font>) 00337 <font class="keywordflow">return</font> 0; 00338 <font class="comment">/*</font> 00339 <font class="comment"> if (!isdigit(buf[2]))</font> 00340 <font class="comment"> return 0;</font> 00341 <font class="comment"> for (loop = 3; loop < 7; loop++) {</font> 00342 <font class="comment"> if (buf[loop] == ' ')</font> 00343 <font class="comment"> break;</font> 00344 <font class="comment"> if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))</font> 00345 <font class="comment"> return 0;</font> 00346 <font class="comment"> }</font> 00347 <font class="comment">*/</font> 00348 <font class="keywordflow">return</font> 1; 00349 } 00350 00351 00352 <font class="keywordtype">char</font> startchap(<font class="keywordtype">char</font> *buf) 00353 { 00354 <font class="comment">//char loop;</font> 00355 00356 <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'<'</font>) 00357 <font class="keywordflow">return</font> 0; 00358 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>) 00359 <font class="keywordflow">return</font> 0; 00360 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'C'</font>) 00361 <font class="keywordflow">return</font> 0; 00362 <font class="comment">/*</font> 00363 <font class="comment"> if (!isdigit(buf[2]))</font> 00364 <font class="comment"> return 0;</font> 00365 <font class="comment"> for (loop = 3; loop < 7; loop++) {</font> 00366 <font class="comment"> if (buf[loop] == ' ')</font> 00367 <font class="comment"> break;</font> 00368 <font class="comment"> if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))</font> 00369 <font class="comment"> return 0;</font> 00370 <font class="comment"> }</font> 00371 <font class="comment">*/</font> 00372 <font class="keywordflow">return</font> 1; 00373 } 00374 00375 00376 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf) 00377 { 00378 <font class="comment">//char loop;</font> 00379 <font class="comment">//cfile << "{SV}";</font> 00380 00381 <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'<'</font>) 00382 { 00383 <font class="comment">//cfile << "{no<}";</font> 00384 <font class="keywordflow">return</font> 0; 00385 } 00386 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>) 00387 { 00388 <font class="comment">//cfile << "\n{noS}\n";</font> 00389 <font class="keywordflow">return</font> 0; 00390 } 00391 <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'V'</font>) 00392 { 00393 <font class="comment">//cfile << "\n{noV}\n";</font> 00394 <font class="keywordflow">return</font> 0; 00395 } 00396 <font class="comment">/*</font> 00397 <font class="comment"> if (!isdigit(buf[2]))</font> 00398 <font class="comment"> return 0;</font> 00399 <font class="comment"> for (loop = 3; loop < 7; loop++) {</font> 00400 <font class="comment"> if (buf[loop] == ' ')</font> 00401 <font class="comment"> break;</font> 00402 <font class="comment"> if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))</font> 00403 <font class="comment"> return 0;</font> 00404 <font class="comment"> }</font> 00405 <font class="comment">*/</font> 00406 <font class="keywordflow">return</font> 1; 00407 } 00408 00409 00410 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *size) 00411 { 00412 <font class="keywordtype">char</font> buf[8]; 00413 <font class="comment">//char buf2[20];</font> 00414 <font class="comment">//char ch;</font> 00415 <font class="keywordtype">char</font> loop=0; 00416 <font class="keywordtype">long</font> offset2; 00417 <font class="keywordtype">int</font> ch2, vs2, rm2; 00418 <font class="keywordtype">bool</font> flag; 00419 <font class="keywordtype">long</font> versestart = 0; 00420 <font class="keywordtype">long</font> chapstart = 0; 00421 <font class="keywordtype">long</font> bookstart = 0; 00422 <font class="keywordtype">long</font> teststart = 0; 00423 00424 memset(buf, <font class="charliteral">' '</font>, 8); 00425 00426 <font class="keywordflow">while</font> (1) { 00427 <font class="comment">//cfile << "#" << buf << "#";</font> 00428 <font class="comment">//if (lseek(fp, 0, SEEK_CUR) > 2000000)</font> 00429 <font class="comment">//{</font> 00430 <font class="comment">// cfile << lseek(fp, 0, SEEK_CUR) << "\n";</font> 00431 <font class="comment">//}</font> 00432 <font class="keywordflow">if</font> (starttest(buf)) { 00433 cfile << <font class="stringliteral">"\n{start of testament}\n"</font>; 00434 <font class="comment">//chapstart = lseek(fp, 0, SEEK_CUR) - 7;</font> 00435 teststart = lseek(fp, 0, SEEK_CUR) - 7; 00436 testoffset = teststart; 00437 memset(buf, <font class="charliteral">' '</font>, 3); 00438 flag = <font class="keyword">false</font>; 00439 <font class="keywordflow">for</font> (loop = 3; loop < 6; loop++) { 00440 <font class="keywordflow">if</font> (buf[loop]!=<font class="charliteral">'>'</font>) 00441 flag = <font class="keyword">true</font>; 00442 <font class="keywordflow">else</font> { 00443 buf[loop] = 0; 00444 <font class="keywordflow">break</font>; 00445 } 00446 } 00447 ch2 = *num1; 00448 vs2 = 1; 00449 <font class="keywordflow">if</font> (size) { 00450 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) { 00451 testsize = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>) (lseek(fp, 0, SEEK_END) - teststart-7); 00452 } 00453 <font class="keywordflow">else</font> { 00454 <font class="keywordflow">if</font> (vs2) { 00455 testsize = (offset2 - teststart - 7); 00456 } 00457 } 00458 lseek(fp, teststart+7, SEEK_SET); 00459 cfile << <font class="stringliteral">"\nGot testsize "</font> << testsize << <font class="stringliteral">"\n"</font>; 00460 } 00461 } 00462 00463 00464 <font class="keywordflow">if</font> (startbook(buf)) { 00465 cfile << <font class="stringliteral">"\n{start of book}\n"</font>; 00466 bookmark++; 00467 <font class="comment">//chapstart = lseek(fp, 0, SEEK_CUR) - 7;</font> 00468 bookstart = lseek(fp, 0, SEEK_CUR) - 7; 00469 bookoffset = bookstart; 00470 memset(buf, <font class="charliteral">' '</font>, 3); 00471 flag = <font class="keyword">false</font>; 00472 <font class="keywordflow">for</font> (loop = 3; loop < 6; loop++) { 00473 <font class="keywordflow">if</font> (buf[loop]!=<font class="charliteral">'>'</font>) 00474 flag = <font class="keyword">true</font>; 00475 <font class="keywordflow">else</font> { 00476 buf[loop] = 0; 00477 <font class="keywordflow">break</font>; 00478 } 00479 } 00480 <font class="keywordflow">if</font> (size) { 00481 ch2 = *num1; 00482 vs2 = 1; 00483 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) { 00484 booksize = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>) (lseek(fp, 0, SEEK_END) - bookstart - 7); 00485 } 00486 <font class="keywordflow">else</font> { 00487 <font class="keywordflow">if</font> (vs2) { 00488 booksize = (offset2 - bookstart - 7); 00489 } 00490 } 00491 lseek(fp, bookstart+7, SEEK_SET); 00492 cfile << <font class="stringliteral">"\nGot booksize "</font> << booksize << <font class="stringliteral">"\n"</font>; 00493 } 00494 } 00495 00496 <font class="keywordflow">if</font> (startchap(buf)) { 00497 cfile << <font class="stringliteral">"{start of chapter}"</font>; 00498 chapmark++; 00499 <font class="comment">//chapstart = lseek(fp, 0, SEEK_CUR) - 7;</font> 00500 chapstart = lseek(fp, 0, SEEK_CUR) - 7; 00501 chapoffset = chapstart; 00502 memset(buf, <font class="charliteral">' '</font>, 3); 00503 flag = <font class="keyword">false</font>; 00504 <font class="keywordflow">for</font> (loop = 3; loop < 6; loop++) { 00505 <font class="keywordflow">if</font> (isdigit(buf[loop])) 00506 flag = <font class="keyword">true</font>; 00507 <font class="keywordflow">else</font> { 00508 buf[loop] = 0; 00509 <font class="keywordflow">break</font>; 00510 } 00511 } 00512 <font class="keywordflow">if</font> (flag) 00513 *num1 = atoi(buf); 00514 <font class="keywordflow">else</font> (*num1)++; 00515 00516 <font class="keywordflow">if</font> (size) { 00517 ch2 = *num1; 00518 vs2 = 1; 00519 lseek(fp, chapstart, SEEK_SET); 00520 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) { 00521 chapsize = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>) (lseek(fp, 0, SEEK_END) - chapstart); 00522 cfile << <font class="stringliteral">"getting chapsizeend{"</font> << chapsize << <font class="stringliteral">"} = "</font> << lseek(fp, 0, SEEK_END) << <font class="stringliteral">" - "</font> << chapstart << <font class="stringliteral">"\n"</font>; 00523 } 00524 <font class="keywordflow">else</font> { 00525 <font class="keywordflow">if</font> (vs2) { 00526 chapsize = (offset2 - chapstart); 00527 cfile << <font class="stringliteral">"getting chapsize{"</font> << chapsize << <font class="stringliteral">"} = "</font> << offset2 << <font class="stringliteral">" - "</font> << chapstart << <font class="stringliteral">"\n"</font>; 00528 } 00529 } 00530 lseek(fp, chapstart + 7, SEEK_SET); 00531 cfile << <font class="stringliteral">"\nGot chapsize "</font> << chapsize << <font class="stringliteral">" loop{"</font> << (int) loop << <font class="stringliteral">"}\n"</font>; 00532 } 00533 <font class="comment">//return 0;</font> 00534 00535 } 00536 <font class="keywordflow">if</font> (startentry(buf)) { 00537 <font class="comment">//cfile << "{start of verse}";</font> 00538 memset(buf, <font class="charliteral">' '</font>, 3); 00539 flag = <font class="keyword">false</font>; 00540 <font class="keywordflow">for</font> (loop = 3; loop < 6; loop++) { 00541 <font class="keywordflow">if</font> (isdigit(buf[loop])) 00542 flag = <font class="keyword">true</font>; 00543 <font class="keywordflow">else</font> { 00544 buf[loop] = 0; 00545 <font class="keywordflow">break</font>; 00546 } 00547 <font class="keywordflow">if</font> (flag) 00548 *num2 = atoi(buf); 00549 <font class="keywordflow">else</font> (*num2)++; 00550 } 00551 loop++; 00552 <font class="comment">/*</font> 00553 <font class="comment"> if (size)</font> 00554 <font class="comment"> {</font> 00555 <font class="comment"> // *offset = lseek(fp, 0, SEEK_CUR) - (7 - loop);</font> 00556 <font class="comment"> *offset = lseek(fp, 0, SEEK_CUR) - 7;</font> 00557 <font class="comment"> }</font> 00558 <font class="comment"> //else *offset = (chapstart) ? chapstart : lseek(fp, 0, SEEK_CUR) - 7;</font> 00559 <font class="comment"> else *offset = (chapstart) ? chapstart : lseek(fp, 0, SEEK_CUR) - 7;</font> 00560 <font class="comment"> */</font> 00561 <font class="comment">/*if (chapstart)</font> 00562 <font class="comment"> {</font> 00563 <font class="comment"> chapsize = *offset-chapstart;</font> 00564 <font class="comment"> }</font> 00565 <font class="comment"> else</font> 00566 <font class="comment"> {</font> 00567 <font class="comment"> chapsize = 0;</font> 00568 <font class="comment"> }*/</font> 00569 *offset = lseek(fp, 0, SEEK_CUR) - 7; 00570 versestart = *offset; 00571 <font class="keywordflow">if</font> (size) { 00572 ch2 = *num1; 00573 vs2 = *num2; 00574 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) { 00575 *size = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>) (lseek(fp, 0, SEEK_END) - versestart); 00576 cfile << <font class="stringliteral">"getting sizeend{"</font> << *size << <font class="stringliteral">"} = "</font> << lseek(fp, 0, SEEK_END) << <font class="stringliteral">" - "</font> << versestart << <font class="stringliteral">"\n"</font>; 00577 } 00578 <font class="keywordflow">else</font> { 00579 <font class="keywordflow">if</font> (vs2) { 00580 *size = (offset2 - versestart); 00581 cfile << <font class="stringliteral">"getting size{"</font> << *size << <font class="stringliteral">"} = "</font> << offset2 << <font class="stringliteral">" - "</font> << versestart << <font class="stringliteral">"\n"</font>; 00582 } 00583 } 00584 lseek(fp, *offset+1, SEEK_SET); 00585 } 00586 <font class="keywordflow">else</font> 00587 { 00588 cfile << <font class="stringliteral">"got offset{"</font> << *offset << <font class="stringliteral">"}\n"</font>; 00589 } 00590 <font class="keywordflow">return</font> 0; 00591 } 00592 <font class="comment">//cfile << "{ng}";</font> 00593 <font class="comment">//deadcount++;</font> 00594 <font class="comment">//if (deadcount==1000) exit(-1);</font> 00595 <font class="comment">//if (!size)</font> 00596 <font class="comment">//{</font> 00597 <font class="comment">// cfile << "not bound offset{" << *offset << "}\n";</font> 00598 <font class="comment">//}</font> 00599 memmove(buf, &buf[1], 6); 00600 <font class="keywordflow">if</font> (read(fp, &buf[6], 1) != 1) 00601 <font class="keywordflow">return</font> 1; 00602 } 00603 } 00604 00605 00606 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname) 00607 { 00608 <font class="preprocessor">#ifndef O_BINARY // O_BINARY is needed in Borland C++ 4.53</font> 00609 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0 // If it hasn't been defined than we probably</font> 00610 <font class="preprocessor"></font><font class="preprocessor">#endif // don't need it.</font> 00611 <font class="preprocessor"></font> <font class="keywordtype">char</font> buf[255]; 00612 00613 <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY|O_BINARY)) == -1) { 00614 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname); 00615 exit(1); 00616 } 00617 00618 sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname); 00619 <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC)) == -1) { 00620 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf); 00621 exit(1); 00622 } 00623 00624 sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname); 00625 <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC)) == -1) { 00626 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf); 00627 exit(1); 00628 } 00629 00630 sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname); 00631 <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC)) == -1) { 00632 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf); 00633 exit(1); 00634 } 00635 cfile.open(<font class="stringliteral">"gbfidx.log"</font>, ios::out); 00636 <font class="keywordflow">if</font> (!cfile.is_open()) 00637 { 00638 cerr << <font class="stringliteral">"Failed to open log file\n"</font>; 00639 exit(-1); 00640 } 00641 } 00642 00643 00644 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv) 00645 { 00646 <font class="keywordflow">if</font> (argc < 2) { 00647 fprintf(stderr, <font class="stringliteral">"usage: %s <file to process> [nt - for new testmt file]\n"</font>, argv[0]); 00648 exit(1); 00649 } 00650 <font class="keywordflow">if</font> (!strcmp(argv[1], <font class="stringliteral">"nt"</font>)) 00651 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>; 00652 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strcmp(argv[1], <font class="stringliteral">"ot"</font>)) 00653 { 00654 key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>; 00655 } 00656 <font class="keywordflow">else</font> 00657 { 00658 cerr << <font class="stringliteral">"File must be ot or nt\n"</font>; 00659 exit(-1); 00660 } 00661 } </pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>