aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/nuidx_8cpp-source.html
blob: cf643508a50e171a2199872a0d704049f2fb9e49 (plain) (tree)



























































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
<!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>nuidx.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>nuidx.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 &lt;stdio.h&gt;</font>
00007 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00008 <font class="preprocessor">#include &lt;string.h&gt;</font>
00009 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00010 
00011 <font class="preprocessor">#ifndef __GNUC__</font>
00012 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00013 <font class="preprocessor">#else</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00015 <font class="preprocessor">#endif</font>
00016 <font class="preprocessor"></font>
00017 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00018 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00019 
00020 
00021 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;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         num1 = key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00047         num2 = key1.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00048         pos  = 0;
00049         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00050         pos = 4;
00051         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00052 
00053 
00054 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00055         pos = 0;
00056         size = 0;
00057         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00058         write(vfp, &amp;size, 2);
00059         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00060         write(vfp, &amp;size, 2);
00061 
00062         <font class="keywordflow">while</font>(!findbreak(fp, &amp;offset, &amp;num1, &amp;num2, &amp;rangemax, &amp;size)) {
00063                 writeidx(key1, key2, key3, offset, size);
00064                 key2++;
00065                 key3 = key2;
00066         }
00067         close(vfp);
00068         close(cfp);
00069         close(bfp);
00070         close(fp);
00071 }
00072 
00073 
00074 <font class="comment">/**************************************************************************</font>
00075 <font class="comment"> * ENT: key1    - current location of index</font>
00076 <font class="comment"> *      key2    - minimum keyval for which this offset is valid</font>
00077 <font class="comment"> *      key3    - maximum keyval for which this offset is valid</font>
00078 <font class="comment"> */</font>
00079 
00080 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size)
00081 {
00082         <font class="keywordtype">long</font> pos;
00083         <font class="keywordtype">short</font> tmp;
00084 
00085         <font class="keywordflow">for</font> (; ((key1 &lt;= key3) &amp;&amp; (key1.<a class="code" href="class_s_w_key.html#a6">Error</a>() != KEYERR_OUTOFBOUNDS) &amp;&amp; (key1.<a class="code" href="class_verse_key.html#a22">Testament</a>() == testmnt)); key1+=1) {
00086                 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) {        <font class="comment">// new chapter</font>
00087                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) {      <font class="comment">// new book</font>
00088                                 pos = lseek(cfp, 0, SEEK_CUR);
00089                                 write(bfp, &amp;pos, 4);
00090                                 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00091                                 write(cfp, &amp;pos, 4);
00092                                 write(vfp, &amp;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>
00093                                 write(vfp, &amp;chapsize, 2);
00094                         }
00095                         pos = lseek(vfp, 0, SEEK_CUR);
00096                         write(cfp, &amp;pos, 4);
00097                         write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Chapter intro */</font>
00098                         write(vfp, &amp;chapsize, 2);
00099                 }
00100                 <font class="keywordflow">if</font> (key1 &gt;= key2) {
00101                         write(vfp, &amp;offset, 4);
00102                         write(vfp, &amp;size, 2);
00103                 }
00104                 <font class="keywordflow">else</font>    {
00105                         pos = 0;
00106                         tmp = 0;
00107                         write(vfp, &amp;pos, 4);
00108                         write(vfp, &amp;tmp, 2);
00109                 }
00110         }
00111 }
00112 
00113 
00114 <font class="keywordtype">char</font> startchap(<font class="keywordtype">char</font> *buf)
00115 {
00116         <font class="keywordtype">char</font> loop;
00117 
00118         <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'&lt;'</font>)
00119                 <font class="keywordflow">return</font> 0;
00120         <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>)
00121                 <font class="keywordflow">return</font> 0;
00122         <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'C'</font>)
00123                 <font class="keywordflow">return</font> 0;
00124 <font class="comment">/*</font>
00125 <font class="comment">        if (!isdigit(buf[2]))</font>
00126 <font class="comment">                return 0;</font>
00127 <font class="comment">        for (loop = 3; loop &lt; 7; loop++) {</font>
00128 <font class="comment">                if (buf[loop] == ' ')</font>
00129 <font class="comment">                        break;</font>
00130 <font class="comment">                if ((!isdigit(buf[loop])) &amp;&amp; (buf[loop] != ',') &amp;&amp; (buf[loop] != '-'))</font>
00131 <font class="comment">                        return 0;</font>
00132 <font class="comment">        }</font>
00133 <font class="comment">*/</font>
00134         <font class="keywordflow">return</font> 1;
00135 }
00136 
00137 
00138 <font class="keywordtype">char</font> startentry(<font class="keywordtype">char</font> *buf)
00139 {
00140         <font class="keywordtype">char</font> loop;
00141 
00142         <font class="keywordflow">if</font> (buf[0] != <font class="charliteral">'&lt;'</font>)
00143                 <font class="keywordflow">return</font> 0;
00144         <font class="keywordflow">if</font> (buf[1] != <font class="charliteral">'S'</font>)
00145                 <font class="keywordflow">return</font> 0;
00146         <font class="keywordflow">if</font> (buf[2] != <font class="charliteral">'V'</font>)
00147                 <font class="keywordflow">return</font> 0;
00148 <font class="comment">/*</font>
00149 <font class="comment">        if (!isdigit(buf[2]))</font>
00150 <font class="comment">                return 0;</font>
00151 <font class="comment">        for (loop = 3; loop &lt; 7; loop++) {</font>
00152 <font class="comment">                if (buf[loop] == ' ')</font>
00153 <font class="comment">                        break;</font>
00154 <font class="comment">                if ((!isdigit(buf[loop])) &amp;&amp; (buf[loop] != ',') &amp;&amp; (buf[loop] != '-'))</font>
00155 <font class="comment">                        return 0;</font>
00156 <font class="comment">        }</font>
00157 <font class="comment">*/</font>
00158         <font class="keywordflow">return</font> 1;
00159 }
00160 
00161 
00162 <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)
00163 {
00164         <font class="keywordtype">char</font> buf[7];
00165         <font class="keywordtype">char</font> buf2[20];
00166         <font class="keywordtype">char</font> ch;
00167         <font class="keywordtype">char</font> loop;
00168         <font class="keywordtype">long</font> offset2;
00169         <font class="keywordtype">int</font> ch2, vs2, rm2;
00170         <font class="keywordtype">bool</font> flag;
00171         <font class="keywordtype">long</font> chapstart = 0; 
00172         
00173         memset(buf, <font class="charliteral">' '</font>, 7);
00174 
00175         <font class="keywordflow">while</font> (1) {
00176                 <font class="keywordflow">if</font> (startentry(buf)) {
00177                         <font class="keywordflow">if</font> (size)
00178                                 *offset = lseek(fp, 0, SEEK_CUR) - 3;
00179                         <font class="keywordflow">else</font>    *offset = lseek(fp, 0, SEEK_CUR) - 7;
00180                         <font class="keywordflow">if</font> (size) {
00181                                 ch2 = *num1;
00182                                 vs2 = *num2;
00183                                 <font class="keywordflow">if</font> (findbreak(fp, &amp;offset2, &amp;ch2, &amp;vs2, &amp;rm2, 0)) {
00184                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00185                                 }
00186                                 <font class="keywordflow">else</font> {
00187                                         *size = (offset2 - (*offset));
00188                                 }
00189                                 lseek(fp, *offset, SEEK_SET);
00190                         }
00191                         <font class="keywordflow">return</font> 0;
00192                 }
00193                 memmove(buf, &amp;buf[1], 6);
00194                 <font class="keywordflow">if</font> (read(fp, &amp;buf[6], 1) != 1)
00195                         <font class="keywordflow">return</font> 1;
00196         }
00197 }
00198 
00199 
00200 <font class="keywordtype">void</font> openfiles(<font class="keywordtype">char</font> *fname)
00201 {
00202         <font class="keywordtype">char</font> buf[255];
00203 
00204         <font class="keywordflow">if</font> ((fp = open(fname, O_RDONLY)) == -1) {
00205                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00206                 exit(1);
00207         }
00208 
00209         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00210         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00211                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00212                 exit(1);
00213         }
00214 
00215         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00216         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00217                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00218                 exit(1);
00219         }
00220 
00221         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00222         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00223                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00224                 exit(1);
00225         }
00226 }
00227 
00228 
00229 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00230 {
00231         <font class="keywordflow">if</font> (argc &lt; 2) {
00232                 fprintf(stderr, <font class="stringliteral">"usage: %s &lt;file to process&gt; [nt - for new testmt file]\n"</font>, argv[0]);
00233                 exit(1);
00234         }
00235         <font class="keywordflow">if</font> (argc == 3)
00236                 key1 = key2 = key3 = <font class="stringliteral">"Matthew 1:1"</font>;
00237         <font class="keywordflow">else</font>    key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00238 }
</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>