59 RawStr::RawStr(
const char *ipath,
int fileMode,
bool caseSensitive) : caseSensitive(caseSensitive)
80 SWLOGD(
"Couldn't open file: %s. errno: %d", buf.
c_str(), errno);
118 for (size = 0;
datfd->
read(&ch, 1) == 1; size++) {
119 if ((ch ==
'\\') || (ch == 10) || (ch == 13))
122 *buf = (*buf) ? (
char *)
realloc(*buf, size*2 + 1) : (
char *)
malloc(size*2 + 1);
131 *buf = (*buf) ? (
char *)
realloc(*buf, 1) : (
char *)
malloc(1);
175 char *trybuf, *maxbuf, *key = 0, quitflag = 0;
176 signed char retval = -1;
177 long headoff, tailoff, tryoff = 0, maxoff = 0;
179 bool awayFromSubstrCheck =
false;
183 retval = (tailoff >= 0) ? 0 : -2;
184 if (*ikey && retval != -2) {
190 int keylen = (int)strlen(key);
196 while (headoff < tailoff) {
197 tryoff = (
lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 :
lastoff;
201 if (!*trybuf && tryoff) {
202 tryoff += (tryoff > (maxoff / 2))?-6:6;
207 diff = strcmp(key, trybuf);
212 if (!strncmp(trybuf, key, keylen)) substr =
true;
215 tailoff = (tryoff == headoff) ? headoff : tryoff;
216 else headoff = tryoff;
218 if (tailoff == headoff + 6) {
225 if (headoff >= tailoff) {
227 if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
228 awayFromSubstrCheck =
true;
244 *start = *size = tmpStart = tmpSize = 0;
254 unsigned long laststart = *start;
255 unsigned short lastsize = *
size;
256 long lasttry = tryoff;
257 tryoff += (away > 0) ? 6 : -6;
260 if (((tryoff + (away*6)) < -6) || (tryoff + (away*6) > (maxoff+6)))
265 if(!awayFromSubstrCheck)
267 *start = (
SW_u32)laststart;
282 if (((laststart != *start) || (lastsize != *size)) && (*size))
283 away += (away < 0) ? 1 : -1;
312 char *idxbuflocal = 0;
324 *idxbuf =
new char [ (*isize) ];
329 for (ch = 0; buf[ch]; ch++) {
337 if (!strncmp(buf.
c_str(),
"@LINK", 5)) {
338 for (ch = 0; buf[ch]; ch++) {
351 int localsize = (int)strlen(idxbuflocal);
352 localsize = (localsize < (*isize - 1)) ? localsize : (*isize - 1);
353 strncpy(*idxbuf, idxbuflocal, localsize);
354 (*idxbuf)[localsize] = 0;
384 char errorStatus =
findOffset(ikey, &start, &size, 0, &idxoff);
388 len = (len < 0) ? strlen(buf) : len;
392 if (strcmp(key, dbKey) < 0) {
394 else if (strcmp(key, dbKey) > 0) {
395 if (errorStatus != (
char)-2)
399 else if ((!strcmp(key, dbKey)) && (len>0 )) {
401 tmpbuf =
new char [ size + 2 ];
402 memset(tmpbuf, 0, size + 2);
406 for (ch = tmpbuf; *ch; ch++) {
412 memmove(tmpbuf, ch, size - (
unsigned short)(ch-tmpbuf));
415 if (!strncmp(tmpbuf,
"@LINK", 5) && (len)) {
416 for (ch = tmpbuf; *ch; ch++) {
422 findOffset(tmpbuf + 6, &start, &size, 0, &idxoff);
431 shiftSize = endoff - idxoff;
434 idxBytes =
new char [ shiftSize ];
439 outbuf =
new char [ len + strlen(key) + 5 ];
440 sprintf(outbuf,
"%s%c%c", key, 13, 10);
441 size = strlen(outbuf);
442 memcpy(outbuf + size, buf, len);
443 size = outsize = size + (len);
489 char *text =
new char [ strlen(destkey) + 7 ];
490 sprintf(text,
"@LINK %s", destkey);
505 char *buf =
new char [ strlen (ipath) + 20 ];
510 if ((path[strlen(path)-1] ==
'/') || (path[strlen(path)-1] ==
'\\'))
511 path[strlen(path)-1] = 0;
513 sprintf(buf,
"%s.dat", path);
519 sprintf(buf,
"%s.idx", path);
void setFillByte(char ch)
#define SWORD_NAMESPACE_START
long seek(long offset, int whence)
FileDesc * open(const char *path, int mode, bool tryDowngrade)
void doLinkEntry(const char *destkey, const char *srckey)
long write(const void *buf, long count)
signed char trunc(FileDesc *file)
char * toupperstr_utf8(char *t, unsigned int max=0)
void doSetText(const char *key, const char *buf, long len=-1)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
void close(FileDesc *file)
const char * c_str() const
static int removeFile(const char *fName)
RawStr(const char *ipath, int fileMode=-1, bool caseSensitive=false)
static const int IDXENTRYSIZE
static unsigned int CREAT
void readText(SW_u32 start, SW_u16 *size, char **idxbuf, SWBuf &buf) const
static unsigned int IWRITE
static unsigned int WRONLY
long read(void *buf, long count)
static unsigned int IREAD
#define SWORD_NAMESPACE_END
void getIDXBufDat(long ioffset, char **buf) const
signed char findOffset(const char *key, SW_u32 *start, SW_u16 *size, long away=0, SW_u32 *idxoff=0) const
void getIDXBuf(long ioffset, char **buf) const
SWBuf & setFormatted(const char *format,...)
static signed char createModule(const char *path)
void setSize(unsigned long len)
static FileMgr * getSystemFileMgr()