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

« back to all changes in this revision

Viewing changes to src/modules/filters/gbfwordjs.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
 * gbfstrongs - SWFilter descendant to hide or show strongs number
 
4
 *                      in a GBF module.
 
5
 *
 
6
 *
 
7
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
8
 *      CrossWire Bible Society
 
9
 *      P. O. Box 2528
 
10
 *      Tempe, AZ  85280-2528
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify it
 
13
 * under the terms of the GNU General Public License as published by the
 
14
 * Free Software Foundation version 2.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful, but
 
17
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
 * General Public License for more details.
 
20
 *
 
21
 */
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <gbfwordjs.h>
 
26
#include <swmodule.h>
 
27
#include <ctype.h>
 
28
#include <utilstr.h>
 
29
#include <versekey.h>
 
30
 
 
31
SWORD_NAMESPACE_START
 
32
 
 
33
const char oName[] = "Word Javascript";
 
34
const char oTip[] = "Toggles Word Javascript data";
 
35
 
 
36
const SWBuf choices[3] = {"Off", "On", ""};
 
37
const StringList oValues(&choices[0], &choices[2]);
 
38
 
 
39
 
 
40
GBFWordJS::GBFWordJS() : SWOptionFilter(oName, oTip, &oValues) {
 
41
        setOptionValue("Off");
 
42
 
 
43
     defaultGreekLex   = 0;
 
44
     defaultHebLex     = 0;
 
45
     defaultGreekParse = 0;
 
46
     defaultHebParse   = 0;
 
47
     mgr               = 0;
 
48
}
 
49
 
 
50
 
 
51
GBFWordJS::~GBFWordJS() {
 
52
}
 
53
 
 
54
 
 
55
char GBFWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
 
