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

#include <rawverse.h>

+ Inheritance diagram for RawVerse:
+ Collaboration diagram for RawVerse:

Public Member Functions

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

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 36 of file rawverse.h.

Constructor & Destructor Documentation

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

Definition at line 59 of file rawverse.cpp.

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

Definition at line 93 of file rawverse.cpp.

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

Member Function Documentation

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

Definition at line 248 of file rawverse.cpp.

249 {
250  char *path = 0;
251  char *buf = new char [ strlen (ipath) + 20 ];
252  FileDesc *fd, *fd2;
253 
254  stdstr(&path, ipath);
255 
256  if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
257  path[strlen(path)-1] = 0;
258 
259  sprintf(buf, "%s/ot", path);
260  FileMgr::removeFile(buf);
262  fd->getFd();
264 
265  sprintf(buf, "%s/nt", path);
266  FileMgr::removeFile(buf);
268  fd->getFd();
270 
271  sprintf(buf, "%s/ot.vss", path);
272  FileMgr::removeFile(buf);
274  fd->getFd();
275 
276  sprintf(buf, "%s/nt.vss", path);
277  FileMgr::removeFile(buf);
279  fd2->getFd();
280 
281  VerseKey vk;
283  vk.setIntros(1);
284 
285  SW_s32 offset = 0;
286  SW_u16 size = 0;
287  offset = archtosword32(offset);
288  size = archtosword16(size);
289 
290  for (vk = TOP; !vk.popError(); vk++) {
291  if (vk.getTestament() < 2) {
292  fd->write(&offset, 4);
293  fd->write(&size, 2);
294  }
295  else {
296  fd2->write(&offset, 4);
297  fd2->write(&size, 2);
298  }
299  }
300  fd2->write(&offset, 4);
301  fd2->write(&size, 2);
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
#define archtosword32(x)
Definition: sysdata.h:97
signed int SW_s32
Definition: sysdata.h:40
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
char * path
Definition: rawverse.h:45
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
unsigned short SW_u16
Definition: sysdata.h:38
virtual char popError()
Definition: swkey.cpp:147
int size
Definition: regex.c:5043
static unsigned int CREAT
Definition: filemgr.h:72
static unsigned int IWRITE
Definition: filemgr.h:79
static unsigned int WRONLY
Definition: filemgr.h:77
static unsigned int IREAD
Definition: filemgr.h:78
#define archtosword16(x)
Definition: sysdata.h:96
virtual char getTestament() const
Definition: versekey.cpp:1498
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
void RawVerse::doLinkEntry ( char  testmt,
long  destidxoff,
long  srcidxoff 
)
protected

Definition at line 219 of file rawverse.cpp.

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

Definition at line 178 of file rawverse.cpp.

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

Definition at line 118 of file rawverse.cpp.

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

Definition at line 154 of file rawverse.cpp.

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

Member Data Documentation

FileDesc* RawVerse::idxfp[2]
protected

Definition at line 42 of file rawverse.h.

SWORD_NAMESPACE_START int RawVerse::instance = 0
staticprivate

Definition at line 39 of file rawverse.h.

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

Definition at line 50 of file rawverse.h.

char* RawVerse::path
protected

Definition at line 45 of file rawverse.h.

FileDesc* RawVerse::textfp[2]
protected

Definition at line 43 of file rawverse.h.


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