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

« back to all changes in this revision

Viewing changes to src/modules/filters/gbffootnotes.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
 * gbffootnotes -       SWFilter descendant to hide or show footnotes
 
4
 *                      in a GBF module.
 
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
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <gbffootnotes.h>
 
26
#include <swmodule.h>
 
27
#include <swbuf.h>
 
28
#include <versekey.h>
 
29
#include <utilxml.h>
 
30
 
 
31
SWORD_NAMESPACE_START
 
32
 
 
33
const char oName[] = "Footnotes";
 
34
const char oTip[] = "Toggles Footnotes On and Off if they exist";
 
35
 
 
36
const SWBuf choices[3] = {"Off", "On", ""};
 
37
const StringList oValues(&choices[0], &choices[2]);
 
38
 
 
39
 
 
40
GBFFootnotes::GBFFootnotes() : SWOptionFilter(oName, oTip, &oValues) {
 
41
        setOptionValue("Off");
 
42
}
 
43
 
 
44
 
 
45
GBFFootnotes::~GBFFootnotes() {
 
46
}
 
47
 
 
48
 
 
49
char GBFFootnotes::processText (SWBuf &text, const SWKey *key, const SWModule *module)
 
50
{
 
51
 
 
52
        SWBuf token;
 
53
        bool intoken    = false;
 
54
        bool hide       = false;
 
55
        SWBuf tagText;
 
56
        XMLTag startTag;
 
57
        SWBuf refs = "";
 
58
        int footnoteNum = 1;
 
59
        char buf[254];
 
60
 
 
61
        SWBuf orig = text;
 
62
        const char *from = orig.c_str();
 
63
 
 
64
        //XMLTag tag;
 
65
 
 
66
        for (text = ""; *from; from++) {
 
67
                if (*from == '<') {
 
68
                        intoken = true;
 
69
                        token = "";
 
70
                        continue;
 
71
                }
 
72
                if (*from == '>') {     // process tokens
 
73
                        intoken = false;
 
74
 
 
75
                        //XMLTag tag(token);
 
76
                        if (!strncmp(token, "RF",2)) {
 
77
//                              tag = token;
 
78
 
 
79
                                refs = "";
 
80
                                startTag = token;
 
81
                                hide = true;
 
82
                                tagText = "";
 
83
                                continue;
 
84
                        }
 
85
                        else if (!strncmp(token, "Rf",2)) {
 
86
                                if (module->isProcessEntryAttributes()) {
 
87
                                        //tag = token;
 
88
 
 
89
                                        if((tagText.length() == 1) || !strcmp(module->Name(), "IGNT")) {
 
90
                                                if (option) { // for ASV marks text in verse then put explanation at end of verse
 
91
                                                        text.append(" <FS>[");
 
92
                                                        text.append(tagText);
 
93
                                                        text.append("]<Fs>");
 
94
                                                        hide = false;
 
95
                                                        continue;
 
96
                                                }
 
97
                                        }
 
98
                                        SWBuf fc = module->getEntryAttributes()["Footnote"]["count"]["value"];
 
99
                                        footnoteNum = (fc.length()) ? atoi(fc.c_str()) : 0;
 
100
                                        sprintf(buf, "%i", ++footnoteNum);
 
101
                                        module->getEntryAttributes()["Footnote"]["count"]["value"] = buf;
 
102
                                        StringList attributes = startTag.getAttributeNames();
 
103
                                        for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
 
104
                                                module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
 
105
                                        }
 
106
                                        module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
 
107
                                        startTag.setAttribute("swordFootnote", buf);
 
108
                                }
 
109
                                hide = false;
 
110
                                if (option) {
 
111
                                        text.append(startTag);
 
112
                                        text.append(tagText);
 
113
                                }
 
114
                                else    continue;
 
115
                        }
 
116
                        if (!hide) {
 
117
                                text.append('<');
 
118
                                text.append(token);
 
119
                                text.append('>');
 
120
                        }
 
121
                        else {
 
122
                                tagText.append('<');
 
123
                                tagText.append(token);
 
124
                                tagText.append('>');
 
125
                        }
 
126
                        continue;
 
127
                }
 
128
                if (intoken) { //copy token
 
129
                        token.append(*from);
 
130
                }
 
131
                else if (!hide) { //copy text which is not inside a token
 
132
                        text.append(*from);
 
133
                }
 
134
                else tagText.append(*from);
 
135
        }
 
136
        return 0;
 
137
 
 
138
        /*
 
139
        if (!option) {  // if we don't want footnotes
 
140
                char token[4096]; // cheese.  Fix.
 
141
                int tokpos = 0;
 
142
                bool intoken = false;
 
143
                int len;
 
144
                bool hide = false;
 
145
 
 
146
                const char *from;
 
147
                SWBuf orig = text;
 
148
                from = orig.c_str();
 
149
                for (text = ""; *from; from++) {
 
150
                        if (*from == '<') {
 
151
                                intoken = true;
 
152
                                tokpos = 0;
 
153
//                              memset(token, 0, 4096);
 
154
                                token[0] = 0;
 
155
                                token[1] = 0;
 
156
                                token[2] = 0;
 
157
                                continue;
 
158
                        }
 
159
                        if (*from == '>') {     // process tokens
 
160
                                intoken = false;
 
161
                                switch (*token) {
 
162
                                case 'R':                               // Reference
 
163
                                        switch(token[1]) {
 
164
                                        case 'F':               // Begin footnote
 
165
                                                hide = true;
 
166
                                                break;
 
167
                                        case 'f':               // end footnote
 
168
                                                hide = false;
 
169
                                                break;
 
170
                                        }
 
171
                                        continue;       // skip token
 
172
                                case 'W':
 
173
                                        if (token[1] == 'T') {
 
174
                                                switch (token[2]) {
 
175
                                                case 'P':
 
176
                                                case 'S':
 
177
                                                case 'A':
 
178
                                                        continue; // remove this token
 
179
                                                default:
 
180
                                                        break;
 
181
                                                }
 
182
                                        }
 
183
                                }
 
184
                                // if not a footnote token, keep token in text
 
185
                                if (!hide) {
 
186
                                        text += '<';
 
187
                                        text += token;
 
188
                                        text += '>';
 
189
                                }
 
190
                                continue;
 
191
                        }
 
192
                        if (intoken) {
 
193
                                if (tokpos < 4090)
 
194
                                        token[tokpos++] = *from;
 
195
                                        token[tokpos+2] = 0;    // +2 cuz we init token with 2 extra '0' because of switch statement
 
196
                        }
 
197
                        else    {
 
198
                                if (!hide) {
 
199
                                        text += *from;
 
200
                                }
 
201
                        }
 
202
                }
 
203
        }
 
204
        return 0;*/
 
205
}
 
206
 
 
207
SWORD_NAMESPACE_END