1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/***************************************************************************
thmlcgi.cpp - ThML to Diatheke/CGI format
-------------------
begin : 2001-11-12
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 <string.h>
#include "thmlcgi.h"
SWORD_NAMESPACE_START
ThMLCGI::ThMLCGI() {
setTokenStart("<");
setTokenEnd(">");
setTokenCaseSensitive(true);
addTokenSubstitute("note", " <font color=\"#008000\"><small>(");
addTokenSubstitute("/note", ")</small></font> ");
}
bool ThMLCGI::handleToken(char **buf, const char *token, DualStringMap &userData) {
unsigned long i;
if (!substituteToken(buf, token)) {
// manually process if it wasn't a simple substitution
if (!strncmp(token, "sync ", 5)) {
pushString(buf, "<a href=\"!DIATHEKE_URL!");
char* pbuf;
char typ[32]; typ[0] = 0;
char val[32]; val[0] = 0;
char cls[32]; cls[0] = 0;
for (unsigned int j = 5; j < strlen(token); j++) {
if (!strncmp(token+j, "type=\"", 6)) {
pbuf = typ;
j += 6;
for (;token[j] != '\"'; j++)
*(pbuf)++ = token[j];
*(pbuf) = 0;
}
else if (!strncmp(token+j, "value=\"", 7)) {
pbuf = val;
j += 7;
for (;token[j] != '\"'; j++)
*(pbuf)++ = token[j];
*(pbuf) = 0;
}
else if (!strncmp(token+j, "class=\"", 7)) {
pbuf = cls;
j += 7;
for (;token[j] != '\"'; j++)
*(pbuf)++ = token[j];
*(pbuf) = 0;
}
}
if (*cls && *val) {
pushString(buf, "%s=on&verse=%s", cls, val);
}
else if (*typ && *val) {
if (!strnicmp(typ, "Strongs", 7)) {
if (*val == 'G') {
pushString(buf, "Thayer=on&verse=%s", val + 1);
}
else if (*val == 'H') {
pushString(buf, "BDB=on&verse=%s", val + 1);
}
}
else if (!strnicmp(typ, "Morph", 5)) {
if (*val == 'G') {
pushString(buf, "Thayer=on&verse=%s", val + 1);
}
else if (*val == 'H') {
pushString(buf, "BDB=on&verse=%s", val + 1);
}
else {
pushString(buf, "Packard=on&verse=%s", val);
}
}
else {
pushString(buf, "%s=on&verse=%s", typ, val);
}
}
*(*buf)++ = '\"';
*(*buf)++ = '>';
if (*val) {
pushString(buf, val);
}
pushString(buf, "</a>");
}
else if (!strncmp(token, "scripRef p", 10) || !strncmp(token, "scripRef v", 10)) {
userData["inscriptRef"] = "true";
pushString(buf, "<a href=\"!DIATHEKE_URL!");
for (i = 9; i < strlen(token); i++) {
if (!strncmp(token+i, "version=\"", 9)) {
i += 9;
for (;token[i] != '\"'; i++)
*(*buf)++ = token[i];
pushString(buf, "=on&");
}
if (!strncmp(token+i, "passage=\"", 9)) {
i += 9;
pushString(buf, "verse=");
for (;token[i] != '\"'; i++) {
if (token[i] == ' ') *(*buf)++ = '+';
else *(*buf)++ = token[i];
}
*(*buf)++ = '&';
}
}
*(*buf)++ = '\"';
*(*buf)++ = '>';
}
// we're starting a scripRef like "<scripRef>John 3:16</scripRef>"
else if (!strcmp(token, "scripRef")) {
userData["inscriptRef"] = "false";
// let's stop text from going to output
userData["suspendTextPassThru"] = "true";
}
// we've ended a scripRef
else if (!strcmp(token, "/scripRef")) {
if (userData["inscriptRef"] == "true") { // like "<scripRef passage="John 3:16">John 3:16</scripRef>"
userData["inscriptRef"] = "false";
pushString(buf, "</a>");
}
else { // like "<scripRef>John 3:16</scripRef>"
pushString(buf, "<a href=\"!DIATHEKE_URL!verse=");
char* vref = (char*)userData["lastTextNode"].c_str();
while (*vref) {
if (*vref == ' ') *(*buf)++ = '+';
else *(*buf)++ = *vref;
vref++;
}
*(*buf)++ = '\"';
*(*buf)++ = '>';
pushString(buf, userData["lastTextNode"].c_str());
// let's let text resume to output again
userData["suspendTextPassThru"] = "false";
pushString(buf, "</a>");
}
}
else if (!strncmp(token, "div class=\"sechead\"", 19)) {
userData["SecHead"] = "true";
pushString(buf, "<br /><b><i>");
}
else if (!strncmp(token, "div class=\"title\"", 19)) {
userData["SecHead"] = "true";
pushString(buf, "<br /><b><i>");
}
else if (!strncmp(token, "/div", 4)) {
if (userData["SecHead"] == "true") {
pushString(buf, "</i></b><br />");
userData["SecHead"] = "false";
}
}
else if(!strncmp(token, "note", 4)) {
pushString(buf, " <small><font color=\"#008000\">{");
}
else {
*(*buf)++ = '<';
for (i = 0; i < strlen(token); i++)
*(*buf)++ = token[i];
*(*buf)++ = '>';
//return false; // we still didn't handle token
}
}
return true;
}
SWORD_NAMESPACE_END
|