Sophie

Sophie

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

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>zcom.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>zcom.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  rawcom.cpp - code for class 'zCom'- a module that reads raw commentary</font>
00003 <font class="comment"> *                      files:  ot and nt using indexs ??.bks ??.cps ??.vss</font>
00004 <font class="comment"> */</font>
00005 
00006 
00007 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00008 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00009 <font class="preprocessor">#include &lt;fcntl.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;string.h&gt;</font>
00018 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00019 <font class="preprocessor">#include &lt;zverse.h&gt;</font>
00020 <font class="preprocessor">#include &lt;zcom.h&gt;</font>
00021 
00022 
00023 <font class="comment">/******************************************************************************</font>
00024 <font class="comment"> * zCom Constructor - Initializes data for instance of zCom</font>
00025 <font class="comment"> *</font>
00026 <font class="comment"> * ENT: ipath - path to data files</font>
00027 <font class="comment"> *              iname - Internal name for module</font>
00028 <font class="comment"> *              idesc - Name to display to user for module</font>
00029 <font class="comment"> *              iblockType - verse, chapter, book, etc. of index chunks</font>
00030 <font class="comment"> *              icomp - Compressor object</font>
00031 <font class="comment"> *              idisp - Display object to use for displaying</font>
00032 <font class="comment"> */</font>
00033 
00034 zCom::zCom(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keyword">const</font> <font class="keywordtype">char</font> *iname, <font class="keyword">const</font> <font class="keywordtype">char</font> *idesc, <font class="keywordtype">int</font> iblockType, SWCompress *icomp, <a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, <font class="keyword">const</font> <font class="keywordtype">char</font>* ilang) : zVerse(ipath, -1, iblockType, icomp), <a class="code" href="class_s_w_com.html">SWCom</a>(iname, idesc, idisp, enc, dir, mark, ilang)<font class="comment">/*, SWCompress()*/</font>
00035 {
00036         blockType = iblockType;
00037         lastWriteKey = 0;
00038 }
00039 
00040 <font class="comment">/******************************************************************************</font>
00041 <font class="comment"> * zCom Destructor - Cleans up instance of zCom</font>
00042 <font class="comment"> */</font>
00043 
00044 zCom::~zCom() {
00045         flushCache();
00046 
00047         <font class="keywordflow">if</font> (lastWriteKey)
00048                 <font class="keyword">delete</font> lastWriteKey;
00049 }
00050 
00051 <font class="comment">/******************************************************************************</font>
00052 <font class="comment"> * zCom::operator char *        - Returns the correct verse when char * cast</font>
00053 <font class="comment"> *                                      is requested</font>
00054 <font class="comment"> *</font>
00055 <font class="comment"> * RET: string buffer with verse</font>
00056 <font class="comment"> */</font>
00057 <font class="keywordtype">char</font> *zCom::getRawEntry() {
00058         <font class="keywordtype">long</font>  start = 0;
00059         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size = 0;
00060         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00061 
00062 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00063 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00064 <font class="preprocessor">#endif</font>
00065 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00066 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00067 <font class="preprocessor"></font>        }
00068         <font class="keywordflow">catch</font> ( ... ) {}
00069 <font class="preprocessor">#endif</font>
00070 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00071         <font class="keywordflow">if</font> (!key)
00072                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(this-&gt;key);
00073 
00074         findoffset(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00075         entrySize = size;        <font class="comment">// support getEntrySize call</font>
00076 
00077         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> newsize = (size + 2) * FILTERPAD;
00078         <font class="keywordflow">if</font> (newsize &gt; entrybufallocsize) {
00079                 <font class="keywordflow">if</font> (entrybuf)
00080                         <font class="keyword">delete</font> [] entrybuf;
00081                 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ newsize ];
00082                 entrybufallocsize = newsize;
00083         }
00084         *entrybuf = 0;
00085 
00086         swgettext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), start, (size + 2), entrybuf);
00087 
00088         rawFilter(entrybuf, size, key);
00089 
00090         <font class="keywordflow">if</font> (!isUnicode())
00091                 preptext(entrybuf);
00092 
00093         <font class="keywordflow">if</font> (this-&gt;key != key) <font class="comment">// free our key if we created a VerseKey</font>
00094                 <font class="keyword">delete</font> key;
00095 
00096         <font class="keywordflow">return</font> entrybuf;
00097 }
00098 
00099 
00100 <font class="keywordtype">bool</font> zCom::sameBlock(<a class="code" href="class_verse_key.html">VerseKey</a> *k1, <a class="code" href="class_verse_key.html">VerseKey</a> *k2) {
00101         <font class="keywordflow">if</font> (k1-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>() != k2-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>())
00102                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00103 
00104         <font class="keywordflow">switch</font> (blockType) {
00105         <font class="keywordflow">case</font> VERSEBLOCKS:
00106                 <font class="keywordflow">if</font> (k1-&gt;<a class="code" href="class_verse_key.html#a25">Verse</a>() != k2-&gt;<a class="code" href="class_verse_key.html#a25">Verse</a>())
00107                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00108         <font class="keywordflow">case</font> CHAPTERBLOCKS:
00109                 <font class="keywordflow">if</font> (k1-&gt;<a class="code" href="class_verse_key.html#a24">Chapter</a>() != k2-&gt;<a class="code" href="class_verse_key.html#a24">Chapter</a>())
00110                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00111         <font class="keywordflow">case</font> BOOKBLOCKS:
00112                 <font class="keywordflow">if</font> (k1-&gt;<a class="code" href="class_verse_key.html#a23">Book</a>() != k2-&gt;<a class="code" href="class_verse_key.html#a23">Book</a>())
00113                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
00114         }
00115         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00116 }
00117 
00118 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zCom::setentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf, <font class="keywordtype">long</font> len) {
00119         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00120         <font class="comment">// see if we have a VerseKey * or decendant</font>
00121 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00122 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00123 <font class="preprocessor">#endif</font>
00124 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00125 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00126 <font class="preprocessor"></font>        }
00127         <font class="keywordflow">catch</font> ( ... ) {}
00128 <font class="preprocessor">#endif</font>
00129 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00130         <font class="keywordflow">if</font> (!key)
00131                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(this-&gt;key);
00132 
00133 
00134         <font class="comment">// see if we've jumped across blocks since last write</font>
00135         <font class="keywordflow">if</font> (lastWriteKey) {
00136                 <font class="keywordflow">if</font> (!sameBlock(lastWriteKey, key)) {
00137                         flushCache();
00138                 }
00139                 <font class="keyword">delete</font> lastWriteKey;
00140         }
00141 
00142         settext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), inbuf, len);
00143 
00144         lastWriteKey = (<a class="code" href="class_verse_key.html">VerseKey</a> *)key-&gt;<a class="code" href="class_verse_key.html#a10">clone</a>();        <font class="comment">// must delete</font>
00145 
00146         <font class="keywordflow">if</font> (this-&gt;key != key) <font class="comment">// free our key if we created a VerseKey</font>
00147                 <font class="keyword">delete</font> key;
00148 
00149         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00150 }
00151 
00152 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zCom::operator &lt;&lt;(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) {
00153         <font class="keywordflow">return</font> setentry(inbuf, 0);
00154 }
00155 
00156 
00157 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zCom::operator &lt;&lt;(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) {
00158         <a class="code" href="class_verse_key.html">VerseKey</a> *destkey = 0;
00159         <font class="keyword">const</font> <a class="code" href="class_verse_key.html">VerseKey</a> *srckey = 0;
00160         <font class="comment">// see if we have a VerseKey * or decendant</font>
00161 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00162 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00163 <font class="preprocessor">#endif</font>
00164 <font class="preprocessor"></font>                destkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00165 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00166 <font class="preprocessor"></font>        }
00167         <font class="keywordflow">catch</font> ( ... ) {}
00168 <font class="preprocessor">#endif</font>
00169 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00170         <font class="keywordflow">if</font> (!destkey)
00171                 destkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(this-&gt;key);
00172 
00173         <font class="comment">// see if we have a VerseKey * or decendant</font>
00174 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00175 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00176 <font class="preprocessor">#endif</font>
00177 <font class="preprocessor"></font>                srckey = (<font class="keyword">const</font> <a class="code" href="class_verse_key.html">VerseKey</a> *) SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, inkey);
00178 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00179 <font class="preprocessor"></font>        }
00180         <font class="keywordflow">catch</font> ( ... ) {
00181         }
00182 <font class="preprocessor">#endif</font>
00183 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00184         <font class="keywordflow">if</font> (!srckey)
00185                 srckey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(inkey);
00186 
00187         linkentry(destkey-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), destkey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), srckey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>());
00188 
00189         <font class="keywordflow">if</font> (this-&gt;key != destkey) <font class="comment">// free our key if we created a VerseKey</font>
00190                 <font class="keyword">delete</font> destkey;
00191 
00192         <font class="keywordflow">if</font> (inkey != srckey) <font class="comment">// free our key if we created a VerseKey</font>
00193                 <font class="keyword">delete</font> srckey;
00194 
00195         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00196 }
00197 
00198 <font class="comment">/******************************************************************************</font>
00199 <font class="comment"> * zCom::deleteEntry    - deletes this entry</font>
00200 <font class="comment"> *</font>
00201 <font class="comment"> * RET: *this</font>
00202 <font class="comment"> */</font>
00203 
00204 <font class="keywordtype">void</font> zCom::deleteEntry() {
00205 
00206         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00207 
00208 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00209 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00210 <font class="preprocessor">#endif</font>
00211 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00212 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00213 <font class="preprocessor"></font>        }
00214         <font class="keywordflow">catch</font> ( ... ) {}
00215 <font class="preprocessor">#endif</font>
00216 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00217                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(this-&gt;key);
00218 
00219         settext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), <font class="stringliteral">""</font>);
00220 
00221         <font class="keywordflow">if</font> (key != this-&gt;key)
00222                 <font class="keyword">delete</font> key;
00223 }
00224 
00225 
00226 <font class="comment">/******************************************************************************</font>
00227 <font class="comment"> * zCom::operator +=    - Increments module key a number of entries</font>
00228 <font class="comment"> *</font>
00229 <font class="comment"> * ENT: increment       - Number of entries to jump forward</font>
00230 <font class="comment"> *</font>
00231 <font class="comment"> * RET: *this</font>
00232 <font class="comment"> */</font>
00233 
00234 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zCom::operator +=(<font class="keywordtype">int</font> increment) {
00235         <font class="keywordtype">long</font>  start;
00236         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00237         <a class="code" href="class_verse_key.html">VerseKey</a> *tmpkey = 0;
00238 
00239 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00240 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00241 <font class="preprocessor">#endif</font>
00242 <font class="preprocessor"></font>                tmpkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, key);
00243 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00244 <font class="preprocessor"></font>        }
00245         <font class="keywordflow">catch</font> ( ... ) {}
00246 <font class="preprocessor">#endif</font>
00247 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!tmpkey)
00248                 tmpkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(key);
00249 
00250         findoffset(tmpkey-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), tmpkey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00251 
00252         <a class="code" href="class_s_w_key.html">SWKey</a> lastgood = *tmpkey;
00253         <font class="keywordflow">while</font> (increment) {
00254                 <font class="keywordtype">long</font> laststart = start;
00255                 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> lastsize = size;
00256                 <a class="code" href="class_s_w_key.html">SWKey</a> lasttry = *tmpkey;
00257                 (<a class="code" href="class_verse_key.html#a18">increment</a> &gt; 0) ? (*key)++ : (*key)--;
00258                 <font class="keywordflow">if</font> (tmpkey != key)
00259                         <font class="keyword">delete</font> tmpkey;
00260                 tmpkey = 0;
00261 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00262 <font class="preprocessor"></font>                <font class="keywordflow">try</font> {
00263 <font class="preprocessor">#endif</font>
00264 <font class="preprocessor"></font>                        tmpkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, key);
00265 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00266 <font class="preprocessor"></font>                }
00267                 <font class="keywordflow">catch</font> ( ... ) {}
00268 <font class="preprocessor">#endif</font>
00269 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (!tmpkey)
00270                         tmpkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html#a0">VerseKey</a>(key);
00271 
00272                 <font class="keywordflow">if</font> ((error = key-&gt;Error())) {
00273                         *key = lastgood;
00274                         <font class="keywordflow">break</font>;
00275                 }
00276                 <font class="keywordtype">long</font> index = tmpkey-&gt;<a class="code" href="class_s_w_key.html#a17">Index</a>();
00277                 findoffset(tmpkey-&gt;Testament(), index, &amp;start, &amp;size);
00278                 <font class="keywordflow">if</font> ((((laststart != start) || (lastsize != size))||(!skipConsecutiveLinks)) &amp;&amp; (start &gt;= 0) &amp;&amp; (size)) {
00279                         <a class="code" href="class_verse_key.html#a18">increment</a> += (<a class="code" href="class_verse_key.html#a18">increment</a> &lt; 0) ? 1 : -1;
00280                         lastgood = *tmpkey;
00281                 }
00282         }
00283         error = (error) ? KEYERR_OUTOFBOUNDS : 0;
00284 
00285         <font class="keywordflow">if</font> (tmpkey != key)
00286                 <font class="keyword">delete</font> tmpkey;
00287 
00288         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00289 }
00290 
</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>