56
        if (option) {
 
57
                char token[2112]; // cheese.  Fix.
 
58
                int tokpos = 0;
 
59
                bool intoken = false;
 
60
                bool lastspace = false;
 
61
                int word = 1;
 
62
                char val[128];
 
63
                char wordstr[5];
 
64
                unsigned int textStart = 0, lastAppendLen = 0, textEnd = 0;
 
65
                SWBuf tmp;
 
66
                bool newText = false;
 
67
                bool needWordOut = false;
 
68
                AttributeValue *wordAttrs = 0;
 
69
                SWBuf modName = (module)?module->Name():"";
 
70
                SWBuf wordSrcPrefix = modName;
 
71
                
 
72
                const SWBuf orig = text;
 
73
                const char * from = orig.c_str();
 
74
                VerseKey *vkey = 0;
 
75
                if (key) {
 
76
                        vkey = SWDYNAMIC_CAST(VerseKey, key);
 
77
                }
 
78
 
 
79
                for (text = ""; *from; from++) {
 
80
                        if (*from == '<') {
 
81
                                intoken = true;
 
82
                                tokpos = 0;
 
83
                                token[0] = 0;
 
84
                                token[1] = 0;
 
85
                                token[2] = 0;
 
86
                                textEnd = text.length();
 
87
                                continue;
 
88
                        }
 
89
                        if (*from == '>') {     // process tokens
 
90
                                intoken = false;
 
91
                                if (*token == 'W' && (token[1] == 'G' || token[1] == 'H')) {    // Strongs
 
92
                                        strcpy(val,token+1);
 
93
                                        if (atoi((!isdigit(*val))?val+1:val) < 5627) {
 
94
                                                // normal strongs number
 
95
                                                sprintf(wordstr, "%03d", word++);
 
96
                                                needWordOut = (word > 2);
 
97
                                                wordAttrs = &(module->getEntryAttributes()["Word"][wordstr]);
 
98
                                                (*wordAttrs)["Lemma"] = val;
 
99
        //printf("Adding: [\"Word\"][%s][\"Strongs\"] = %s\n", wordstr, val);
 
100
                                                tmp = "";
 
101
                                                tmp.append(text.c_str()+textStart, (int)(textEnd - textStart));
 
102
                                                (*wordAttrs)["Text"] = tmp;
 
103
                                                text.append("</span>");
 
104
                                                SWBuf ts;
 
105
                                                ts.appendFormatted("%d", textStart);
 
106
                                                (*wordAttrs)["TextStart"] = ts;
 
107
        //printf("Adding: [\"Word\"][%s][\"Text\"] = %s\n", wordstr, tmp.c_str());
 
108
                                                newText = true;
 
109
                                        }
 
110
                                        else {
 
111
                                                // verb morph
 
112
                                                if (wordAttrs) {
 
113
                                                        (*wordAttrs)["Morph"] = val;
 
114
                                                }
 
115
        //printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val);
 
116
                                        }
 
117
 
 
118
                                }
 
119
                                if (*token == 'W' && token[1] == 'T') { // Morph
 
120
                                        if (token[2] == 'G' || token[2] == 'H') {
 
121
                                                strcpy(val, token+2);
 
122
                                        }
 
123
                                        else strcpy(val, token+1);
 
124
                                        if (wordAttrs) {
 
125
                                                (*wordAttrs)["Morph"] = val;
 
126
                                                (*wordAttrs)["MorphClass"] = "StrongsMorph";
 
127
                                        }
 
128
                                        newText = true;
 
129
                                }
 
130
                                // if not a strongs token, keep token in text
 
131
                                text += '<';
 
132
                                text += token;
 
133
                                text += '>';
 
134
                                if (needWordOut) {
 
135
                                        char wstr[10];
 
136
                                        sprintf(wstr, "%03d", word-2);
 
137
                                        AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
 
138
                                        needWordOut = false;
 
139
                                        SWBuf strong = (*wAttrs)["Lemma"];
 
140
                                        SWBuf morph = (*wAttrs)["Morph"];
 
141
                                        SWBuf morphClass = (*wAttrs)["MorphClass"];
 
142
                                        SWBuf wordText = (*wAttrs)["Text"];
 
143
                                        SWBuf textSt = (*wAttrs)["TextStart"];
 
144
                                        if (strong.size()) {
 
145
                                                char gh = 0;
 
146
                                                gh = isdigit(strong[0]) ? 0:strong[0];
 
147
                                                if (!gh) {
 
148
                                                        if (vkey) {
 
149
                                                                gh = vkey->Testament() ? 'H' : 'G';
 
150
                                                        }
 
151
                                                }
 
152
                                                else strong << 1;
 
153
 
 
154
                                                SWModule *sLex = 0;
 
155
                                                SWModule *sMorph = 0;
 
156
                                                if (gh == 'G') {
 
157
                                                        sLex = defaultGreekLex;
 
158
                                                        sMorph = defaultGreekParse;
 
159
                                                }
 
160
                                                if (gh == 'H') {
 
161
                                                        sLex = defaultHebLex;
 
162
                                                        sMorph = defaultHebParse;
 
163
                                                }
 
164
                                                SWBuf lexName = "";
 
165
                                                if (sLex) {
 
166
                                                        // we can pass the real lex name in, but we have some
 
167
                                                        // aliases in the javascript to optimize bandwidth
 
168
                                                        lexName = sLex->Name();
 
169
                                                        if (lexName == "StrongsGreek")
 
170
                                                                lexName = "G";
 
171
                                                        if (lexName == "StrongsHebrew")
 
172
                                                                lexName = "H";
 
173
                                                }
 
174
                                                SWBuf wordID;
 
175
                                                if (vkey) {
 
176
                                                        // optimize for bandwidth and use only the verse as the unique entry id
 
177
                                                        wordID.appendFormatted("%d", vkey->Verse());
 
178
                                                }
 
179
                                                else {
 
180
                                                        wordID = key->getText();
 
181
                                                }
 
182
                                                for (unsigned int i = 0; i < wordID.size(); i++) {
 
183
                                                        if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) {
 
184
                                                                wordID[i] = '_';
 
185
                                                        }
 
186
                                                }
 
187
                                                wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr));
 
188
                                                if (textSt.size()) {
 
189
                                                        int textStr = atoi(textSt.c_str());
 
190
                                                        textStr += lastAppendLen;
 
191
                                                        SWBuf spanStart = "";
 
192
 
 
193
 
 
194
 
 
195
/*
 
196
                                                        if (sMorph) {
 
197
                                                                SWBuf popMorph = "<a onclick=\"";
 
198
                                                                popMorph.appendFormatted("p(\'%s\',\'%s\','%s','');\" >%s</a>", sMorph->Name(), morph.c_str(), wordID.c_str(), morph.c_str());
 
199
                                                                morph = popMorph;
 
200
                                                        }
 
201
*/
 
202
 
 
203
                                                        // 'p' = 'fillpop' to save bandwidth
 
204
                                                        const char *m = strchr(morph.c_str(), ':');
 
205
                                                        if (m) m++;
 
206
                                                        else m = morph.c_str();
 
207
                                                        spanStart.appendFormatted("<span class=\"clk\" onclick=\"p('%s','%s','%s','%s','','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m, modName.c_str());
 
208
                                                        text.insert(textStr, spanStart);
 
209
                                                        lastAppendLen = spanStart.length();
 
210
                                                }
 
211
                                        }
 
212
 
 
213
                                }
 
214
                                if (newText) {
 
215
                                        textStart = text.length(); newText = false;
 
216
                                }
 
217
                                continue;
 
218
                        }
 
