The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RawVerse4 Class Reference

#include <rawverse4.h>

+ Inheritance diagram for RawVerse4:
+ Collaboration diagram for RawVerse4:

Public Member Functions

void findOffset (char testmt, long idxoff, long *start, unsigned long *end) const
 
 RawVerse4 (const char *ipath, int fileMode=-1)
 
void readText (char testmt, long start, unsigned long size, SWBuf &buf) const
 
virtual ~RawVerse4 ()
 

Static Public Member Functions

static char createModule (const char *path, const char *v11n="KJV")
 

Static Public Attributes

static const char nl = '\n'
 

Protected Member Functions

void doLinkEntry (char testmt, long destidxoff, long srcidxoff)
 
void doSetText (char testmt, long idxoff, const char *buf, long len=-1)
 

Protected Attributes

FileDescidxfp [2]
 
char * path
 
FileDesctextfp [2]
 

Static Private Attributes

static int instance = 0
 

Detailed Description

Definition at line 37 of file rawverse4.h.

Constructor & Destructor Documentation

RawVerse4::RawVerse4 ( const char *  ipath,
int  fileMode = -1 
)

Definition at line 60 of file rawverse4.cpp.

61 {
62  SWBuf buf;
63 
64  path = 0;
65  stdstr(&path, ipath);
66 
67  if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
68  path[strlen(path)-1] = 0;
69 
70  if (fileMode == -1) { // try read/write if possible
71  fileMode = FileMgr::RDWR;
72  }
73 
74  buf.setFormatted("%s/ot.vss", path);
75  idxfp[0] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
76 
77  buf.setFormatted("%s/nt.vss", path);
78  idxfp[1] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
79 
80  buf.setFormatted("%s/ot", path);
81  textfp[0] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
82 
83  buf.setFormatted("%s/nt", path);
84  textfp[1] = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
85 
86  instance++;
87 }
static int instance
Definition: rawverse4.h:40
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
Definition: swbuf.h:47
char * path
Definition: rawverse4.h:46
static unsigned int RDWR
Definition: filemgr.h:76
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
FileDesc * textfp[2]
Definition: rawverse4.h:44
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
FileDesc * idxfp[2]
Definition: rawverse4.h:43
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
RawVerse4::~RawVerse4 ( )
virtual

Definition at line 94 of file rawverse4.cpp.

95 {
96  int loop1;
97 
98  if (path)
99  delete [] path;
100 
101  --instance;
102 
103  for (loop1 = 0; loop1 < 2; loop1++) {
106  }
107 }
static int instance
Definition: rawverse4.h:40
char * path
Definition: rawverse4.h:46
void close(FileDesc *file)
Definition: filemgr.cpp:196
FileDesc * textfp[2]
Definition: rawverse4.h:44
FileDesc * idxfp[2]
Definition: rawverse4.h:43
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101

Member Function Documentation

char RawVerse4::createModule ( const char *  path,
const char *  v11n = "KJV" 
)
static

Definition at line 249 of file rawverse4.cpp.

250 {
251  char *path = 0;
252  char *buf = new char [ strlen (ipath) + 20 ];
253  FileDesc *fd, *fd2;
254 
255  stdstr(&path, ipath);
256 
257  if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
258  path[strlen(path)-1] = 0;
259 
260  sprintf(buf, "%s/ot", path);
261  FileMgr::removeFile(buf);
263  fd->getFd();
265 
266  sprintf(buf, "%s/nt", path);
267  FileMgr::removeFile(buf);
269  fd->getFd();
271 
272  sprintf(buf, "%s/ot.vss", path);
273  FileMgr::removeFile(buf);
275  fd->getFd();
276 
277  sprintf(buf, "%s/nt.vss", path);
278  FileMgr::removeFile(buf);
280  fd2->getFd();
281 
282  VerseKey vk;
284  vk.setIntros(1);
285  SW_u32 offset = 0;
286  SW_u32 size = 0;
287  offset = archtosword32(offset);
288  size = archtosword32(size);
289 
290  for (vk = TOP; !vk.popError(); vk++) {
291  if (vk.getTestament() < 2) {
292  fd->write(&offset, 4);
293  fd->write(&size, 4);
294  }
295  else {
296  fd2->write(&offset, 4);
297  fd2->write(&size, 4);
298  }
299  }
300  fd2->write(&offset, 4);
301  fd2->write(&size, 4);
302 
305 
306  delete [] path;
307  delete [] buf;
308 
309  return 0;
310 }
#define TOP
Definition: swkey.h:68
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
char * path
Definition: rawverse4.h:46
#define archtosword32(x)
Definition: sysdata.h:97
SWBuf v11n
Definition: osis2mod.cpp:107
int getFd()
Definition: filemgr.h:231
long write(const void *buf, long count)
Definition: filemgr.cpp:153
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void close(FileDesc *file)
Definition: filemgr.cpp:196
virtual void setIntros(bool val)
Definition: versekey.cpp:1663
virtual void setVersificationSystem(const char *name)
Definition: versekey.cpp:298
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
virtual char popError()
Definition: swkey.cpp:147
int size
Definition: regex.c:5043
static unsigned int CREAT
Definition: filemgr.h:72
unsigned int SW_u32
Definition: sysdata.h:41
static unsigned int IWRITE
Definition: filemgr.h:79
static unsigned int WRONLY
Definition: filemgr.h:77
static unsigned int IREAD
Definition: filemgr.h:78
virtual char getTestament() const
Definition: versekey.cpp:1498
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
void RawVerse4::doLinkEntry ( char  testmt,
long  destidxoff,
long  srcidxoff 
)
protected

Definition at line 220 of file rawverse4.cpp.

