aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/thmlstrongs_8cpp-source.html
blob: 0f0297076b8b09e8391f5d93bc854662989e6aed (plain) (tree)









































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
<!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>thmlstrongs.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>thmlstrongs.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * thmlstrongs -        SWFilter decendant to hide or show strongs number</font>
00004 <font class="comment"> *                      in a ThML module.</font>
00005 <font class="comment"> */</font>
00006 
00007 
00008 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00009 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00010 <font class="preprocessor">#include &lt;string.h&gt;</font>
00011 <font class="preprocessor">#include &lt;thmlstrongs.h&gt;</font>
00012 <font class="preprocessor">#include &lt;swmodule.h&gt;</font>
00013 <font class="preprocessor">#ifndef __GNUC__</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#else</font>
00015 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unixstr.h&gt;</font>
00016 <font class="preprocessor">#endif</font>
00017 <font class="preprocessor"></font>
00018 
00019 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLStrongs::on[] = <font class="stringliteral">"On"</font>;
00020 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLStrongs::off[] = <font class="stringliteral">"Off"</font>;
00021 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLStrongs::optName[] = <font class="stringliteral">"Strong's Numbers"</font>;
00022 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLStrongs::optTip[] = <font class="stringliteral">"Toggles Strong's Numbers On and Off if they exist"</font>;
00023 
00024 
00025 ThMLStrongs::ThMLStrongs() {
00026         option = <font class="keyword">false</font>;
00027         options.push_back(on);
00028         options.push_back(off);
00029 }
00030 
00031 
00032 ThMLStrongs::~ThMLStrongs() {
00033 }
00034 
00035 <font class="keywordtype">void</font> ThMLStrongs::setOptionValue(<font class="keyword">const</font> <font class="keywordtype">char</font> *ival)
00036 {
00037         option = (!stricmp(ival, on));
00038 }
00039 
00040 <font class="keyword">const</font> <font class="keywordtype">char</font> *ThMLStrongs::getOptionValue()
00041 {
00042         <font class="keywordflow">return</font> (option) ? on:off;
00043 }
00044 
00045 <font class="keywordtype">char</font> ThMLStrongs::ProcessText(<font class="keywordtype">char</font> *text, <font class="keywordtype">int</font> maxlen, <font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *key, <font class="keyword">const</font> <a class="code" href="class_s_w_module.html">SWModule</a> *module)
00046 {
00047         <font class="keywordtype">char</font> *to, *from, token[2048]; <font class="comment">// cheese.  Fix.</font>
00048         <font class="keywordtype">int</font> tokpos = 0;
00049         <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00050         <font class="keywordtype">int</font> len;
00051         <font class="keywordtype">bool</font> lastspace = <font class="keyword">false</font>;
00052         <font class="keywordtype">int</font> word = 1;
00053         <font class="keywordtype">char</font> val[128];
00054         <font class="keywordtype">char</font> wordstr[5];
00055         <font class="keywordtype">char</font> *valto;
00056         <font class="keywordtype">char</font> *ch;
00057         <font class="keywordtype">char</font> *textStart = text, *textEnd = 0;
00058         string tmp;
00059         <font class="keywordtype">bool</font> newText = <font class="keyword">false</font>;
00060 
00061         len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00062         <font class="keywordflow">if</font> (len &lt; maxlen) {
00063                 memmove(&amp;text[maxlen - len], text, len);
00064                 from = &amp;text[maxlen - len];
00065         }
00066         <font class="keywordflow">else</font>    from = text;
00067         
00068         <font class="comment">// -------------------------------</font>
00069 
00070         <font class="keywordflow">for</font> (to = text; *from; from++) {
00071                 <font class="keywordflow">if</font> (*from == <font class="charliteral">'&lt;'</font>) {
00072                         intoken = <font class="keyword">true</font>;
00073                         tokpos = 0;
00074                         token[0] = 0;
00075                         token[1] = 0;
00076                         token[2] = 0;
00077                         textEnd = to;
00078                         <font class="keywordflow">continue</font>;
00079                 }
00080                 <font class="keywordflow">if</font> (*from == <font class="charliteral">'&gt;'</font>) {     <font class="comment">// process tokens</font>
00081                         intoken = <font class="keyword">false</font>;
00082                         <font class="keywordflow">if</font> (!strnicmp(token, <font class="stringliteral">"sync type=\"Strongs\" "</font>, 20)) {   <font class="comment">// Strongs</font>
00083                                 <font class="keywordflow">if</font> (module-&gt;<a class="code" href="class_s_w_module.html#a64">isProcessEntryAttributes</a>()) {
00084                                         valto = val;
00085                                         <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 27; token[i] != <font class="charliteral">'\"'</font> &amp;&amp; i &lt; 150; i++)
00086                                                 *valto++ = token[i];
00087                                         *valto = 0;
00088                                         <font class="keywordflow">if</font> (atoi((!isdigit(*val))?val+1:val) &lt; 5627) {
00089                                                 <font class="comment">// normal strongs number</font>
00090                                                 sprintf(wordstr, <font class="stringliteral">"%03d"</font>, word++);
00091                                                 module-&gt;<a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"Strongs"</font>] = val;
00092                                                 tmp = <font class="stringliteral">""</font>;
00093                                                 tmp.append(textStart, (<font class="keywordtype">int</font>)(textEnd - textStart));
00094                                                 module-&gt;<a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"Text"</font>] = tmp;
00095                                                 newText = <font class="keyword">true</font>;
00096                                         }
00097                                         <font class="keywordflow">else</font> {
00098                                                 <font class="comment">// verb morph</font>
00099                                                 sprintf(wordstr, <font class="stringliteral">"%03d"</font>, word-1);
00100                                                 module-&gt;<a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"Morph"</font>] = val;
00101                                         }
00102                                 }
00103 
00104                                 <font class="keywordflow">if</font> (!option) {  <font class="comment">// if we don't want strongs</font>
00105                                         <font class="keywordflow">if</font> ((from[1] == <font class="charliteral">' '</font>) || (from[1] == <font class="charliteral">','</font>) || (from[1] == <font class="charliteral">';'</font>) || (from[1] == <font class="charliteral">'.'</font>) || (from[1] == <font class="charliteral">'?'</font>) || (from[1] == <font class="charliteral">'!'</font>) || (from[1] == <font class="charliteral">')'</font>) || (from[1] == <font class="charliteral">'\''</font>) || (from[1] == <font class="charliteral">'\"'</font>)) {
00106                                                 <font class="keywordflow">if</font> (lastspace)
00107                                                         to--;
00108                                         }
00109                                         <font class="keywordflow">if</font> (newText) {textStart = to; newText = <font class="keyword">false</font>; }
00110                                         <font class="keywordflow">continue</font>;
00111                                 }
00112                         }
00113                         <font class="keywordflow">if</font> (module-&gt;<a class="code" href="class_s_w_module.html#a64">isProcessEntryAttributes</a>()) {
00114                                 <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"sync type=\"morph\""</font>, 17)) {
00115                                         <font class="keywordflow">for</font> (ch = token+17; *ch; ch++) {
00116                                                 <font class="keywordflow">if</font> (!strncmp(ch, <font class="stringliteral">"class=\""</font>, 7)) {
00117                                                         valto = val;
00118                                                         <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 7; ch[i] != <font class="charliteral">'\"'</font> &amp;&amp; i &lt; 127; i++)
00119                                                                 *valto++ = ch[i];
00120                                                         *valto = 0;
00121                                                         sprintf(wordstr, <font class="stringliteral">"%03d"</font>, word-1);
00122                                                         module-&gt;<a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"MorphClass"</font>] = val;
00123                                                 }
00124                                                 <font class="keywordflow">if</font> (!strncmp(ch, <font class="stringliteral">"value=\""</font>, 7)) {
00125                                                         valto = val;
00126                                                         <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 7; ch[i] != <font class="charliteral">'\"'</font> &amp;&amp; i &lt; 127; i++)
00127                                                                 *valto++ = ch[i];
00128                                                         *valto = 0;
00129                                                         sprintf(wordstr, <font class="stringliteral">"%03d"</font>, word-1);
00130                                                         module-&gt;<a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"Morph"</font>] = val;
00131                                                 }
00132                                         }
00133                                 }
00134                         }
00135                         <font class="comment">// if not a strongs token, keep token in text</font>
00136                         *to++ = <font class="charliteral">'&lt;'</font>;
00137                         <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *tok = token; *tok; tok++)
00138                                 *to++ = *tok;
00139                         *to++ = <font class="charliteral">'&gt;'</font>;
00140                         <font class="keywordflow">if</font> (newText) {textStart = to; newText = <font class="keyword">false</font>; }
00141                         <font class="keywordflow">continue</font>;
00142                 }
00143                 <font class="keywordflow">if</font> (intoken) {
00144                         <font class="keywordflow">if</font> (tokpos &lt; 2045)
00145                                 token[tokpos++] = *from;
00146                                 token[tokpos+2] = 0;
00147                 }
00148                 <font class="keywordflow">else</font>    {
00149                         *to++ = *from;
00150                         lastspace = (*from == <font class="charliteral">' '</font>);
00151                 }
00152         }
00153         *to++ = 0;
00154         *to = 0;
00155         <font class="keywordflow">return</font> 0;
00156 }
</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>