1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
<!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>
|