220  {
221  SW_u32 start;
222  SW_u32 size;
223 
224  destidxoff *= 8;
225  srcidxoff *= 8;
226 
227  if (!testmt)
228  testmt = ((idxfp[1]) ? 1:2);
229 
230  // get source
231  idxfp[testmt-1]->seek(srcidxoff, SEEK_SET);
232  idxfp[testmt-1]->read(&start, 4);
233  idxfp[testmt-1]->read(&size, 4);
234 
235  // write dest
236  idxfp[testmt-1]->seek(destidxoff, SEEK_SET);
237  idxfp[testmt-1]->write(&start, 4);
238  idxfp[testmt-1]->write(&size, 4);
239 }
long seek(long offset, int whence)
Definition: filemgr.cpp:143
long write(const void *buf, long count)
Definition: filemgr.cpp:153
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
unsigned int SW_u32
Definition: sysdata.h:41
long read(void *buf, long count)
Definition: filemgr.cpp:148
FileDesc * idxfp[2]
Definition: rawverse4.h:43
void RawVerse4::doSetText ( char  testmt,
long  idxoff,
const char *  buf,
long  len = -1 
)
protected

Definition at line 179 of file rawverse4.cpp.

180 {
181  SW_u32 start;
182  SW_u32 size;
183 
184  idxoff *= 8;
185  if (!testmt)
186  testmt = ((idxfp[1]) ? 1:2);
187 
188  size = (SW_u32)((len < 0) ? strlen(buf) : len);
189 
190  start = (SW_u32)textfp[testmt - 1]->seek(0, SEEK_END);
191  idxfp[testmt-1]->seek(idxoff, SEEK_SET);
192 
193  if (size) {
194  textfp[testmt-1]->seek(start, SEEK_SET);
195  textfp[testmt-1]->write(buf, (int)size);
196 
197  // add a new line to make data file easier to read in an editor
198  textfp[testmt-1]->write(&nl, 1);
199  }
200  else {
201  start = 0;
202  }
203 
204  start = archtosword32(start);
205  size = archtosword32(size);
206 
207  idxfp[testmt-1]->write(&start, 4);
208  idxfp[testmt-1]->write(&size, 4);
209 }
long seek(long offset, int whence)
Definition: filemgr.cpp:143
#define archtosword32(x)
Definition: sysdata.h:97
#define SEEK_END
Definition: zconf.h:246
long write(const void *buf, long count)
Definition: filemgr.cpp:153
FileDesc * textfp[2]
Definition: rawverse4.h:44
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
unsigned int SW_u32
Definition: sysdata.h:41
FileDesc * idxfp[2]
Definition: rawverse4.h:43
static const char nl
Definition: rawverse4.h:51
void RawVerse4::findOffset ( char  testmt,
long  idxoff,
long *  start,
unsigned long *  end 
) const

Definition at line 119 of file rawverse4.cpp.

119  {
120  idxoff *= 8;
121  if (!testmt)
122  testmt = ((idxfp[1]) ? 1:2);
123 
124  if (idxfp[testmt-1]->getFd() >= 0) {
125  idxfp[testmt-1]->seek(idxoff, SEEK_SET);
126  SW_u32 tmpStart;
127  SW_u32 tmpSize;
128  idxfp[testmt-1]->read(&tmpStart, 4);
129  long len = idxfp[testmt-1]->read(&tmpSize, 4); // read size
130 
131  *start = swordtoarch32(tmpStart);
132  *size = swordtoarch32(tmpSize);
133 
134  if (len < 4) {
135  *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
136  }
137  }
138  else {
139  *start = 0;
140  *size = 0;
141  }
142 }
long seek(long offset, int whence)
Definition: filemgr.cpp:143
#define SEEK_END
Definition: zconf.h:246
#define swordtoarch32(x)
Definition: sysdata.h:94
FileDesc * textfp[2]
Definition: rawverse4.h:44
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
unsigned int SW_u32
Definition: sysdata.h:41
long read(void *buf, long count)
Definition: filemgr.cpp:148
FileDesc * idxfp[2]
Definition: rawverse4.h:43
void RawVerse4::readText ( char  testmt,
long  start,
unsigned long  size,
SWBuf buf 
) const

Definition at line 155 of file rawverse4.cpp.

155  {
156  buf = "";
157  buf.setFillByte(0);
158  buf.setSize(size + 1);
159  if (!testmt)
160  testmt = ((idxfp[1]) ? 1:2);
161  if (size) {
162  if (textfp[testmt-1]->getFd() >= 0) {
163  textfp[testmt-1]->seek(start, SEEK_SET);
164  textfp[testmt-1]->read(buf.getRawData(), (int)size);
165  }
166  }
167 }
void setFillByte(char ch)
Definition: swbuf.h:146
long seek(long offset, int whence)
Definition: filemgr.cpp:143
char * getRawData()
Definition: swbuf.h:379
FileDesc * textfp[2]
Definition: rawverse4.h:44
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
long read(void *buf, long count)
Definition: filemgr.cpp:148
FileDesc * idxfp[2]
Definition: rawverse4.h:43
void setSize(unsigned long len)
Definition: swbuf.h:255

Member Data Documentation

FileDesc* RawVerse4::idxfp[2]
protected

Definition at line 43 of file rawverse4.h.

SWORD_NAMESPACE_START int RawVerse4::instance = 0
staticprivate

Definition at line 40 of file rawverse4.h.

const char RawVerse4::nl = '\n'
static

Definition at line 51 of file rawverse4.h.

char* RawVerse4::path
protected

Definition at line 46 of file rawverse4.h.

FileDesc* RawVerse4::textfp[2]
protected

Definition at line 44 of file rawverse4.h.


The documentation for this class was generated from the following files: