2
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
3
* CrossWire Bible Society
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation version 2.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
27
#include <lzsscomprs.h>
28
#include <zipcomprs.h>
32
#include <markupfiltmgr.h>
35
#ifndef NO_SWORD_NAMESPACE
36
using namespace sword;
42
void errorOutHelp(char *appName) {
43
cerr << appName << " - a tool to output a Sword module in OSIS format\n";
44
cerr << "usage: "<< appName << " <modname> \n";
50
int main(int argc, char **argv)
52
SWModule *inModule = 0;
56
errorOutHelp(argv[0]);
59
if ((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
60
errorOutHelp(argv[0]);
63
SWMgr mgr(new MarkupFilterMgr(FMT_OSIS));
64
StringList options = mgr.getGlobalOptions();
65
for (StringList::iterator it = options.begin(); it != options.end(); it++) {
66
StringList values = mgr.getGlobalOptionValues(it->c_str());
67
if (find(values.begin(), values.end(), "On") != values.end()) {
68
mgr.setGlobalOption(it->c_str(), "On");
70
if (find(values.begin(), values.end(), "All Readings") != values.end()) {
71
mgr.setGlobalOption(it->c_str(), "All Readings");
75
// mgr.setGlobalOption("Strong's Numbers", "Off");
76
// mgr.setGlobalOption("Morphological Tags", "Off");
78
ModMap::iterator it = mgr.Modules.find(argv[1]);
79
if (it == mgr.Modules.end()) {
80
fprintf(stderr, "error: %s: couldn't find module: %s \n", argv[0], argv[1]);
84
inModule = it->second;
85
// inModule->AddRenderFilter(&filter);
87
SWKey *key = (SWKey *)*inModule;
88
VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
91
bool opentest = false;
92
bool openbook = false;
93
bool openchap = false;
98
cerr << "Currently mod2osis only works with verse keyed modules\n\n";
104
cout << "<?xml version=\"1.0\" ";
105
if (inModule->getConfigEntry("Encoding")) {
106
if (*(inModule->getConfigEntry("Encoding")))
107
cout << "encoding=\"" << inModule->getConfigEntry("Encoding") << "\" ";
108
else cout << "encoding=\"UTF-8\" ";
110
else cout << "encoding=\"UTF-8\" ";
115
cout << " xmlns=\"http://www.bibletechnologies.net/2003/OSIS/namespace\"";
116
cout << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
117
cout << " xsi:schemaLocation=\"http://www.bibletechnologies.net/2003/OSIS/namespace osisCore.2.5.xsd\">\n\n";
119
cout << " osisIDWork=\"";
120
cout << inModule->Name() << "\"";
121
cout << " osisRefWork=\"defaultReferenceScheme\"";
122
if (inModule->Lang()) {
123
if (strlen(inModule->Lang()))
124
cout << " xml:lang=\"" << inModule->Lang() << "\"";
128
cout << "\t<header>\n";
129
cout << "\t\t<work osisWork=\"";
130
cout << inModule->Name() << "\">\n";
131
cout << "\t\t\t<title>" << inModule->Description() << "</title>\n";
132
cout << "\t\t\t<identifier type=\"OSIS\">Bible." << inModule->Name() << "</identifier>\n";
133
cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
134
cout << "\t\t</work>\n";
135
cout << "\t\t<work osisWork=\"defaultReferenceScheme\">\n";
136
cout << "\t\t\t<refSystem>Bible.KJV</refSystem>\n";
137
cout << "\t\t</work>\n";
138
cout << "\t</header>\n\n";
143
SWKey *p = inModule->CreateKey();
144
VerseKey *tmpKey = SWDYNAMIC_CAST(VerseKey, p);
147
tmpKey = new VerseKey();
149
*tmpKey = inModule->getKeyText();
152
tmpKey->AutoNormalize(0);
154
for ((*inModule) = TOP; !inModule->Error(); (*inModule)++) {
155
bool newTest = false;
156
bool newBook = false;
158
if (!strlen(inModule->RenderText())) {
162
if ((vkey->Testament() != lastTest)) {
164
cout << "\t</chapter>\n";
166
cout << "\t</div>\n";
168
cout << "\t</div>\n";
169
cout << "\t<div type=\"x-testament\">\n";
173
if ((vkey->Book() != lastBook) || newTest) {
176
cout << "\t</chapter>\n";
178
cout << "\t</div>\n";
184
sprintf(buf, "\t<div type=\"book\" osisID=\"%s\">\n", tmpKey->getOSISRef());
185
// filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
186
cout << "" << buf << endl;
190
if ((vkey->Chapter() != lastChap) || newBook) {
193
cout << "\t</chapter>\n";
198
sprintf(buf, "\t<chapter osisID=\"%s\">\n", tmpKey->getOSISRef());
199
// filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
203
SWBuf verseText = inModule->getRawEntry();
204
sprintf(buf, "\t\t<verse osisID=\"%s\">", vkey->getOSISRef());
205
cout << buf << verseText.c_str() << "</verse>\n" << endl;
206
lastChap = vkey->Chapter();
207
lastBook = vkey->Book();
208
lastTest = vkey->Testament();
211
cout << "\t</chapter>\n";
213
cout << "\t</div>\n";
215
cout << "\t</div>\n";
216
cout << "\t</osisText>\n";