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

« back to all changes in this revision

Viewing changes to src/modules/lexdict/zld/zld.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
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
6
 *      CrossWire Bible Society
 
7
 *      P. O. Box 2528
 
8
 *      Tempe, AZ  85280-2528
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify it
 
11
 * under the terms of the GNU General Public License as published by the
 
12
 * Free Software Foundation version 2.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful, but
 
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * General Public License for more details.
 
18
 *
 
19
 */
 
20
 
 
21
#include <fcntl.h>
 
22
 
 
23
#include <utilstr.h>
 
24
#include <zstr.h>
 
25
#include <zld.h>
 
26
#include <filemgr.h>
 
27
 
 
28
#include <stdio.h>
 
29
 
 
30
SWORD_NAMESPACE_START
 
31
 
 
32
 /******************************************************************************
 
33
 * RawLD Constructor - Initializes data for instance of RawLD
 
34
 *
 
35
 * ENT: ipath   - path and filename of files (no extension)
 
36
 *              iname   - Internal name for module
 
37
 *              idesc   - Name to display to user for module
 
38
 *              idisp   - Display object to use for displaying
 
39
 */
 
40
 
 
41
zLD::zLD(const char *ipath, const char *iname, const char *idesc, long blockCount, SWCompress *icomp, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : zStr(ipath, -1, blockCount, icomp), SWLD(iname, idesc, idisp, enc, dir, mark, ilang) {
 
42
 
 
43
}
 
44
 
 
45
 
 
46
/******************************************************************************
 
47
 * RawLD Destructor - Cleans up instance of RawLD
 
48
 */
 
49
 
 
50
zLD::~zLD() {
 
51
 
 
52
}
 
53
 
 
54
 
 
55
bool zLD::isWritable() {
 
56
        return ((idxfd->getFd() > 0) && ((idxfd->mode & FileMgr::RDWR) == FileMgr::RDWR));
 
57
}
 
58
 
 
59
 
 
60
/******************************************************************************
 
61
 * zLD::getEntry        - Looks up entry from data file.  'Snaps' to closest
 
62
 *                              entry and sets 'entrybuf'.
 
63
 *
 
64
 * ENT: away - number of entries offset from key (default = 0)
 
65
 *
 
66
 * RET: error status
 
67
 */
 
68
 
 
69
char zLD::getEntry(long away) {
 
70
        char *idxbuf = 0;
 
71
        char *ebuf = 0;
 
72
        char retval = 0;
 
73
        long index;
 
74
        unsigned long size;
 
75
        char *buf = new char [ strlen(*key) + 6 ];
 
76
        strcpy(buf, *key);
 
77
 
 
78
        strongsPad(buf);
 
79
 
 
80
        entryBuf = "";
 
81
        if (!(retval = findKeyIndex(buf, &index, away))) {
 
82
                getText(index, &idxbuf, &ebuf);
 
83
                size = strlen(ebuf) + 1;
 
84
                entryBuf = ebuf;
 
85
 
 
86
                rawFilter(entryBuf, key);
 
87
 
 
88
                entrySize = size;        // support getEntrySize call
 
89
                if (!key->Persist())                    // If we have our own key
 
90
                        *key = idxbuf;                          // reset it to entry index buffer
 
91
 
 
92
                stdstr(&entkeytxt, idxbuf);     // set entry key text that module 'snapped' to.
 
93
                free(idxbuf);
 
94
                free(ebuf);
 
95
        }
 
96
                
 
97
        delete [] buf;
 
98
        return retval;
 
99
}
 
100
 
 
101
 
 
102
/******************************************************************************
 
103
 * zLD::getRawEntry     - Returns the correct entry when char * cast
 
104
 *                                                      is requested
 
105
 *
 
106
 * RET: string buffer with entry
 
107
 */
 
108
 
 
109
SWBuf &zLD::getRawEntryBuf() {
 
110
        if (!getEntry() /*&& !isUnicode()*/) {
 
111
                prepText(entryBuf);
 
112
        }
 
113
 
 
114
        return entryBuf;
 
115
}
 
116
 
 
117
 
 
118
/******************************************************************************
 
119
 * zLD::increment       - Increments module key a number of entries
 
120
 *
 
121
 * ENT: increment       - Number of entries to jump forward
 
122
 *
 
123
 * RET: *this
 
124
 */
 
125
 
 
126
void zLD::increment(int steps) {
 
127
        char tmperror;
 
128
 
 
129
        if (key->isTraversable()) {
 
130
                *key += steps;
 
131
                error = key->Error();
 
132
                steps = 0;
 
133
        }
 
134
        
 
135
        tmperror = (getEntry(steps)) ? KEYERR_OUTOFBOUNDS : 0;
 
136
        error = (error)?error:tmperror;
 
137
        *key = entkeytxt;
 
138
}
 
139
 
 
140
 
 
141
void zLD::setEntry(const char *inbuf, long len) {
 
142
        setText(*key, inbuf, len);
 
143
}
 
144
 
 
145
 
 
146
void zLD::linkEntry(const SWKey *inkey) {
 
147
        zStr::linkEntry(*key, *inkey);
 
148
}
 
149
 
 
150
 
 
151
/******************************************************************************
 
152
 * RawFiles::deleteEntry        - deletes this entry
 
153
 *
 
154
 * RET: *this
 
155
 */
 
156
 
 
157
void zLD::deleteEntry() {
 
158
        setText(*key, "");
 
159
}
 
160
 
 
161
 
 
162
long zLD::getEntryCount() const
 
163
{
 
164
        if (idxfd < 0) return 0;
 
165
        return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
 
166
}
 
167
 
 
168
 
 
169
long zLD::getEntryForKey(const char* key) const
 
170
{
 
171
        long offset;
 
172
        char *buf = new char [ strlen(key) + 6 ];
 
173
        strcpy(buf, key);
 
174
 
 
175
        strongsPad(buf);
 
176
        
 
177
        findKeyIndex(buf, &offset);
 
178
 
 
179
        delete [] buf;
 
180
 
 
181
        return offset/IDXENTRYSIZE;
 
182
}
 
183
 
 
184
 
 
185
char *zLD::getKeyForEntry(long entry) const
 
186
{
 
187
        char *key = 0;
 
188
        getKeyFromIdxOffset(entry * IDXENTRYSIZE, &key);
 
189
        return key;
 
190
}
 
191
 
 
192
 
 
193
SWORD_NAMESPACE_END