219
                        if (intoken) {
 
220
                                if (tokpos < 2045)
 
221
                                        token[tokpos++] = *from;
 
222
                                        token[tokpos+2] = 0;
 
223
                        }
 
224
                        else    {
 
225
                                text += *from;
 
226
                                lastspace = (*from == ' ');
 
227
                        }
 
228
                }
 
229
 
 
230
                char wstr[10];
 
231
                sprintf(wstr, "%03d", word-1);
 
232
                AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
 
233
                needWordOut = false;
 
234
                SWBuf strong = (*wAttrs)["Lemma"];
 
235
                SWBuf morph = (*wAttrs)["Morph"];
 
236
                SWBuf morphClass = (*wAttrs)["MorphClass"];
 
237
                SWBuf wordText = (*wAttrs)["Text"];
 
238
                SWBuf textSt = (*wAttrs)["TextStart"];
 
239
                if (strong.size()) {
 
240
                        char gh = 0;
 
241
                        gh = isdigit(strong[0]) ? 0:strong[0];
 
242
                        if (!gh) {
 
243
                                if (vkey) {
 
244
                                        gh = vkey->Testament() ? 'H' : 'G';
 
245
                                }
 
246
                        }
 
247
                        else strong << 1;
 
248
 
 
249
                        SWModule *sLex = 0;
 
250
                        if (gh == 'G') {
 
251
                                sLex = defaultGreekLex;
 
252
                        }
 
253
                        if (gh == 'H') {
 
254
                                sLex = defaultHebLex;
 
255
                        }
 
256
                        SWBuf lexName = "";
 
257
                        if (sLex) {
 
258
                                // we can pass the real lex name in, but we have some
 
259
                                // aliases in the javascript to optimize bandwidth
 
260
                                lexName = sLex->Name();
 
261
                                if (lexName == "StrongsGreek")
 
262
                                        lexName = "G";
 
263
                                if (lexName == "StrongsHebrew")
 
264
                                        lexName = "H";
 
265
                        }
 
266
                        SWBuf wordID;
 
267
                        if (vkey) {
 
268
                                // optimize for bandwidth and use only the verse as the unique entry id
 
269
                                wordID.appendFormatted("%d", vkey->Verse());
 
270
                        }
 
271
                        else {
 
272
                                wordID = key->getText();
 
273
                        }
 
274
                        for (unsigned int i = 0; i < wordID.size(); i++) {
 
275
                                if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) {
 
276
                                        wordID[i] = '_';
 
277
                                }
 
278
                        }
 
279
                        wordID.appendFormatted("_%s%d", wordSrcPrefix.c_str(), atoi(wstr));
 
280
                        if (textSt.size()) {
 
281
                                int textStr = atoi(textSt.c_str());
 
282
                                textStr += lastAppendLen;
 
283
                                SWBuf spanStart = "";
 
284
                                // 'p' = 'fillpop' to save bandwidth
 
285
                                const char *m = strchr(morph.c_str(), ':');
 
286
                                if (m) m++;
 
287
                                else m = morph.c_str();
 
288
                                spanStart.appendFormatted("<span class=\"clk\" onclick=\"p('%s','%s','%s','%s','','%s');\" >", lexName.c_str(), strong.c_str(), wordID.c_str(), m, modName.c_str());
 
289
                                text.insert(textStr, spanStart);
 
290
                        }
 
291
                }
 
292
        }
 
293
 
 
294
        return 0;
 
295
}
 
296
 
 
297
SWORD_NAMESPACE_END