1
/******************************************************************************
2
* rawld.cpp - code for class 'RawLD'- a module that reads raw lexicon and
3
* dictionary files: *.dat *.idx
6
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
7
* CrossWire Bible Society
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.
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.
33
/******************************************************************************
34
* RawLD Constructor - Initializes data for instance of RawLD
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
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)
47
/******************************************************************************
48
* RawLD Destructor - Cleans up instance of RawLD
56
bool RawLD::isWritable() {
57
return ((idxfd->getFd() > 0) && ((idxfd->mode & FileMgr::RDWR) == FileMgr::RDWR));
61
/******************************************************************************
62
* RawLD::getEntry - Looks up entry from data file. 'Snaps' to closest
63
* entry and sets 'entrybuf'.
65
* ENT: away - number of entries offset from key (default = 0)
70
char RawLD::getEntry(long away)
77
char *buf = new char [ strlen(*key) + 6 ];
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
90
stdstr(&entkeytxt, idxbuf); // set entry key text that module 'snapped' to.
102
/******************************************************************************
103
* RawLD::getRawEntry - Returns the correct entry when char * cast
106
* RET: string buffer with entry
109
SWBuf &RawLD::getRawEntryBuf() {
111
char ret = getEntry();
122
/******************************************************************************
123
* RawLD::increment - Increments module key a number of entries
125
* ENT: increment - Number of entries to jump forward
130
void RawLD::increment(int steps) {
133
if (key->isTraversable()) {
135
error = key->Error();
139
tmperror = (getEntry(steps)) ? KEYERR_OUTOFBOUNDS : 0;
140
error = (error)?error:tmperror;
145
void RawLD::setEntry(const char *inbuf, long len) {
146
doSetText(*key, inbuf, len);
150
void RawLD::linkEntry(const SWKey *inkey) {
151
doLinkEntry(*key, *inkey);
155
/******************************************************************************
156
* RawFiles::deleteEntry - deletes this entry
161
void RawLD::deleteEntry() {
166
long RawLD::getEntryCount() const {
167
if (idxfd < 0) return 0;
168
return idxfd->seek(0, SEEK_END) / IDXENTRYSIZE;
172
long RawLD::getEntryForKey(const char *key) const {
176
char *buf = new char [ strlen(key) + 6 ];
181
findOffset(buf, &start, &size, 0, &offset);
185
return offset / IDXENTRYSIZE;
189
char *RawLD::getKeyForEntry(long entry) const {
191
getIDXBuf(entry * IDXENTRYSIZE, &key);