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

« back to all changes in this revision

Viewing changes to src/modules/common/rawverse4.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
 *  rawverse.cpp   - code for class 'RawVerse4'- a module that reads raw text
 
3
 *                      files:  ot and nt using indexs ??.bks ??.cps ??.vss
 
4
 *                      and provides lookup and parsing functions based on
 
5
 *                      class VerseKey
 
6
 *
 
7
 *
 
8
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
9
 *      CrossWire Bible Society
 
10
 *      P. O. Box 2528
 
11
 *      Tempe, AZ  85280-2528
 
12
 *
 
13
 * This program is free software; you can redistribute it and/or modify it
 
14
 * under the terms of the GNU General Public License as published by the
 
15
 * Free Software Foundation version 2.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful, but
 
18
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
 * General Public License for more details.
 
21
 *
 
22
 */
 
23
 
 
24
 
 
25
 
 
26
#include <ctype.h>
 
27
#include <stdio.h>
 
28
#include <fcntl.h>
 
29
#include <errno.h>
 
30
 
 
31
#include <utilstr.h>
 
32
#include <rawverse4.h>
 
33
#include <versekey.h>
 
34
#include <sysdata.h>
 
35
#include <filemgr.h>
 
36
#include <swbuf.h>
 
37
 
 
38
 
 
39
SWORD_NAMESPACE_START
 
40
 
 
41
/******************************************************************************
 
42
 * RawVerse4 Statics
 
43
 */
 
44
 
 
45
int RawVerse4::instance = 0;
 
46
const char *RawVerse4::nl = "\r\n";
 
47
 
 
48
 
 
49
/******************************************************************************
 
50
 * RawVerse4 Constructor - Initializes data for instance of RawVerse4
 
51
 *
 
52
 * ENT: ipath - path of the directory where data and index files are located.
 
53
 *              be sure to include the trailing separator (e.g. '/' or '\')
 
54
 *              (e.g. 'modules/texts/rawtext/webster/')
 
55
 */
 
56
 
 
57
RawVerse4::RawVerse4(const char *ipath, int fileMode)
 
58
{
 
59
        SWBuf buf;
 
60
 
 
61
        path = 0;
 
62
        stdstr(&path, ipath);
 
63
        
 
64
        if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
 
65
                path[strlen(path)-1] = 0;
 
66
 
 
67
        if (fileMode == -1) { // try read/write if possible
 
68
                fileMode = FileMgr::RDWR;
 
69
        }
 
70
                
 
71
        buf.setFormatted("%s/ot.vss", path);
 
72
        idxfp[0] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
 
73
 
 
74
        buf.setFormatted("%s/nt.vss", path);
 
75
        idxfp[1] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
 
76
 
 
77
        buf.setFormatted("%s/ot", path);
 
78
        textfp[0] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
 
79
 
 
80
        buf.setFormatted("%s/nt", path);
 
81
        textfp[1] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
 
82
 
 
83
        instance++;
 
84
}
 
85
 
 
86
 
 
87
/******************************************************************************
 
88
 * RawVerse4 Destructor - Cleans up instance of RawVerse4
 
89
 */
 
90
 
 
91
RawVerse4::~RawVerse4()
 
92
{
 
93
        int loop1;
 
94
 
 
95
        if (path)
 
96
                delete [] path;
 
97
 
 
98
        --instance;
 
99
 
 
100
        for (loop1 = 0; loop1 < 2; loop1++) {
 
101
                FileMgr::getSystemFileMgr()->close(idxfp[loop1]);
 
102
                FileMgr::getSystemFileMgr()->close(textfp[loop1]);
 
103
        }
 
104
}
 
105
 
 
106
 
 
107
/******************************************************************************
 
108
 * RawVerse4::findoffset        - Finds the offset of the key verse from the indexes
 
109
 *
 
110
 * ENT: testmt  - testament to find (0 - Bible/module introduction)
 
111
 *      idxoff  - offset into .vss
 
112
 *      start   - address to store the starting offset
 
113
 *      size    - address to store the size of the entry
 
114
 */
 
