1
/******************************************************************************
3
* gbffootnotes - SWFilter descendant to hide or show footnotes
6
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
7
* CrossWire Bible Society
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.
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.
25
#include <gbffootnotes.h>
33
const char oName[] = "Footnotes";
34
const char oTip[] = "Toggles Footnotes On and Off if they exist";
36
const SWBuf choices[3] = {"Off", "On", ""};
37
const StringList oValues(&choices[0], &choices[2]);
40
GBFFootnotes::GBFFootnotes() : SWOptionFilter(oName, oTip, &oValues) {
41
setOptionValue("Off");
45
GBFFootnotes::~GBFFootnotes() {
49
char GBFFootnotes::processText (SWBuf &text, const SWKey *key, const SWModule *module)
62
const char *from = orig.c_str();
66
for (text = ""; *from; from++) {
72
if (*from == '>') { // process tokens
76
if (!strncmp(token, "RF",2)) {
85
else if (!strncmp(token, "Rf",2)) {
86
if (module->isProcessEntryAttributes()) {
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>[");
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());
106
module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
107
startTag.setAttribute("swordFootnote", buf);
111
text.append(startTag);
112
text.append(tagText);
123
tagText.append(token);
128
if (intoken) { //copy token
131
else if (!hide) { //copy text which is not inside a token
134
else tagText.append(*from);
139
if (!option) { // if we don't want footnotes
140
char token[4096]; // cheese. Fix.
142
bool intoken = false;
149
for (text = ""; *from; from++) {
153
// memset(token, 0, 4096);
159
if (*from == '>') { // process tokens
162
case 'R': // Reference
164
case 'F': // Begin footnote
167
case 'f': // end footnote
171
continue; // skip token
173
if (token[1] == 'T') {
178
continue; // remove this token
184
// if not a footnote token, keep token in text
194
token[tokpos++] = *from;
195
token[tokpos+2] = 0; // +2 cuz we init token with 2 extra '0' because of switch statement