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

« back to all changes in this revision

Viewing changes to src/modules/lexdict/rawld/rawld.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
 *  rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and
 
3
 *                              dictionary files: *.dat *.idx
 
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 <fcntl.h>
 
23
 
 
24
#include <utilstr.h>
 
25
#include <rawstr.h>
 
26
#include <rawld.h>
 
27
#include <filemgr.h>
 
28
 
 
29
#include <stdio.h>
 
30
 
 
31
SWORD_NAMESPACE_START
 
32
 
 
33
 /******************************************************************************
 
34
 * RawLD Constructor - Initializes data for instance of RawLD
 
35
 *
 
36
 * ENT: ipath   - path and filename of files (no extension)
 
37
 *              iname   - Internal name for module
 
38
 *              idesc   - Name to display to user for module
 
39
 *              idisp   - Display object to use for displaying
 
40
 */
 
41
 
 
42
RawLD::RawLD(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : RawStr(ipath), SWLD(iname, idesc, idisp, enc, dir, mark, ilang)
 
43
{
 
44
}
 
45
 
 
46
 
 
47
/******************************************************************************
 
48
 * RawLD Destructor - Cleans up instance of RawLD
 
49
 */
 
50
 
 
51
RawLD::~RawLD()
 
52
{
 
53
}
 
54
 
 
55
 
 
56
bool RawLD::isWritable() {
 
57
         return ((idxfd->getFd() > 0) && ((idxfd->mode & FileMgr::RDWR) == FileMgr::RDWR));
 
58
}
 
59
 
 
60
 
 
61
/******************************************************************************
 
62
 * RawLD::getEntry      - Looks up entry from data file.  'Snaps' to closest
 
63
 *                              entry and sets 'entrybuf'.
 
64
 *
 
65
 * ENT: away - number of entries offset from key (default = 0)
 
66
 *
 
67
 * RET: error status
 
68
 */
 
69
 
 
70
char RawLD::getEntry(long away)
 
71
{
 
72
        __u32 start = 0;
 
73
        __u16 size = 0;
 
74
        char *idxbuf = 0;
 
75
        char retval = 0;
 
76
 
 
77
        char *buf = new char [ strlen(*key) + 6 ];
 
78
        strcpy(buf, *key);
 
79
 
 
80
        strongsPad(buf);
 
81
 
 
82
        if (!(retval = findOffset(buf, &start, &size, away))) {
 
83
                readText(start, &size, &idxbuf, entryBuf);
 
84
                rawFilter(entryBuf, 0); // hack, decipher
 
85
                rawFilter(entryBuf, key);
 
86
                entrySize = size;        // support getEntrySize call
 
87
                if (!key->Persist())                    // If we have our own key
 
88
                        *key = idxbuf;                          // reset it to entry index buffer
 
89
 
 
90
                stdstr(&entkeytxt, idxbuf);     // set entry key text that module 'snapped' to.
 
91
                delete [] idxbuf;
 
92
        }
 
93
        else {
 
94
                entryBuf = "";
 
95
        }
 
96
                
 
97
        delete [] buf;
 
98
        return retval;
 
99
}
 
100
 
 
101
 
 
102
/******************************************************************************
 
103
 * RawLD::getRawEntry   - Returns the correct entry when char * cast
 
104
 *                                                      is requested
 
105
 *
 
106
 * RET: string buffer with entry
 
107
 */
 
108
 
 
109
SWBuf &RawLD::getRawEntryBuf() {
 
110
 
 
111
        char ret = getEntry();
 
112
        if (!ret) {
 
113
//              if (!isUnicode())
 
114
                        prepText(entryBuf);
 
115
        }
 
116
        else error = ret;
 
117
 
 
118
        return entryBuf;
 
119
}
 
120
 
 
121
 
 
122
/******************************************************************************
 
123
 * RawLD::increment     - Increments module key a number of entries
 
124
 *
 
125
 * ENT: increment       - Number of entries to jump forward
 
126
 *
 
127
 * RET: *this
 
128
 */
 
129
 
 
130
void RawLD::increment(int steps) {
 
131
        char tmperror;
 
132
 
 
133
        if (key->isTraversable()) {
 
134
                *key += steps;
 
135
                error = key->Error();
 
136
                steps = 0;
 
137
        }
 
138
        
 
139
        tmperror = (getEntry(steps)) ? KEYERR_OUTOFBOUNDS : 0;
 
140
        error = (error)?error:tmperror;
 
141
        *key = entkeytxt;
 
142
}
 
143
 
 
144
 
 
145
void RawLD::setEntry(const char *inbuf, long len) {
 
146
        doSetText(*key, inbuf, len);
 
147
}
 
148
 
 
149
 
 
150
void RawLD::linkEntry(const SWKey *inkey) {
 
151
        doLinkEntry(*key, *inkey);
 
152
}
 
153
 
 
154
 
 
155
/******************************************************************************
 
156
 * RawFiles::deleteEntry        - deletes this entry
 
157
 *
 
158
 * RET: *this
 
159
 */
 
160
 
 
161
void RawLD::deleteEntry() {
 
162
        doSetText(*key, "");
 
163
}
 
164
 
 
165
 
 
166
long RawLD::getEntryCount() const {
 
167
        if (idxfd < 0) return 0;
 
168
        return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
 
169
}
 
170
 
 
171
 
 
172
long RawLD::getEntryForKey(const char *key) const {
 
173
        __u32 start, offset;
 
174
        __u16 size;
 
175
        
 
176
        char *buf = new char [ strlen(key) + 6 ];
 
177
        strcpy(buf, key);
 
178
 
 
179
        strongsPad(buf);
 
180
        
 
181
        findOffset(buf, &start, &size, 0, &offset);
 
182
 
 
183
        delete [] buf;
 
184
 
 
185
        return offset / IDXENTRYSIZE;
 
186
}
 
187
 
 
188
 
 
189
char *RawLD::getKeyForEntry(long entry) const {
 
190
        char *key = 0;
 
191
        getIDXBuf(entry * IDXENTRYSIZE, &key);
 
192
        return key;
 
193
}
 
194
 
 
195
SWORD_NAMESPACE_END