1
/******************************************************************************
2
* rawtext4.cpp - code for class 'RawText4'- a module that reads raw text
3
* files: ot and nt using indexs ??.bks ??.cps ??.vss
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.
27
#include <rawverse4.h>
32
#include <stringmgr.h>
34
#include <regex.h> // GNU
48
typedef map < SWBuf, list<long> > strlist;
49
typedef list<long> longlist;
52
/******************************************************************************
53
* RawText4 Constructor - Initializes data for instance of RawText4
55
* ENT: iname - Internal name for module
56
* idesc - Name to display to user for module
57
* idisp - Display object to use for displaying
60
RawText4::RawText4(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),
66
/******************************************************************************
67
* RawText4 Destructor - Cleans up instance of RawText4
70
RawText4::~RawText4() {
74
bool RawText4::isWritable() {
75
return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
79
/******************************************************************************
80
* RawText4::getRawEntry - Returns the correct verse when char * cast
83
* RET: string buffer with verse
86
SWBuf &RawText4::getRawEntryBuf() {
88
unsigned long size = 0;
89
VerseKey &key = getVerseKey();
91
findOffset(key.Testament(), key.TestamentIndex(), &start, &size);
92
entrySize = size; // support getEntrySize call
95
readText(key.Testament(), start, size, entryBuf);
97
rawFilter(entryBuf, 0); // hack, decipher
98
rawFilter(entryBuf, &key);
107
void RawText4::setEntry(const char *inbuf, long len) {
108
VerseKey &key = getVerseKey();
109
doSetText(key.Testament(), key.TestamentIndex(), inbuf, len);
113
void RawText4::linkEntry(const SWKey *inkey) {
114
VerseKey &destkey = getVerseKey();
115
const VerseKey *srckey = &getVerseKey(inkey);
116
doLinkEntry(destkey.Testament(), destkey.TestamentIndex(), srckey->TestamentIndex());
120
/******************************************************************************
121
* RawText4::deleteEntry - deletes this entry
126
void RawText4::deleteEntry() {
127
VerseKey &key = getVerseKey();
128
doSetText(key.Testament(), key.TestamentIndex(), "");
131
/******************************************************************************
132
* RawText4::increment - Increments module key a number of entries
134
* ENT: increment - Number of entries to jump forward
139
void RawText4::increment(int steps) {
142
VerseKey *tmpkey = &getVerseKey();
144
findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size);
146
SWKey lastgood = *tmpkey;
148
long laststart = start;
149
unsigned long lastsize = size;
150
SWKey lasttry = *tmpkey;
151
(steps > 0) ? ++(*key) : --(*key);
152
tmpkey = &getVerseKey();
154
if ((error = key->Error())) {
158
long index = tmpkey->TestamentIndex();
159
findOffset(tmpkey->Testament(), index, &start, &size);
161
(((laststart != start) || (lastsize != size)) // we're a different entry
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;
169
error = (error) ? KEYERR_OUTOFBOUNDS : 0;
172
bool RawText4::isLinked(const SWKey *k1, const SWKey *k2) const {
174
unsigned long size1, size2;
175
VerseKey *vk1 = &getVerseKey(k1);
176
VerseKey *vk2 = &getVerseKey(k2);
177
if (vk1->Testament() != vk2->Testament()) return false;
179
findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1);
180
findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2);
181
return start1 == start2;
184
bool RawText4::hasEntry(const SWKey *k) const {
187
VerseKey *vk = &getVerseKey(k);
189
findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size);