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