<!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>thmlhtmlhref.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>thmlhtmlhref.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/***************************************************************************</font>
00002 <font class="comment"> thmlhtmlhref.cpp - ThML to HTML filter with hrefs </font>
00003 <font class="comment"> -------------------</font>
00004 <font class="comment"> begin : 2001-09-03</font>
00005 <font class="comment"> copyright : 2001 by CrossWire Bible Society</font>
00006 <font class="comment"> ***************************************************************************/</font>
00007
00008 <font class="comment">/***************************************************************************</font>
00009 <font class="comment"> * *</font>
00010 <font class="comment"> * This program is free software; you can redistribute it and/or modify *</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by *</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or *</font>
00013 <font class="comment"> * (at your option) any later version. *</font>
00014 <font class="comment"> * *</font>
00015 <font class="comment"> ***************************************************************************/</font>
00016
00017 <font class="preprocessor">#include <stdlib.h></font>
00018 <font class="preprocessor">#include <string.h></font>
00019 <font class="preprocessor">#include <thmlhtmlhref.h></font>
00020 <font class="preprocessor">#include <swmodule.h></font>
00021
00022
00023 ThMLHTMLHREF::ThMLHTMLHREF() {
00024 <a class="code" href="class_s_w_basic_filter.html#b2">setTokenStart</a>(<font class="stringliteral">"<"</font>);
00025 <a class="code" href="class_s_w_basic_filter.html#b3">setTokenEnd</a>(<font class="stringliteral">">"</font>);
00026 <font class="comment">/* </font>
00027 <font class="comment"> setEscapeStart("&");</font>
00028 <font class="comment"> setEscapeEnd(";");</font>
00029 <font class="comment"></font>
00030 <font class="comment"> setEscapeStringCaseSensitive(true);</font>
00031 <font class="comment"></font>
00032 <font class="comment"> addEscapeStringSubstitute("nbsp", " ");</font>
00033 <font class="comment"> addEscapeStringSubstitute("quot", "\"");</font>
00034 <font class="comment"> addEscapeStringSubstitute("amp", "&");</font>
00035 <font class="comment"> addEscapeStringSubstitute("lt", "<");</font>
00036 <font class="comment"> addEscapeStringSubstitute("gt", ">");</font>
00037 <font class="comment"> addEscapeStringSubstitute("brvbar", "|");</font>
00038 <font class="comment"> addEscapeStringSubstitute("sect", "§");</font>
00039 <font class="comment"> addEscapeStringSubstitute("copy", "©");</font>
00040 <font class="comment"> addEscapeStringSubstitute("laquo", "«");</font>
00041 <font class="comment"> addEscapeStringSubstitute("reg", "®");</font>
00042 <font class="comment"> addEscapeStringSubstitute("acute", "´");</font>
00043 <font class="comment"> addEscapeStringSubstitute("para", "¶");</font>
00044 <font class="comment"> addEscapeStringSubstitute("raquo", "»");</font>
00045 <font class="comment"></font>
00046 <font class="comment"> addEscapeStringSubstitute("Aacute", "Á");</font>
00047 <font class="comment"> addEscapeStringSubstitute("Agrave", "À");</font>
00048 <font class="comment"> addEscapeStringSubstitute("Acirc", "Â");</font>
00049 <font class="comment"> addEscapeStringSubstitute("Auml", "Ä");</font>
00050 <font class="comment"> addEscapeStringSubstitute("Atilde", "Ã");</font>
00051 <font class="comment"> addEscapeStringSubstitute("Aring", "Å");</font>
00052 <font class="comment"> addEscapeStringSubstitute("aacute", "á");</font>
00053 <font class="comment"> addEscapeStringSubstitute("agrave", "à");</font>
00054 <font class="comment"> addEscapeStringSubstitute("acirc", "â");</font>
00055 <font class="comment"> addEscapeStringSubstitute("auml", "ä");</font>
00056 <font class="comment"> addEscapeStringSubstitute("atilde", "ã");</font>
00057 <font class="comment"> addEscapeStringSubstitute("aring", "å");</font>
00058 <font class="comment"> addEscapeStringSubstitute("Eacute", "É");</font>
00059 <font class="comment"> addEscapeStringSubstitute("Egrave", "È");</font>
00060 <font class="comment"> addEscapeStringSubstitute("Ecirc", "Ê");</font>
00061 <font class="comment"> addEscapeStringSubstitute("Euml", "Ë");</font>
00062 <font class="comment"> addEscapeStringSubstitute("eacute", "é");</font>
00063 <font class="comment"> addEscapeStringSubstitute("egrave", "è");</font>
00064 <font class="comment"> addEscapeStringSubstitute("ecirc", "ê");</font>
00065 <font class="comment"> addEscapeStringSubstitute("euml", "ë");</font>
00066 <font class="comment"> addEscapeStringSubstitute("Iacute", "Í");</font>
00067 <font class="comment"> addEscapeStringSubstitute("Igrave", "Ì");</font>
00068 <font class="comment"> addEscapeStringSubstitute("Icirc", "Î");</font>
00069 <font class="comment"> addEscapeStringSubstitute("Iuml", "Ï");</font>
00070 <font class="comment"> addEscapeStringSubstitute("iacute", "í");</font>
00071 <font class="comment"> addEscapeStringSubstitute("igrave", "ì");</font>
00072 <font class="comment"> addEscapeStringSubstitute("icirc", "î");</font>
00073 <font class="comment"> addEscapeStringSubstitute("iuml", "ï");</font>
00074 <font class="comment"> addEscapeStringSubstitute("Oacute", "Ó");</font>
00075 <font class="comment"> addEscapeStringSubstitute("Ograve", "Ò");</font>
00076 <font class="comment"> addEscapeStringSubstitute("Ocirc", "Ô");</font>
00077 <font class="comment"> addEscapeStringSubstitute("Ouml", "Ö");</font>
00078 <font class="comment"> addEscapeStringSubstitute("Otilde", "Õ");</font>
00079 <font class="comment"> addEscapeStringSubstitute("oacute", "ó");</font>
00080 <font class="comment"> addEscapeStringSubstitute("ograve", "ò");</font>
00081 <font class="comment"> addEscapeStringSubstitute("ocirc", "ô");</font>
00082 <font class="comment"> addEscapeStringSubstitute("ouml", "ö");</font>
00083 <font class="comment"> addEscapeStringSubstitute("otilde", "õ");</font>
00084 <font class="comment"> addEscapeStringSubstitute("Uacute", "Ú");</font>
00085 <font class="comment"> addEscapeStringSubstitute("Ugrave", "Ù");</font>
00086 <font class="comment"> addEscapeStringSubstitute("Ucirc", "Û");</font>
00087 <font class="comment"> addEscapeStringSubstitute("Uuml", "Ü");</font>
00088 <font class="comment"> addEscapeStringSubstitute("uacute", "ú");</font>
00089 <font class="comment"> addEscapeStringSubstitute("ugrave", "ù");</font>
00090 <font class="comment"> addEscapeStringSubstitute("ucirc", "û");</font>
00091 <font class="comment"> addEscapeStringSubstitute("uuml", "ü");</font>
00092 <font class="comment"> addEscapeStringSubstitute("Yacute", "Ý");</font>
00093 <font class="comment"> addEscapeStringSubstitute("yacute", "ý");</font>
00094 <font class="comment"> addEscapeStringSubstitute("yuml", "ÿ");</font>
00095 <font class="comment"></font>
00096 <font class="comment"> addEscapeStringSubstitute("deg", "°");</font>
00097 <font class="comment"> addEscapeStringSubstitute("plusmn", "±");</font>
00098 <font class="comment"> addEscapeStringSubstitute("sup2", "²");</font>
00099 <font class="comment"> addEscapeStringSubstitute("sup3", "³");</font>
00100 <font class="comment"> addEscapeStringSubstitute("sup1", "¹");</font>
00101 <font class="comment"> addEscapeStringSubstitute("nbsp", "º");</font>
00102 <font class="comment"> addEscapeStringSubstitute("pound", "£");</font>
00103 <font class="comment"> addEscapeStringSubstitute("cent", "¢");</font>
00104 <font class="comment"> addEscapeStringSubstitute("frac14", "¼");</font>
00105 <font class="comment"> addEscapeStringSubstitute("frac12", "½");</font>
00106 <font class="comment"> addEscapeStringSubstitute("frac34", "¾");</font>
00107 <font class="comment"> addEscapeStringSubstitute("iquest", "¿");</font>
00108 <font class="comment"> addEscapeStringSubstitute("iexcl", "¡");</font>
00109 <font class="comment"> addEscapeStringSubstitute("ETH", "Ð");</font>
00110 <font class="comment"> addEscapeStringSubstitute("eth", "ð");</font>
00111 <font class="comment"> addEscapeStringSubstitute("THORN", "Þ");</font>
00112 <font class="comment"> addEscapeStringSubstitute("thorn", "þ");</font>
00113 <font class="comment"> addEscapeStringSubstitute("AElig", "Æ");</font>
00114 <font class="comment"> addEscapeStringSubstitute("aelig", "æ");</font>
00115 <font class="comment"> addEscapeStringSubstitute("Oslash", "Ø");</font>
00116 <font class="comment"> addEscapeStringSubstitute("curren", "¤");</font>
00117 <font class="comment"> addEscapeStringSubstitute("Ccedil", "Ç");</font>
00118 <font class="comment"> addEscapeStringSubstitute("ccedil", "ç");</font>
00119 <font class="comment"> addEscapeStringSubstitute("szlig", "ß");</font>
00120 <font class="comment"> addEscapeStringSubstitute("Ntilde", "Ñ");</font>
00121 <font class="comment"> addEscapeStringSubstitute("ntilde", "ñ");</font>
00122 <font class="comment"> addEscapeStringSubstitute("yen", "¥");</font>
00123 <font class="comment"> addEscapeStringSubstitute("not", "¬");</font>
00124 <font class="comment"> addEscapeStringSubstitute("ordf", "ª");</font>
00125 <font class="comment"> addEscapeStringSubstitute("uml", "¨");</font>
00126 <font class="comment"> addEscapeStringSubstitute("shy", "");</font>
00127 <font class="comment"> addEscapeStringSubstitute("macr", "¯");</font>
00128 <font class="comment">*/</font>
00129 setTokenCaseSensitive(<font class="keyword">true</font>);
00130
00131 addTokenSubstitute(<font class="stringliteral">"note"</font>, <font class="stringliteral">" <font color=\"#800000\"><small>("</font>);
00132 addTokenSubstitute(<font class="stringliteral">"/note"</font>, <font class="stringliteral">")</small></font> "</font>);
00133 addTokenSubstitute(<font class="stringliteral">"/scripture"</font>, <font class="stringliteral">"</i> "</font>);
00134 }
00135
00136
<a name="l00137"></a><a class="code" href="class_th_m_l_h_t_m_l_h_r_e_f.html#b0">00137</a> <font class="keywordtype">bool</font> <a class="code" href="class_th_m_l_h_t_m_l_h_r_e_f.html#b0">ThMLHTMLHREF::handleToken</a>(<font class="keywordtype">char</font> **buf, <font class="keyword">const</font> <font class="keywordtype">char</font> *token, DualStringMap &userData) {
00138 <font class="keyword">const</font> <font class="keywordtype">char</font> *tok;
00139 <font class="keywordflow">if</font> (!substituteToken(buf, token)) {
00140 <font class="comment">// manually process if it wasn't a simple substitution</font>
00141 <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"sync "</font>, 5)) {
00142 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<a href=\""</font>);
00143 <font class="keywordflow">for</font> (tok = token + 5; *(tok+1); tok++)
00144 <font class="keywordflow">if</font>(*tok != <font class="charliteral">'\"'</font>)
00145 *(*buf)++ = *tok;
00146 *(*buf)++ = <font class="charliteral">'\"'</font>;
00147 *(*buf)++ = <font class="charliteral">'>'</font>;
00148
00149 <font class="comment">//scan for value and add it to the buffer</font>
00150 <font class="keywordflow">for</font> (tok = token + 5; *tok; tok++) {
00151 <font class="keywordflow">if</font> (!strncmp(tok, <font class="stringliteral">"value=\""</font>, 7)) {
00152 tok += 7;
00153 <font class="keywordflow">for</font> (;*tok != <font class="charliteral">'\"'</font>; tok++)
00154 *(*buf)++ = *tok;
00155 <font class="keywordflow">break</font>;
00156 }
00157 }
00158 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"</a>"</font>);
00159 }
00160
00161 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"scripture "</font>, 10)) {
00162 userData[<font class="stringliteral">"inscriptRef"</font>] = <font class="stringliteral">"true"</font>;
00163 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<i>"</font>);
00164 }
00165
00166 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"scripRef p"</font>, 10) || !strncmp(token, <font class="stringliteral">"scripRef v"</font>, 10)) {
00167 userData[<font class="stringliteral">"inscriptRef"</font>] = <font class="stringliteral">"true"</font>;
00168 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<a href=\""</font>);
00169 <font class="keywordflow">for</font> (<font class="keyword">const</font> <font class="keywordtype">char</font> *tok = token + 9; *(tok+1); tok++)
00170 <font class="keywordflow">if</font>(*tok != <font class="charliteral">'\"'</font>)
00171 *(*buf)++ = *tok;
00172 *(*buf)++ = <font class="charliteral">'\"'</font>;
00173 *(*buf)++ = <font class="charliteral">'>'</font>;
00174 }
00175
00176 <font class="comment">// we're starting a scripRef like "<scripRef>John 3:16</scripRef>"</font>
00177 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strcmp(token, <font class="stringliteral">"scripRef"</font>)) {
00178 userData[<font class="stringliteral">"inscriptRef"</font>] = <font class="stringliteral">"false"</font>;
00179 <font class="comment">// let's stop text from going to output</font>
00180 userData[<font class="stringliteral">"suspendTextPassThru"</font>] = <font class="stringliteral">"true"</font>;
00181 }
00182
00183 <font class="comment">// we've ended a scripRef </font>
00184 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strcmp(token, <font class="stringliteral">"/scripRef"</font>)) {
00185 <font class="keywordflow">if</font> (userData[<font class="stringliteral">"inscriptRef"</font>] == <font class="stringliteral">"true"</font>) { <font class="comment">// like "<scripRef passage="John 3:16">John 3:16</scripRef>"</font>
00186 userData[<font class="stringliteral">"inscriptRef"</font>] = <font class="stringliteral">"false"</font>;
00187 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"</a>"</font>);
00188 }
00189
00190 <font class="keywordflow">else</font> { <font class="comment">// like "<scripRef>John 3:16</scripRef>"</font>
00191 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<a href=\"passage="</font>);
00192 <font class="comment">//char *strbuf = (char *)userData["lastTextNode"].c_str();</font>
00193 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, userData[<font class="stringliteral">"lastTextNode"</font>].c_str());
00194 *(*buf)++ = <font class="charliteral">'\"'</font>;
00195 *(*buf)++ = <font class="charliteral">'>'</font>;
00196 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, userData[<font class="stringliteral">"lastTextNode"</font>].c_str());
00197 <font class="comment">// let's let text resume to output again</font>
00198 userData[<font class="stringliteral">"suspendTextPassThru"</font>] = <font class="stringliteral">"false"</font>;
00199 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"</a>"</font>);
00200 }
00201 }
00202
00203 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"div class=\"sechead\""</font>, 19)) {
00204 userData[<font class="stringliteral">"SecHead"</font>] = <font class="stringliteral">"true"</font>;
00205 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<br /><b><i>"</font>);
00206 }
00207 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"div class=\"title\""</font>, 19)) {
00208 userData[<font class="stringliteral">"SecHead"</font>] = <font class="stringliteral">"true"</font>;
00209 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<br /><b><i>"</font>);
00210 }
00211 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"/div"</font>, 4)) {
00212 <font class="keywordflow">if</font> (userData[<font class="stringliteral">"SecHead"</font>] == <font class="stringliteral">"true"</font>) {
00213 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"</i></b><br />"</font>);
00214 userData[<font class="stringliteral">"SecHead"</font>] = <font class="stringliteral">"false"</font>;
00215 }
00216 }
00217
00218 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"sync type=\"Strongs\" value=\"T"</font>, 28)) {
00219 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"<a href=\""</font>);
00220 <font class="keywordflow">for</font> (tok = token + 5; *(tok+1); tok++)
00221 <font class="keywordflow">if</font>(*tok != <font class="charliteral">'\"'</font>)
00222 *(*buf)++ = *tok;
00223 *(*buf)++ = <font class="charliteral">'\"'</font>;
00224 *(*buf)++ = <font class="charliteral">'>'</font>;
00225 <font class="keywordflow">for</font> (tok = token + 29; *(tok+2); tok++)
00226 <font class="keywordflow">if</font>(*tok != <font class="charliteral">'\"'</font>)
00227 *(*buf)++ = *tok;
00228 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"</a>"</font>);
00229 }
00230 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"img "</font>, 4)) {
00231 <font class="keyword">const</font> <font class="keywordtype">char</font> *src = strstr(token, <font class="stringliteral">"src"</font>);
00232 <font class="keywordflow">if</font> (!src) <font class="comment">// assert we have a src attribute</font>
00233 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00234
00235 *(*buf)++ = <font class="charliteral">'<'</font>;
00236 <font class="keywordflow">for</font> (<font class="keyword">const</font> <font class="keywordtype">char</font> *c = token; *c; c++) {
00237 <font class="keywordflow">if</font> (c == src) {
00238 <font class="keywordflow">for</font> (;((*c) && (*c != <font class="charliteral">'"'</font>)); c++)
00239 *(*buf)++ = *c;
00240
00241 <font class="keywordflow">if</font> (!*c) { c--; <font class="keywordflow">continue</font>; }
00242
00243 *(*buf)++ = <font class="charliteral">'"'</font>;
00244 <font class="keywordflow">if</font> (*(c+1) == <font class="charliteral">'/'</font>) {
00245 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">"file:"</font>);
00246 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, module-><a class="code" href="class_s_w_module.html#a6">getConfigEntry</a>(<font class="stringliteral">"AbsoluteDataPath"</font>));
00247 <font class="keywordflow">if</font> (*((*buf)-1) == <font class="charliteral">'/'</font>)
00248 c++; <font class="comment">// skip '/'</font>
00249 }
00250 <font class="keywordflow">continue</font>;
00251 }
00252 *(*buf)++ = *c;
00253 }
00254 *(*buf)++ = <font class="charliteral">'>'</font>;
00255 }
00256 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"note"</font>, 4)) {
00257 <a class="code" href="class_s_w_basic_filter.html#b12">pushString</a>(buf, <font class="stringliteral">" <small><font color=\"#800000\">("</font>);
00258 }
00259 <font class="keywordflow">else</font> {
00260 *(*buf)++ = <font class="charliteral">'<'</font>;
00261 <font class="keywordflow">for</font> (<font class="keyword">const</font> <font class="keywordtype">char</font> *tok = token; *tok; tok++)
00262 *(*buf)++ = *tok;
00263 *(*buf)++ = <font class="charliteral">'>'</font>;
00264 <font class="comment">//return false; // we still didn't handle token</font>
00265 }
00266 }
00267 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00268 }
00269
</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>