115
 
 
116
void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long *size) const {
 
117
        idxoff *= 8;
 
118
        if (!testmt)
 
119
                testmt = ((idxfp[1]) ? 1:2);
 
120
                
 
121
        if (idxfp[testmt-1]->getFd() >= 0) {
 
122
                idxfp[testmt-1]->seek(idxoff, SEEK_SET);
 
123
                __u32 tmpStart;
 
124
                __u32 tmpSize;
 
125
                idxfp[testmt-1]->read(&tmpStart, 4);
 
126
                long len = idxfp[testmt-1]->read(&tmpSize, 4);          // read size
 
127
 
 
128
                *start = swordtoarch32(tmpStart);
 
129
                *size  = swordtoarch32(tmpSize);
 
130
 
 
131
                if (len < 2) {
 
132
                        *size = (unsigned long)((*start) ? (textfp[testmt-1]->seek(0, SEEK_END) - (long)*start) : 0);   // if for some reason we get an error reading size, make size to end of file
 
133
                }
 
134
        }
 
135
        else {
 
136
                *start = 0;
 
137
                *size = 0;
 
138
        }
 
139
}
 
140
 
 
141
 
 
142
/******************************************************************************
 
143
 * RawVerse4::readtext  - gets text at a given offset
 
144
 *
 
145
 * ENT: testmt  - testament file to search in (0 - Old; 1 - New)
 
146
 *      start   - starting offset where the text is located in the file
 
147
 *      size    - size of text entry + 2 (null)(null)
 
148
 *      buf     - buffer to store text
 
149
 *
 
150
 */
 
151
 
 
152
void RawVerse4::readText(char testmt, long start, unsigned long size, SWBuf &buf) {
 
153
        buf = "";
 
154
        buf.setFillByte(0);
 
155
        buf.setSize(size + 1);
 
156
        if (!testmt)
 
157
                testmt = ((idxfp[1]) ? 1:2);
 
158
        if (size) {
 
159
                if (textfp[testmt-1]->getFd() >= 0) {
 
160
                        textfp[testmt-1]->seek(start, SEEK_SET);
 
161
                        textfp[testmt-1]->read(buf.getRawData(), (int)size); 
 
162
                }
 
163
        }
 
164
}
 
165
 
 
166
 
 
167
/******************************************************************************
 
168
 * RawVerse4::settext   - Sets text for current offset
 
169
 *
 
170
 * ENT: testmt  - testament to find (0 - Bible/module introduction)
 
171
 *      idxoff  - offset into .vss
 
172
 *      buf     - buffer to store
 
173
 *      len     - length of buffer (0 - null terminated)
 
174
 */
 
175
 
 
176
void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len)
 
177
{
 
178
        __u32 start;
 
179
        __u32 size;
 
180
 
 
181
        idxoff *= 8;
 
182
        if (!testmt)
 
183
                testmt = ((idxfp[1]) ? 1:2);
 
184
 
 
185
        size = (len < 0) ? strlen(buf) : len;
 
186
 
 
187
        start = textfp[testmt-1]->seek(0, SEEK_END);
 
188
        idxfp[testmt-1]->seek(idxoff, SEEK_SET);
 
189
 
 
190
        if (size) {
 
191
                textfp[testmt-1]->seek(start, SEEK_SET);
 
192
                textfp[testmt-1]->write(buf, (int)size);
 
193
 
 
194
                // add a new line to make data file easier to read in an editor
 
195
                textfp[testmt-1]->write(nl, 2);
 
196
        }
 
197
        else {
 
198
                start = 0;
 
199
        }
 
200
 
 
201
        start = archtosword32(start);
 
202
        size  = archtosword32(size);
 
203
 
 
204
        idxfp[testmt-1]->write(&start, 4);
 
205
        idxfp[testmt-1]->write(&size, 4);
 
206
}
 
