1
/******************************************************************************
2
* rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and
3
* dictionary files: *.dat *.idx
5
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
6
* CrossWire Bible Society
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.
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.
32
/******************************************************************************
33
* RawLD Constructor - Initializes data for instance of RawLD
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
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) {
46
/******************************************************************************
47
* RawLD Destructor - Cleans up instance of RawLD
55
bool zLD::isWritable() {
56
return ((idxfd->getFd() > 0) && ((idxfd->mode & FileMgr::RDWR) == FileMgr::RDWR));
60
/******************************************************************************
61
* zLD::getEntry - Looks up entry from data file. 'Snaps' to closest
62
* entry and sets 'entrybuf'.
64
* ENT: away - number of entries offset from key (default = 0)
69
char zLD::getEntry(long away) {
75
char *buf = new char [ strlen(*key) + 6 ];
81
if (!(retval = findKeyIndex(buf, &index, away))) {
82
getText(index, &idxbuf, &ebuf);
83
size = strlen(ebuf) + 1;
86
rawFilter(entryBuf, key);
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
92
stdstr(&entkeytxt, idxbuf); // set entry key text that module 'snapped' to.
102
/******************************************************************************
103
* zLD::getRawEntry - Returns the correct entry when char * cast
106
* RET: string buffer with entry
109
SWBuf &zLD::getRawEntryBuf() {
110
if (!getEntry() /*&& !isUnicode()*/) {
118
/******************************************************************************
119
* zLD::increment - Increments module key a number of entries
121
* ENT: increment - Number of entries to jump forward
126
void zLD::increment(int steps) {
129
if (key->isTraversable()) {
131
error = key->Error();
135
tmperror = (getEntry(steps)) ? KEYERR_OUTOFBOUNDS : 0;
136
error = (error)?error:tmperror;
141
void zLD::setEntry(const char *inbuf, long len) {
142
setText(*key, inbuf, len);
146
void zLD::linkEntry(const SWKey *inkey) {
147
zStr::linkEntry(*key, *inkey);
151
/******************************************************************************
152
* RawFiles::deleteEntry - deletes this entry
157
void zLD::deleteEntry() {
162
long zLD::getEntryCount() const
164
if (idxfd < 0) return 0;
165
return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
169
long zLD::getEntryForKey(const char* key) const
172
char *buf = new char [ strlen(key) + 6 ];
177
findKeyIndex(buf, &offset);
181
return offset/IDXENTRYSIZE;
185
char *zLD::getKeyForEntry(long entry) const
188
getKeyFromIdxOffset(entry * IDXENTRYSIZE, &key);