~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/modules/filters/gbfrtf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *
 
3
 * gbfrtf -     SWFilter descendant to convert all GBF tags to RTF tags
 
4
 *
 
5
 *
 
6
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
7
 *      CrossWire Bible Society
 
8
 *      P. O. Box 2528
 
9
 *      Tempe, AZ  85280-2528
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify it
 
12
 * under the terms of the GNU General Public License as published by the
 
13
 * Free Software Foundation version 2.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
 * General Public License for more details.
 
19
 *
 
20
 */
 
21
 
 
22
#include <gbfrtf.h>
 
23
#include <utilstr.h>
 
24
#include <ctype.h>
 
25
#include <swbuf.h>
 
26
 
 
27
SWORD_NAMESPACE_START
 
28
 
 
29
GBFRTF::GBFRTF() {
 
30
}
 
31
 
 
32
 
 
33
char GBFRTF::processText(SWBuf &text, const SWKey *key, const SWModule *module)
 
34
{
 
35
        char token[2048];
 
36
        char val[128];
 
37
        char *valto;
 
38
        char *num;
 
39
        int tokpos = 0;
 
40
        bool intoken = false;
 
41
        const char *tok;
 
42
        SWBuf strongnum;
 
43
        SWBuf strongtense;
 
44
        bool hideText = false;
 
45
        int wordLen = 0;
 
46
        int wordCount = 0;
 
47
 
 
48
        const char *from;
 
49
        SWBuf orig = text;
 
50
        from = orig.c_str();
 
51
        for (text = ""; *from; from++) {
 
52
                if (*from == '<') {
 
53
                        wordLen = wordCount;
 
54
                        wordCount = 0;
 
55
                        intoken = true;
 
56
                        tokpos = 0;
 
57
                        token[0] = 0;
 
58
                        token[1] = 0;
 
59
                        token[2] = 0;
 
60
                        continue;
 
61
                }
 
62
                if (*from == '>') {
 
63
                        intoken = false;
 
64
                                                // process desired tokens
 
65
                        // deal with OSIS note tags.  Just hide till OSISRTF
 
66
                        if (!strncmp(token, "note ", 5)) {
 
67
                                hideText = true;
 
68
                        }
 
69
                        if (!strncmp(token, "/note", 5)) {
 
70
                                hideText = false;
 
71
                        }
 
72
 
 
73
                        switch (*token) {
 
74
                        case 'w':       // OSIS Word (temporary until OSISRTF is done)
 
75
                                strongnum = "";
 
76
                                strongtense = "";
 
77
                                valto = val;
 
78
                                num = strstr(token, "lemma=\"x-Strongs:");
 
79
                                if (num) {
 
80
                                        for (num+=17; ((*num) && (*num != '\"')); num++)
 
81
                                                *valto++ = *num;
 
82
                                        *valto = 0;
 
83
                                        if (atoi((!isdigit(*val))?val+1:val) < 5627) {
 
84
                                                // normal strongs number
 
85
                                                strongnum += "{\\cf3 \\sub <";
 
86
                                                for (tok = (!isdigit(*val))?val+1:val; *tok; tok++)
 
87
                                                        strongnum += *tok;
 
88
                                                strongnum += ">}";
 
89
                                        }
 
90
                                        /*      forget these for now
 
91
                                        else {
 
92
                                                // verb morph
 
93
                                                sprintf(wordstr, "%03d", word-1);
 
94
                                                module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
 
95
                                        }
 
96
                                        */
 
97
                                }
 
98
                                else {
 
99
                                        num = strstr(token, "lemma=\"strong:");
 
100
                                        if (num) {
 
101
                                                for (num+=14; ((*num) && (*num != '\"')); num++)
 
102
                                                        *valto++ = *num;
 
103
                                                *valto = 0;
 
104
                                                if (atoi((!isdigit(*val))?val+1:val) < 5627) {
 
105
                                                        // normal strongs number
 
106
                                                        strongnum += "{\\cf3 \\sub <";
 
107
                                                        for (tok = (!isdigit(*val))?val+1:val; *tok; tok++)
 
108
                                                                strongnum += *tok;
 
109
                                                        strongnum += ">}";
 
110
                                                }
 
111
                                                /*      forget these for now
 
112
                                                else {
 
113
                                                        // verb morph
 
114
                                                        sprintf(wordstr, "%03d", word-1);
 
115
                                                        module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
 
116
                                                }
 
117
                                                */
 
118
                                        }
 
119
                                }
 
120
                                valto = val;
 
121
                                num = strstr(token, "morph=\"x-Robinson:");
 
122
                                if (num) {
 
123
                                        for (num+=18; ((*num) && (*num != '\"')); num++)
 
124
                                                *valto++ = *num;
 
125
                                        *valto = 0;
 
126
                                        // normal robinsons tense
 
127
                                        strongtense += "{\\cf4 \\sub (";
 
128
                                        for (tok = val; *tok; tok++)
 
129
                                                strongtense += *tok;
 
130
                                        strongtense += ")}";
 
131
                                }
 
132
                                continue;
 
133
 
 
134
                        case '/':
 
135
                                if (token[1] == 'w') {
 
136
                                        if ((wordCount > 0) || (strongnum != "{\\cf3 \\sub <3588>}")) {
 
137
                                                //for (i = 0; i < strongnum.length(); i++)
 
138
                                                        text += strongnum;
 
139
                                        //for (i = 0; i < strongtense.length(); i++)
 
140
                                                text += strongtense;
 
141
                                        }
 
142
                                }
 
143
                                continue;
 
144
 
 
145
                        case 'W':       // Strongs
 
146
                                switch(token[1]) {
 
147
                                case 'G':               // Greek
 
148
                                case 'H':               // Hebrew
 
149
                                        text += "{\\cf3 \\sub <";
 
150
                                        for (tok = token + 2; *tok; tok++)
 
151
                                                text += *tok;
 
152
                                        text += ">}";
 
153
                                        continue;
 
154
 
 
155
                                case 'T':               // Tense
 
156
                                        text += "{\\cf4 \\sub (";
 
157
                                        bool separate = false;
 
158
                                        for (tok = token + 2; *tok; tok++) {
 
159
                                                if (separate) {
 
160
                                                        text += "; ";
 
161
                                                        separate = false;
 
162
                                                }
 
163
                                                switch (*tok) {
 
164
                                                case 'G':
 
165
                                                case 'H':
 
166
                                                        for (tok++; *tok; tok++) {
 
167
                                                                if (isdigit(*tok)) {
 
168
                                                                        text += *tok;
 
169
                                                                        separate = true;
 
170
                                                                }
 
171
                                                                else {
 
172
                                                                        tok--;
 
173
                                                                        break;
 
174
                                                                }
 
175
                                                        }
 
176
                                                        break;
 
177
                                                default:
 
178
                                                        for (; *tok; tok++) {
 
179
                                                               text += *tok;
 
180
                                                        }
 
181
                                                }
 
182
                                        }
 
183
                                        text += ")}";
 
184
                                        continue;
 
185
                                }
 
186
                                break;
 
187
                        case 'R':
 
188
                                switch(token[1]) {
 
189
                                case 'X':
 
190
                                        text += "<a href=\"\">";
 
191
                                  continue;
 
192
                                case 'x':
 
193
                                        text += "</a>";
 
194
                                  continue;
 
195
                                case 'F':               // footnote begin
 
196
                                        text += "{\\i1 \\sub [ ";
 
197
                                        continue;
 
198
                                case 'f':               // footnote end
 
199
                                        text += " ] }";
 
200
                                        continue;
 
201
                                }
 
202
                                break;
 
203
                        case 'F':                       // font tags
 
204
                                switch(token[1]) {
 
205
                                case 'I':               // italic start
 
206
                                        text += "\\i1 ";
 
207
                                        continue;
 
208
                                case 'i':               // italic end
 
209
                                        text += "\\i0 ";
 
210
                                        continue;
 
211
                                case 'B':               // bold start
 
212
                                        text += "\\b1 ";
 
213
                                        continue;
 
214
                                case 'b':               // bold end
 
215
                                        text += "\\b0 ";
 
216
                                        continue;
 
217
                                case 'N':
 
218
                                        text += '{';
 
219
                                        if (!strnicmp(token+2, "Symbol", 6))
 
220
                                                text += "\\f7 ";
 
221
                                        if (!strnicmp(token+2, "Courier", 7))
 
222
                                                text += "\\f8 ";
 
223
                                        continue;
 
224
                                case 'n':
 
225
                                        text += '}';
 
226
                                        continue;
 
227
                                case 'S':
 
228
                                        text += "{\\super ";
 
229
                                        continue;
 
230
                                case 's':
 
231
                                        text += '}';
 
232
                                        continue;
 
233
                                case 'R':
 
234
                                        text += "{\\cf6 ";
 
235
                                        continue;
 
236
                                case 'r':
 
237
                                        text += '}';
 
238
                                        continue;
 
239
                                case 'O':
 
240
                                case 'C':
 
241
                                        text += "\\scaps1 ";
 
242
                                        continue;
 
243
                                case 'o':
 
244
                                case 'c':
 
245
                                        text += "\\scaps0 ";
 
246
                                        continue;
 
247
                                case 'V':
 
248
                                        text += "{\\sub ";
 
249
                                        continue;
 
250
                                case 'v':
 
251
                                        text += '}';
 
252
                                        continue;
 
253
                                case 'U':
 
254
                                        text += "\\ul1 ";
 
255
                                        continue;
 
256
                                case 'u':
 
257
                                        text += "\\ul0 ";
 
258
                                        continue;
 
259
                                }
 
260
                                break;
 
261
                        case 'C':                       // special character tags
 
262
                                switch(token[1]) {
 
263
                                case 'A':               // ASCII value
 
264
                                        text += (char)atoi(&token[2]);
 
265
                                        continue;
 
266
                                case 'G':
 
267
                                        text += '>';
 
268
                                        continue;
 
269
                                case 'L':               // line break
 
270
                                        text += "\\line ";
 
271
                                        continue;
 
272
                                case 'M':               // new paragraph
 
273
                                        text += "\\par ";
 
274
                                        continue;
 
275
                                case 'T':
 
276
                                        text += '<';
 
277
                                }
 
278
                                break;
 
279
                        case 'T':                       // title formatting
 
280
                          switch(token[1])
 
281
                            {
 
282
                            case 'T':               // Book title begin
 
283
                                        text += "{\\large ";
 
284
                                 continue;
 
285
                            case 't':
 
286
                                 text += '}';
 
287
                                 continue;
 
288
                            case 'S':
 
289
                                        text += "\\par {\\i1\\b1 ";
 
290
                              continue;
 
291
                            case 's':
 
292
                                        text += "}\\par ";
 
293
                              continue;
 
294
                            }
 
295
                          break;
 
296
                        case 'J':       // Strongs
 
297
                                switch(token[1]) {
 
298
                                case 'L':
 
299
                                        text += "\\ql ";
 
300
                                case 'C':
 
301
                                        text += "\\qc ";
 
302
                                case 'R':
 
303
                                        text += "\\qr ";
 
304
                                case 'F':
 
305
                                        text += "\\qj ";
 
306
                                }
 
307
                        }
 
308
                        continue;
 
309
                }
 
310
                if (intoken) {
 
311
                        if (tokpos < 2045)
 
312
                                token[tokpos++] = *from;
 
313
                                token[tokpos+2] = 0;
 
314
                }
 
315
                else {
 
316
                        if (!hideText) {
 
317
                                wordCount++;
 
318
                                text += *from;
 
319
                        }
 
320
                }
 
321
        }
 
322
        return 0;
 
323
}
 
324
 
 
325
SWORD_NAMESPACE_END
 
326