summaryrefslogtreecommitdiff
path: root/src/modules/filters/thmlfootnotes.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
commit8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch)
treeda38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/modules/filters/thmlfootnotes.cpp
parent8d3fc864d094eeadc721f8e93436b37a5fab173e (diff)
Imported Upstream version 1.5.7
Diffstat (limited to 'src/modules/filters/thmlfootnotes.cpp')
-rw-r--r--src/modules/filters/thmlfootnotes.cpp156
1 files changed, 90 insertions, 66 deletions
diff --git a/src/modules/filters/thmlfootnotes.cpp b/src/modules/filters/thmlfootnotes.cpp
index d9b1f0e..8b52d98 100644
--- a/src/modules/filters/thmlfootnotes.cpp
+++ b/src/modules/filters/thmlfootnotes.cpp
@@ -1,103 +1,127 @@
/******************************************************************************
*
- * thmlfootnotes - SWFilter decendant to hide or show footnotes
+ * thmlfootnotes - SWFilter descendant to hide or show footnotes
* in a ThML module.
*/
#include <stdlib.h>
-#include <string.h>
#include <thmlfootnotes.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 ThMLFootnotes::on[] = "On";
-const char ThMLFootnotes::off[] = "Off";
-const char ThMLFootnotes::optName[] = "Footnotes";
-const char ThMLFootnotes::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]);
-ThMLFootnotes::ThMLFootnotes() {
- option = false;
- options.push_back(on);
- options.push_back(off);
+ThMLFootnotes::ThMLFootnotes() : SWOptionFilter(oName, oTip, &oValues) {
+ setOptionValue("Off");
}
ThMLFootnotes::~ThMLFootnotes() {
}
-void ThMLFootnotes::setOptionValue(const char *ival)
-{
- option = (!stricmp(ival, on));
-}
-const char *ThMLFootnotes::getOptionValue()
-{
- return (option) ? on:off;
-}
+char ThMLFootnotes::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+ 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 ThMLFootnotes::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
-{
- if (!option) { // if we don't want footnotes
- char *to, *from, token[2048]; // cheese. Fix.
- int tokpos = 0;
- bool intoken = false;
- int len;
- bool hide = false;
+ SWBuf orig = text;
+ const char *from = orig.c_str();
- len = strlen(text) + 1; // shift string to right of buffer
- if (len < maxlen) {
- memmove(&text[maxlen - len], text, len);
- from = &text[maxlen - len];
+ for (text = ""; *from; from++) {
+ if (*from == '<') {
+ intoken = true;
+ token = "";
+ continue;
}
- else from = text; // -------------------------------
+ if (*from == '>') { // process tokens
+ intoken = false;
- for (to = text; *from; from++) {
- if (*from == '<') {
- intoken = true;
- tokpos = 0;
- token[0] = 0;
- token[1] = 0;
- token[2] = 0;
- continue;
- }
- if (*from == '>') { // process tokens
- intoken = false;
- if (!strncmp(token, "note", 4)) {
- hide = true;
- continue;
+ XMLTag tag(token);
+ if (!strcmp(tag.getName(), "note")) {
+ if (!tag.isEndTag()) {
+ if (!tag.isEmpty()) {
+ refs = "";
+ startTag = tag;
+ hide = true;
+ tagText = "";
+ continue;
+ }
}
- else if (!strncmp(token, "/note", 5)) {
- hide = false;
- continue;
+ if (hide && tag.isEndTag()) {
+ if (module->isProcessEntryAttributes()) {
+ 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);
+ if ((startTag.getAttribute("type")) && (!strcmp(startTag.getAttribute("type"), "crossReference"))) {
+ if (!refs.length())
+ refs = parser.ParseVerseList(tagText.c_str(), parser, true).getRangeText();
+ module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str();
+ }
+ }
+ hide = false;
+ if ((option) || ((startTag.getAttribute("type") && (!strcmp(startTag.getAttribute("type"), "crossReference"))))) { // we want the tag in the text; crossReferences are handled by another filter
+ text += startTag;
+ text.append(tagText);
+ }
+ else continue;
}
+ }
- // if not a footnote token, keep token in text
- if (!hide) {
- *to++ = '<';
- for (char *tok = token; *tok; tok++)
- *to++ = *tok;
- *to++ = '>';
- }
- continue;
+ // if not a note token, keep token in text
+ if ((!strcmp(tag.getName(), "scripRef")) && (!tag.isEndTag())) {
+ SWBuf osisRef = tag.getAttribute("passage");
+ if (refs.length())
+ refs += "; ";
+ refs += osisRef;
}
- if (intoken) {
- if (tokpos < 2045)
- token[tokpos++] = *from;
- token[tokpos+2] = 0;
+ if (!hide) {
+ text += '<';
+ text.append(token);
+ text += '>';
}
- else {
- if (!hide) {
- *to++ = *from;
- }
+ else {
+ tagText += '<';
+ tagText.append(token);
+ tagText += '>';
}
+ continue;
+ }
+ if (intoken) { //copy token
+ token += *from;
}
- *to++ = 0;
- *to = 0;
+ else if (!hide) { //copy text which is not inside a token
+ text += *from;
+ }
+ else tagText += *from;
}
return 0;
}
+
+SWORD_NAMESPACE_END