207
 
 
208
 
 
209
/******************************************************************************
 
210
 * RawVerse4::linkentry - links one entry to another
 
211
 *
 
212
 * ENT: testmt  - testament to find (0 - Bible/module introduction)
 
213
 *      destidxoff      - dest offset into .vss
 
214
 *      srcidxoff               - source offset into .vss
 
215
 */
 
216
 
 
217
void RawVerse4::doLinkEntry(char testmt, long destidxoff, long srcidxoff) {
 
218
        __u32 start;
 
219
        __u32 size;
 
220
 
 
221
        destidxoff *= 8;
 
222
        srcidxoff  *= 8;
 
223
 
 
224
        if (!testmt)
 
225
                testmt = ((idxfp[1]) ? 1:2);
 
226
 
 
227
        // get source
 
228
        idxfp[testmt-1]->seek(srcidxoff, SEEK_SET);
 
229
        idxfp[testmt-1]->read(&start, 4);
 
230
        idxfp[testmt-1]->read(&size, 4);
 
231
 
 
232
        // write dest
 
233
        idxfp[testmt-1]->seek(destidxoff, SEEK_SET);
 
234
        idxfp[testmt-1]->write(&start, 4);
 
235
        idxfp[testmt-1]->write(&size, 4);
 
236
}
 
237
 
 
238
 
 
239
/******************************************************************************
 
240
 * RawVerse4::CreateModule      - Creates new module files
 
241
 *
 
242
 * ENT: path    - directory to store module files
 
243
 * RET: error status
 
244
 */
 
245
 
 
246
char RawVerse4::createModule(const char *ipath, const char *v11n)
 
247
{
 
248
        char *path = 0;
 
249
        char *buf = new char [ strlen (ipath) + 20 ];
 
250
        FileDesc *fd, *fd2;
 
251
 
 
252
        stdstr(&path, ipath);
 
253
 
 
254
        if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
 
255
                path[strlen(path)-1] = 0;
 
256
 
 
257
        sprintf(buf, "%s/ot", path);
 
258
        FileMgr::removeFile(buf);
 
259
        fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE);
 
260
        fd->getFd();
 
261
        FileMgr::getSystemFileMgr()->close(fd);
 
262
 
 
263
        sprintf(buf, "%s/nt", path);
 
264
        FileMgr::removeFile(buf);
 
265
        fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE);
 
266
        fd->getFd();
 
267
        FileMgr::getSystemFileMgr()->close(fd);
 
268
 
 
269
        sprintf(buf, "%s/ot.vss", path);
 
270
        FileMgr::removeFile(buf);
 
271
        fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE);
 
272
        fd->getFd();
 
273
 
 
274
        sprintf(buf, "%s/nt.vss", path);
 
275
        FileMgr::removeFile(buf);
 
276
        fd2 = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE);
 
277
        fd2->getFd();
 
278
 
 
279
        VerseKey vk;
 
280
        vk.setVersificationSystem(v11n);
 
281
        vk.Headings(1);
 
282
        __u32 offset = 0;
 
283
        __u32 size = 0;
 
284
        offset = archtosword32(offset);
 
285
        size   = archtosword32(size);
 
286
 
 
287
        for (vk = TOP; !vk.Error(); vk++) {
 
288
                if (vk.Testament() < 2) {
 
289
                        fd->write(&offset, 4);
 
290
                        fd->write(&size, 4);
 
291
                }
 
292
                else    {
 
293
                        fd2->write(&offset, 4);
 
294
                        fd2->write(&size, 4);
 
295
                }
 
296
        }
 
297
        fd2->write(&offset, 4);
 
298
        fd2->write(&size, 4);
 
299
 
 
300
        FileMgr::getSystemFileMgr()->close(fd);
 
301
        FileMgr::getSystemFileMgr()->close(fd2);
 
302
 
 
303
        delete [] path;
 
304
        delete [] buf;
 
305
        
 
306
        return 0;
 
307
}
 
308
 
 
309
SWORD_NAMESPACE_END