blob: 504743f6517f07afcf4cb9a9ae702f38b2ff8643 (
plain) (
blame)
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
|
<!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>gbfrtf.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>gbfrtf.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * gbfrtf - SWFilter decendant to convert all GBF tags to RTF tags</font>
00004 <font class="comment"> */</font>
00005
00006
00007 <font class="preprocessor">#include <stdlib.h></font>
00008 <font class="preprocessor">#include <string.h></font>
00009 <font class="preprocessor">#include <gbfrtf.h></font>
00010 <font class="preprocessor">#include <ctype.h></font>
00011
00012 GBFRTF::GBFRTF() {
00013 }
00014
00015
00016 <font class="keywordtype">char</font> GBFRTF::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)
00017 {
00018 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *to, *from;
00019 <font class="keywordtype">char</font> token[2048];
00020 <font class="keywordtype">int</font> tokpos = 0;
00021 <font class="keywordtype">bool</font> intoken = <font class="keyword">false</font>;
00022 <font class="keywordtype">int</font> len;
00023 <font class="keyword">const</font> <font class="keywordtype">char</font> *tok;
00024
00025 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font>
00026 <font class="keywordflow">if</font> (len < maxlen) {
00027 memmove(&text[maxlen - len], text, len);
00028 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *)&text[maxlen - len];
00029 }
00030 <font class="keywordflow">else</font> from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *)text; <font class="comment">// -------------------------------</font>
00031 <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *)text; *from; from++) {
00032 <font class="keywordflow">if</font> (*from == <font class="charliteral">'<'</font>) {
00033 intoken = <font class="keyword">true</font>;
00034 tokpos = 0;
00035 token[0] = 0;
00036 token[1] = 0;
00037 token[2] = 0;
00038 <font class="keywordflow">continue</font>;
00039 }
00040 <font class="keywordflow">if</font> (*from == <font class="charliteral">'>'</font>) {
00041 intoken = <font class="keyword">false</font>;
00042 <font class="comment">// process desired tokens</font>
00043 <font class="keywordflow">switch</font> (*token) {
00044 <font class="keywordflow">case</font> <font class="charliteral">'W'</font>: <font class="comment">// Strongs</font>
00045 <font class="keywordflow">switch</font>(token[1]) {
00046 <font class="keywordflow">case</font> <font class="charliteral">'G'</font>: <font class="comment">// Greek</font>
00047 <font class="keywordflow">case</font> <font class="charliteral">'H'</font>: <font class="comment">// Hebrew</font>
00048 *to++ = <font class="charliteral">'{'</font>;
00049 *to++ = <font class="charliteral">'\\'</font>;
00050 *to++ = <font class="charliteral">'f'</font>;
00051 *to++ = <font class="charliteral">'s'</font>;
00052 *to++ = <font class="charliteral">'1'</font>;
00053 *to++ = <font class="charliteral">'7'</font>;
00054 *to++ = <font class="charliteral">' '</font>;
00055 *to++ = <font class="charliteral">'<'</font>;
00056 <font class="keywordflow">for</font> (tok = token + 2; *tok; tok++)
00057 *to++ = *tok;
00058 *to++ = <font class="charliteral">'>'</font>;
00059 *to++ = <font class="charliteral">'}'</font>;
00060 <font class="keywordflow">continue</font>;
00061
00062 <font class="keywordflow">case</font> <font class="charliteral">'T'</font>: <font class="comment">// Tense</font>
00063 *to++ = <font class="charliteral">'{'</font>;
00064 *to++ = <font class="charliteral">'\\'</font>;
00065 *to++ = <font class="charliteral">'f'</font>;
00066 *to++ = <font class="charliteral">'s'</font>;
00067 *to++ = <font class="charliteral">'1'</font>;
00068 *to++ = <font class="charliteral">'7'</font>;
00069 *to++ = <font class="charliteral">' '</font>;
00070 *to++ = <font class="charliteral">'('</font>;
00071 <font class="keywordtype">bool</font> separate = <font class="keyword">false</font>;
00072 <font class="keywordflow">for</font> (tok = token + 2; *tok; tok++) {
00073 <font class="keywordflow">if</font> (separate) {
00074 *to++ = <font class="charliteral">';'</font>;
00075 *to++ = <font class="charliteral">' '</font>;
00076 separate = <font class="keyword">false</font>;
00077 }
00078 <font class="keywordflow">switch</font> (*tok) {
00079 <font class="keywordflow">case</font> <font class="charliteral">'G'</font>:
00080 <font class="keywordflow">case</font> <font class="charliteral">'H'</font>:
00081 <font class="keywordflow">for</font> (tok++; *tok; tok++) {
00082 <font class="keywordflow">if</font> (isdigit(*tok)) {
00083 *to++ = *tok;
00084 separate = <font class="keyword">true</font>;
00085 }
00086 <font class="keywordflow">else</font> {
00087 tok--;
00088 <font class="keywordflow">break</font>;
00089 }
00090 }
00091 <font class="keywordflow">break</font>;
00092 <font class="keywordflow">default</font>:
00093 <font class="keywordflow">for</font> (; *tok; tok++) {
00094 *to++ = *tok;
00095 }
00096 }
00097 }
00098 *to++ = <font class="charliteral">')'</font>;
00099 *to++ = <font class="charliteral">'}'</font>;
00100 <font class="keywordflow">continue</font>;
00101 }
00102 <font class="keywordflow">break</font>;
00103 <font class="keywordflow">case</font> <font class="charliteral">'R'</font>:
00104 <font class="keywordflow">switch</font>(token[1]) {
00105 <font class="keywordflow">case</font> <font class="charliteral">'X'</font>:
00106 *to++ = <font class="charliteral">'<'</font>;
00107 *to++ = <font class="charliteral">'a'</font>;
00108 *to++ = <font class="charliteral">' '</font>;
00109 *to++ = <font class="charliteral">'h'</font>;
00110 *to++ = <font class="charliteral">'r'</font>;
00111 *to++ = <font class="charliteral">'e'</font>;
00112 *to++ = <font class="charliteral">'f'</font>;
00113 *to++ = <font class="charliteral">'='</font>;
00114 *to++ = <font class="charliteral">'"'</font>;
00115 *to++ = <font class="charliteral">'"'</font>;
00116 *to++ = <font class="charliteral">'>'</font>;
00117 <font class="keywordflow">continue</font>;
00118 <font class="keywordflow">case</font> <font class="charliteral">'x'</font>:
00119 *to++ = <font class="charliteral">'<'</font>;
00120 *to++ = <font class="charliteral">'/'</font>;
00121 *to++ = <font class="charliteral">'a'</font>;
00122 *to++ = <font class="charliteral">'>'</font>;
00123 <font class="keywordflow">continue</font>;
00124 <font class="keywordflow">case</font> <font class="charliteral">'F'</font>: <font class="comment">// footnote begin</font>
00125 *to++ = <font class="charliteral">'{'</font>;
00126 *to++ = <font class="charliteral">'\\'</font>;
00127 *to++ = <font class="charliteral">'i'</font>;
00128 *to++ = <font class="charliteral">'1'</font>;
00129 *to++ = <font class="charliteral">' '</font>;
00130 *to++ = <font class="charliteral">'\\'</font>;
00131 *to++ = <font class="charliteral">'f'</font>;
00132 *to++ = <font class="charliteral">'s'</font>;
00133 *to++ = <font class="charliteral">'1'</font>;
00134 *to++ = <font class="charliteral">'7'</font>;
00135 *to++ = <font class="charliteral">' '</font>;
00136 *to++ = <font class="charliteral">'('</font>;
00137 <font class="keywordflow">continue</font>;
00138 <font class="keywordflow">case</font> <font class="charliteral">'f'</font>: <font class="comment">// footnote end</font>
00139 *to++ = <font class="charliteral">')'</font>;
00140 *to++ = <font class="charliteral">' '</font>;
00141 *to++ = <font class="charliteral">'}'</font>;
00142 <font class="keywordflow">continue</font>;
00143 }
00144 <font class="keywordflow">break</font>;
00145 <font class="keywordflow">case</font> <font class="charliteral">'F'</font>: <font class="comment">// font tags</font>
00146 <font class="keywordflow">switch</font>(token[1]) {
00147 <font class="keywordflow">case</font> <font class="charliteral">'I'</font>: <font class="comment">// italic start</font>
00148 *to++ = <font class="charliteral">'\\'</font>;
00149 *to++ = <font class="charliteral">'i'</font>;
00150 *to++ = <font class="charliteral">'1'</font>;
00151 *to++ = <font class="charliteral">' '</font>;
00152 <font class="keywordflow">continue</font>;
00153 <font class="keywordflow">case</font> <font class="charliteral">'i'</font>: <font class="comment">// italic end</font>
00154 *to++ = <font class="charliteral">'\\'</font>;
00155 *to++ = <font class="charliteral">'i'</font>;
00156 *to++ = <font class="charliteral">'0'</font>;
00157 *to++ = <font class="charliteral">' '</font>;
00158 <font class="keywordflow">continue</font>;
00159 <font class="keywordflow">case</font> <font class="charliteral">'B'</font>: <font class="comment">// bold start</font>
00160 *to++ = <font class="charliteral">'\\'</font>;
00161 *to++ = <font class="charliteral">'b'</font>;
00162 *to++ = <font class="charliteral">'1'</font>;
00163 *to++ = <font class="charliteral">' '</font>;
00164 <font class="keywordflow">continue</font>;
00165 <font class="keywordflow">case</font> <font class="charliteral">'b'</font>: <font class="comment">// bold end</font>
00166 *to++ = <font class="charliteral">'\\'</font>;
00167 *to++ = <font class="charliteral">'b'</font>;
00168 *to++ = <font class="charliteral">'0'</font>;
00169 *to++ = <font class="charliteral">' '</font>;
00170 <font class="keywordflow">continue</font>;
00171 <font class="keywordflow">case</font> <font class="charliteral">'N'</font>:
00172 *to++ = <font class="charliteral">'{'</font>;
00173 <font class="keywordflow">if</font> (!strnicmp(token+2, <font class="stringliteral">"Symbol"</font>, 6)) {
00174 *to++ = <font class="charliteral">'\\'</font>;
00175 *to++ = <font class="charliteral">'f'</font>;
00176 *to++ = <font class="charliteral">'7'</font>;
00177 *to++ = <font class="charliteral">' '</font>;
00178 }
00179 <font class="keywordflow">continue</font>;
00180 <font class="keywordflow">case</font> <font class="charliteral">'n'</font>:
00181 *to++ = <font class="charliteral">'}'</font>;
00182 <font class="keywordflow">continue</font>;
00183 <font class="keywordflow">case</font> <font class="charliteral">'S'</font>:
00184 *to++ = <font class="charliteral">'{'</font>;
00185 *to++ = <font class="charliteral">'\\'</font>;
00186 *to++ = <font class="charliteral">'s'</font>;
00187 *to++ = <font class="charliteral">'u'</font>;
00188 *to++ = <font class="charliteral">'p'</font>;
00189 *to++ = <font class="charliteral">'e'</font>;
00190 *to++ = <font class="charliteral">'r'</font>;
00191 *to++ = <font class="charliteral">' '</font>;
00192 <font class="keywordflow">continue</font>;
00193 <font class="keywordflow">case</font> <font class="charliteral">'s'</font>:
00194 *to++ = <font class="charliteral">'}'</font>;
00195 <font class="keywordflow">continue</font>;
00196 <font class="keywordflow">case</font> <font class="charliteral">'R'</font>:
00197 *to++ = <font class="charliteral">'{'</font>;
00198 *to++ = <font class="charliteral">'\\'</font>;
00199 *to++ = <font class="charliteral">'c'</font>;
00200 *to++ = <font class="charliteral">'f'</font>;
00201 *to++ = <font class="charliteral">'6'</font>;
00202 *to++ = <font class="charliteral">' '</font>;
00203 <font class="keywordflow">continue</font>;
00204 <font class="keywordflow">case</font> <font class="charliteral">'r'</font>:
00205 *to++ = <font class="charliteral">'}'</font>;
00206 <font class="keywordflow">continue</font>;
00207 }
00208 <font class="keywordflow">break</font>;
00209 <font class="keywordflow">case</font> <font class="charliteral">'C'</font>: <font class="comment">// special character tags</font>
00210 <font class="keywordflow">switch</font>(token[1]) {
00211 <font class="keywordflow">case</font> <font class="charliteral">'A'</font>: <font class="comment">// ASCII value</font>
00212 *to++ = (char)atoi(&token[2]);
00213 <font class="keywordflow">continue</font>;
00214 <font class="keywordflow">case</font> <font class="charliteral">'G'</font>:
00215 *to++ = <font class="charliteral">'>'</font>;
00216 <font class="keywordflow">continue</font>;
00217 <font class="keywordflow">case</font> <font class="charliteral">'L'</font>: <font class="comment">// line break</font>
00218 *to++ = <font class="charliteral">'\\'</font>;
00219 *to++ = <font class="charliteral">'l'</font>;
00220 *to++ = <font class="charliteral">'i'</font>;
00221 *to++ = <font class="charliteral">'n'</font>;
00222 *to++ = <font class="charliteral">'e'</font>;
00223 *to++ = <font class="charliteral">' '</font>;
00224 <font class="keywordflow">continue</font>;
00225 <font class="keywordflow">case</font> <font class="charliteral">'M'</font>: <font class="comment">// new paragraph</font>
00226 *to++ = <font class="charliteral">'\\'</font>;
00227 *to++ = <font class="charliteral">'p'</font>;
00228 *to++ = <font class="charliteral">'a'</font>;
00229 *to++ = <font class="charliteral">'r'</font>;
00230 *to++ = <font class="charliteral">' '</font>;
00231 <font class="keywordflow">continue</font>;
00232 <font class="keywordflow">case</font> <font class="charliteral">'T'</font>:
00233 *to++ = <font class="charliteral">'<'</font>;
00234 }
00235 <font class="keywordflow">break</font>;
00236 <font class="keywordflow">case</font> <font class="charliteral">'T'</font>: <font class="comment">// title formatting</font>
00237 <font class="keywordflow">switch</font>(token[1])
00238 {
00239 <font class="keywordflow">case</font> <font class="charliteral">'T'</font>: <font class="comment">// Book title begin</font>
00240 *to++ = <font class="charliteral">'{'</font>;
00241 *to++ = <font class="charliteral">'\\'</font>;
00242 *to++ = <font class="charliteral">'f'</font>;
00243 *to++ = <font class="charliteral">'s'</font>;
00244 *to++ = <font class="charliteral">'2'</font>;
00245 *to++ = <font class="charliteral">'2'</font>;
00246 *to++ = <font class="charliteral">' '</font>;
00247 <font class="keywordflow">continue</font>;
00248 <font class="keywordflow">case</font> <font class="charliteral">'t'</font>:
00249 *to++ = <font class="charliteral">'}'</font>;
00250 <font class="keywordflow">continue</font>;
00251 <font class="keywordflow">case</font> <font class="charliteral">'S'</font>:
00252 *to++ = <font class="charliteral">'\\'</font>;
00253 *to++ = <font class="charliteral">'p'</font>;
00254 *to++ = <font class="charliteral">'a'</font>;
00255 *to++ = <font class="charliteral">'r'</font>;
00256 *to++ = <font class="charliteral">' '</font>;
00257 *to++ = <font class="charliteral">'{'</font>;
00258 *to++ = <font class="charliteral">'\\'</font>;
00259 *to++ = <font class="charliteral">'i'</font>;
00260 *to++ = <font class="charliteral">'1'</font>;
00261 *to++ = <font class="charliteral">'\\'</font>;
00262 *to++ = <font class="charliteral">'b'</font>;
00263 *to++ = <font class="charliteral">'1'</font>;
00264 *to++ = <font class="charliteral">' '</font>;
00265 <font class="keywordflow">continue</font>;
00266 <font class="keywordflow">case</font> <font class="charliteral">'s'</font>:
00267 *to++ = <font class="charliteral">'}'</font>;
00268 *to++ = <font class="charliteral">'\\'</font>;
00269 *to++ = <font class="charliteral">'p'</font>;
00270 *to++ = <font class="charliteral">'a'</font>;
00271 *to++ = <font class="charliteral">'r'</font>;
00272 *to++ = <font class="charliteral">' '</font>;
00273 <font class="keywordflow">continue</font>;
00274 }
00275 <font class="keywordflow">break</font>;
00276
00277 }
00278 <font class="keywordflow">continue</font>;
00279 }
00280 <font class="keywordflow">if</font> (intoken) {
00281 <font class="keywordflow">if</font> (tokpos < 2045)
00282 token[tokpos++] = *from;
00283 token[tokpos+2] = 0;
00284 }
00285 <font class="keywordflow">else</font> *to++ = *from;
00286 }
00287 *to++ = 0;
00288 *to = 0;
00289 <font class="keywordflow">return</font> 0;
00290 }
</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>
|