summaryrefslogtreecommitdiff
path: root/src/modules/filters/gbfthml.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:59 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:59 -0400
commit03134fa5f6f25d92724ce4c183f9bbe12a9e37dc (patch)
tree847326a4de82f0241ac87cbbc427a1b92a696a02 /src/modules/filters/gbfthml.cpp
parentd7469385b05b9510338407fa123e9ad090f80af6 (diff)
Imported Upstream version 1.5.11
Diffstat (limited to 'src/modules/filters/gbfthml.cpp')
-rw-r--r--src/modules/filters/gbfthml.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/src/modules/filters/gbfthml.cpp b/src/modules/filters/gbfthml.cpp
new file mode 100644
index 0000000..2664f48
--- /dev/null
+++ b/src/modules/filters/gbfthml.cpp
@@ -0,0 +1,216 @@
+/***************************************************************************
+ gbfthml.cpp - GBF to ThML filter
+ -------------------
+ begin : 1999-10-27
+ copyright : 2001 by CrossWire Bible Society
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <gbfthml.h>
+#include <swbuf.h>
+
+SWORD_NAMESPACE_START
+
+GBFThML::GBFThML()
+{
+}
+
+
+char GBFThML::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+ const char *from;
+ char token[2048];
+ int tokpos = 0;
+ bool intoken = false;
+ const char *tok;
+
+ SWBuf orig = text;
+ from = orig.c_str();
+
+ for (text = ""; *from; from++) {
+ if (*from == '<') {
+ intoken = true;
+ tokpos = 0;
+ token[0] = 0;
+ token[1] = 0;
+ token[2] = 0;
+ continue;
+ }
+ if (*from == '>')
+ {
+ intoken = false;
+ // process desired tokens
+ switch (*token) {
+ case 'W': // Strongs
+ switch(token[1]) {
+ case 'G':
+ case 'H':
+ text += "<sync type=\"Strongs\" value=\"";
+ for (tok = token + 1; *tok; tok++)
+ text += *tok;
+ text += "\" />";
+ continue;
+
+ case 'T': // Tense
+ text += "<sync type=\"Morph\" value=\"";
+ for (tok = token + 2; *tok; tok++)
+ text += *tok;
+ text += "\" />";
+ continue;
+ }
+ break;
+ case 'R':
+ switch(token[1])
+ {
+ case 'X':
+ text += "<a href=\"";
+ for (tok = token + 3; *tok; tok++) {
+ if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
+ text += *tok;
+ }
+ else {
+ break;
+ }
+ }
+ text += "\">";
+ continue;
+ case 'x':
+ text += "</a>";
+ continue;
+ case 'F': // footnote begin
+ text += "<note>";
+ continue;
+ case 'f': // footnote end
+ text += "</note>";
+ continue;
+ }
+ break;
+ case 'F': // font tags
+ switch(token[1])
+ {
+ case 'N':
+ text += "<font face=\"";
+ for (tok = token + 2; *tok; tok++)
+ text += *tok;
+ text += "\">";
+ continue;
+ case 'n':
+ text += "</font>";
+ continue;
+ case 'I': // italic start
+ text += "<i>";
+ continue;
+ case 'i': // italic end
+ text += "</i>";
+ continue;
+ case 'B': // bold start
+ text += "<b>";
+ continue;
+ case 'b': // bold end
+ text += "</b>";
+ continue;
+
+ case 'R': // words of Jesus begin
+ text += "<font color=\"#ff0000\">";
+ continue;
+ case 'r': // words of Jesus end
+ text += "</font>";
+ continue;
+ case 'U': // Underline start
+ text += "<u>";
+ continue;
+ case 'u': // Underline end
+ text += "</u>";
+ continue;
+ case 'O': // Old Testament quote begin
+ text += "<cite>";
+ continue;
+ case 'o': // Old Testament quote end
+ text += "</cite>";
+ continue;
+ case 'S': // Superscript begin
+ text += "<sup>";
+ continue;
+ case 's': // Superscript end
+ text += "</sup>";
+ continue;
+ case 'V': // Subscript begin
+ text += "<sub>";
+ continue;
+ case 'v': // Subscript end
+ text += "</sub>";
+ continue;
+ }
+ break;
+ case 'C': // special character tags
+ switch(token[1])
+ {
+ case 'A': // ASCII value
+ text += (char)atoi(&token[2]);
+ continue;
+ case 'G':
+ //*to++ = ' ';
+ continue;
+ case 'L': // line break
+ text += "<br /> ";
+ continue;
+ case 'M': // new paragraph
+ text += "<p />";
+ continue;
+ case 'T':
+ //*to++ = ' ';
+ continue;
+ }
+ break;
+ case 'T': // title formatting
+ switch(token[1])
+ {
+ case 'T': // Book title begin
+ text += "<big>";
+ continue;
+ case 't':
+ text += "</big>";
+ continue;
+ case 'S':
+ text += "<div class=\"sechead\">";
+ continue;
+ case 's':
+ text += "</div>";
+ continue;
+ }
+ break;
+
+ case 'P': // special formatting
+ switch(token[1]) {
+ case 'P': // Poetry begin
+ text += "<verse>";
+ continue;
+ case 'p':
+ text += "</verse>";
+ continue;
+ }
+ break;
+ }
+ continue;
+ }
+ if (intoken) {
+ if (tokpos < 2045)
+ token[tokpos++] = *from;
+ token[tokpos+2] = 0;
+ }
+ else text += *from;
+ }
+ return 0;
+}
+
+
+
+SWORD_NAMESPACE_END