diff options
Diffstat (limited to 'src/modules/filters/thmlscripref.cpp')
-rw-r--r-- | src/modules/filters/thmlscripref.cpp | 157 |
1 files changed, 90 insertions, 67 deletions
diff --git a/src/modules/filters/thmlscripref.cpp b/src/modules/filters/thmlscripref.cpp index 23edd6d..7b93f90 100644 --- a/src/modules/filters/thmlscripref.cpp +++ b/src/modules/filters/thmlscripref.cpp @@ -1,103 +1,126 @@ /****************************************************************************** * - * thmlscripref - SWFilter decendant to hide or show scripture references - * in a ThML module. + * thmlscripref - SWFilter descendant to hide or show scripture + * referebces in a ThML module. */ #include <stdlib.h> -#include <string.h> #include <thmlscripref.h> +#include <utilxml.h> +#include <versekey.h> +#include <swmodule.h> #ifndef __GNUC__ #else #include <unixstr.h> #endif +SWORD_NAMESPACE_START -const char ThMLScripref::on[] = "On"; -const char ThMLScripref::off[] = "Off"; -const char ThMLScripref::optName[] = "Scripture Cross-references"; -const char ThMLScripref::optTip[] = "Toggles Scripture Cross-references On and Off if they exist"; +const char oName[] = "Cross-references"; +const char oTip[] = "Toggles Scripture Cross-references On and Off if they exist"; +const SWBuf choices[3] = {"On", "Off", ""}; +const StringList oValues(&choices[0], &choices[2]); -ThMLScripref::ThMLScripref() { - option = false; - options.push_back(on); - options.push_back(off); +ThMLScripref::ThMLScripref() : SWOptionFilter(oName, oTip, &oValues) { + setOptionValue("On"); } ThMLScripref::~ThMLScripref() { } -void ThMLScripref::setOptionValue(const char *ival) -{ - option = (!stricmp(ival, on)); -} -const char *ThMLScripref::getOptionValue() -{ - return (option) ? on:off; -} +char ThMLScripref::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 ThMLScripref::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module) -{ - if (!option) { // if we don't want scriprefs - 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 (!strnicmp(token, "scripRef", 8)) { - hide = true; - continue; + XMLTag tag(token); + if (!strcmp(tag.getName(), "scripRef")) { + if (!tag.isEndTag()) { + if (!tag.isEmpty()) { + refs = ""; + startTag = tag; + hide = true; + tagText = ""; + continue; + } } - else if (!strnicmp(token, "/scripRef", 9)) { - 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); + SWBuf passage = startTag.getAttribute("passage"); + if (passage.length()) + refs = parser.ParseVerseList(passage.c_str(), parser, true).getRangeText(); + else refs = parser.ParseVerseList(tagText.c_str(), parser, true).getRangeText(); + module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str(); + } + hide = false; + if (option) { // we want the tag in the text + text += startTag; + text.append(tagText); + } + else continue; } + } - // if not a scripref token, keep token in text - if (!hide) { - *to++ = '<'; - for (char *tok = token; *tok; tok++) - *to++ = *tok; - *to++ = '>'; - } - continue; + // if not a scripRef 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 |