Sophie

Sophie

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

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>zld.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>zld.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and</font>
00003 <font class="comment"> *                              dictionary files: *.dat *.idx</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;zstr.h&gt;</font>
00020 <font class="preprocessor">#include &lt;zld.h&gt;</font>
00021 
00022 
00023  <font class="comment">/******************************************************************************</font>
00024 <font class="comment"> * RawLD Constructor - Initializes data for instance of RawLD</font>
00025 <font class="comment"> *</font>
00026 <font class="comment"> * ENT: ipath   - path and filename of files (no extension)</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"> *              idisp   - Display object to use for displaying</font>
00030 <font class="comment"> */</font>
00031 
00032 zLD::zLD(<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">long</font> blockCount, 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) : zStr(ipath, -1, blockCount, icomp), <a class="code" href="class_s_w_l_d.html">SWLD</a>(iname, idesc, idisp, enc, dir, mark, ilang)
00033 {
00034 }
00035 
00036 
00037 <font class="comment">/******************************************************************************</font>
00038 <font class="comment"> * RawLD Destructor - Cleans up instance of RawLD</font>
00039 <font class="comment"> */</font>
00040 
00041 zLD::~zLD()
00042 {
00043 }
00044 
00045 
00046 <font class="comment">/******************************************************************************</font>
00047 <font class="comment"> * zLD::strongsPad      - Pads a key if it is 100% digits to 5 places</font>
00048 <font class="comment"> *</font>
00049 <font class="comment"> * ENT: buf -   buffer to check and pad</font>
00050 <font class="comment"> */</font>
00051 
00052 <font class="keywordtype">void</font> zLD::strongsPad(<font class="keywordtype">char</font> *buf)
00053 {
00054         <font class="keyword">const</font> <font class="keywordtype">char</font> *check;
00055         <font class="keywordtype">long</font> size = 0;
00056         <font class="keywordtype">int</font> len = strlen(buf);
00057         <font class="keywordflow">if</font> ((len &lt; 5) &amp;&amp; (len &gt; 0)) {
00058                 <font class="keywordflow">for</font> (check = buf; *check; check++) {
00059                         <font class="keywordflow">if</font> (!isdigit(*check))
00060                                 <font class="keywordflow">break</font>;
00061                         <font class="keywordflow">else</font> size++;
00062                 }
00063 
00064                 <font class="keywordflow">if</font> ((size == len) &amp;&amp; size) 
00065                         sprintf(buf, <font class="stringliteral">"%.5d"</font>, atoi(buf));
00066         }
00067 }
00068 
00069 
00070 <font class="comment">/******************************************************************************</font>
00071 <font class="comment"> * zLD::getEntry        - Looks up entry from data file.  'Snaps' to closest</font>
00072 <font class="comment"> *                              entry and sets 'entrybuf'.</font>
00073 <font class="comment"> *</font>
00074 <font class="comment"> * ENT: away - number of entries offset from key (default = 0)</font>
00075 <font class="comment"> *</font>
00076 <font class="comment"> * RET: error status</font>
00077 <font class="comment"> */</font>
00078 
00079 <font class="keywordtype">char</font> zLD::getEntry(<font class="keywordtype">long</font> away)
00080 {
00081         <font class="keywordtype">char</font> *idxbuf = 0;
00082         <font class="keywordtype">char</font> *ebuf = 0;
00083         <font class="keywordtype">char</font> retval = 0;
00084         <font class="keywordtype">long</font> index;
00085         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> size;
00086         <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(*key) + 6 ];
00087         strcpy(buf, *key);
00088 
00089         strongsPad(buf);
00090 
00091         *entrybuf = 0;
00092         <font class="keywordflow">if</font> (!(retval = findKeyIndex(buf, &amp;index, away))) {
00093                 <a class="code" href="class_verse_key.html#a11">getText</a>(index, &amp;idxbuf, &amp;ebuf);
00094                 size = strlen(ebuf) + 1;
00095                 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size * FILTERPAD ];
00096                 strcpy(entrybuf, ebuf);
00097 
00098                 entrySize = size;        <font class="comment">// support getEntrySize call</font>
00099                 <font class="keywordflow">if</font> (!key-&gt;Persist())                    <font class="comment">// If we have our own key</font>
00100                         *key = idxbuf;                          <font class="comment">// reset it to entry index buffer</font>
00101 
00102                 stdstr(&amp;entkeytxt, idxbuf);     <font class="comment">// set entry key text that module 'snapped' to.</font>
00103                 free(idxbuf);
00104                 free(ebuf);
00105         }
00106         <font class="keywordflow">else</font> {
00107                 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ 5 ];
00108                 entrybuf[0] = 0;
00109                 entrybuf[1] = 0;
00110         }
00111                 
00112         <font class="keyword">delete</font> [] buf;
00113         <font class="keywordflow">return</font> retval;
00114 }
00115 
00116 
00117 <font class="comment">/******************************************************************************</font>
00118 <font class="comment"> * zLD::operator char * - Returns the correct entry when char * cast</font>
00119 <font class="comment"> *                                                      is requested</font>
00120 <font class="comment"> *</font>
00121 <font class="comment"> * RET: string buffer with entry</font>
00122 <font class="comment"> */</font>
00123 
00124 <font class="keywordtype">char</font> *zLD::getRawEntry() {
00125         <font class="keywordflow">if</font> (!getEntry() &amp;&amp; !isUnicode()) {
00126                 prepText(entrybuf);
00127         }
00128 
00129         <font class="keywordflow">return</font> entrybuf;
00130 }
00131 
00132 
00133 <font class="comment">/******************************************************************************</font>
00134 <font class="comment"> * zLD::operator +=     - Increments module key a number of entries</font>
00135 <font class="comment"> *</font>
00136 <font class="comment"> * ENT: increment       - Number of entries to jump forward</font>
00137 <font class="comment"> *</font>
00138 <font class="comment"> * RET: *this</font>
00139 <font class="comment"> */</font>
00140 
00141 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zLD::operator +=(<font class="keywordtype">int</font> increment)
00142 {
00143         <font class="keywordtype">char</font> tmperror;
00144 
00145         <font class="keywordflow">if</font> (key-&gt;Traversable()) {
00146                 *key += <a class="code" href="class_verse_key.html#a18">increment</a>;
00147                 error = key-&gt;Error();
00148                 <a class="code" href="class_verse_key.html#a18">increment</a> = 0;
00149         }
00150         
00151         tmperror = (getEntry(<a class="code" href="class_verse_key.html#a18">increment</a>)) ? KEYERR_OUTOFBOUNDS : 0;
00152         error = (error)?error:tmperror;
00153         *key = entkeytxt;
00154         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00155 }
00156 
00157 
00158 <font class="comment">/******************************************************************************</font>
00159 <font class="comment"> * zLD::operator =(SW_POSITION) - Positions this key if applicable</font>
00160 <font class="comment"> */</font>
00161 
00162 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zLD::operator =(SW_POSITION p)
00163 {
00164         <font class="keywordflow">if</font> (!key-&gt;Traversable()) {
00165                 <font class="keywordflow">switch</font> (p) {
00166                 <font class="keywordflow">case</font> POS_TOP:
00167                         *key = <font class="stringliteral">""</font>;
00168                         <font class="keywordflow">break</font>;
00169                 <font class="keywordflow">case</font> POS_BOTTOM:
00170                         *key = <font class="stringliteral">"zzzzzzzzz"</font>;
00171                         <font class="keywordflow">break</font>;
00172                 } 
00173         }
00174         <font class="keywordflow">else</font>    *key = p;
00175         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00176 }
00177 
00178 
00179 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zLD::setentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf, <font class="keywordtype">long</font> len) {
00180         <a class="code" href="class_verse_key.html#a13">setText</a>(*key, inbuf, len);
00181 
00182         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00183 }
00184 
00185 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zLD::operator &lt;&lt;(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) {
00186         <font class="keywordflow">return</font> setentry(inbuf, 0);
00187 }
00188 
00189 
00190 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;zLD::operator &lt;&lt;(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) {
00191         linkEntry(*key, *inkey);
00192 
00193         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00194 }
00195 
00196 
00197 <font class="comment">/******************************************************************************</font>
00198 <font class="comment"> * RawFiles::deleteEntry        - deletes this entry</font>
00199 <font class="comment"> *</font>
00200 <font class="comment"> * RET: *this</font>
00201 <font class="comment"> */</font>
00202 
00203 <font class="keywordtype">void</font> zLD::deleteEntry() {
00204         <a class="code" href="class_verse_key.html#a13">setText</a>(*key, <font class="stringliteral">""</font>);
00205 }
</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>