<!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>gbfosis.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>gbfosis.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * gbfstrongs - SWFilter decendant to hide or show strongs number</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 <stdio.h></font>
00010 <font class="preprocessor">#include <string.h></font>
00011 <font class="preprocessor">#include <gbfosis.h></font>
00012 <font class="preprocessor">#include <swmodule.h></font>
00013 <font class="preprocessor">#include <versekey.h></font>
00014 <font class="preprocessor">#ifndef __GNUC__</font>
00015 <font class="preprocessor"></font><font class="preprocessor">#else</font>
00016 <font class="preprocessor"></font><font class="preprocessor">#include <unixstr.h></font>
00017 <font class="preprocessor">#endif</font>
00018 <font class="preprocessor"></font>
00019
00020 GBFOSIS::GBFOSIS() {
00021 }
00022
00023
00024 GBFOSIS::~GBFOSIS() {
00025 }
00026
00027
00028 <font class="keywordtype">char</font> GBFOSIS::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) {
00029
00030 <font class="keywordtype">char</font> *to, *from, token[2048]; <font class="comment">// cheese. Fix.</font>
00031 <font class="keywordtype">int</font> tokpos = 0;
00032 <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00033 <font class="keywordtype">int</font> len;
00034 <font class="keywordtype">bool</font> lastspace = <font class="keyword">false</font>;
00035 <font class="keywordtype">int</font> word = 1;
00036 <font class="keywordtype">char</font> val[128];
00037 <font class="keywordtype">char</font> buf[128];
00038 <font class="keywordtype">char</font> wordstr[5];
00039 <font class="keywordtype">char</font> *valto;
00040 <font class="keywordtype">char</font> *ch;
00041 <font class="keywordtype">char</font> *textStart, *textEnd;
00042 <font class="keywordtype">char</font> *wordStart, *wordEnd;
00043 <font class="keywordtype">bool</font> newText = <font class="keyword">false</font>;
00044 <font class="keywordtype">bool</font> newWord = <font class="keyword">false</font>;
00045 string tmp;
00046 <font class="keywordtype">bool</font> suspendTextPassThru = <font class="keyword">false</font>;
00047 <font class="keywordtype">bool</font> keepToken = <font class="keyword">false</font>;
00048
00049 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00050 <font class="keywordflow">if</font> (len < maxlen) {
00051 memmove(&text[maxlen - len], text, len);
00052 from = &text[maxlen - len];
00053 }
00054 <font class="keywordflow">else</font> from = text;
00055
00056 textStart = from;
00057 wordStart = text;
00058
00059 <font class="comment">// -------------------------------</font>
00060
00061 <font class="keywordflow">for</font> (to = text; *from; from++) {
00062 <font class="keywordflow">if</font> (*from == <font class="charliteral">'<'</font>) {
00063 intoken = <font class="keyword">true</font>;
00064 tokpos = 0;
00065 token[0] = 0;
00066 token[1] = 0;
00067 token[2] = 0;
00068 textEnd = from-1;
00069 wordEnd = to;
00070 <font class="keywordflow">continue</font>;
00071 }
00072 <font class="keywordflow">if</font> (*from == <font class="charliteral">'>'</font>) { <font class="comment">// process tokens</font>
00073 intoken = <font class="keyword">false</font>;
00074 keepToken = <font class="keyword">false</font>;
00075 suspendTextPassThru = <font class="keyword">false</font>;
00076 newWord = <font class="keyword">true</font>;
00077
00078
00079 <font class="keywordflow">while</font> (wordStart < (text+maxlen)) {
00080 <font class="comment">// if (strchr(" ,;.?!()'\"", *wordStart))</font>
00081 <font class="keywordflow">if</font> (strchr(<font class="stringliteral">";, .:?!()'\""</font>, *wordStart))
00082 wordStart++;
00083 <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00084 }
00085 <font class="keywordflow">while</font> (wordEnd > wordStart) {
00086 <font class="keywordflow">if</font> (strchr(<font class="stringliteral">" ,;.:?!()'\""</font>, *wordEnd))
00087 wordEnd--;
00088 <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00089 }
00090
00091 <font class="comment">// Scripture Reference</font>
00092 <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"scripRef"</font>, 8)) {
00093 <font class="comment">// pushString(buf, "<reference work=\"Bible.KJV\" reference=\"");</font>
00094 suspendTextPassThru = <font class="keyword">true</font>;
00095 newText = <font class="keyword">true</font>;
00096 }
00097 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"/scripRef"</font>, 9)) {
00098 tmp = <font class="stringliteral">""</font>;
00099 tmp.append(textStart, (<font class="keywordtype">int</font>)(textEnd - textStart)+1);
00100 pushString(&to, convertToOSIS(tmp.c_str(), key));
00101 suspendTextPassThru = <font class="keyword">false</font>;
00102 }
00103
00104 <font class="comment">// Footnote</font>
00105 <font class="keywordflow">if</font> (!strcmp(token, <font class="stringliteral">"RF"</font>)) {
00106 <font class="comment">// pushString(buf, "<reference work=\"Bible.KJV\" reference=\"");</font>
00107 suspendTextPassThru = <font class="keyword">true</font>;
00108 newText = <font class="keyword">true</font>;
00109 }
00110 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strcmp(token, <font class="stringliteral">"Rf"</font>)) {
00111 tmp = <font class="stringliteral">"<note type=\"x-StudyNote\"><notePart type=\"x-MainText\">"</font>;
00112 tmp.append(textStart, (<font class="keywordtype">int</font>)(textEnd - textStart)+1);
00113 tmp += <font class="stringliteral">"</notePart></note>"</font>;
00114 pushString(&to, tmp.c_str());
00115 suspendTextPassThru = <font class="keyword">false</font>;
00116 }
00117
00118 <font class="comment">// Figure</font>
00119 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!strncmp(token, <font class="stringliteral">"img "</font>, 4)) {
00120 <font class="keyword">const</font> <font class="keywordtype">char</font> *src = strstr(token, <font class="stringliteral">"src"</font>);
00121 <font class="keywordflow">if</font> (!src) <font class="comment">// assert we have a src attribute</font>
00122 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00123
00124 pushString(&to, <font class="stringliteral">"<figure src=\""</font>);
00125 <font class="keyword">const</font> <font class="keywordtype">char</font> *c;
00126 <font class="keywordflow">for</font> (c = src;((*c) && (*c != <font class="charliteral">'"'</font>)); c++);
00127
00128 <font class="comment">/* uncomment for SWORD absolute path logic</font>
00129 <font class="comment"> if (*(c+1) == '/') {</font>
00130 <font class="comment"> pushString(buf, "file:");</font>
00131 <font class="comment"> pushString(buf, module->getConfigEntry("AbsoluteDataPath"));</font>
00132 <font class="comment"> if (*((*buf)-1) == '/')</font>
00133 <font class="comment"> c++; // skip '/'</font>
00134 <font class="comment"> }</font>
00135 <font class="comment"> end of uncomment for asolute path logic */</font>
00136
00137 <font class="keywordflow">for</font> (c++;((*c) && (*c != <font class="charliteral">'"'</font>)); c++)
00138 *to++ = *c;
00139
00140 pushString(&to, <font class="stringliteral">"\" />"</font>);
00141 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00142 }
00143
00144 <font class="comment">// Strongs numbers</font>
00145 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (*token == <font class="charliteral">'W'</font> && (token[1] == <font class="charliteral">'G'</font> || token[1] == <font class="charliteral">'H'</font>)) { <font class="comment">// Strongs</font>
00146 <font class="keywordflow">if</font> (module-><a class="code" href="class_s_w_module.html#a64">isProcessEntryAttributes</a>()) {
00147 valto = val;
00148 <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 1; ((token[i]) && (i < 150)); i++)
00149 *valto++ = token[i];
00150 *valto = 0;
00151 <font class="comment">// normal strongs number</font>
00152 strstrip(val);
00153 <font class="keywordflow">if</font> (!strncmp(wordStart, <font class="stringliteral">"<w "</font>, 3)) {
00154 sprintf(buf, <font class="stringliteral">"lemma=\"x-Strong:%s\" "</font>, val);
00155 memmove(wordStart+3+strlen(buf), wordStart+3, (to-wordStart)+1);
00156 memcpy(wordStart+3, buf, strlen(buf));
00157 to+=strlen(buf);
00158 }
00159 <font class="keywordflow">else</font> {
00160 sprintf(buf, <font class="stringliteral">"<w lemma=\"x-Strong:%s\">"</font>, val);
00161 memmove(wordStart+strlen(buf), wordStart, (to-wordStart)+1);
00162 memcpy(wordStart, buf, strlen(buf));
00163 to+=strlen(buf);
00164 pushString(&to, <font class="stringliteral">"</w>"</font>);
00165 module-><a class="code" href="class_s_w_module.html#a62">getEntryAttributes</a>()[<font class="stringliteral">"Word"</font>][wordstr][<font class="stringliteral">"Strongs"</font>] = val;
00166 }
00167 }
00168 }
00169
00170 <font class="comment">// Morphology</font>
00171 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (*token == <font class="charliteral">'W'</font> && token[1] == <font class="charliteral">'T'</font> && (token[2] == <font class="charliteral">'G'</font> || token[2] == <font class="charliteral">'H'</font>)) { <font class="comment">// Strongs</font>
00172 valto = val;
00173 <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 1; ((token[i]) && (i < 150)); i++)
00174 *valto++ = token[i];
00175 *valto = 0;
00176 strstrip(val);
00177 <font class="keywordflow">if</font> (!strncmp(wordStart, <font class="stringliteral">"<w "</font>, 3)) {
00178 sprintf(buf, <font class="stringliteral">"morph=\"x-%s:%s\" "</font>, <font class="stringliteral">"StrongsMorph"</font>, val);
00179 memmove(wordStart+3+strlen(buf), wordStart+3, (to-wordStart)+1);
00180 memcpy(wordStart+3, buf, strlen(buf));
00181 to+=strlen(buf);
00182 }
00183 <font class="keywordflow">else</font> {
00184 sprintf(buf, <font class="stringliteral">"<w morph=\"x-%s:%s\">"</font>, <font class="stringliteral">"StrongsMorph"</font>, val);
00185 memmove(wordStart+strlen(buf), wordStart, (to-wordStart)+1);
00186 memcpy(wordStart, buf, strlen(buf));
00187 to+=strlen(buf);
00188 pushString(&to, <font class="stringliteral">"</w>"</font>);
00189 }
00190 }
00191
00192 <font class="keywordflow">if</font> (!keepToken) { <font class="comment">// if we don't want strongs</font>
00193 <font class="keywordflow">if</font> (from[1] && strchr(<font class="stringliteral">" ,;.:?!()'\""</font>, from[1])) {
00194 <font class="keywordflow">if</font> (lastspace)
00195 to--;
00196 }
00197 <font class="keywordflow">if</font> (newText) {textStart = from+1; newText = <font class="keyword">false</font>; }
00198 <font class="comment">// if (newWord) {wordStart = to; newWord = false; }</font>
00199 <font class="keywordflow">continue</font>;
00200 }
00201 <font class="comment">// if not a strongs token, keep token in text</font>
00202 *to++ = <font class="charliteral">'<'</font>;
00203 <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *tok = token; *tok; tok++)
00204 *to++ = *tok;
00205 *to++ = <font class="charliteral">'>'</font>;
00206 <font class="keywordflow">if</font> (newText) {textStart = to; newWord = <font class="keyword">false</font>; }
00207 <font class="comment">// if (newWord) {wordStart = to; newWord = false; }</font>
00208 <font class="keywordflow">continue</font>;
00209 }
00210 <font class="keywordflow">if</font> (intoken) {
00211 <font class="keywordflow">if</font> ((tokpos < 2045) && ((*from != 10)&&(*from != 13))) {
00212 token[tokpos++] = *from;
00213 token[tokpos+2] = 0;
00214 }
00215 }
00216 <font class="keywordflow">else</font> {
00217 <font class="keywordflow">if</font> (newWord && (*from != <font class="charliteral">' '</font>)) {wordStart = to; newWord = <font class="keyword">false</font>; memset(to, 0, 10); }
00218 <font class="keywordflow">if</font> (!suspendTextPassThru) {
00219 *to++ = *from;
00220 lastspace = (*from == <font class="charliteral">' '</font>);
00221 }
00222 }
00223 }
00224
00225 <a class="code" href="class_verse_key.html">VerseKey</a> *vkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, key);
00226 <font class="keywordflow">if</font> (vkey) {
00227 <font class="keywordtype">char</font> ref[254];
00228 <font class="keywordflow">if</font> (vkey-><a class="code" href="class_verse_key.html#a25">Verse</a>())
00229 sprintf(ref, <font class="stringliteral">"<verseStart ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00230 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (vkey-><a class="code" href="class_verse_key.html#a24">Chapter</a>())
00231 sprintf(ref, <font class="stringliteral">"<chapterStart ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00232 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (vkey-><a class="code" href="class_verse_key.html#a23">Book</a>())
00233 sprintf(ref, <font class="stringliteral">"<bookStart ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00234 <font class="keywordflow">else</font> *ref = 0;
00235 <font class="keywordflow">if</font> (*ref) {
00236 memmove(text+strlen(ref), text, maxlen-strlen(ref)-1);
00237 memcpy(text, ref, strlen(ref));
00238 to+=strlen(ref);
00239 <font class="keywordflow">if</font> (vkey-><a class="code" href="class_verse_key.html#a25">Verse</a>()) {
00240 <a class="code" href="class_verse_key.html">VerseKey</a> tmp;
00241 tmp = *vkey;
00242 tmp.<a class="code" href="class_verse_key.html#a31">AutoNormalize</a>(0);
00243 tmp.<a class="code" href="class_verse_key.html#a32">Headings</a>(1);
00244 sprintf(ref, <font class="stringliteral">"<verseEnd ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00245 pushString(&to, ref);
00246 tmp = MAXVERSE;
00247 <font class="keywordflow">if</font> (*vkey == tmp) {
00248 tmp.<a class="code" href="class_verse_key.html#a25">Verse</a>(0);
00249 sprintf(ref, <font class="stringliteral">"<chapterEnd ref=\"%s\" />"</font>, tmp.<a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00250 pushString(&to, ref);
00251 tmp = MAXCHAPTER;
00252 tmp = MAXVERSE;
00253 <font class="keywordflow">if</font> (*vkey == tmp) {
00254 tmp.<a class="code" href="class_verse_key.html#a24">Chapter</a>(0);
00255 tmp.<a class="code" href="class_verse_key.html#a25">Verse</a>(0);
00256 sprintf(ref, <font class="stringliteral">"<bookEnd ref=\"%s\" />"</font>, tmp.<a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00257 pushString(&to, ref);
00258 }
00259 }
00260 }
00261
00262 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (vkey-><a class="code" href="class_verse_key.html#a24">Chapter</a>())
00263 sprintf(ref, <font class="stringliteral">"<chapterStart ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00264 <font class="keywordflow">else</font> sprintf(ref, <font class="stringliteral">"<bookStart ref=\"%s\" />"</font>, vkey-><a class="code" href="class_verse_key.html#a36">getOSISRef</a>());
00265 }
00266 }
00267 *to++ = 0;
00268 *to = 0;
00269 <font class="keywordflow">return</font> 0;
00270 }
00271
00272
00273 <font class="keywordtype">void</font> GBFOSIS::pushString(<font class="keywordtype">char</font> **buf, <font class="keyword">const</font> <font class="keywordtype">char</font> *format, ...) {
00274 va_list argptr;
00275
00276 va_start(argptr, format);
00277 *buf += vsprintf(*buf, format, argptr);
00278 va_end(argptr);
00279
00280 <font class="comment">// *buf += strlen(*buf);</font>
00281 }
00282
00283
00284 <font class="keyword">const</font> <font class="keywordtype">char</font> *GBFOSIS::convertToOSIS(<font class="keyword">const</font> <font class="keywordtype">char</font> *inRef, <font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *key) {
00285 <font class="keyword">static</font> string outRef;
00286
00287 outRef = <font class="stringliteral">""</font>;
00288
00289 <a class="code" href="class_verse_key.html">VerseKey</a> defLanguage;
00290 <a class="code" href="class_list_key.html">ListKey</a> verses = defLanguage.<a class="code" href="class_verse_key.html#a37">ParseVerseList</a>(inRef, (*key), <font class="keyword">true</font>);
00291 <font class="keyword">const</font> <font class="keywordtype">char</font> *startFrag = inRef;
00292 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i = 0; i < verses.<a class="code" href="class_list_key.html#a5">Count</a>(); i++) {
00293 <a class="code" href="class_verse_key.html">VerseKey</a> *element = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, verses.<a class="code" href="class_list_key.html#a8">GetElement</a>(i));
00294 <font class="keywordtype">char</font> buf[5120];
00295 <font class="keywordtype">char</font> frag[800];
00296 <font class="keywordflow">if</font> (element) {
00297 memmove(frag, startFrag, ((<font class="keyword">const</font> <font class="keywordtype">char</font> *)element-><a class="code" href="class_s_w_key.html#m0">userData</a> - startFrag) + 1);
00298 frag[((<font class="keyword">const</font> <font class="keywordtype">char</font> *)element-><a class="code" href="class_s_w_key.html#m0">userData</a> - startFrag) + 1] = 0;
00299 startFrag = (<font class="keyword">const</font> <font class="keywordtype">char</font> *)element-><a class="code" href="class_s_w_key.html#m0">userData</a> + 1;
00300 sprintf(buf, <font class="stringliteral">"<reference refStart=\"KJV:%s\" refEnd=\"%s\">%s</reference>"</font>, element-><a class="code" href="class_verse_key.html#a5">LowerBound</a>().<a class="code" href="class_verse_key.html#a36">getOSISRef</a>(), element-><a class="code" href="class_verse_key.html#a6">UpperBound</a>().<a class="code" href="class_verse_key.html#a36">getOSISRef</a>(), frag);
00301 }
00302 <font class="keywordflow">else</font> {
00303 memmove(frag, startFrag, ((<font class="keyword">const</font> <font class="keywordtype">char</font> *)verses.<a class="code" href="class_list_key.html#a8">GetElement</a>(i)-><a class="code" href="class_s_w_key.html#m0">userData</a> - startFrag) + 1);
00304 frag[((<font class="keyword">const</font> <font class="keywordtype">char</font> *)verses.<a class="code" href="class_list_key.html#a8">GetElement</a>(i)-><a class="code" href="class_s_w_key.html#m0">userData</a> - startFrag) + 1] = 0;
00305 startFrag = (<font class="keyword">const</font> <font class="keywordtype">char</font> *)verses.<a class="code" href="class_list_key.html#a8">GetElement</a>(i)-><a class="code" href="class_s_w_key.html#m0">userData</a> + 1;
00306 sprintf(buf, <font class="stringliteral">"<reference refStart=\"KJV:%s\">%s</reference>"</font>, <a class="code" href="class_verse_key.html">VerseKey</a>(*verses.<a class="code" href="class_list_key.html#a8">GetElement</a>(i)).getOSISRef(), frag);
00307 }
00308 outRef+=buf;
00309 }
00310 <font class="keywordflow">return</font> outRef.c_str();
00311 }
</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>