59 zStr::zStr(
const char *ipath,
int fileMode,
long blockCount,
SWCompress *icomp,
bool caseSensitive) : caseSensitive(caseSensitive)
89 SWLOGD(
"Couldn't open file: %s. errno: %d", buf.
c_str(), errno);
140 for (size = 0;
datfd->
read(&ch, 1) == 1; size++) {
141 if ((ch ==
'\\') || (ch == 10) || (ch == 13))
144 *buf = (*buf) ? (
char *)
realloc(*buf, size*2 + 1) : (
char *)
malloc(size*2 + 1);
153 *buf = (*buf) ? (
char *)
realloc(*buf, 1) : (
char *)
malloc(1);
195 char *maxbuf = 0, *trybuf = 0, *key = 0, quitflag = 0;
196 signed char retval = 0;
197 SW_s32 headoff, tailoff, tryoff = 0, maxoff = 0;
200 bool awayFromSubstrCheck =
false;
209 int keylen = (int)strlen(key);
214 while (headoff < tailoff) {
220 if (!*trybuf && tryoff) {
226 diff = strcmp(key, trybuf);
231 if (!strncmp(trybuf, key, keylen)) substr =
true;
234 tailoff = (tryoff == headoff) ? headoff : tryoff;
235 else headoff = tryoff;
244 if (headoff >= tailoff) {
246 if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
247 awayFromSubstrCheck =
true;
262 retval = (
idxfd->
read(&start, 4) == 4) ? retval : -1;
263 retval = (
idxfd->
read(&size, 4) == 4) ? retval : -1;
277 if (((
long)(tryoff + (away*
IDXENTRYSIZE)) < -IDXENTRYSIZE) || (tryoff + (away*
IDXENTRYSIZE) > (maxoff+IDXENTRYSIZE)))
282 if(!awayFromSubstrCheck)
300 if (((laststart != start) || (lastsize != size)) && size)
301 away += (away < 0) ? 1 : -1;
329 char *idxbuflocal = 0;
341 *buf = (*buf) ? (
char *)
realloc(*buf, size*2 + 1) : (
char *)
malloc(size*2 + 1);
342 *idxbuf = (*idxbuf) ? (
char *)
realloc(*idxbuf, size*2 + 1) : (
char *)
malloc(size*2 + 1);
343 memset(*buf, 0, size + 1);
344 memset(*idxbuf, 0, size + 1);
348 for (ch = *buf; *ch; ch++) {
354 memmove(*buf, ch, size - (
unsigned long)(ch-*buf));
357 if (!strncmp(*buf,
"@LINK", 5)) {
358 for (ch = *buf; *ch; ch++) {
372 localsize = (localsize < (size - 1)) ? localsize : (size - 1);
373 strncpy(*idxbuf, idxbuflocal, localsize);
374 (*idxbuf)[localsize] = 0;
379 memmove(&block, *buf,
sizeof(
SW_u32));
412 unsigned long len =
size;
422 *buf = (*buf) ? (
char *)
realloc(*buf, size*2 + 1) : (
char *)
malloc(size*2 + 1);
437 static const char nl[] = {13, 10};
451 len = (len < 0) ? strlen(buf) : len;
458 int diff = strcmp(key, dbKey);
464 else if ((!diff) && (len > 0 )) {
472 tmpbuf =
new char [ size + 2 ];
473 memset(tmpbuf, 0, size + 2);
477 for (ch = tmpbuf; *ch; ch++) {
483 memmove(tmpbuf, ch, size - (
unsigned long)(ch-tmpbuf));
486 if (!strncmp(tmpbuf,
"@LINK", 5) && (len)) {
487 for (ch = tmpbuf; *ch; ch++) {
504 shiftSize = endoff - (
SW_s32)idxoff;
507 idxBytes =
new char [ shiftSize ];
512 outbuf =
new char [ len + strlen(key) + 5 ];
513 sprintf(outbuf,
"%s%c%c", key, 13, 10);
514 size = (
SW_u32)strlen(outbuf);
530 memcpy (outbuf + size, &outstart,
sizeof(
SW_u32));
531 memcpy (outbuf + size +
sizeof(
SW_u32), &outsize,
sizeof(
SW_u32));
532 size += (
sizeof(
SW_u32) * 2);
535 memcpy(outbuf + size, buf, len);
583 char *text =
new char [ strlen(destkey) + 7 ];
584 sprintf(text,
"@LINK %s", destkey);
592 static const char nl[] = {13, 10};
597 unsigned long size = 0;
598 SW_u32 outstart = 0, outsize = 0;
622 if (start + outsize >= zdtSize) {
625 else if (size < outsize) {
665 char *buf =
new char [ strlen (ipath) + 20 ];
670 if ((path[strlen(path)-1] ==
'/') || (path[strlen(path)-1] ==
'\\'))
671 path[strlen(path)-1] = 0;
673 sprintf(buf,
"%s.dat", path);
679 sprintf(buf,
"%s.idx", path);
685 sprintf(buf,
"%s.zdt", path);
691 sprintf(buf,
"%s.zdx", path);
#define SWORD_NAMESPACE_START
long seek(long offset, int whence)
FileDesc * open(const char *path, int mode, bool tryDowngrade)
void getKeyFromIdxOffset(long ioffset, char **buf) const
virtual void setCompressedBuf(unsigned long *len, char *buf=0)
virtual char * getCompressedBuf(unsigned long *len=0)
int addEntry(const char *entry)
const char * getEntry(int entryIndex)
long write(const void *buf, long count)
virtual char * getUncompressedBuf(unsigned long *len=0)
signed char findKeyIndex(const char *ikey, long *idxoff, long away=0) const
signed char trunc(FileDesc *file)
char * toupperstr_utf8(char *t, unsigned int max=0)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
virtual void setUncompressedBuf(const char *buf=0, unsigned long *len=0)
void close(FileDesc *file)
void getCompressedText(long block, long entry, char **buf) const
const char * c_str() const
const char * getRawData(unsigned long *size)
static int removeFile(const char *fName)
void setText(const char *ikey, const char *buf, long len=-1)
void getKeyFromDatOffset(long ioffset, char **buf) const
static const int ZDXENTRYSIZE
void getText(long index, char **idxbuf, char **buf) const
static const int IDXENTRYSIZE
static unsigned int CREAT
virtual void rawZFilter(SWBuf &buf, char direction=0) const
static signed char createModule(const char *path)
unsigned long getEntrySize(int entryIndex)
static unsigned int IWRITE
static unsigned int WRONLY
void linkEntry(const char *destkey, const char *srckey)
long read(void *buf, long count)
static unsigned int IREAD
#define SWORD_NAMESPACE_END
zStr(const char *ipath, int fileMode=-1, long blockCount=100, SWCompress *icomp=0, bool caseSensitive=false)
SWBuf & setFormatted(const char *format,...)
EntriesBlock * cacheBlock
void setSize(unsigned long len)
static FileMgr * getSystemFileMgr()