<!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>mhcidx.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>mhcidx.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/*****************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * This code wreaks but works (at least for MHC). Good luck!</font>
00004 <font class="comment"> */</font>
00005
00006 <font class="preprocessor">#include <stdio.h></font>
00007 <font class="preprocessor">#include <stdlib.h></font>
00008 <font class="preprocessor">#include <string.h></font>
00009 <font class="preprocessor">#include <ctype.h></font>
00010
00011 <font class="preprocessor">#ifndef __GNUC__</font>
00012 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00013 <font class="preprocessor">#else</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00015 <font class="preprocessor">#endif</font>
00016 <font class="preprocessor"></font>
00017 <font class="preprocessor">#include <fcntl.h></font>
00018 <font class="preprocessor">#include <versekey.h></font>
00019
00020
00021 <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);
00022 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size);
00023 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname);
00024 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv);
00025
00026
00027 <a class="code" href="class_verse_key.html">VerseKey</a> key1, key2, key3;
00028 <font class="keywordtype">int</font> fp, vfp, cfp, bfp;
00029 <font class="keywordtype">long</font> chapoffset;
00030 <font class="keywordtype">short</font> chapsize;
00031 <font class="keywordtype">char</font> testmnt;
00032
00033
00034 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00035 {
00036 <font class="keywordtype">long</font> pos, offset;
00037 <font class="keywordtype">int</font> num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
00038 <font class="keywordtype">char</font> buf[127], startflag = 0;
00039 <font class="keywordtype">short</font> size, tmp;
00040
00041 checkparams(argc, argv);
00042
00043 openfiles(argv[1]);
00044
00045 testmnt = key1.<a class="code" href="class_verse_key.html#a22">Testament</a>();
00046 pos = 0;
00047 write(bfp, &pos, 4); <font class="comment">/* Book offset for testament intros */</font>
00048 pos = 4;
00049 write(cfp, &pos, 4); <font class="comment">/* Chapter offset for testament intro */</font>
00050
00051
00052 <font class="comment">/* Right now just zero out intros until parsing correctly */</font>
00053 pos = 0;
00054 size = 0;
00055 write(vfp, &pos, 4); <font class="comment">/* Module intro */</font>
00056 write(vfp, &size, 2);
00057 write(vfp, &pos, 4); <font class="comment">/* Testament intro */</font>
00058 write(vfp, &size, 2);
00059
00060 <font class="keywordflow">while</font>(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
00061 <font class="keywordflow">if</font> (num2) {
00062 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00063 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00064 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(num2);
00065 }
00066 <font class="keywordflow">else</font> {
00067 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00068 <font class="keywordflow">if</font> (!startflag) {
00069 startflag = 1;
00070 }
00071 <font class="keywordflow">else</font> {
00072 <font class="keywordflow">if</font> (num1 <= key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>()) { <font class="comment">// new book</font>
00073 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00074 key2.<a class="code" href="class_verse_key.html#a23">Book</a>(key2.<a class="code" href="class_verse_key.html#a23">Book</a>()+1);
00075 }
00076 }
00077 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00078 printf(<font class="stringliteral">"Found Chapter Break: %d ('%s')\n"</font>, num1, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00079 chapoffset = offset;
00080 chapsize = size;
00081 <font class="keywordflow">continue</font>;
00082 }
00083
00084 key3 = key2;
00085 key3 += (rangemax - key3.<a class="code" href="class_verse_key.html#a25">Verse</a>());
00086
00087 writeidx(key1, key2, key3, offset, size);
00088 }
00089 close(vfp);
00090 close(cfp);
00091 close(bfp);
00092 close(fp);
00093 }
00094
00095
00096 <font class="comment">/**************************************************************************</font>
00097 <font class="comment"> * ENT: key1 - current location of index</font>
00098 <font class="comment"> * key2 - minimum keyval for which this offset is valid</font>
00099 <font class="comment"> * key3 - maximum keyval for which this offset is valid</font>
00100 <font class="comment"> */</font>
00101
00102 <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)
00103 {
00104 <font class="keywordtype">long</font> pos;
00105 <font class="keywordtype">short</font> tmp;
00106
00107 <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) {
00108 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) { <font class="comment">// new chapter</font>
00109 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) { <font class="comment">// new book</font>
00110 pos = lseek(cfp, 0, SEEK_CUR);
00111 write(bfp, &pos, 4);
00112 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00113 write(cfp, &pos, 4);
00114 write(vfp, &chapoffset, 4); <font class="comment">/* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/</font>
00115 write(vfp, &chapsize, 2);
00116 }
00117 pos = lseek(vfp, 0, SEEK_CUR);
00118 write(cfp, &pos, 4);
00119 write(vfp, &chapoffset, 4); <font class="comment">/* Chapter intro */</font>
00120 write(vfp, &chapsize, 2);
00121 }
00122 <font class="keywordflow">if</font> (key1 >= key2) {
00123 write(vfp, &offset, 4);
00124 write(vfp, &size, 2);
00125 }
00126 <font class="keywordflow">else</font> {
00127 pos = 0;
00128 tmp = 0;
00129 write(vfp, &pos, 4);
00130 write(vfp, &tmp, 2);
00131 }
00132 }
00133 }
00134
00135
00136 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf)
00137 {
00138 <font class="keywordtype">char</font> loop;
00139
00140 <font class="keywordflow">if</font> (buf[0] != 10)
00141 <font class="keywordflow">return</font> 0;
00142 <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'#'</font>)
00143 <font class="keywordflow">return</font> 0;
00144 <font class="keywordflow">if</font> (!isdigit(buf[2]))
00145 <font class="keywordflow">return</font> 0;
00146 <font class="keywordflow">for</font> (loop = 3; loop < 7; loop++) {
00147 <font class="keywordflow">if</font> (buf[loop] == <font class="charliteral">' '</font>)
00148 <font class="keywordflow">break</font>;
00149 <font class="keywordflow">if</font> ((!isdigit(buf[loop])) && (buf[loop] != <font class="charliteral">','</font>) && (buf[loop] != <font class="charliteral">'-'</font>))
00150 <font class="keywordflow">return</font> 0;
00151 }
00152 <font class="keywordflow">return</font> 1;
00153 }
00154
00155
00156 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size)
00157 {
00158 <font class="keywordtype">char</font> buf[7];
00159 <font class="keywordtype">char</font> buf2[20];
00160 <font class="keywordtype">char</font> ch;
00161 <font class="keywordtype">char</font> loop;
00162 <font class="keywordtype">long</font> offset2;
00163 <font class="keywordtype">int</font> ch2, vs2, rm2;
00164
00165 memset(buf, <font class="charliteral">' '</font>, 7);
00166
00167 <font class="keywordflow">while</font> (1) {
00168 <font class="keywordflow">if</font> (startentry(buf)) {
00169 memset(buf, <font class="charliteral">' '</font>, 2);
00170 <font class="keywordflow">for</font> (loop = 2; loop < 7; loop++) {
00171 <font class="keywordflow">if</font> ((buf[loop] == <font class="charliteral">'-'</font>) || (buf[loop] == <font class="charliteral">','</font>) || (buf[loop] == <font class="charliteral">' '</font>)) {
00172 buf[loop] = 0;
00173 *num2 = atoi(buf);
00174 <font class="keywordflow">break</font>;
00175 }
00176 }
00177 <font class="keywordflow">for</font> (ch = loop + 1; ch < 7; ch++) {
00178 <font class="keywordflow">if</font> (buf[ch] == <font class="charliteral">' '</font>) {
00179 <font class="keywordflow">break</font>;
00180 }
00181 }
00182 buf[ch] = 0;
00183 *rangemax = atoi(&buf[loop+1]);
00184 <font class="keywordflow">if</font> (!*rangemax)
00185 *rangemax = *num2;
00186 *offset = lseek(fp, 0, SEEK_CUR) - 5;
00187 <font class="keywordflow">if</font> (size) {
00188 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
00189 *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00190 }
00191 <font class="keywordflow">else</font> {
00192 <font class="keywordflow">if</font> (vs2) {
00193 *size = (offset2 - (*offset)) - 3;
00194 }
00195 <font class="keywordflow">else</font> {
00196 sprintf(buf2, <font class="stringliteral">"$-$-$- XX:%d"</font>, ch2);
00197 *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
00198 }
00199 }
00200 lseek(fp, *offset, SEEK_SET);
00201 }
00202 <font class="keywordflow">return</font> 0;
00203 }
00204
00205 <font class="keywordflow">if</font> (!strncmp(buf, <font class="stringliteral">"$-$-$-"</font>, 6)) {
00206 memset(buf2, 0, 7);
00207 loop = 0;
00208 <font class="keywordflow">while</font> ((read(fp, &buf2[loop], 1) == 1) && (loop < 7)) {
00209 <font class="keywordflow">if</font> ((buf2[loop] == 10) || (buf2[loop] == 13)) {
00210 buf2[loop] = 0;
00211 <font class="keywordflow">break</font>;
00212 }
00213 loop++;
00214 }
00215 <font class="keywordflow">while</font> (read(fp, &ch, 1) == 1) {
00216 <font class="keywordflow">if</font> (ch == <font class="charliteral">'*'</font>)
00217 <font class="keywordflow">break</font>;
00218 }
00219
00220 *offset = lseek(fp, 0, SEEK_CUR) - 1;
00221 *num2 = 0;
00222 <font class="keywordflow">for</font> (loop = strlen(buf2) - 1; loop; loop--) {
00223 <font class="keywordflow">if</font> (buf2[loop] == <font class="charliteral">':'</font>)
00224 <font class="keywordflow">break</font>;
00225 }
00226 *num1 = atoi(&buf2[loop+1]);
00227 printf(<font class="stringliteral">"Chapter marker: %s\n"</font>, buf2);
00228 <font class="keywordflow">if</font> (size) {
00229 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
00230 *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00231 }
00232 <font class="keywordflow">else</font> {
00233 <font class="keywordflow">if</font> (vs2) {
00234 *size = (offset2 - (*offset)) - 3;
00235 }
00236 <font class="keywordflow">else</font> {
00237 sprintf(buf2, <font class="stringliteral">"$-$-$- XX:%d"</font>, ch2);
00238 *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
00239 }
00240 }
00241 lseek(fp, *offset, SEEK_SET);
00242 }
00243 <font class="keywordflow">return</font> 0;
00244 }
00245
00246
00247 memmove(buf, &buf[1], 6);
00248 <font class="keywordflow">if</font> (read(fp, &buf[6], 1) != 1)
00249 <font class="keywordflow">return</font> 1;
00250 }
00251 }
00252
00253
00254 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname)
00255 {
00256 <font class="keywordtype">char</font> buf[255];
00257
00258 <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY)) == -1) {
00259 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00260 exit(1);
00261 }
00262
00263 sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00264 <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00265 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00266 exit(1);
00267 }
00268
00269 sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00270 <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00271 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00272 exit(1);
00273 }
00274
00275 sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00276 <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00277 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00278 exit(1);
00279 }
00280 }
00281
00282
00283 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00284 {
00285 <font class="keywordflow">if</font> (argc < 2) {
00286 fprintf(stderr, <font class="stringliteral">"usage: %s <file to process> [nt - for new testmt file]\n"</font>, argv[0]);
00287 exit(1);
00288 }
00289 <font class="keywordflow">if</font> (argc == 3)
00290 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>;
00291 <font class="keywordflow">else</font> key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00292 }
</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>