Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a74ec78bdb789d910d054e3918f3f007 > files > 602

libsword1-devel-1.5.5-2mdk.ppc.rpm

<!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>zverse.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>zverse.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  zverse.h   - code for class 'zVerse'- a module that reads raw text</font>
00003 <font class="comment"> *                              files:  ot and nt using indexs ??.bks ??.cps ??.vss</font>
00004 <font class="comment"> *                              and provides lookup and parsing functions based on</font>
00005 <font class="comment"> *                              class VerseKey for compressed modules</font>
00006 <font class="comment"> */</font>
00007 
00008 
00009 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00010 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00011 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00012 <font class="preprocessor">#include &lt;errno.h&gt;</font>
00013 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00014 
00015 <font class="preprocessor">#ifndef __GNUC__</font>
00016 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00017 <font class="preprocessor">#else</font>
00018 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00019 <font class="preprocessor">#endif</font>
00020 <font class="preprocessor"></font>
00021 <font class="preprocessor">#include &lt;string.h&gt;</font>
00022 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00023 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00024 <font class="preprocessor">#include &lt;zverse.h&gt;</font>
00025 <font class="preprocessor">#include &lt;sysdata.h&gt;</font>
00026 
00027 
00028 <font class="preprocessor">#ifndef O_BINARY</font>
00029 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00030 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00031 <font class="preprocessor"></font>
00032 
00033 <font class="comment">/******************************************************************************</font>
00034 <font class="comment"> * zVerse Statics</font>
00035 <font class="comment"> */</font>
00036 
00037 <font class="keywordtype">int</font> zVerse::instance = 0;
00038 
00039 <font class="keyword">const</font> <font class="keywordtype">char</font> zVerse::uniqueIndexID[] = {<font class="charliteral">'X'</font>, <font class="charliteral">'r'</font>, <font class="charliteral">'v'</font>, <font class="charliteral">'c'</font>, <font class="charliteral">'b'</font>};
00040 
00041 <font class="comment">/******************************************************************************</font>
00042 <font class="comment"> * zVerse Constructor - Initializes data for instance of zVerse</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * ENT: ipath - path of the directory where data and index files are located.</font>
00045 <font class="comment"> *              be sure to include the trailing separator (e.g. '/' or '\')</font>
00046 <font class="comment"> *              (e.g. 'modules/texts/rawtext/webster/')</font>
00047 <font class="comment"> *              fileMode - open mode for the files (O_RDONLY, etc.)</font>
00048 <font class="comment"> *              blockType - verse, chapter, book, etc.</font>
00049 <font class="comment"> */</font>
00050 
00051 zVerse::zVerse(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keywordtype">int</font> fileMode, <font class="keywordtype">int</font> blockType, SWCompress *icomp)
00052 {
00053         <font class="keywordtype">char</font> buf[127];
00054 
00055         nl = <font class="charliteral">'\n'</font>;
00056         path = 0;
00057         cacheBufIdx = -1;
00058         cacheTestament = 0;
00059         cacheBuf = 0;
00060         dirtyCache = <font class="keyword">false</font>;
00061         stdstr(&amp;path, ipath);
00062 
00063         <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>))
00064                 path[strlen(path)-1] = 0;
00065 
00066         compressor = (icomp) ? icomp : <font class="keyword">new</font> SWCompress();
00067 
00068         <font class="keywordflow">if</font> (fileMode == -1) { <font class="comment">// try read/write if possible</font>
00069                 fileMode = O_RDWR;
00070         }
00071                 
00072         sprintf(buf, <font class="stringliteral">"%s/ot.%czs"</font>, path, uniqueIndexID[blockType]);
00073         idxfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00074 
00075         sprintf(buf, <font class="stringliteral">"%s/nt.%czs"</font>, path, uniqueIndexID[blockType]);
00076         idxfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00077 
00078         sprintf(buf, <font class="stringliteral">"%s/ot.%czz"</font>, path, uniqueIndexID[blockType]);
00079         textfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00080 
00081         sprintf(buf, <font class="stringliteral">"%s/nt.%czz"</font>, path, uniqueIndexID[blockType]);
00082         textfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00083 
00084         sprintf(buf, <font class="stringliteral">"%s/ot.%czv"</font>, path, uniqueIndexID[blockType]);
00085         compfp[0] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00086 
00087         sprintf(buf, <font class="stringliteral">"%s/nt.%czv"</font>, path, uniqueIndexID[blockType]);
00088         compfp[1] = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00089         
00090         <a class="code" href="class_verse_key.html#r3">instance</a>++;
00091 }
00092 
00093 
00094 <font class="comment">/******************************************************************************</font>
00095 <font class="comment"> * zVerse Destructor - Cleans up instance of zVerse</font>
00096 <font class="comment"> */</font>
00097 
00098 zVerse::~zVerse()
00099 {
00100         <font class="keywordtype">int</font> loop1;
00101 
00102         <font class="keywordflow">if</font> (cacheBuf) {
00103                 flushCache();
00104                 free(cacheBuf);
00105         }
00106 
00107         <font class="keywordflow">if</font> (path)
00108                 <font class="keyword">delete</font> [] path;
00109 
00110         <font class="keywordflow">if</font> (compressor)
00111                 <font class="keyword">delete</font> compressor;
00112 
00113         --<a class="code" href="class_verse_key.html#r3">instance</a>;
00114 
00115         <font class="keywordflow">for</font> (loop1 = 0; loop1 &lt; 2; loop1++) {
00116                 FileMgr::systemFileMgr.close(idxfp[loop1]);
00117                 FileMgr::systemFileMgr.close(textfp[loop1]);
00118                 FileMgr::systemFileMgr.close(compfp[loop1]);
00119         }
00120 }
00121 
00122 
00123 <font class="comment">/******************************************************************************</font>
00124 <font class="comment"> * zVerse::findoffset   - Finds the offset of the key verse from the indexes</font>
00125 <font class="comment"> *</font>
00126 <font class="comment"> *</font>
00127 <font class="comment"> *</font>
00128 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00129 <font class="comment"> *      book    - book      to find (0 - testament    introduction)</font>
00130 <font class="comment"> *      chapter - chapter   to find (0 - book         introduction)</font>
00131 <font class="comment"> *      verse   - verse     to find (0 - chapter      introduction)</font>
00132 <font class="comment"> *      start   - address to store the starting offset</font>
00133 <font class="comment"> *      size    - address to store the size of the entry</font>
00134 <font class="comment"> */</font>
00135 
00136 <font class="keywordtype">void</font> zVerse::findoffset(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> idxoff, <font class="keywordtype">long</font> *start, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *size)
00137 {
00138         <font class="comment">// set start to offset in</font>
00139         <font class="comment">// set size to</font>
00140         <font class="comment">// set</font>
00141         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulBuffNum=0;                <font class="comment">// buffer number</font>
00142         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulVerseStart=0;          <font class="comment">// verse offset within buffer</font>
00143         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> usVerseSize=0;          <font class="comment">// verse size</font>
00144         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulCompOffset=0;          <font class="comment">// compressed buffer start</font>
00145         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulCompSize=0;                  <font class="comment">// buffer size compressed</font>
00146         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ulUnCompSize=0;             <font class="comment">// buffer size uncompressed</font>
00147         <font class="keywordtype">char</font> *pcCompText=NULL;                                   <font class="comment">// compressed text</font>
00148 
00149         *start = *size = 0;
00150         <font class="comment">//printf ("Finding offset %ld\n", idxoff);</font>
00151         idxoff *= 10;
00152         <font class="keywordflow">if</font> (!testmt) {
00153                 testmt = ((idxfp[0]) ? 1:2);
00154         }
00155         
00156         <font class="comment">// assert we have and valid file descriptor</font>
00157         <font class="keywordflow">if</font> (compfp[testmt-1]-&gt;getFd() &lt; 1)
00158                 <font class="keywordflow">return</font>;
00159                 
00160         <font class="keywordtype">long</font> newOffset = lseek(compfp[testmt-1]-&gt;getFd(), idxoff, SEEK_SET);
00161         <font class="keywordflow">if</font> (newOffset == idxoff) {
00162                 <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;ulBuffNum, 4) != 4) {
00163                         printf (<font class="stringliteral">"Error reading ulBuffNum\n"</font>);
00164                         <font class="keywordflow">return</font>;
00165                 }
00166         }
00167         <font class="keywordflow">else</font> <font class="keywordflow">return</font>;
00168 
00169         ulBuffNum = swordtoarch32(ulBuffNum);
00170 
00171         <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;ulVerseStart, 4) &lt; 2)
00172         {
00173                 printf (<font class="stringliteral">"Error reading ulVerseStart\n"</font>);
00174                 <font class="keywordflow">return</font>;
00175         }
00176         <font class="keywordflow">if</font> (read(compfp[testmt-1]-&gt;getFd(), &amp;usVerseSize, 2) &lt; 2)
00177         {
00178                 printf (<font class="stringliteral">"Error reading usVerseSize\n"</font>);
00179                 <font class="keywordflow">return</font>;
00180         }
00181 
00182         *start = swordtoarch32(ulVerseStart);
00183         *size = swordtoarch16(usVerseSize);
00184 
00185         <font class="keywordflow">if</font> (*size) {
00186                 <font class="keywordflow">if</font> (((long) ulBuffNum == cacheBufIdx) &amp;&amp; (testmt == cacheTestament) &amp;&amp; (cacheBuf)) {
00187                         <font class="comment">// have the text buffered</font>
00188                         <font class="keywordflow">return</font>;
00189                 }
00190 
00191                 <font class="comment">//printf ("Got buffer number{%ld} versestart{%ld} versesize{%d}\n", ulBuffNum, ulVerseStart, usVerseSize);</font>
00192 
00193 
00194                 <font class="keywordflow">if</font> (lseek(idxfp[testmt-1]-&gt;getFd(), ulBuffNum*12, SEEK_SET)!=(long) ulBuffNum*12)
00195                 {
00196                         printf (<font class="stringliteral">"Error seeking compressed file index\n"</font>);
00197                         <font class="keywordflow">return</font>;
00198                 }
00199                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulCompOffset, 4)&lt;4)
00200                 {
00201                         printf (<font class="stringliteral">"Error reading ulCompOffset\n"</font>);
00202                         <font class="keywordflow">return</font>;
00203                 }
00204                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulCompSize, 4)&lt;4)
00205                 {
00206                         printf (<font class="stringliteral">"Error reading ulCompSize\n"</font>);
00207                         <font class="keywordflow">return</font>;
00208                 }
00209                 <font class="keywordflow">if</font> (read(idxfp[testmt-1]-&gt;getFd(), &amp;ulUnCompSize, 4)&lt;4)
00210                 {
00211                         printf (<font class="stringliteral">"Error reading ulUnCompSize\n"</font>);
00212                         <font class="keywordflow">return</font>;
00213                 }
00214 
00215                 ulCompOffset  = swordtoarch32(ulCompOffset);
00216                 ulCompSize  = swordtoarch32(ulCompSize);
00217                 ulUnCompSize  = swordtoarch32(ulUnCompSize);
00218 
00219                 <font class="keywordflow">if</font> (lseek(textfp[testmt-1]-&gt;getFd(), ulCompOffset, SEEK_SET)!=(long)ulCompOffset)
00220                 {
00221                         printf (<font class="stringliteral">"Error: could not seek to right place in compressed text\n"</font>);
00222                         <font class="keywordflow">return</font>;
00223                 }
00224                 pcCompText = <font class="keyword">new</font> <font class="keywordtype">char</font>[ulCompSize];
00225 
00226                 <font class="keywordflow">if</font> (read(textfp[testmt-1]-&gt;getFd(), pcCompText, ulCompSize)&lt;(long)ulCompSize)
00227                 {
00228                         printf (<font class="stringliteral">"Error reading compressed text\n"</font>);
00229                         <font class="keywordflow">return</font>;
00230                 }
00231                 compressor-&gt;zBuf(&amp;ulCompSize, pcCompText);
00232 
00233                 <font class="keywordflow">if</font> (cacheBuf) {
00234                         flushCache();
00235                         free(cacheBuf);
00236                 }
00237                 
00238                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> len = 0;
00239                 compressor-&gt;Buf(0, &amp;len);
00240                 cacheBuf = (<font class="keywordtype">char</font> *)calloc(len + 1, 1);
00241                 memcpy(cacheBuf, compressor-&gt;Buf(), len);
00242 
00243                 cacheTestament = testmt;
00244                 cacheBufIdx = ulBuffNum;
00245         }
00246 }
00247 
00248 
00249 <font class="comment">/******************************************************************************</font>
00250 <font class="comment"> * zVerse::swgettext    - gets text at a given offset</font>
00251 <font class="comment"> *</font>
00252 <font class="comment"> * ENT: testmt  - testament file to search in (0 - Old; 1 - New)</font>
00253 <font class="comment"> *      start   - starting offset where the text is located in the file</font>
00254 <font class="comment"> *      size    - size of text entry + 1 (null)</font>
00255 <font class="comment"> *      buf     - buffer to store text</font>
00256 <font class="comment"> *</font>
00257 <font class="comment"> */</font>
00258 
00259 <font class="keywordtype">void</font> zVerse::swgettext(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> start, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size, <font class="keywordtype">char</font> *inbuf)
00260 {
00261         memset(inbuf, 0, size);
00262         <font class="keywordflow">if</font> (size &gt; 2) {
00263                 strncpy(inbuf, &amp;(cacheBuf[start]), size-2);
00264         }
00265 }
00266 
00267 
00268 <font class="comment">/******************************************************************************</font>
00269 <font class="comment"> * zVerse::settext      - Sets text for current offset</font>
00270 <font class="comment"> *</font>
00271 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00272 <font class="comment"> *      idxoff  - offset into .vss</font>
00273 <font class="comment"> *      buf     - buffer to store</font>
00274 <font class="comment"> *      len     - length of buffer (0 - null terminated)</font>
00275 <font class="comment"> */</font>
00276 
00277 <font class="keywordtype">void</font> zVerse::settext(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> idxoff, <font class="keyword">const</font> <font class="keywordtype">char</font> *buf, <font class="keywordtype">long</font> len)
00278 {
00279         <font class="keywordflow">if</font> (!testmt) 
00280                 testmt = ((idxfp[0]) ? 1:2);
00281         <font class="keywordflow">if</font> ((!dirtyCache) || (cacheBufIdx &lt; 0)) {
00282                 cacheBufIdx = lseek(idxfp[testmt-1]-&gt;getFd(), 0, SEEK_END) / 12;
00283                 cacheTestament = testmt;
00284                 <font class="keywordflow">if</font> (cacheBuf)
00285                         free(cacheBuf);
00286                 cacheBuf = (<font class="keywordtype">char</font> *)calloc(len ? len : strlen(buf)+1, 1);
00287         }
00288         <font class="keywordflow">else</font> cacheBuf = (<font class="keywordtype">char</font> *)((cacheBuf)?realloc(cacheBuf, strlen(cacheBuf)+(len ? len : strlen(buf)+1)):calloc((len ? len : strlen(buf)+1), 1));
00289 
00290         dirtyCache = <font class="keyword">true</font>;
00291 
00292         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> start, outstart;
00293         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> outBufIdx = cacheBufIdx;
00294         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00295         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> outsize;
00296 
00297         idxoff *= 10;
00298         size = outsize = len ? len : strlen(buf);
00299 
00300         start = strlen(cacheBuf);
00301 
00302         <font class="keywordflow">if</font> (!size)
00303                 start = outBufIdx = 0;
00304 
00305         outBufIdx = archtosword32(outBufIdx);
00306         outstart  = archtosword32(start);
00307         outsize   = archtosword16(size);
00308 
00309         lseek(compfp[testmt-1]-&gt;getFd(), idxoff, SEEK_SET);
00310         write(compfp[testmt-1]-&gt;getFd(), &amp;outBufIdx, 4);
00311         write(compfp[testmt-1]-&gt;getFd(), &amp;outstart, 4);
00312         write(compfp[testmt-1]-&gt;getFd(), &amp;outsize, 2);
00313         strcat(cacheBuf, buf);
00314 }
00315 
00316 
00317 <font class="keywordtype">void</font> zVerse::flushCache() {
00318         <font class="keywordflow">if</font> (dirtyCache) {
00319                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> idxoff;
00320                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> start, outstart;
00321                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> size, outsize;
00322                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> zsize, outzsize;
00323 
00324                 idxoff = cacheBufIdx * 12;
00325                 size = outsize = zsize = outzsize = strlen(cacheBuf);
00326                 <font class="keywordflow">if</font> (size) {
00327 <font class="comment">//                      if (compressor) {</font>
00328 <font class="comment">//                              delete compressor;</font>
00329 <font class="comment">//                              compressor = new LZSSCompress();</font>
00330 <font class="comment">//                      }</font>
00331                         compressor-&gt;Buf(cacheBuf);
00332                         compressor-&gt;zBuf(&amp;zsize);
00333                         outzsize = zsize;
00334 
00335                         start = outstart = lseek(textfp[cacheTestament-1]-&gt;getFd(), 0, SEEK_END);
00336 
00337                         outstart  = archtosword32(start);
00338                         outsize   = archtosword32(size);
00339                         outzsize  = archtosword32(zsize);
00340 
00341                         write(textfp[cacheTestament-1]-&gt;getFd(), compressor-&gt;zBuf(&amp;zsize), zsize);
00342 
00343                         lseek(idxfp[cacheTestament-1]-&gt;getFd(), idxoff, SEEK_SET);
00344                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outstart, 4);
00345                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outzsize, 4);
00346                         write(idxfp[cacheTestament-1]-&gt;getFd(), &amp;outsize, 4);
00347                 }
00348                 dirtyCache = <font class="keyword">false</font>;
00349         }
00350 }
00351 
00352 <font class="comment">/******************************************************************************</font>
00353 <font class="comment"> * RawVerse::linkentry  - links one entry to another</font>
00354 <font class="comment"> *</font>
00355 <font class="comment"> * ENT: testmt  - testament to find (0 - Bible/module introduction)</font>
00356 <font class="comment"> *      destidxoff      - dest offset into .vss</font>
00357 <font class="comment"> *      srcidxoff               - source offset into .vss</font>
00358 <font class="comment"> */</font>
00359 
00360 <font class="keywordtype">void</font> zVerse::linkentry(<font class="keywordtype">char</font> testmt, <font class="keywordtype">long</font> destidxoff, <font class="keywordtype">long</font> srcidxoff) {
00361         <font class="keywordtype">long</font> bufidx;
00362         <font class="keywordtype">long</font> start;
00363         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00364 
00365         destidxoff *= 10;
00366         srcidxoff  *= 10;
00367 
00368         <font class="keywordflow">if</font> (!testmt)
00369                 testmt = ((idxfp[1]) ? 1:2);
00370 
00371         <font class="comment">// get source</font>
00372         lseek(compfp[testmt-1]-&gt;getFd(), srcidxoff, SEEK_SET);
00373         read(compfp[testmt-1]-&gt;getFd(), &amp;bufidx, 4);
00374         read(compfp[testmt-1]-&gt;getFd(), &amp;start, 4);
00375         read(compfp[testmt-1]-&gt;getFd(), &amp;size, 2);
00376 
00377         <font class="comment">// write dest</font>
00378         lseek(compfp[testmt-1]-&gt;getFd(), destidxoff, SEEK_SET);
00379         write(compfp[testmt-1]-&gt;getFd(), &amp;bufidx, 4);
00380         write(compfp[testmt-1]-&gt;getFd(), &amp;start, 4);
00381         write(compfp[testmt-1]-&gt;getFd(), &amp;size, 2);
00382 }
00383 
00384 
00385 <font class="comment">/******************************************************************************</font>
00386 <font class="comment"> * RawVerse::CreateModule       - Creates new module files</font>
00387 <font class="comment"> *</font>
00388 <font class="comment"> * ENT: path    - directory to store module files</font>
00389 <font class="comment"> * RET: error status</font>
00390 <font class="comment"> */</font>
00391 
00392 <font class="keywordtype">char</font> zVerse::createModule(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keywordtype">int</font> blockBound)
00393 {
00394         <font class="keywordtype">char</font> *path = 0;
00395         <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ];
00396         FileDesc *fd, *fd2;
00397 
00398         stdstr(&amp;path, ipath);
00399 
00400         <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>))
00401                 path[strlen(path)-1] = 0;
00402 
00403         sprintf(buf, <font class="stringliteral">"%s/ot.%czs"</font>, path, uniqueIndexID[blockBound]);
00404         unlink(buf);
00405         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00406         fd-&gt;getFd();
00407         FileMgr::systemFileMgr.close(fd);
00408 
00409         sprintf(buf, <font class="stringliteral">"%s/nt.%czs"</font>, path, uniqueIndexID[blockBound]);
00410         unlink(buf);
00411         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00412         fd-&gt;getFd();
00413         FileMgr::systemFileMgr.close(fd);
00414 
00415         sprintf(buf, <font class="stringliteral">"%s/ot.%czz"</font>, path, uniqueIndexID[blockBound]);
00416         unlink(buf);
00417         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00418         fd-&gt;getFd();
00419         FileMgr::systemFileMgr.close(fd);
00420 
00421         sprintf(buf, <font class="stringliteral">"%s/nt.%czz"</font>, path, uniqueIndexID[blockBound]);
00422         unlink(buf);
00423         fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00424         fd2-&gt;getFd();
00425         FileMgr::systemFileMgr.close(fd);
00426 
00427         sprintf(buf, <font class="stringliteral">"%s/ot.%czv"</font>, path, uniqueIndexID[blockBound]);
00428         unlink(buf);
00429         fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00430         fd-&gt;getFd();
00431 
00432         sprintf(buf, <font class="stringliteral">"%s/nt.%czv"</font>, path, uniqueIndexID[blockBound]);
00433         unlink(buf);
00434         fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00435         fd2-&gt;getFd();
00436 
00437         <a class="code" href="class_verse_key.html">VerseKey</a> vk;
00438         vk.<a class="code" href="class_verse_key.html#a32">Headings</a>(1);
00439         <font class="keywordtype">long</font> offset = 0;
00440         <font class="keywordtype">short</font> size = 0;
00441         <font class="keywordflow">for</font> (vk = TOP; !vk.<a class="code" href="class_s_w_key.html#a6">Error</a>(); vk++) {
00442                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;offset, 4);  <font class="comment">//compBufIdxOffset</font>
00443                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;offset, 4);
00444                 write((vk.<a class="code" href="class_verse_key.html#a22">Testament</a>() == 1) ? fd-&gt;getFd() : fd2-&gt;getFd(), &amp;size, 2);
00445         }
00446 
00447         FileMgr::systemFileMgr.close(fd);
00448         FileMgr::systemFileMgr.close(fd2);
00449 
00450         <font class="keyword">delete</font> [] path;
00451 <font class="comment">/*</font>
00452 <font class="comment">        RawVerse rv(path);</font>
00453 <font class="comment">        VerseKey mykey("Rev 22:21");</font>
00454 <font class="comment">*/</font>
00455         
00456         <font class="keywordflow">return</font> 0;
00457 }
00458 
00459 
00460 <font class="comment">/******************************************************************************</font>
00461 <font class="comment"> * zVerse::preptext     - Prepares the text before returning it to external</font>
00462 <font class="comment"> *                              objects</font>
00463 <font class="comment"> *</font>
00464 <font class="comment"> * ENT: buf     - buffer where text is stored and where to store the prep'd</font>
00465 <font class="comment"> *                      text.</font>
00466 <font class="comment"> */</font>
00467 
00468 <font class="keywordtype">void</font> zVerse::preptext(<font class="keywordtype">char</font> *buf)
00469 {
00470         <font class="keywordtype">char</font> *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
00471 
00472         <font class="keywordflow">for</font> (to = from = buf; *from; from++) {
00473                 <font class="keywordflow">switch</font> (*from) {
00474                 <font class="keywordflow">case</font> 10:
00475                         <font class="keywordflow">if</font> (!realdata)
00476                                 <font class="keywordflow">continue</font>;
00477                         space = (cr) ? 0 : 1;
00478                         cr = 0;
00479                         nlcnt++;
00480                         <font class="keywordflow">if</font> (nlcnt &gt; 1) {
00481 <font class="comment">//                              *to++ = nl;</font>
00482                                 *to++ = nl;
00483 <font class="comment">//                              nlcnt = 0;</font>
00484                         }
00485                         <font class="keywordflow">continue</font>;
00486                 <font class="keywordflow">case</font> 13:
00487                         <font class="keywordflow">if</font> (!realdata)
00488                                 <font class="keywordflow">continue</font>;
00489                         *to++ = nl;
00490                         space = 0;
00491                         cr = 1;
00492                         <font class="keywordflow">continue</font>;
00493                 }
00494                 realdata = 1;
00495                 nlcnt = 0;
00496                 <font class="keywordflow">if</font> (space) {
00497                         space = 0;
00498                         <font class="keywordflow">if</font> (*from != <font class="charliteral">' '</font>) {
00499                                 *to++ = <font class="charliteral">' '</font>;
00500                                 from--;
00501                                 <font class="keywordflow">continue</font>;
00502                         }
00503                 }
00504                 *to++ = *from;
00505         }
00506         *to = 0;
00507 
00508      <font class="keywordflow">if</font> (to &gt; buf) {
00509           <font class="keywordflow">for</font> (to--; to &gt; buf; to--) {                  <font class="comment">// remove trailing excess</font>
00510                <font class="keywordflow">if</font> ((*to == 10) || (*to == <font class="charliteral">' '</font>))
00511                     *to = 0;
00512                <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00513           }
00514      }
00515 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 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>