~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to utilities/mod2osis.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
3
 *      CrossWire Bible Society
 
4
 *      P. O. Box 2528
 
5
 *      Tempe, AZ  85280-2528
 
6
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
16
 */
 
17
 
 
18
#include <fcntl.h>
 
19
#include <iostream>
 
20
#include <fstream>
 
21
#include <string>
 
22
 
 
23
#include <ztext.h>
 
24
#include <zld.h>
 
25
#include <zcom.h>
 
26
#include <swmgr.h>
 
27
#include <lzsscomprs.h>
 
28
#include <zipcomprs.h>
 
29
#include <versekey.h>
 
30
#include <thmlosis.h>
 
31
#include <stdio.h>
 
32
#include <markupfiltmgr.h>
 
33
#include <algorithm>
 
34
 
 
35
#ifndef NO_SWORD_NAMESPACE
 
36
using namespace sword;
 
37
#endif
 
38
using std::endl;
 
39
using std::cerr;
 
40
using std::cout;
 
41
 
 
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";
 
45
        cerr << "\n\n";
 
46
        exit(-1);
 
47
}
 
48
 
 
49
 
 
50
int main(int argc, char **argv)
 
51
{
 
52
        SWModule *inModule = 0;
 
53
        ThMLOSIS filter;
 
54
        
 
55
        if ((argc != 2)) {
 
56
                errorOutHelp(argv[0]);
 
57
        }
 
58
 
 
59
        if ((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "-help"))) {
 
60
                errorOutHelp(argv[0]);
 
61
        }
 
62
 
 
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");
 
69
                }
 
70
                if (find(values.begin(), values.end(), "All Readings") != values.end()) {
 
71
                        mgr.setGlobalOption(it->c_str(), "All Readings");
 
72
                }
 
73
        }
 
74
 
 
75
//      mgr.setGlobalOption("Strong's Numbers", "Off");
 
76
//      mgr.setGlobalOption("Morphological Tags", "Off");
 
77
 
 
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]);
 
81
                exit(-2);
 
82
        }
 
83
 
 
84
        inModule = it->second;
 
85
//      inModule->AddRenderFilter(&filter);
 
86
 
 
87
        SWKey *key = (SWKey *)*inModule;
 
88
        VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key);
 
89
 
 
90
        char buf[1024];
 
91
        bool opentest = false;
 
92
        bool openbook = false;
 
93
        bool openchap = false;
 
94
        int lastTest = 5;
 
95
        int lastBook = 9999;
 
96
        int lastChap = 9999;
 
97
        if (!vkey) {
 
98
                cerr << "Currently mod2osis only works with verse keyed modules\n\n";
 
99
                exit(-1);
 
100
        }
 
101
 
 
102
        vkey->Headings(0);
 
103
 
 
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\" ";
 
109
                }
 
110
                else cout << "encoding=\"UTF-8\" ";
 
111
                cout << "?>\n\n";
 
112
 
 
113
 
 
114
        cout << "<osis";
 
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";
 
118
        cout << "<osisText";
 
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() << "\"";
 
125
                }
 
126
                cout << ">\n\n";
 
127
 
 
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";
 
139
 
 
140
 
 
141
        (*inModule) = TOP;
 
142
 
 
143
        SWKey *p = inModule->CreateKey();
 
144
        VerseKey *tmpKey = SWDYNAMIC_CAST(VerseKey, p);
 
145
        if (!tmpKey) {
 
146
                delete p;
 
147
                tmpKey = new VerseKey();
 
148
        }
 
149
        *tmpKey = inModule->getKeyText();
 
150
 
 
151
        tmpKey->Headings(1);
 
152
        tmpKey->AutoNormalize(0);
 
153
 
 
154
        for ((*inModule) = TOP; !inModule->Error(); (*inModule)++) {
 
155
                bool newTest = false;
 
156
                bool newBook = false;
 
157
 
 
158
                if (!strlen(inModule->RenderText())) {
 
159
                        continue;
 
160
                }
 
161
 
 
162
                if ((vkey->Testament() != lastTest)) {
 
163
                        if (openchap)
 
164
                                cout << "\t</chapter>\n";
 
165
                        if (openbook)
 
166
                                cout << "\t</div>\n";
 
167
                        if (opentest)
 
168
                                cout << "\t</div>\n";
 
169
                        cout << "\t<div type=\"x-testament\">\n";
 
170
                        opentest = true;
 
171
                        newTest = true;
 
172
                }
 
173
                if ((vkey->Book() != lastBook) || newTest) {
 
174
                        if (!newTest) {
 
175
                                if (openchap)
 
176
                                        cout << "\t</chapter>\n";
 
177
                                if (openbook)
 
178
                                        cout << "\t</div>\n";
 
179
                        }
 
180
                        *buf = 0;
 
181
                        *tmpKey = *vkey;
 
182
                        tmpKey->Chapter(0);
 
183
                        tmpKey->Verse(0);
 
184
                        sprintf(buf, "\t<div type=\"book\" osisID=\"%s\">\n", tmpKey->getOSISRef());
 
185
//                      filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
 
186
                        cout << "" << buf << endl;
 
187
                        openbook = true;
 
188
                        newBook = true;
 
189
                }
 
190
                if ((vkey->Chapter() != lastChap) || newBook) {
 
191
                        if (!newBook) {
 
192
                                if (openchap)
 
193
                                        cout << "\t</chapter>\n";
 
194
                        }
 
195
                        *buf = 0;
 
196
                        *tmpKey = *vkey;
 
197
                        tmpKey->Verse(0);
 
198
                        sprintf(buf, "\t<chapter osisID=\"%s\">\n", tmpKey->getOSISRef());
 
199
//                      filter.ProcessText(buf, 200 - 3, &lastHeading, inModule);
 
200
                        cout << "" << buf;
 
201
                        openchap = true;
 
202
                }
 
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();
 
209
        }
 
210
        if (openchap)
 
211
                cout << "\t</chapter>\n";
 
212
        if (openbook)
 
213
                cout << "\t</div>\n";
 
214
        if (opentest)
 
215
                cout << "\t</div>\n";
 
216
        cout << "\t</osisText>\n";
 
217
        cout << "</osis>\n";
 
218
        return 0;
 
219
}
 
220
 
 
221