The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfcgi.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * gbfcgi.cpp - GBF to Diatheke/CGI format
4  *
5  * $Id: gbfcgi.cpp 2833 2013-06-29 06:40:28Z chrislit $
6  *
7  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include <map>
26 #include "gbfcgi.h"
27 
29 
30 typedef std::map<SWBuf, SWBuf> DualStringMap;
31 
32 namespace {
33  class MyUserData : public BasicFilterUserData {
34  public:
35  MyUserData(const SWModule *module, const SWKey *key) : BasicFilterUserData(module, key) {}
36  DualStringMap properties;
37  };
38 }
39 
40 
42  return new MyUserData(module, key);
43 }
44 
46  setTokenStart("<");
47  setTokenEnd(">");
48 
50 
51  addTokenSubstitute("Rf", ")</small></font>");
52  addTokenSubstitute("FI", "<i>"); // italics begin
53  addTokenSubstitute("Fi", "</i>");
54  addTokenSubstitute("FB", "<n>"); // bold begin
55  addTokenSubstitute("Fb", "</n>");
56  addTokenSubstitute("FR", "<font color=\"#FF0000\">"); // words of Jesus begin
57  addTokenSubstitute("Fr", "</font>");
58  addTokenSubstitute("FU", "<u>"); // underline begin
59  addTokenSubstitute("Fu", "</u>");
60  addTokenSubstitute("FO", "<cite>"); // Old Testament quote begin
61  addTokenSubstitute("Fo", "</cite>");
62  addTokenSubstitute("FS", "<sup>"); // Superscript begin// Subscript begin
63  addTokenSubstitute("Fs", "</sup>");
64  addTokenSubstitute("FV", "<sub>"); // Subscript begin
65  addTokenSubstitute("Fv", "</sub>");
66  addTokenSubstitute("TT", "<big>"); // Book title begin
67  addTokenSubstitute("Tt", "</big>");
68  addTokenSubstitute("PP", "<cite>"); // poetry begin
69  addTokenSubstitute("Pp", "</cite>");
70  addTokenSubstitute("Fn", "</font>"); // font end
71  addTokenSubstitute("CL", "<br />"); // new line
72  addTokenSubstitute("CM", "<br />"); // paragraph
73  addTokenSubstitute("CG", "&gt;"); // ???
74  addTokenSubstitute("CT", "&lt;"); // ???
75  addTokenSubstitute("JR", "<div align=\"right\">"); // right align begin
76  addTokenSubstitute("JC", "<div align=\"center\">"); // center align begin
77  addTokenSubstitute("JL", "</div>"); // align end
78 
79 }
80 
81 
82 bool GBFCGI::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *baseUserData) {
83  MyUserData *userData = (MyUserData *) baseUserData;
84  unsigned long i;
85  if (!substituteToken(buf, token)) {
86  if (!strncmp(token, "WG", 2) || !strncmp(token, "WH", 2)) { // strong's numbers
87  buf += " <small><em>&lt;<a href=\"!DIATHEKE_URL!";
88  if (token[1] == 'H') {
89  buf += "StrongsHebrew";
90  }
91  else if (token[1] == 'G') {
92  buf += "StrongsGreek";
93  }
94  buf += "=on&verse=";
95  for (i = 2; i < strlen(token); i++)
96  buf += token[i];
97  buf += "\">";
98  for (i = 2; i < strlen(token); i++)
99  buf += token[i];
100  buf += "</a>&gt;</em></small>";
101  }
102 
103  else if (!strncmp(token, "WTG", 3) || !strncmp(token, "WTH", 3)) { // strong's numbers tense
104  buf += " <small><em>&lt;<a href=\"!DIATHEKE_URL!";
105  if (token[2] == 'H') {
106  buf += "StrongsHebrew";
107  }
108  else if (token[2] == 'G') {
109  buf += "StrongsGreek";
110  }
111  buf += "=on&verse=";
112  for (i = 3; i < strlen(token); i++)
113  buf += token[i];
114  buf += "\">";
115  for (i = 3; i < strlen(token); i++)
116  buf += token[i];
117  buf += "</a>&gt;</em></small>";
118  }
119 
120  else if (!strncmp(token, "WT", 2)) { // morph tags
121  buf += " <small><em>(<a href=\"!DIATHEKE_URL!Packard=on&verse=";
122  for (i = 1; i < strlen(token); i++)
123  buf += token[i];
124  buf += "\">";
125  for (i = 1; i < strlen(token); i++)
126  buf += token[i];
127  buf += "</a>)</em></small>";
128  }
129 
130  else if (!strncmp(token, "RB", 2)) {
131  buf += "<i>";
132  userData->properties["hasFootnotePreTag"] = "true";
133  }
134 
135  else if (!strncmp(token, "RF", 2)) {
136  if(userData->properties["hasFootnotePreTag"] == "true") {
137  userData->properties["hasFootnotePreTag"] = "false";
138  buf += "</i> ";
139  }
140  buf += "<font color=\"#800000\"><small> (";
141  }
142 
143  else if (!strncmp(token, "FN", 2)) {
144  buf += "<font face=\"";
145  for (i = 2; i < strlen(token); i++)
146  buf += token[i];
147  buf += "\">";
148  }
149 
150  else if (!strncmp(token, "CA", 2)) { // ASCII value
151  buf += (char)atoi(&token[2]);
152  }
153 
154  else {
155  return false;
156  }
157  }
158  return true;
159 }
160 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
void setTokenEnd(const char *tokenEnd)
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
void setTokenCaseSensitive(bool val)
bool substituteToken(SWBuf &buf, const char *token)
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: gbfcgi.cpp:82
GBFCGI()
Definition: gbfcgi.cpp:45
void setTokenStart(const char *tokenStart)
BasicFilterUserData(const SWModule *module, const SWKey *key)
SWORD_NAMESPACE_START typedef std::map< SWBuf, SWBuf > DualStringMap
virtual BasicFilterUserData * createUserData(const SWModule *module, const SWKey *key)
Definition: gbfcgi.cpp:41
void addTokenSubstitute(const char *findString, const char *replaceString)
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77