Sophie

Sophie

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

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>swmodule.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>swmodule.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  swmodule.cpp -code for base class 'module'.  Module is the basis for all</font>
00003 <font class="comment"> *                types of modules (e.g. texts, commentaries, maps, lexicons,</font>
00004 <font class="comment"> *                etc.)</font>
00005 <font class="comment"> */</font>
00006 
00007 <font class="preprocessor">#include &lt;string.h&gt;</font>
00008 <font class="preprocessor">#include &lt;swmodule.h&gt;</font>
00009 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00010 <font class="preprocessor">#include &lt;regex.h&gt;</font>      <font class="comment">// GNU</font>
00011 <font class="preprocessor">#include &lt;swfilter.h&gt;</font>
00012 <font class="preprocessor">#include &lt;versekey.h&gt;</font>   <font class="comment">// KLUDGE for Search</font>
00013 <font class="preprocessor">#ifndef _MSC_VER</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include &lt;iostream.h&gt;</font>
00015 <font class="preprocessor">#endif</font>
00016 <font class="preprocessor"></font>
00017 <a class="code" href="class_s_w_display.html">SWDisplay</a> SWModule::rawdisp;
<a name="l00018"></a><a class="code" href="class_s_w_module.html#d0">00018</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_module.html#d0">SWModule::nullPercent</a>(<font class="keywordtype">char</font> percent, <font class="keywordtype">void</font> *percentUserData) {}
00019 
00020 <font class="comment">/******************************************************************************</font>
00021 <font class="comment"> * SWModule Constructor - Initializes data for instance of SWModule</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> * ENT: imodname - Internal name for module</font>
00024 <font class="comment"> *      imoddesc - Name to display to user for module</font>
00025 <font class="comment"> *      idisp    - Display object to use for displaying</font>
00026 <font class="comment"> *      imodtype - Type of Module (All modules will be displayed with</font>
00027 <font class="comment"> *                      others of same type under their modtype heading</font>
00028 <font class="comment"> *      unicode  - if this module is unicode</font>
00029 <font class="comment"> */</font>
00030 
<a name="l00031"></a><a class="code" href="class_s_w_module.html#a0">00031</a> <a class="code" href="class_s_w_module.html#a0">SWModule::SWModule</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *imodname, <font class="keyword">const</font> <font class="keywordtype">char</font> *imoddesc, <a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp, <font class="keywordtype">char</font> *imodtype, SWTextEncoding encoding, SWTextDirection direction, SWTextMarkup markup, <font class="keyword">const</font> <font class="keywordtype">char</font>* imodlang)
00032 {
00033         <a class="code" href="class_s_w_module.html#n6">key</a>       = <a class="code" href="class_s_w_module.html#a26">CreateKey</a>();
00034         entrybuf  = <font class="keyword">new</font> <font class="keywordtype">char</font> [1];
00035         *entrybuf = 0;
00036         config    = &amp;ownConfig;
00037         entrybufallocsize = 0;
00038         modname   = 0;
00039         error     = 0;
00040         moddesc   = 0;
00041         modtype   = 0;
00042         modlang   = 0;
00043         this-&gt;encoding = encoding;
00044         this-&gt;direction = direction;
00045         this-&gt;markup  = markup;
00046         entrySize= -1;
00047         <a class="code" href="class_s_w_module.html#n15">disp</a>     = (idisp) ? idisp : &amp;rawdisp;
00048         stdstr(&amp;modname, imodname);
00049         stdstr(&amp;moddesc, imoddesc);
00050         stdstr(&amp;modtype, imodtype);
00051         stdstr(&amp;modlang, imodlang);
00052         <a class="code" href="class_s_w_module.html#n18">stripFilters</a> = <font class="keyword">new</font> FilterList();
00053         <a class="code" href="class_s_w_module.html#n19">rawFilters</a> = <font class="keyword">new</font> FilterList();
00054         <a class="code" href="class_s_w_module.html#n20">renderFilters</a> = <font class="keyword">new</font> FilterList();
00055         <a class="code" href="class_s_w_module.html#n21">optionFilters</a> = <font class="keyword">new</font> FilterList();
00056         <a class="code" href="class_s_w_module.html#n22">encodingFilters</a> = <font class="keyword">new</font> FilterList();
00057         skipConsecutiveLinks = <font class="keyword">true</font>;
00058         procEntAttr = <font class="keyword">true</font>;
00059 }
00060 
00061 
00062 <font class="comment">/******************************************************************************</font>
00063 <font class="comment"> * SWModule Destructor - Cleans up instance of SWModule</font>
00064 <font class="comment"> */</font>
00065 
<a name="l00066"></a><a class="code" href="class_s_w_module.html#a1">00066</a> <a class="code" href="class_s_w_module.html#a1">SWModule::~SWModule</a>()
00067 {
00068         <font class="keywordflow">if</font> (entrybuf)
00069                 <font class="keyword">delete</font> [] entrybuf;
00070         <font class="keywordflow">if</font> (modname)
00071                 <font class="keyword">delete</font> [] modname;
00072         <font class="keywordflow">if</font> (moddesc)
00073                 <font class="keyword">delete</font> [] moddesc;
00074         <font class="keywordflow">if</font> (modtype)
00075                 <font class="keyword">delete</font> [] modtype;
00076         <font class="keywordflow">if</font> (modlang)
00077                 <font class="keyword">delete</font> [] modlang;
00078 
00079         <font class="keywordflow">if</font> (key) {
00080                 <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())
00081                         <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n6">key</a>;
00082         }
00083 
00084         <a class="code" href="class_s_w_module.html#n18">stripFilters</a>-&gt;clear();
00085      <a class="code" href="class_s_w_module.html#n19">rawFilters</a>-&gt;clear();
00086      <a class="code" href="class_s_w_module.html#n20">renderFilters</a>-&gt;clear();
00087      <a class="code" href="class_s_w_module.html#n21">optionFilters</a>-&gt;clear();
00088      <a class="code" href="class_s_w_module.html#n22">encodingFilters</a>-&gt;clear();
00089         entryAttributes.clear();
00090 
00091      <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n18">stripFilters</a>;
00092      <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n19">rawFilters</a>;
00093      <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n20">renderFilters</a>;
00094      <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n21">optionFilters</a>;
00095      <font class="keyword">delete</font> <a class="code" href="class_s_w_module.html#n22">encodingFilters</a>;
00096 }
00097 
00098 
00099 <font class="comment">/******************************************************************************</font>
00100 <font class="comment"> * SWModule::CreateKey - Allocates a key of specific type for module</font>
00101 <font class="comment"> *</font>
00102 <font class="comment"> * RET: pointer to allocated key</font>
00103 <font class="comment"> */</font>
00104 
<a name="l00105"></a><a class="code" href="class_s_w_module.html#a26">00105</a> <a class="code" href="class_s_w_key.html">SWKey</a> *<a class="code" href="class_s_w_module.html#a26">SWModule::CreateKey</a>()
00106 {
00107         <font class="keywordflow">return</font> <font class="keyword">new</font> <a class="code" href="class_s_w_key.html">SWKey</a>();
00108 }
00109 
00110 
00111 <font class="comment">/******************************************************************************</font>
00112 <font class="comment"> * SWModule::Error - Gets and clears error status</font>
00113 <font class="comment"> *</font>
00114 <font class="comment"> * RET: error status</font>
00115 <font class="comment"> */</font>
00116 
<a name="l00117"></a><a class="code" href="class_s_w_module.html#a2">00117</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a2">SWModule::Error</a>()
00118 {
00119         <font class="keywordtype">char</font> retval = error;
00120 
00121         error = 0;
00122         <font class="keywordflow">return</font> retval;
00123 }
00124 
00125 
00126 <font class="comment">/******************************************************************************</font>
00127 <font class="comment"> * SWModule::Name - Sets/gets module name</font>
00128 <font class="comment"> *</font>
00129 <font class="comment"> * ENT: imodname - value which to set modname</font>
00130 <font class="comment"> *              [0] - only get</font>
00131 <font class="comment"> *</font>
00132 <font class="comment"> * RET: pointer to modname</font>
00133 <font class="comment"> */</font>
00134 
<a name="l00135"></a><a class="code" href="class_s_w_module.html#a15">00135</a> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a15">SWModule::Name</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *imodname)
00136 {
00137         <font class="keywordflow">return</font> stdstr(&amp;modname, imodname);
00138 }
00139 
00140 
00141 <font class="comment">/******************************************************************************</font>
00142 <font class="comment"> * SWModule::Description - Sets/gets module description</font>
00143 <font class="comment"> *</font>
00144 <font class="comment"> * ENT: imoddesc - value which to set moddesc</font>
00145 <font class="comment"> *              [0] - only get</font>
00146 <font class="comment"> *</font>
00147 <font class="comment"> * RET: pointer to moddesc</font>
00148 <font class="comment"> */</font>
00149 
<a name="l00150"></a><a class="code" href="class_s_w_module.html#a16">00150</a> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a16">SWModule::Description</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *imoddesc)
00151 {
00152         <font class="keywordflow">return</font> stdstr(&amp;moddesc, imoddesc);
00153 }
00154 
00155 
00156 <font class="comment">/******************************************************************************</font>
00157 <font class="comment"> * SWModule::Type - Sets/gets module type</font>
00158 <font class="comment"> *</font>
00159 <font class="comment"> * ENT: imodtype - value which to set modtype</font>
00160 <font class="comment"> *              [0] - only get</font>
00161 <font class="comment"> *</font>
00162 <font class="comment"> * RET: pointer to modtype</font>
00163 <font class="comment"> */</font>
00164 
<a name="l00165"></a><a class="code" href="class_s_w_module.html#a17">00165</a> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a17">SWModule::Type</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *imodtype)
00166 {
00167         <font class="keywordflow">return</font> stdstr(&amp;modtype, imodtype);
00168 }
00169 
00170 <font class="comment">/******************************************************************************</font>
00171 <font class="comment"> * SWModule::Direction - Sets/gets module direction</font>
00172 <font class="comment"> *</font>
00173 <font class="comment"> * ENT: newdir - value which to set direction</font>
00174 <font class="comment"> *              [-1] - only get</font>
00175 <font class="comment"> *</font>
00176 <font class="comment"> * RET: char direction</font>
00177 <font class="comment"> */</font>
<a name="l00178"></a><a class="code" href="class_s_w_module.html#a18">00178</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a18">SWModule::Direction</a>(<font class="keywordtype">signed</font> <font class="keywordtype">char</font> newdir) {
00179         <font class="keywordflow">if</font> (newdir != -1)
00180                 direction = newdir;
00181         <font class="keywordflow">return</font> direction;
00182 }
00183 
00184 <font class="comment">/******************************************************************************</font>
00185 <font class="comment"> * SWModule::Encoding - Sets/gets module encoding</font>
00186 <font class="comment"> *</font>
00187 <font class="comment"> * ENT: newdir - value which to set direction</font>
00188 <font class="comment"> *              [-1] - only get</font>
00189 <font class="comment"> *</font>
00190 <font class="comment"> * RET: char encoding</font>
00191 <font class="comment"> */</font>
<a name="l00192"></a><a class="code" href="class_s_w_module.html#a19">00192</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a19">SWModule::Encoding</a>(<font class="keywordtype">signed</font> <font class="keywordtype">char</font> newenc) {
00193         <font class="keywordflow">if</font> (newenc != -1)
00194                 encoding = newenc;
00195         <font class="keywordflow">return</font> encoding;
00196 }
00197 
00198 <font class="comment">/******************************************************************************</font>
00199 <font class="comment"> * SWModule::Markup - Sets/gets module markup</font>
00200 <font class="comment"> *</font>
00201 <font class="comment"> * ENT: newdir - value which to set direction</font>
00202 <font class="comment"> *              [-1] - only get</font>
00203 <font class="comment"> *</font>
00204 <font class="comment"> * RET: char markup</font>
00205 <font class="comment"> */</font>
<a name="l00206"></a><a class="code" href="class_s_w_module.html#a20">00206</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a20">SWModule::Markup</a>(<font class="keywordtype">signed</font> <font class="keywordtype">char</font> newmark) {
00207         <font class="keywordflow">if</font> (newmark != -1)
00208                 markup = newmark;
00209         <font class="keywordflow">return</font> markup;
00210 }
00211 
00212 
00213 <font class="comment">/******************************************************************************</font>
00214 <font class="comment"> * SWModule::Lang - Sets/gets module language</font>
00215 <font class="comment"> *</font>
00216 <font class="comment"> * ENT: imodlang - value which to set modlang</font>
00217 <font class="comment"> *              [0] - only get</font>
00218 <font class="comment"> *</font>
00219 <font class="comment"> * RET: pointer to modname</font>
00220 <font class="comment"> */</font>
00221 
<a name="l00222"></a><a class="code" href="class_s_w_module.html#a21">00222</a> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a21">SWModule::Lang</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *imodlang)
00223 {
00224         <font class="keywordflow">return</font> stdstr(&amp;modlang, imodlang);
00225 }
00226 
00227 
00228 <font class="comment">/******************************************************************************</font>
00229 <font class="comment"> * SWModule::Disp - Sets/gets display driver</font>
00230 <font class="comment"> *</font>
00231 <font class="comment"> * ENT: idisp - value which to set disp</font>
00232 <font class="comment"> *              [0] - only get</font>
00233 <font class="comment"> *</font>
00234 <font class="comment"> * RET: pointer to disp</font>
00235 <font class="comment"> */</font>
00236 
<a name="l00237"></a><a class="code" href="class_s_w_module.html#a14">00237</a> <a class="code" href="class_s_w_display.html">SWDisplay</a> *<a class="code" href="class_s_w_module.html#a14">SWModule::Disp</a>(<a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp)
00238 {
00239         <font class="keywordflow">if</font> (idisp)
00240                 <a class="code" href="class_s_w_module.html#n15">disp</a> = idisp;
00241 
00242         <font class="keywordflow">return</font> <a class="code" href="class_s_w_module.html#n15">disp</a>;
00243 }
00244 
00245 
00246 <font class="comment">/******************************************************************************</font>
00247 <font class="comment"> * SWModule::Display - Calls this modules display object and passes itself</font>
00248 <font class="comment"> *</font>
00249 <font class="comment"> * RET: error status</font>
00250 <font class="comment"> */</font>
00251 
<a name="l00252"></a><a class="code" href="class_s_w_module.html#a13">00252</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a13">SWModule::Display</a>()
00253 {
00254         <a class="code" href="class_s_w_module.html#n15">disp</a>-&gt;<a class="code" href="class_s_w_display.html#a1">Display</a>(*<font class="keyword">this</font>);
00255         <font class="keywordflow">return</font> 0;
00256 }
00257 
00258 
00259 <font class="comment">/******************************************************************************</font>
00260 <font class="comment"> * SWModule::SetKey - Sets a key to this module for position to a particular</font>
00261 <font class="comment"> *                      record or set of records</font>
00262 <font class="comment"> *</font>
00263 <font class="comment"> * ENT: ikey - key with which to set this module</font>
00264 <font class="comment"> *</font>
00265 <font class="comment"> * RET: error status</font>
00266 <font class="comment"> */</font>
00267 
<a name="l00268"></a><a class="code" href="class_s_w_module.html#a9">00268</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a8">SWModule::SetKey</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &amp;ikey) {
00269         <font class="keywordflow">return</font> <a class="code" href="class_s_w_module.html#a8">SetKey</a>(&amp;ikey);
00270 }
00271 
<a name="l00272"></a><a class="code" href="class_s_w_module.html#a8">00272</a> <font class="keywordtype">char</font> <a class="code" href="class_s_w_module.html#a8">SWModule::SetKey</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *ikey)
00273 {
00274         <a class="code" href="class_s_w_key.html">SWKey</a> *oldKey = 0;
00275 
00276         <font class="keywordflow">if</font> (key) {
00277                 <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())    <font class="comment">// if we have our own copy</font>
00278                         oldKey = <a class="code" href="class_s_w_module.html#n6">key</a>;
00279         }
00280 
00281         <font class="keywordflow">if</font> (!ikey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>()) {         <font class="comment">// if we are to keep our own copy</font>
00282                  <a class="code" href="class_s_w_module.html#n6">key</a> = <a class="code" href="class_s_w_module.html#a26">CreateKey</a>();
00283                 *<a class="code" href="class_s_w_module.html#n6">key</a> = *ikey;
00284         }
00285         <font class="keywordflow">else</font>     <a class="code" href="class_s_w_module.html#n6">key</a> = (<a class="code" href="class_s_w_key.html">SWKey</a> *)ikey;           <font class="comment">// if we are to just point to an external key</font>
00286 
00287         <font class="keywordflow">if</font> (oldKey)
00288                 <font class="keyword">delete</font> oldKey;
00289 
00290         <font class="keywordflow">return</font> 0;
00291 }
00292 
00293 
00294 <font class="comment">/******************************************************************************</font>
00295 <font class="comment"> * SWModule::KeyText - Sets/gets module KeyText</font>
00296 <font class="comment"> *</font>
00297 <font class="comment"> * ENT: ikeytext - value which to set keytext</font>
00298 <font class="comment"> *              [0] - only get</font>
00299 <font class="comment"> *</font>
00300 <font class="comment"> * RET: pointer to keytext</font>
00301 <font class="comment"> */</font>
00302 
<a name="l00303"></a><a class="code" href="class_s_w_module.html#a12">00303</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a12">SWModule::KeyText</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *ikeytext)
00304 {
00305         <font class="keywordflow">if</font> (ikeytext)
00306                 <a class="code" href="class_s_w_module.html#a8">SetKey</a>(ikeytext);
00307 
00308         <font class="keywordflow">return</font> *<a class="code" href="class_s_w_module.html#n6">key</a>;
00309 }
00310 
00311 
00312 <font class="comment">/******************************************************************************</font>
00313 <font class="comment"> * SWModule::operator =(SW_POSITION)    - Positions this modules to an entry</font>
00314 <font class="comment"> *</font>
00315 <font class="comment"> * ENT: p       - position (e.g. TOP, BOTTOM)</font>
00316 <font class="comment"> *</font>
00317 <font class="comment"> * RET: *this</font>
00318 <font class="comment"> */</font>
00319 
<a name="l00320"></a><a class="code" href="class_s_w_module.html#a40">00320</a> <a class="code" href="class_s_w_module.html">SWModule</a> &amp;<a class="code" href="class_s_w_module.html#a40">SWModule::operator =</a>(SW_POSITION p)
00321 {
00322         *<a class="code" href="class_s_w_module.html#n6">key</a> = p;
00323         <font class="keywordtype">char</font> saveError = <a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a6">Error</a>();
00324 
00325         <font class="keywordflow">switch</font> (p) {
00326         <font class="keywordflow">case</font> POS_TOP:
00327                 (*this)++;
00328                 (*this)--;
00329                 <font class="keywordflow">break</font>;
00330 
00331         <font class="keywordflow">case</font> POS_BOTTOM:
00332                 (*this)--;
00333                 (*this)++;
00334                 <font class="keywordflow">break</font>;
00335         }
00336 
00337         error = saveError;
00338         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00339 }
00340 
00341 
00342 <font class="comment">/******************************************************************************</font>
00343 <font class="comment"> * SWModule::operator +=        - Increments module key a number of entries</font>
00344 <font class="comment"> *</font>
00345 <font class="comment"> * ENT: increment       - Number of entries to jump forward</font>
00346 <font class="comment"> *</font>
00347 <font class="comment"> * RET: *this</font>
00348 <font class="comment"> */</font>
00349 
<a name="l00350"></a><a class="code" href="class_s_w_module.html#a37">00350</a> <a class="code" href="class_s_w_module.html">SWModule</a> &amp;<a class="code" href="class_s_w_module.html#a37">SWModule::operator +=</a>(<font class="keywordtype">int</font> increment)
00351 {
00352         (*key) += increment;
00353         error = <a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a6">Error</a>();
00354 
00355         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00356 }
00357 
00358 
00359 <font class="comment">/******************************************************************************</font>
00360 <font class="comment"> * SWModule::operator -=        - Decrements module key a number of entries</font>
00361 <font class="comment"> *</font>
00362 <font class="comment"> * ENT: decrement       - Number of entries to jump backward</font>
00363 <font class="comment"> *</font>
00364 <font class="comment"> * RET: *this</font>
00365 <font class="comment"> */</font>
00366 
<a name="l00367"></a><a class="code" href="class_s_w_module.html#a36">00367</a> <a class="code" href="class_s_w_module.html">SWModule</a> &amp;<a class="code" href="class_s_w_module.html#a36">SWModule::operator -=</a>(<font class="keywordtype">int</font> increment)
00368 {
00369         (*key) -= increment;
00370         error = <a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a6">Error</a>();
00371 
00372         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00373 }
00374 
00375 
00376 <font class="comment">/******************************************************************************</font>
00377 <font class="comment"> * SWModule::Search     - Searches a module for a string</font>
00378 <font class="comment"> *</font>
00379 <font class="comment"> * ENT: istr            - string for which to search</font>
00380 <font class="comment"> *      searchType      - type of search to perform</font>
00381 <font class="comment"> *                              &gt;=0 - regex</font>
00382 <font class="comment"> *                              -1  - phrase</font>
00383 <font class="comment"> *                              -2  - multiword</font>
00384 <font class="comment"> *      flags           - options flags for search</font>
00385 <font class="comment"> *      justCheckIfSupported    - if set, don't search, only tell if this</font>
00386 <font class="comment"> *                                                      function supports requested search.</font>
00387 <font class="comment"> *</font>
00388 <font class="comment"> * RET: listkey set to verses that contain istr</font>
00389 <font class="comment"> */</font>
00390 
<a name="l00391"></a><a class="code" href="class_s_w_module.html#a22">00391</a> <a class="code" href="class_list_key.html">ListKey</a> &amp;<a class="code" href="class_s_w_module.html#a22">SWModule::Search</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *istr, <font class="keywordtype">int</font> searchType, <font class="keywordtype">int</font> flags, <a class="code" href="class_s_w_key.html">SWKey</a> *scope, <font class="keywordtype">bool</font> *justCheckIfSupported, <font class="keywordtype">void</font> (*percent)(<font class="keywordtype">char</font>, <font class="keywordtype">void</font> *), <font class="keywordtype">void</font> *percentUserData)
00392 {
00393         <a class="code" href="class_s_w_key.html">SWKey</a> *savekey = 0;
00394         <a class="code" href="class_s_w_key.html">SWKey</a> *searchkey = 0;
00395         regex_t preg;
00396         <a class="code" href="class_s_w_key.html">SWKey</a> textkey;
00397         <font class="keywordtype">char</font> **words = 0;
00398         <font class="keywordtype">char</font> *wordBuf = 0;
00399         <font class="keywordtype">int</font> wordCount = 0;
00400         <font class="keyword">const</font> <font class="keywordtype">char</font> *sres;
00401         <a class="code" href="class_s_w_module.html#m0">terminateSearch</a> = <font class="keyword">false</font>;
00402         <font class="keywordtype">char</font> perc = 1;
00403         <font class="keywordtype">bool</font> savePEA = isProcessEntryAttributes();
00404 
00405         processEntryAttributes(<font class="keyword">false</font>);
00406         listkey.<a class="code" href="class_list_key.html#a4">ClearList</a>();
00407 
00408         <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>()) {
00409                 savekey = <a class="code" href="class_s_w_module.html#a26">CreateKey</a>();
00410                 *savekey = *<a class="code" href="class_s_w_module.html#n6">key</a>;
00411         }
00412         <font class="keywordflow">else</font>    savekey = <a class="code" href="class_s_w_module.html#n6">key</a>;
00413 
00414         searchkey = (scope)?scope-&gt;<a class="code" href="class_s_w_key.html#a3">clone</a>():(<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())?<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a3">clone</a>():0;
00415         <font class="keywordflow">if</font> (searchkey) {
00416                 searchkey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>(1);
00417                 <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*searchkey);
00418         }
00419 
00420         (*percent)(perc, percentUserData);
00421         <font class="comment">// MAJOR KLUDGE: VerseKey::Index still return index within testament.</font>
00422         <font class="comment">//      VerseKey::NewIndex should be moved to Index and Index should be some</font>
00423         <font class="comment">//      VerseKey specific name</font>
00424         <a class="code" href="class_verse_key.html">VerseKey</a> *vkcheck = 0;
00425 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00426 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00427 <font class="preprocessor">#endif</font>
00428 <font class="preprocessor"></font>                vkcheck = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, <a class="code" href="class_s_w_module.html#n6">key</a>);
00429 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00430 <font class="preprocessor"></font>        }
00431         <font class="keywordflow">catch</font> (...) {}
00432 <font class="preprocessor">#endif</font>
00433 <font class="preprocessor"></font>        <font class="comment">// end MAJOR KLUDGE</font>
00434 
00435         *<font class="keyword">this</font> = BOTTOM;
00436         <font class="comment">// fix below when we find out the bug</font>
00437         <font class="keywordtype">long</font> highIndex = (vkcheck)?32300<font class="comment">/*vkcheck-&gt;NewIndex()*/</font>:<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a17">Index</a>();
00438         <font class="keywordflow">if</font> (!highIndex)
00439                 highIndex = 1;          <font class="comment">// avoid division by zero errors.</font>
00440         *<font class="keyword">this</font> = TOP;
00441         <font class="keywordflow">if</font> (searchType &gt;= 0) {
00442                 flags |=searchType|REG_NOSUB|REG_EXTENDED;
00443                 regcomp(&amp;preg, istr, flags);
00444         }
00445 
00446         (*percent)(++perc, percentUserData);
00447         <font class="keywordflow">if</font> (searchType == -2) {
00448                 wordBuf = (<font class="keywordtype">char</font> *)calloc(<font class="keyword">sizeof</font>(<font class="keywordtype">char</font>), strlen(istr) + 1);
00449                 strcpy(wordBuf, istr);
00450                 words = (<font class="keywordtype">char</font> **)calloc(<font class="keyword">sizeof</font>(<font class="keywordtype">char</font> *), 10);
00451                 <font class="keywordtype">int</font> allocWords = 10;
00452                 words[wordCount] = strtok(wordBuf, <font class="stringliteral">" "</font>);
00453                 <font class="keywordflow">while</font> (words[wordCount]) {
00454                         wordCount++;
00455                         <font class="keywordflow">if</font> (wordCount == allocWords) {
00456                                 allocWords+=10;
00457                                 words = (<font class="keywordtype">char</font> **)realloc(words, <font class="keyword">sizeof</font>(<font class="keywordtype">char</font> *)*allocWords);
00458                         }
00459                         words[wordCount] = strtok(NULL, <font class="stringliteral">" "</font>);
00460                 }
00461         }
00462 
00463         perc = 5;
00464         (*percent)(perc, percentUserData);
00465 
00466         <font class="keywordflow">while</font> (!<a class="code" href="class_s_w_module.html#a2">Error</a>() &amp;&amp; !<a class="code" href="class_s_w_module.html#m0">terminateSearch</a>) {
00467 
00468         
00469                 <font class="keywordtype">long</font> mindex = 0;
00470                 <font class="keywordflow">if</font> (vkcheck)
00471                         mindex = vkcheck-&gt;<a class="code" href="class_verse_key.html#a33">NewIndex</a>();
00472                 <font class="keywordflow">else</font> mindex = <a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a17">Index</a>();
00473                 <font class="keywordtype">float</font> per = (float)mindex / highIndex;
00474                 per *= 93;
00475                 per += 5;
00476                 <font class="keywordtype">char</font> newperc = (char)per;
00477 <font class="comment">//              char newperc = (char)(5+(93*(((float)((vkcheck)?vkcheck-&gt;NewIndex():key-&gt;Index()))/highIndex)));</font>
00478                 <font class="keywordflow">if</font> (newperc &gt; perc) {
00479                         perc = newperc;
00480                         (*percent)(perc, percentUserData);
00481                 }
00482                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (newperc &lt; perc) {
00483 <font class="preprocessor">#ifndef _MSC_VER</font>
00484 <font class="preprocessor"></font>                        cerr &lt;&lt; <font class="stringliteral">"Serious error: new percentage complete is less than previous value\n"</font>;
00485                         cerr &lt;&lt; <font class="stringliteral">"using vk? "</font> &lt;&lt; ((vkcheck)?<font class="stringliteral">"yes"</font>:<font class="stringliteral">"no"</font>) &lt;&lt; <font class="stringliteral">"\n"</font>;
00486                         cerr &lt;&lt; <font class="stringliteral">"index: "</font> &lt;&lt; ((vkcheck)?vkcheck-&gt;<a class="code" href="class_verse_key.html#a33">NewIndex</a>():<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a17">Index</a>()) &lt;&lt; <font class="stringliteral">"\n"</font>;
00487                         cerr &lt;&lt; <font class="stringliteral">"highIndex: "</font> &lt;&lt; highIndex &lt;&lt; <font class="stringliteral">"\n"</font>;
00488                         cerr &lt;&lt; <font class="stringliteral">"newperc =="</font> &lt;&lt; (int)newperc &lt;&lt; <font class="stringliteral">"%"</font> &lt;&lt; <font class="stringliteral">"is smaller than\n"</font>;
00489                         cerr &lt;&lt; <font class="stringliteral">"perc == "</font>  &lt;&lt; (int )perc &lt;&lt; <font class="stringliteral">"% \n"</font>;
00490 <font class="preprocessor">#endif</font>
00491 <font class="preprocessor"></font>                }
00492                 <font class="keywordflow">if</font> (searchType &gt;= 0) {
00493                         <font class="keywordflow">if</font> (!regexec(&amp;preg,  <a class="code" href="class_s_w_module.html#a56">StripText</a>(), 0, 0, 0)) {
00494                                 textkey = <a class="code" href="class_s_w_module.html#a12">KeyText</a>();
00495                                 listkey &lt;&lt; textkey;
00496                         }
00497                 }
00498                 <font class="keywordflow">else</font> {
00499                         <font class="keywordflow">if</font> (searchType == -1) {
00500                                 sres = ((flags &amp; REG_ICASE) == REG_ICASE) ? stristr(<a class="code" href="class_s_w_module.html#a56">StripText</a>(), istr) : strstr(<a class="code" href="class_s_w_module.html#a56">StripText</a>(), istr);
00501                                 <font class="keywordflow">if</font> (sres) {
00502                                                 textkey = <a class="code" href="class_s_w_module.html#a12">KeyText</a>();
00503                                                 listkey &lt;&lt; textkey;
00504                                 }
00505                         }
00506                         <font class="keywordflow">if</font> (searchType == -2) {
00507                                 <font class="keywordtype">int</font> i;
00508                                 <font class="keyword">const</font> <font class="keywordtype">char</font> *stripBuf = <a class="code" href="class_s_w_module.html#a56">StripText</a>();
00509                                 <font class="keywordflow">for</font> (i = 0; i &lt; wordCount; i++) {
00510                                         sres = ((flags &amp; REG_ICASE) == REG_ICASE) ? stristr(stripBuf, words[i]) : strstr(stripBuf, words[i]);
00511                                         <font class="keywordflow">if</font> (!sres)
00512                                                 <font class="keywordflow">break</font>;
00513                                 }
00514                                 <font class="keywordflow">if</font> (i == wordCount) {
00515                                         textkey = <a class="code" href="class_s_w_module.html#a12">KeyText</a>();
00516                                         listkey &lt;&lt; textkey;
00517                                 }
00518 
00519                         }
00520                 }
00521                 (*this)++;
00522         }
00523         <font class="keywordflow">if</font> (searchType &gt;= 0)
00524                 regfree(&amp;preg);
00525 
00526         <font class="keywordflow">if</font> (searchType == -2) {
00527                 free(words);
00528                 free(wordBuf);
00529         }
00530 
00531         <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*savekey);
00532 
00533         <font class="keywordflow">if</font> (!savekey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())
00534                 <font class="keyword">delete</font> savekey;
00535 
00536         <font class="keywordflow">if</font> (searchkey)
00537                 <font class="keyword">delete</font> searchkey;
00538 
00539         listkey = TOP;
00540         processEntryAttributes(savePEA);
00541         (*percent)(100, percentUserData);
00542 
00543         <font class="keywordflow">return</font> listkey;
00544 }
00545 
00546 
00547 <font class="comment">/******************************************************************************</font>
00548 <font class="comment"> * SWModule::StripText()        - calls all stripfilters on current text</font>
00549 <font class="comment"> *</font>
00550 <font class="comment"> * ENT: buf     - buf to massage instead of this modules current text</font>
00551 <font class="comment"> *      len     - max len of buf</font>
00552 <font class="comment"> *</font>
00553 <font class="comment"> * RET: this module's text at specified key location massaged by Strip filters</font>
00554 <font class="comment"> */</font>
00555 
<a name="l00556"></a><a class="code" href="class_s_w_module.html#a56">00556</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a56">SWModule::StripText</a>(<font class="keywordtype">char</font> *buf, <font class="keywordtype">int</font> len)
00557 {
00558         <font class="keywordflow">return</font> <a class="code" href="class_s_w_module.html#a57">RenderText</a>(buf, len, <font class="keyword">false</font>);
00559 }
00560 
00561 
00562 <font class="comment">/******************************************************************************</font>
00563 <font class="comment"> * SWModule::RenderText         - calls all renderfilters on current text</font>
00564 <font class="comment"> *</font>
00565 <font class="comment"> * ENT: buf     - buffer to Render instead of current module position</font>
00566 <font class="comment"> *</font>
00567 <font class="comment"> * RET: listkey set to verses that contain istr</font>
00568 <font class="comment"> */</font>
00569 
<a name="l00570"></a><a class="code" href="class_s_w_module.html#a57">00570</a>  <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a57">SWModule::RenderText</a>(<font class="keywordtype">char</font> *buf, <font class="keywordtype">int</font> len, <font class="keywordtype">bool</font> render) {
00571         entryAttributes.clear();
00572         <font class="keywordtype">char</font> *tmpbuf = (buf) ? buf : <a class="code" href="class_s_w_module.html#a28">getRawEntry</a>();
00573         <a class="code" href="class_s_w_key.html">SWKey</a> *<a class="code" href="class_s_w_module.html#n6">key</a> = 0;
00574         <font class="keyword">static</font> <font class="keywordtype">char</font> *null = <font class="stringliteral">""</font>;
00575 
00576         <font class="keywordflow">if</font> (tmpbuf) {
00577                 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> size = (len &lt; 0) ? ((<a class="code" href="class_s_w_module.html#a7">getEntrySize</a>()&lt;0) ? strlen(tmpbuf) : <a class="code" href="class_s_w_module.html#a7">getEntrySize</a>()) * FILTERPAD : len;
00578                 <font class="keywordflow">if</font> (size &gt; 0) {
00579                         key = (<a class="code" href="class_s_w_key.html">SWKey</a> *)*<font class="keyword">this</font>;
00580 
00581                         <a class="code" href="class_s_w_module.html#a55">optionFilter</a>(tmpbuf, size, key);
00582         
00583                         <font class="keywordflow">if</font> (render) {
00584                                 <a class="code" href="class_s_w_module.html#a44">renderFilter</a>(tmpbuf, size, key);
00585                                 <a class="code" href="class_s_w_module.html#a48">encodingFilter</a>(tmpbuf, size, key);
00586                         }
00587                         <font class="keywordflow">else</font>    <a class="code" href="class_s_w_module.html#a50">stripFilter</a>(tmpbuf, size, key);
00588                 }
00589         }
00590         <font class="keywordflow">else</font> {
00591                 tmpbuf = null;
00592         }
00593 
00594         <font class="keywordflow">return</font> tmpbuf;
00595 }
00596 
00597 
00598 <font class="comment">/******************************************************************************</font>
00599 <font class="comment"> * SWModule::RenderText         - calls all renderfilters on current text</font>
00600 <font class="comment"> *</font>
00601 <font class="comment"> * ENT: tmpKey  - key to use to grab text</font>
00602 <font class="comment"> *</font>
00603 <font class="comment"> * RET: this module's text at specified key location massaged by RenderFilers</font>
00604 <font class="comment"> */</font>
00605 
<a name="l00606"></a><a class="code" href="class_s_w_module.html#a59">00606</a>  <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a57">SWModule::RenderText</a>(<a class="code" href="class_s_w_key.html">SWKey</a> *tmpKey)
00607 {
00608         <a class="code" href="class_s_w_key.html">SWKey</a> *savekey;
00609         <font class="keyword">const</font> <font class="keywordtype">char</font> *retVal;
00610 
00611         <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>()) {
00612                 savekey = <a class="code" href="class_s_w_module.html#a26">CreateKey</a>();
00613                 *savekey = *<a class="code" href="class_s_w_module.html#n6">key</a>;
00614         }
00615         <font class="keywordflow">else</font>    savekey = <a class="code" href="class_s_w_module.html#n6">key</a>;
00616 
00617         <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*tmpKey);
00618 
00619         retVal = <a class="code" href="class_s_w_module.html#a57">RenderText</a>();
00620 
00621         <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*savekey);
00622 
00623         <font class="keywordflow">if</font> (!savekey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())
00624                 <font class="keyword">delete</font> savekey;
00625 
00626         <font class="keywordflow">return</font> retVal;
00627 }
00628 
00629 
00630 <font class="comment">/******************************************************************************</font>
00631 <font class="comment"> * SWModule::StripText  - calls all StripTextFilters on current text</font>
00632 <font class="comment"> *</font>
00633 <font class="comment"> * ENT: tmpKey  - key to use to grab text</font>
00634 <font class="comment"> *</font>
00635 <font class="comment"> * RET: this module's text at specified key location massaged by Strip filters</font>
00636 <font class="comment"> */</font>
00637 
<a name="l00638"></a><a class="code" href="class_s_w_module.html#a58">00638</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_module.html#a56">SWModule::StripText</a>(<a class="code" href="class_s_w_key.html">SWKey</a> *tmpKey)
00639 {
00640         <a class="code" href="class_s_w_key.html">SWKey</a> *savekey;
00641         <font class="keyword">const</font> <font class="keywordtype">char</font> *retVal;
00642 
00643         <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_module.html#n6">key</a>-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>()) {
00644                 savekey = <a class="code" href="class_s_w_module.html#a26">CreateKey</a>();
00645                 *savekey = *<a class="code" href="class_s_w_module.html#n6">key</a>;
00646         }
00647         <font class="keywordflow">else</font>    savekey = <a class="code" href="class_s_w_module.html#n6">key</a>;
00648 
00649         <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*tmpKey);
00650 
00651         retVal = <a class="code" href="class_s_w_module.html#a56">StripText</a>();
00652 
00653         <a class="code" href="class_s_w_module.html#a8">SetKey</a>(*savekey);
00654 
00655         <font class="keywordflow">if</font> (!savekey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())
00656                 <font class="keyword">delete</font> savekey;
00657 
00658         <font class="keywordflow">return</font> retVal;
00659 }
00660 
00661 
<a name="l00662"></a><a class="code" href="class_s_w_module.html#a27">00662</a> <a class="code" href="class_s_w_module.html#a27">SWModule::operator const char*</a>() {
00663         <font class="keywordflow">return</font> <a class="code" href="class_s_w_module.html#a57">RenderText</a>();
00664 }
00665 
00666 
00667 <font class="keyword">const</font> <font class="keywordtype">char</font> *SWModule::getConfigEntry(<font class="keyword">const</font> <font class="keywordtype">char</font> *key)<font class="keyword"> const </font>{
00668         ConfigEntMap::iterator it = config-&gt;find(<a class="code" href="class_s_w_module.html#n6">key</a>);
00669         <font class="keywordflow">return</font> (it != config-&gt;end()) ? it-&gt;second.c_str() : 0;
00670 }
00671 
00672 
00673 <font class="keywordtype">void</font> SWModule::setConfig(ConfigEntMap *config) {
00674         this-&gt;config = config;
00675 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 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>