aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/thmlvariants_8cpp-source.html
blob: 1f5d6ba609881b32b9fb2f41cd6e13ed678a55f0 (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>thmlvariants.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>thmlvariants.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * thmlvariants -       SWFilter decendant to hide or show textual variants</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;string.h&gt;</font>
00010 <font class="preprocessor">#include &lt;thmlvariants.h&gt;</font>
00011 <font class="preprocessor">#ifndef __GNUC__</font>
00012 <font class="preprocessor"></font><font class="preprocessor">#else</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unixstr.h&gt;</font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016 
00017 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLVariants::primary[] = <font class="stringliteral">"Primary Reading"</font>;
00018 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLVariants::secondary[] = <font class="stringliteral">"Secondary Reading"</font>;
00019 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLVariants::all[] = <font class="stringliteral">"All Readings"</font>;
00020 
00021 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLVariants::optName[] = <font class="stringliteral">"Textual Variants"</font>;
00022 <font class="keyword">const</font> <font class="keywordtype">char</font> ThMLVariants::optTip[] = <font class="stringliteral">"Switch between Textual Variants modes"</font>;
00023 
00024 
00025 ThMLVariants::ThMLVariants() {
00026         option = <font class="keyword">false</font>;
00027         options.push_back(primary);
00028         options.push_back(secondary);
00029         options.push_back(all);
00030 }
00031 
00032 
00033 ThMLVariants::~ThMLVariants() {
00034 }
00035 
00036 <font class="keywordtype">void</font> ThMLVariants::setOptionValue(<font class="keyword">const</font> <font class="keywordtype">char</font> *ival)
00037 {
00038         <font class="keywordflow">if</font> (!stricmp(ival, primary)) option = 0;
00039         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(ival, secondary)) option = 1;
00040         <font class="keywordflow">else</font> option = 2;
00041 }
00042 
00043 <font class="keyword">const</font> <font class="keywordtype">char</font> *ThMLVariants::getOptionValue()
00044 {
00045         <font class="keywordflow">if</font> (option == 0) {
00046                 <font class="keywordflow">return</font> primary;
00047         }
00048         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (option == 1) {
00049                 <font class="keywordflow">return</font> secondary;
00050         }
00051         <font class="keywordflow">else</font> {
00052                 <font class="keywordflow">return</font> all;
00053         }
00054 }
00055 
00056 <font class="keywordtype">char</font> ThMLVariants::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)
00057 {
00058         <font class="keywordflow">if</font> (option == 0) { <font class="comment">//we want primary only</font>
00059                 <font class="keywordtype">char</font> *to, *from, token[2048]; <font class="comment">// cheese.  Fix.</font>
00060                 <font class="keywordtype">int</font> tokpos = 0;
00061                 <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00062                 <font class="keywordtype">int</font> len;
00063                 <font class="keywordtype">bool</font> hide = <font class="keyword">false</font>;
00064 
00065                 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00066                 <font class="keywordflow">if</font> (len &lt; maxlen) {
00067                         memmove(&amp;text[maxlen - len], text, len);
00068                         from = &amp;text[maxlen - len];
00069                 }
00070                 <font class="keywordflow">else</font>    from = text;
00071                 
00072                 <font class="comment">// -------------------------------</font>
00073 
00074                 <font class="keywordflow">for</font> (to = text; *from; from++) {
00075                         <font class="keywordflow">if</font> (*from == <font class="charliteral">'&lt;'</font>) {
00076                                 intoken = <font class="keyword">true</font>;
00077                                 tokpos = 0;
00078                                 token[0] = 0;
00079                                 token[1] = 0;
00080                                 token[2] = 0;
00081                                 <font class="keywordflow">continue</font>;
00082                         }
00083                         <font class="keywordflow">if</font> (*from == <font class="charliteral">'&gt;'</font>) {     <font class="comment">// process tokens</font>
00084                                 intoken = <font class="keyword">false</font>;
00085                                 <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"div type=\"variant\" class=\"2\""</font>, 28)) {
00086                                   hide = <font class="keyword">true</font>;
00087                                   <font class="keywordflow">continue</font>;
00088                                 }
00089                                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"/div"</font>, 4)) {
00090                                   hide = <font class="keyword">false</font>;
00091                                   <font class="keywordflow">continue</font>;
00092                                 }
00093 
00094                                 <font class="comment">// if not a footnote token, keep token in text</font>
00095                                 <font class="keywordflow">if</font> (!hide) {
00096                                         *to++ = <font class="charliteral">'&lt;'</font>;
00097                                         <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *tok = token; *tok; tok++)
00098                                                 *to++ = *tok;
00099                                         *to++ = <font class="charliteral">'&gt;'</font>;
00100                                 }
00101                                 <font class="keywordflow">continue</font>;
00102                         }
00103                         <font class="keywordflow">if</font> (intoken) {
00104                                 <font class="keywordflow">if</font> (tokpos &lt; 2045)
00105                                         token[tokpos++] = *from;
00106                                         token[tokpos+2] = 0;
00107                         }
00108                         <font class="keywordflow">else</font>    {
00109                                 <font class="keywordflow">if</font> (!hide) {
00110                                         *to++ = *from;
00111                                 }
00112                         }
00113                 }
00114                 *to++ = 0;
00115                 *to = 0;
00116 
00117         }
00118         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (option == 1) { <font class="comment">//we want variant only</font>
00119                 <font class="keywordtype">char</font> *to, *from, token[2048]; <font class="comment">// cheese.  Fix.</font>
00120                 <font class="keywordtype">int</font> tokpos = 0;
00121                 <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00122                 <font class="keywordtype">int</font> len;
00123                 <font class="keywordtype">bool</font> hide = <font class="keyword">false</font>;
00124 
00125                 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00126                 <font class="keywordflow">if</font> (len &lt; maxlen) {
00127                         memmove(&amp;text[maxlen - len], text, len);
00128                         from = &amp;text[maxlen - len];
00129                 }
00130                 <font class="keywordflow">else</font>    from = text;
00131 
00132                 <font class="comment">// -------------------------------</font>
00133 
00134                 <font class="keywordflow">for</font> (to = text; *from; from++) {
00135                         <font class="keywordflow">if</font> (*from == <font class="charliteral">'&lt;'</font>) {
00136                                 intoken = <font class="keyword">true</font>;
00137                                 tokpos = 0;
00138                                 token[0] = 0;
00139                                 token[1] = 0;
00140                                 token[2] = 0;
00141                                 <font class="keywordflow">continue</font>;
00142                         }
00143                         <font class="keywordflow">if</font> (*from == <font class="charliteral">'&gt;'</font>) {     <font class="comment">// process tokens</font>
00144                                 intoken = <font class="keyword">false</font>;
00145                                 <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"div type=\"variant\" class=\"1\""</font>, 28)) {
00146                                   hide = <font class="keyword">true</font>;
00147                                   <font class="keywordflow">continue</font>;
00148                                 }
00149                                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"/div"</font>, 4)) {
00150                                   hide = <font class="keyword">false</font>;
00151                                   <font class="keywordflow">continue</font>;
00152                                 }
00153 
00154                                 <font class="comment">// if not a footnote token, keep token in text</font>
00155                                 <font class="keywordflow">if</font> (!hide) {
00156                                         *to++ = <font class="charliteral">'&lt;'</font>;
00157                                         <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *tok = token; *tok; tok++)
00158                                                 *to++ = *tok;
00159                                         *to++ = <font class="charliteral">'&gt;'</font>;
00160                                 }
00161                                 <font class="keywordflow">continue</font>;
00162                         }
00163                         <font class="keywordflow">if</font> (intoken) {
00164                                 <font class="keywordflow">if</font> (tokpos &lt; 2045)
00165                                         token[tokpos++] = *from;
00166                                         token[tokpos+2] = 0;
00167                         }
00168                         <font class="keywordflow">else</font>    {
00169                                 <font class="keywordflow">if</font> (!hide) {
00170                                         *to++ = *from;
00171                                 }
00172                         }
00173                 }
00174                 *to++ = 0;
00175                 *to = 0;
00176 
00177         }
00178         <font class="keywordflow">return</font> 0;
00179 }
00180 
00181 
00182 
00183 
00184 
00185 
</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>