blob: 0e15debd06bdd86def99f2d0f2e742046251cc17 (
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>gbffootnotes.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>gbffootnotes.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * gbffootnotes - SWFilter decendant to hide or show footnotes</font>
00004 <font class="comment"> * in a GBF module.</font>
00005 <font class="comment"> */</font>
00006
00007
00008 <font class="preprocessor">#include <stdlib.h></font>
00009 <font class="preprocessor">#include <string.h></font>
00010 <font class="preprocessor">#include <gbffootnotes.h></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 <unixstr.h></font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016
00017 <font class="keyword">const</font> <font class="keywordtype">char</font> GBFFootnotes::on[] = <font class="stringliteral">"On"</font>;
00018 <font class="keyword">const</font> <font class="keywordtype">char</font> GBFFootnotes::off[] = <font class="stringliteral">"Off"</font>;
00019 <font class="keyword">const</font> <font class="keywordtype">char</font> GBFFootnotes::optName[] = <font class="stringliteral">"Footnotes"</font>;
00020 <font class="keyword">const</font> <font class="keywordtype">char</font> GBFFootnotes::optTip[] = <font class="stringliteral">"Toggles Footnotes On and Off if they exist"</font>;
00021
00022
00023 GBFFootnotes::GBFFootnotes() {
00024 option = <font class="keyword">false</font>;
00025 options.push_back(on);
00026 options.push_back(off);
00027 }
00028
00029
00030 GBFFootnotes::~GBFFootnotes() {
00031 }
00032
00033 <font class="keywordtype">void</font> GBFFootnotes::setOptionValue(<font class="keyword">const</font> <font class="keywordtype">char</font> *ival)
00034 {
00035 option = (!stricmp(ival, on));
00036 }
00037
00038 <font class="keyword">const</font> <font class="keywordtype">char</font> *GBFFootnotes::getOptionValue()
00039 {
00040 <font class="keywordflow">return</font> (option) ? on:off;
00041 }
00042
00043 <font class="keywordtype">char</font> GBFFootnotes::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)
00044 {
00045 <font class="keywordflow">if</font> (!option) { <font class="comment">// if we don't want footnotes</font>
00046 <font class="keywordtype">char</font> *to, *from, token[4096]; <font class="comment">// cheese. Fix.</font>
00047 <font class="keywordtype">int</font> tokpos = 0;
00048 <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00049 <font class="keywordtype">int</font> len;
00050 <font class="keywordtype">bool</font> hide = <font class="keyword">false</font>;
00051
00052 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00053 <font class="keywordflow">if</font> (len < maxlen) {
00054 memmove(&text[maxlen - len], text, len);
00055 from = &text[maxlen - len];
00056 }
00057 <font class="keywordflow">else</font> from = text; <font class="comment">// -------------------------------</font>
00058
00059 <font class="keywordflow">for</font> (to = text; *from; from++) {
00060 <font class="keywordflow">if</font> (*from == <font class="charliteral">'<'</font>) {
00061 intoken = <font class="keyword">true</font>;
00062 tokpos = 0;
00063 <font class="comment">// memset(token, 0, 4096);</font>
00064 token[0] = 0;
00065 token[1] = 0;
00066 token[2] = 0;
00067 <font class="keywordflow">continue</font>;
00068 }
00069 <font class="keywordflow">if</font> (*from == <font class="charliteral">'>'</font>) { <font class="comment">// process tokens</font>
00070 intoken = <font class="keyword">false</font>;
00071 <font class="keywordflow">switch</font> (*token) {
00072 <font class="keywordflow">case</font> <font class="charliteral">'R'</font>: <font class="comment">// Reference</font>
00073 <font class="keywordflow">switch</font>(token[1]) {
00074 <font class="keywordflow">case</font> <font class="charliteral">'F'</font>: <font class="comment">// Begin footnote</font>
00075 hide = <font class="keyword">true</font>;
00076 <font class="keywordflow">break</font>;
00077 <font class="keywordflow">case</font> <font class="charliteral">'f'</font>: <font class="comment">// end footnote</font>
00078 hide = <font class="keyword">false</font>;
00079 <font class="keywordflow">break</font>;
00080 }
00081 <font class="keywordflow">continue</font>; <font class="comment">// skip token</font>
00082 <font class="keywordflow">case</font> <font class="charliteral">'W'</font>:
00083 <font class="keywordflow">if</font> (token[1] == <font class="charliteral">'T'</font>) {
00084 <font class="keywordflow">switch</font> (token[2]) {
00085 <font class="keywordflow">case</font> <font class="charliteral">'P'</font>:
00086 <font class="keywordflow">case</font> <font class="charliteral">'S'</font>:
00087 <font class="keywordflow">case</font> <font class="charliteral">'A'</font>:
00088 <font class="keywordflow">continue</font>; <font class="comment">// remove this token</font>
00089 <font class="keywordflow">default</font>:
00090 <font class="keywordflow">break</font>;
00091 }
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">'<'</font>;
00097 <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *tok = token; *tok; tok++)
00098 *to++ = *tok;
00099 *to++ = <font class="charliteral">'>'</font>;
00100 }
00101 <font class="keywordflow">continue</font>;
00102 }
00103 <font class="keywordflow">if</font> (intoken) {
00104 <font class="keywordflow">if</font> (tokpos < 4090)
00105 token[tokpos++] = *from;
00106 token[tokpos+2] = 0; <font class="comment">// +2 cuz we init token with 2 extra '0' because of switch statement</font>
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 <font class="keywordflow">return</font> 0;
00118 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 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>
|