1
/******************************************************************************
2
* rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs
3
* pointing to actual text desired. Uses standard
4
* files: ot and nt using indexs ??.bks ??.cps ??.vss
7
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
8
* CrossWire Bible Society
10
* Tempe, AZ 85280-2528
12
* This program is free software; you can redistribute it and/or modify it
13
* under the terms of the GNU General Public License as published by the
14
* Free Software Foundation version 2.
16
* This program is distributed in the hope that it will be useful, but
17
* WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
35
/******************************************************************************
36
* RawFiles Constructor - Initializes data for instance of RawFiles
38
* ENT: iname - Internal name for module
39
* idesc - Name to display to user for module
40
* idisp - Display object to use for displaying
43
RawFiles::RawFiles(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : RawVerse(ipath, FileMgr::RDWR), SWCom(iname, idesc, idisp, enc, dir, mark, ilang)
48
/******************************************************************************
49
* RawFiles Destructor - Cleans up instance of RawFiles
57
/** Is the module writable? :)
60
bool RawFiles::isWritable() {
61
return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
65
/******************************************************************************
66
* RawFiles::getRawEntry - Returns the correct verse when char * cast
69
* RET: string buffer with verse
72
SWBuf &RawFiles::getRawEntryBuf() {
75
unsigned short size = 0;
76
VerseKey *key = &getVerseKey();
78
findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
84
readText(key->Testament(), start, size, entryBuf);
87
datafile = FileMgr::getSystemFileMgr()->open(tmpbuf.c_str(), FileMgr::RDONLY);
88
if (datafile->getFd() > 0) {
89
size = datafile->seek(0, SEEK_END);
90
char *tmpBuf = new char [ size + 1 ];
91
memset(tmpBuf, 0, size + 1);
92
datafile->seek(0, SEEK_SET);
93
datafile->read(tmpBuf, size);
96
// preptext(entrybuf);
98
FileMgr::getSystemFileMgr()->close(datafile);
104
/******************************************************************************
105
* RawFiles::setEntry(char *)- Update the modules current key entry with
109
void RawFiles::setEntry(const char *inbuf, long len) {
113
VerseKey *key = &getVerseKey();
115
len = (len<0)?strlen(inbuf):len;
117
findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
123
readText(key->Testament(), start, size, tmpbuf);
130
tmpbuf = getNextFilename();
131
doSetText(key->Testament(), key->TestamentIndex(), tmpbuf);
134
datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
135
if (datafile->getFd() > 0) {
136
datafile->write(inbuf, len);
138
FileMgr::getSystemFileMgr()->close(datafile);
142
/******************************************************************************
143
* RawFiles::linkEntry(SWKey *)- Link the modules current key entry with
144
* another module entry
149
void RawFiles::linkEntry(const SWKey *inkey) {
153
const VerseKey *key = &getVerseKey();
155
findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
159
readText(key->Testament(), start, size + 2, tmpbuf);
161
key = &getVerseKey(inkey);
162
doSetText(key->Testament(), key->TestamentIndex(), tmpbuf.c_str());
167
/******************************************************************************
168
* RawFiles::deleteEntry - deletes this entry
173
void RawFiles::deleteEntry() {
174
VerseKey *key = &getVerseKey();
175
doSetText(key->Testament(), key->TestamentIndex(), "");
179
/******************************************************************************
180
* RawFiles::getNextfilename - generates a valid filename in which to store
186
char *RawFiles::getNextFilename() {
187
static char incfile[255];
191
sprintf(incfile, "%s/incfile", path);
192
datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::RDONLY);
194
if (datafile->read(&number, 4) != 4) number = 0;
195
number = swordtoarch32(number);
198
FileMgr::getSystemFileMgr()->close(datafile);
200
datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
201
sprintf(incfile, "%.7d", number-1);
203
number = archtosword32(number);
204
datafile->write(&number, 4);
206
FileMgr::getSystemFileMgr()->close(datafile);
211
char RawFiles::createModule (const char *path) {
212
char *incfile = new char [ strlen (path) + 16 ];
215
zero = archtosword32(zero);
219
sprintf(incfile, "%s/incfile", path);
220
datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
222
datafile->write(&zero, 4);
223
FileMgr::getSystemFileMgr()->close(datafile);
225
return RawVerse::createModule (path);