summaryrefslogtreecommitdiff
path: root/src/modules/common/rawverse4.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/common/rawverse4.cpp')
-rw-r--r--src/modules/common/rawverse4.cpp129
1 files changed, 44 insertions, 85 deletions
diff --git a/src/modules/common/rawverse4.cpp b/src/modules/common/rawverse4.cpp
index bd438ec..ee0b207 100644
--- a/src/modules/common/rawverse4.cpp
+++ b/src/modules/common/rawverse4.cpp
@@ -3,9 +3,26 @@
* files: ot and nt using indexs ??.bks ??.cps ??.vss
* and provides lookup and parsing functions based on
* class VerseKey
+ *
+ *
+ * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
*/
+
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
@@ -96,18 +113,20 @@ RawVerse4::~RawVerse4()
* size - address to store the size of the entry
*/
-void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long *size) {
+void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long *size) const {
idxoff *= 8;
if (!testmt)
testmt = ((idxfp[1]) ? 1:2);
if (idxfp[testmt-1]->getFd() >= 0) {
idxfp[testmt-1]->seek(idxoff, SEEK_SET);
- idxfp[testmt-1]->read(start, 4);
- long len = idxfp[testmt-1]->read(size, 4); // read size
+ __u32 tmpStart;
+ __u32 tmpSize;
+ idxfp[testmt-1]->read(&tmpStart, 4);
+ long len = idxfp[testmt-1]->read(&tmpSize, 4); // read size
- *start = swordtoarch32(*start);
- *size = swordtoarch32(*size);
+ *start = swordtoarch32(tmpStart);
+ *size = swordtoarch32(tmpSize);
if (len < 2) {
*size = (unsigned long)((*start) ? (textfp[testmt-1]->seek(0, SEEK_END) - (long)*start) : 0); // if for some reason we get an error reading size, make size to end of file
@@ -121,65 +140,6 @@ void RawVerse4::findOffset(char testmt, long idxoff, long *start, unsigned long
/******************************************************************************
- * RawVerse4::preptext - Prepares the text before returning it to external
- * objects
- *
- * ENT: buf - buffer where text is stored and where to store the prep'd
- * text.
- */
-
-void RawVerse4::prepText(SWBuf &buf) {
- unsigned int to, from;
- char space = 0, cr = 0, realdata = 0, nlcnt = 0;
- char *rawBuf = buf.getRawData();
- for (to = from = 0; rawBuf[from]; from++) {
- switch (rawBuf[from]) {
- case 10:
- if (!realdata)
- continue;
- space = (cr) ? 0 : 1;
- cr = 0;
- nlcnt++;
- if (nlcnt > 1) {
-// *to++ = nl;
- rawBuf[to++] = 10;
-// *to++ = nl[1];
-// nlcnt = 0;
- }
- continue;
- case 13:
- if (!realdata)
- continue;
-// *to++ = nl[0];
- rawBuf[to++] = 10;
- space = 0;
- cr = 1;
- continue;
- }
- realdata = 1;
- nlcnt = 0;
- if (space) {
- space = 0;
- if (rawBuf[from] != ' ') {
- rawBuf[to++] = ' ';
- from--;
- continue;
- }
- }
- rawBuf[to++] = rawBuf[from];
- }
- buf.setSize(to);
-
- while (to > 1) { // remove trailing excess
- to--;
- if ((rawBuf[to] == 10) || (rawBuf[to] == ' '))
- buf.setSize(to);
- else break;
- }
-}
-
-
-/******************************************************************************
* RawVerse4::readtext - gets text at a given offset
*
* ENT: testmt - testament file to search in (0 - Old; 1 - New)
@@ -215,17 +175,16 @@ void RawVerse4::readText(char testmt, long start, unsigned long size, SWBuf &buf
void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len)
{
- long start, outstart;
- unsigned long size;
- unsigned long outsize;
+ __u32 start;
+ __u32 size;
idxoff *= 8;
if (!testmt)
testmt = ((idxfp[1]) ? 1:2);
- size = outsize = (len < 0) ? strlen(buf) : len;
+ size = (len < 0) ? strlen(buf) : len;
- start = outstart = textfp[testmt-1]->seek(0, SEEK_END);
+ start = textfp[testmt-1]->seek(0, SEEK_END);
idxfp[testmt-1]->seek(idxoff, SEEK_SET);
if (size) {
@@ -239,13 +198,11 @@ void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len)
start = 0;
}
- outstart = archtosword32(start);
- outsize = archtosword32(size);
-
- idxfp[testmt-1]->write(&outstart, 4);
- idxfp[testmt-1]->write(&outsize, 4);
-
+ start = archtosword32(start);
+ size = archtosword32(size);
+ idxfp[testmt-1]->write(&start, 4);
+ idxfp[testmt-1]->write(&size, 4);
}
@@ -258,8 +215,8 @@ void RawVerse4::doSetText(char testmt, long idxoff, const char *buf, long len)
*/
void RawVerse4::doLinkEntry(char testmt, long destidxoff, long srcidxoff) {
- long start;
- unsigned long size;
+ __u32 start;
+ __u32 size;
destidxoff *= 8;
srcidxoff *= 8;
@@ -286,7 +243,7 @@ void RawVerse4::doLinkEntry(char testmt, long destidxoff, long srcidxoff) {
* RET: error status
*/
-char RawVerse4::createModule(const char *ipath)
+char RawVerse4::createModule(const char *ipath, const char *v11n)
{
char *path = 0;
char *buf = new char [ strlen (ipath) + 20 ];
@@ -320,11 +277,15 @@ char RawVerse4::createModule(const char *ipath)
fd2->getFd();
VerseKey vk;
+ vk.setVersificationSystem(v11n);
vk.Headings(1);
- long offset = 0;
- long size = 0;
+ __u32 offset = 0;
+ __u32 size = 0;
+ offset = archtosword32(offset);
+ size = archtosword32(size);
+
for (vk = TOP; !vk.Error(); vk++) {
- if (vk.Testament() == 1) {
+ if (vk.Testament() < 2) {
fd->write(&offset, 4);
fd->write(&size, 4);
}
@@ -333,16 +294,14 @@ char RawVerse4::createModule(const char *ipath)
fd2->write(&size, 4);
}
}
+ fd2->write(&offset, 4);
+ fd2->write(&size, 4);
FileMgr::getSystemFileMgr()->close(fd);
FileMgr::getSystemFileMgr()->close(fd2);
delete [] path;
delete [] buf;
-/*
- RawVerse4 rv(path);
- VerseKey mykey("Rev 22:21");
-*/
return 0;
}