summaryrefslogtreecommitdiff
path: root/src/modules/filters/gbffootnotes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/filters/gbffootnotes.cpp')
-rw-r--r--src/modules/filters/gbffootnotes.cpp151
1 files changed, 115 insertions, 36 deletions
diff --git a/src/modules/filters/gbffootnotes.cpp b/src/modules/filters/gbffootnotes.cpp
index c5b7b90..38f1106 100644
--- a/src/modules/filters/gbffootnotes.cpp
+++ b/src/modules/filters/gbffootnotes.cpp
@@ -1,62 +1,142 @@
/******************************************************************************
*
- * gbffootnotes - SWFilter decendant to hide or show footnotes
+ * gbffootnotes - SWFilter descendant to hide or show footnotes
* in a GBF module.
*/
#include <stdlib.h>
-#include <string.h>
#include <gbffootnotes.h>
+#include <swmodule.h>
+#include <swbuf.h>
+#include <versekey.h>
+#include <utilxml.h>
#ifndef __GNUC__
#else
#include <unixstr.h>
#endif
+SWORD_NAMESPACE_START
-const char GBFFootnotes::on[] = "On";
-const char GBFFootnotes::off[] = "Off";
-const char GBFFootnotes::optName[] = "Footnotes";
-const char GBFFootnotes::optTip[] = "Toggles Footnotes On and Off if they exist";
+const char oName[] = "Footnotes";
+const char oTip[] = "Toggles Footnotes On and Off if they exist";
+const SWBuf choices[3] = {"On", "Off", ""};
+const StringList oValues(&choices[0], &choices[2]);
-GBFFootnotes::GBFFootnotes() {
- option = false;
- options.push_back(on);
- options.push_back(off);
+
+GBFFootnotes::GBFFootnotes() : SWOptionFilter(oName, oTip, &oValues) {
+ setOptionValue("Off");
}
GBFFootnotes::~GBFFootnotes() {
}
-void GBFFootnotes::setOptionValue(const char *ival)
-{
- option = (!stricmp(ival, on));
-}
-const char *GBFFootnotes::getOptionValue()
+char GBFFootnotes::processText (SWBuf &text, const SWKey *key, const SWModule *module)
{
- return (option) ? on:off;
-}
+
+ SWBuf token;
+ bool intoken = false;
+ bool hide = false;
+ SWBuf tagText;
+ XMLTag startTag;
+ SWBuf refs = "";
+ int footnoteNum = 1;
+ char buf[254];
+ VerseKey parser = key->getText();
-char GBFFootnotes::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
-{
+ SWBuf orig = text;
+ const char *from = orig.c_str();
+
+ for (text = ""; *from; from++) {
+ if (*from == '<') {
+ intoken = true;
+ token = "";
+ continue;
+ }
+ if (*from == '>') { // process tokens
+ intoken = false;
+
+ XMLTag tag(token);
+ if (!strcmp(tag.getName(), "RF")) {
+ refs = "";
+ startTag = tag;
+ hide = true;
+ tagText = "";
+ continue;
+ }
+ else if (!strcmp(tag.getName(), "Rf")) {
+ if (module->isProcessEntryAttributes()) {
+ if(tagText.length() == 1 || !strcmp(module->Name(), "IGNT")) {
+ if (option) { // for ASV marks text in verse then put explanation at end of verse
+ text += " <FA>(";
+ text.append(tagText);
+ text += ")<Fr>";
+ hide = false;
+ continue;
+ }
+ }
+ SWBuf fc = module->getEntryAttributes()["Footnote"]["count"]["value"];
+ footnoteNum = (fc.length()) ? atoi(fc.c_str()) : 0;
+ sprintf(buf, "%i", ++footnoteNum);
+ module->getEntryAttributes()["Footnote"]["count"]["value"] = buf;
+ StringList attributes = startTag.getAttributeNames();
+ for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) {
+ module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
+ }
+ module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
+ startTag.setAttribute("swordFootnote", buf);
+ }
+ hide = false;
+ if (option) {
+ text += startTag;
+ text.append(tagText);
+ }
+ else continue;
+ }
+ if (!hide) {
+ text += '<';
+ text.append(token);
+ text += '>';
+ }
+ else {
+ tagText += '<';
+ tagText.append(token);
+ tagText += '>';
+ }
+ continue;
+ }
+ if (intoken) { //copy token
+ token += *from;
+ }
+ else if (!hide) { //copy text which is not inside a token
+ text += *from;
+ }
+ else tagText += *from;
+ }
+ return 0;
+
+
+
+
+
+
+
+
+ /*
if (!option) { // if we don't want footnotes
- char *to, *from, token[4096]; // cheese. Fix.
+ char token[4096]; // cheese. Fix.
int tokpos = 0;
bool intoken = false;
int len;
bool hide = false;
- len = strlen(text) + 1; // shift string to right of buffer
- if (len < maxlen) {
- memmove(&text[maxlen - len], text, len);
- from = &text[maxlen - len];
- }
- else from = text; // -------------------------------
-
- for (to = text; *from; from++) {
+ const char *from;
+ SWBuf orig = text;
+ from = orig.c_str();
+ for (text = ""; *from; from++) {
if (*from == '<') {
intoken = true;
tokpos = 0;
@@ -93,10 +173,9 @@ char GBFFootnotes::ProcessText(char *text, int maxlen, const SWKey *key, const S
}
// if not a footnote token, keep token in text
if (!hide) {
- *to++ = '<';
- for (char *tok = token; *tok; tok++)
- *to++ = *tok;
- *to++ = '>';
+ text += '<';
+ text += token;
+ text += '>';
}
continue;
}
@@ -107,12 +186,12 @@ char GBFFootnotes::ProcessText(char *text, int maxlen, const SWKey *key, const S
}
else {
if (!hide) {
- *to++ = *from;
+ text += *from;
}
}
}
- *to++ = 0;
- *to = 0;
}
- return 0;
+ return 0;*/
}
+
+SWORD_NAMESPACE_END