<!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>rwpidx.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>rwpidx.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 RWP). 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 = 0, num2 = 0, 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 printf(<font class="stringliteral">"Found verse Break: ('%s')\n"</font>, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00088 writeidx(key1, key2, key3, offset, size);
00089 }
00090 close(vfp);
00091 close(cfp);
00092 close(bfp);
00093 close(fp);
00094 }
00095
00096
00097 <font class="comment">/**************************************************************************</font>
00098 <font class="comment"> * ENT: key1 - current location of index</font>
00099 <font class="comment"> * key2 - minimum keyval for which this offset is valid</font>
00100 <font class="comment"> * key3 - maximum keyval for which this offset is valid</font>
00101 <font class="comment"> */</font>
00102
00103 <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)
00104 {
00105 <font class="keywordtype">long</font> pos;
00106 <font class="keywordtype">short</font> tmp;
00107
00108 <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) {
00109 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) { <font class="comment">// new chapter</font>
00110 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) { <font class="comment">// new book</font>
00111 pos = lseek(cfp, 0, SEEK_CUR);
00112 write(bfp, &pos, 4);
00113 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00114 write(cfp, &pos, 4);
00115 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>
00116 write(vfp, &chapsize, 2);
00117 }
00118 pos = lseek(vfp, 0, SEEK_CUR);
00119 write(cfp, &pos, 4);
00120 write(vfp, &chapoffset, 4); <font class="comment">/* Chapter intro */</font>
00121 write(vfp, &chapsize, 2);
00122 }
00123 <font class="keywordflow">if</font> (key1 >= key2) {
00124 write(vfp, &offset, 4);
00125 write(vfp, &size, 2);
00126 }
00127 <font class="keywordflow">else</font> {
00128 pos = 0;
00129 tmp = 0;
00130 write(vfp, &pos, 4);
00131 write(vfp, &tmp, 2);
00132 }
00133 }
00134 }
00135
00136
00137 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf)
00138 {
00139 <font class="keywordtype">char</font> colon = 0;
00140
00141 <font class="keywordflow">if</font> (buf[0] != 10)
00142 <font class="keywordflow">return</font> 0;
00143 <font class="keywordflow">if</font> (buf[1] != 10)
00144 <font class="keywordflow">return</font> 0;
00145 <font class="keywordflow">if</font> (!isdigit(buf[2]))
00146 <font class="keywordflow">return</font> 0;
00147 <font class="keywordflow">if</font> (!isdigit(buf[3])) {
00148 <font class="keywordflow">if</font> (buf[3]!= <font class="charliteral">':'</font>)
00149 <font class="keywordflow">return</font> 0;
00150 <font class="keywordflow">else</font> colon++;
00151 }
00152 <font class="keywordflow">if</font> (!isdigit(buf[4])) {
00153 <font class="keywordflow">if</font> (buf[4]!= <font class="charliteral">':'</font>)
00154 <font class="keywordflow">return</font> 0;
00155 <font class="keywordflow">else</font> colon++;
00156 }
00157 <font class="keywordflow">if</font> (colon != 1)
00158 <font class="keywordflow">return</font> 0;
00159 <font class="keywordflow">return</font> 1;
00160 }
00161
00162
00163 <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)
00164 {
00165 <font class="keywordtype">char</font> buf[7];
00166 <font class="keywordtype">char</font> buf2[20];
00167 <font class="keywordtype">char</font> ch;
00168 <font class="keywordtype">char</font> loop;
00169 <font class="keywordtype">long</font> offset2;
00170 <font class="keywordtype">int</font> ch2, vs2, rm2;
00171
00172 memset(buf, <font class="charliteral">' '</font>, 7);
00173
00174 <font class="keywordflow">while</font> (1) {
00175 <font class="keywordflow">if</font> (startentry(buf)) {
00176 buf[0] = <font class="charliteral">' '</font>;
00177 buf[1] = <font class="charliteral">' '</font>;
00178 sscanf(buf, <font class="stringliteral">"%d:%d"</font>, num1, num2);
00179 *rangemax = *num2;
00180 *offset = lseek(fp, 0, SEEK_CUR) - 5;
00181 <font class="keywordflow">if</font> (size) {
00182 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
00183 *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00184 }
00185 <font class="keywordflow">else</font> {
00186 <font class="keywordflow">if</font> (vs2) {
00187 *size = (offset2 - (*offset)) - 2;
00188 }
00189 <font class="keywordflow">else</font> {
00190 *size = (offset2 - (*offset)) - 6;
00191 }
00192 }
00193 lseek(fp, *offset, SEEK_SET);
00194 }
00195 <font class="keywordflow">return</font> 0;
00196 }
00197
00198 <font class="keywordflow">if</font> (!strncmp(buf, <font class="stringliteral">"$-$-$-"</font>, 6)) {
00199 *offset = lseek(fp, 0, SEEK_CUR) - 1;
00200 *num2 = 0;
00201 (*num1)++;
00202 printf(<font class="stringliteral">"Book marker: %s\n"</font>, buf2);
00203 <font class="keywordflow">if</font> (size) {
00204 <font class="keywordflow">if</font> (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
00205 *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00206 }
00207 <font class="keywordflow">else</font> {
00208 <font class="keywordflow">if</font> (vs2) {
00209 *size = (offset2 - (*offset)) - 2;
00210 }
00211 <font class="keywordflow">else</font> {
00212 *size = (offset2 - (*offset)) - 6;
00213 }
00214 }
00215 lseek(fp, *offset, SEEK_SET);
00216 }
00217 <font class="keywordflow">return</font> 0;
00218 }
00219
00220
00221 memmove(buf, &buf[1], 6);
00222 <font class="keywordflow">if</font> (read(fp, &buf[6], 1) != 1)
00223 <font class="keywordflow">return</font> 1;
00224 }
00225 }
00226
00227
00228 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname)
00229 {
00230 <font class="keywordtype">char</font> buf[255];
00231
00232 <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY)) == -1) {
00233 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00234 exit(1);
00235 }
00236
00237 sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00238 <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00239 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00240 exit(1);
00241 }
00242
00243 sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00244 <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00245 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00246 exit(1);
00247 }
00248
00249 sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00250 <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00251 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00252 exit(1);
00253 }
00254 }
00255
00256
00257 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00258 {
00259 <font class="keywordflow">if</font> (argc < 2) {
00260 fprintf(stderr, <font class="stringliteral">"usage: %s <file to process> [nt - for new testmt file]\n"</font>, argv[0]);
00261 exit(1);
00262 }
00263 <font class="keywordflow">if</font> (argc == 3)
00264 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>;
00265 <font class="keywordflow">else</font> key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00266 }
</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>