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

« back to all changes in this revision

Viewing changes to src/modules/texts/rawtext/rawtext.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
 *  rawtext.cpp - code for class 'RawText'- a module that reads raw text files:
 
3
 *                ot and nt using indexs ??.bks ??.cps ??.vss
 
4
 *
 
5
 *
 
6
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
7
 *      CrossWire Bible Society
 
8
 *      P. O. Box 2528
 
9
 *      Tempe, AZ  85280-2528
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify it
 
12
 * under the terms of the GNU General Public License as published by the
 
13
 * Free Software Foundation version 2.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
 * General Public License for more details.
 
19
 *
 
20
 */
 
21
 
 
22
#include <stdio.h>
 
23
#include <fcntl.h>
 
24
#include <sysdata.h>
 
25
 
 
26
#include <utilstr.h>
 
27
#include <rawverse.h>
 
28
#include <rawtext.h>
 
29
#include <rawstr.h>
 
30
#include <filemgr.h>
 
31
#include <versekey.h>
 
32
#include <stringmgr.h>
 
33
 
 
34
#include <regex.h>      // GNU
 
35
#include <map>
 
36
#include <list>
 
37
#include <algorithm>
 
38
 
 
39
#ifndef USELUCENE
 
40
using std::map;
 
41
using std::list;
 
42
using std::find;
 
43
#endif
 
44
 
 
45
SWORD_NAMESPACE_START
 
46
 
 
47
#ifndef USELUCENE
 
48
typedef  map < SWBuf, list<long> > strlist;
 
49
typedef list<long> longlist;
 
50
#endif
 
51
 
 
52
/******************************************************************************
 
53
 * RawText Constructor - Initializes data for instance of RawText
 
54
 *
 
55
 * ENT: iname - Internal name for module
 
56
 *      idesc - Name to display to user for module
 
57
 *      idisp    - Display object to use for displaying
 
58
 */
 
59
 
 
60
RawText::RawText(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang, const char *versification)
 
61
                : SWText(iname, idesc, idisp, enc, dir, mark, ilang, versification),
 
62
                RawVerse(ipath) {
 
63
}
 
64
 
 
65
 
 
66
/******************************************************************************
 
67
 * RawText Destructor - Cleans up instance of RawText
 
68
 */
 
69
 
 
70
RawText::~RawText() {
 
71
}
 
72
 
 
73
 
 
74
bool RawText::isWritable() {
 
75
        return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
 
76
}
 
77
 
 
78
 
 
79
/******************************************************************************
 
80
 * RawText::getRawEntry - Returns the correct verse when char * cast
 
81
 *                                      is requested
 
82
 *
 
83
 * RET: string buffer with verse
 
84
 */
 
85
 
 
86
SWBuf &RawText::getRawEntryBuf() {
 
87
        long  start = 0;
 
88
        unsigned short size = 0;
 
89
        VerseKey &key = getVerseKey();
 
90
 
 
91
        findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
 
92
        entrySize = size;        // support getEntrySize call
 
93
 
 
94
        entryBuf = "";
 
95
        readText(key.Testament(), start, size, entryBuf);
 
96
 
 
97
        rawFilter(entryBuf, 0); // hack, decipher
 
98
        rawFilter(entryBuf, &key);
 
99
 
 
100
//      if (!isUnicode())
 
101
                prepText(entryBuf);
 
102
 
 
103
        return entryBuf;
 
104
}
 
105
 
 
106
 
 
107
void RawText::setEntry(const char *inbuf, long len) {
 
108
        VerseKey &key = getVerseKey();
 
109
        doSetText(key.Testament(), key.TestamentIndex(), inbuf, len);
 
110
}
 
111
 
 
112
 
 
113
void RawText::linkEntry(const SWKey *inkey) {
 
114
        VerseKey &destkey = getVerseKey();
 
115
        const VerseKey *srckey = &getVerseKey(inkey);
 
116
        doLinkEntry(destkey.Testament(), destkey.TestamentIndex(), srckey->TestamentIndex());
 
117
}
 
118
 
 
119
 
 
120
/******************************************************************************
 
121
 * RawText::deleteEntry - deletes this entry
 
122
 *
 
123
 * RET: *this
 
124
 */
 
125
 
 
126
void RawText::deleteEntry() {
 
127
        VerseKey &key = getVerseKey();
 
128
        doSetText(key.Testament(), key.TestamentIndex(), "");
 
129
}
 
130
 
 
131
/******************************************************************************
 
132
 * RawText::increment   - Increments module key a number of entries
 
133
 *
 
134
 * ENT: increment       - Number of entries to jump forward
 
135
 *
 
136
 * RET: *this
 
137
 */
 
138
 
 
139
void RawText::increment(int steps) {
 
140
        long  start;
 
141
        unsigned short size;
 
142
        VerseKey *tmpkey = &getVerseKey();
 
143
 
 
144
        findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
 
145
 
 
146
        SWKey lastgood = *tmpkey;
 
147
        while (steps) {
 
148
                long laststart = start;
 
149
                unsigned short lastsize = size;
 
150
                SWKey lasttry = *tmpkey;
 
151
                (steps > 0) ? ++(*key) : --(*key);
 
152
                tmpkey = &getVerseKey();
 
153
 
 
154
                if ((error = key->Error())) {
 
155
                        *key = lastgood;
 
156
                        break;
 
157
                }
 
158
                long index = tmpkey->TestamentIndex();
 
159
                findOffset(tmpkey->Testament(), index, &start, &size);
 
160
                if (
 
161
                        (((laststart != start) || (lastsize != size))   // we're a different entry
 
162
//                              && (start > 0)
 
163
                                && (size))      // and we actually have a size
 
164
                                ||(!skipConsecutiveLinks)) {    // or we don't want to skip consecutive links
 
165
                        steps += (steps < 0) ? 1 : -1;
 
166
                        lastgood = *tmpkey;
 
167
                }
 
168
        }
 
169
        error = (error) ? KEYERR_OUTOFBOUNDS : 0;
 
170
}
 
171
 
 
172
bool RawText::isLinked(const SWKey *k1, const SWKey *k2) const {
 
173
        long start1, start2;
 
174
        unsigned short size1, size2;
 
175
        VerseKey *vk1 = &getVerseKey(k1);
 
176
        VerseKey *vk2 = &getVerseKey(k2);
 
177
        if (vk1->Testament() != vk2->Testament()) return false;
 
178
 
 
179
        findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1);
 
180
        findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2);
 
181
        if (!size1 || !size2) return false;
 
182
        return start1 == start2;
 
183
}
 
184
 
 
185
bool RawText::hasEntry(const SWKey *k) const {
 
186
        long start;
 
187
        unsigned short size;
 
188
        VerseKey *vk = &getVerseKey(k);
 
189
 
 
190
        findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);
 
191
        return size;
 
192
}
 
193
 
 
194
        
 
195
 
 
196
SWORD_NAMESPACE_END