The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zstr.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * zstr.cpp - code for class 'zStr'- a module that reads compressed text
4  * files and provides lookup and parsing functions based on
5  * class StrKey
6  *
7  * $Id: zstr.cpp 3822 2020-11-03 18:54:47Z scribe $
8  *
9  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
10  * CrossWire Bible Society
11  * P. O. Box 2528
12  * Tempe, AZ 85280-2528
13  *
14  * This program is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by the
16  * Free Software Foundation version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * General Public License for more details.
22  *
23  */
24 
25 
26 #include <stdio.h>
27 #include <fcntl.h>
28 #include <errno.h>
29 
30 #include <stdlib.h>
31 #include <utilstr.h>
32 #include <zstr.h>
33 #include <swcomprs.h>
34 
35 #include <sysdata.h>
36 #include <entriesblk.h>
37 #include <swlog.h>
38 #include <stringmgr.h>
39 #include <filemgr.h>
40 #include <swbuf.h>
41 
43 
44 /******************************************************************************
45  * zStr Statics
46  */
47 
48 int zStr::instance = 0;
49 const int zStr::IDXENTRYSIZE = 8;
50 const int zStr::ZDXENTRYSIZE = 8;
51 
52 
53 /******************************************************************************
54  * zStr Constructor - Initializes data for instance of zStr
55  *
56  * ENT: ipath - path of the directory where data and index files are located.
57  */
58 
59 zStr::zStr(const char *ipath, int fileMode, long blockCount, SWCompress *icomp, bool caseSensitive) : caseSensitive(caseSensitive)
60 {
61  SWBuf buf;
62 
63  lastoff = -1;
64  path = 0;
65  stdstr(&path, ipath);
66 
67  compressor = (icomp) ? icomp : new SWCompress();
68  this->blockCount = blockCount;
69 
70  if (fileMode == -1) { // try read/write if possible
71  fileMode = FileMgr::RDWR;
72  }
73 
74  buf.setFormatted("%s.idx", path);
75  idxfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
76 
77  buf.setFormatted("%s.dat", path);
78  datfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
79 
80  buf.setFormatted("%s.zdx", path);
81  zdxfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
82 
83  buf.setFormatted("%s.zdt", path);
84  zdtfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true);
85 
86  if (!zdtfd || zdtfd->getFd() < 0) {
87 // couldn't find datafile but this might be fine if we're
88 // merely instantiating a remote InstallMgr SWMgr
89 SWLOGD("Couldn't open file: %s. errno: %d", buf.c_str(), errno);
90  }
91 
92  cacheBlock = 0;
93  cacheBlockIndex = -1;
94  cacheDirty = false;
95 
96  instance++;
97 }
98 
99 
100 /******************************************************************************
101  * zStr Destructor - Cleans up instance of zStr
102  */
103 
105 
106  flushCache();
107 
108  if (path)
109  delete [] path;
110 
111  --instance;
112 
117 
118 
119  if (compressor)
120  delete compressor;
121 
122 }
123 
124 
125 /******************************************************************************
126  * zStr::getidxbufdat - Gets the index string at the given dat offset
127  * NOTE: buf is calloc'd, or if not null, realloc'd and must
128  * be free'd by calling function
129  *
130  * ENT: ioffset - offset in dat file to lookup
131  * buf - address of pointer to allocate for storage of string
132  */
133 
134 void zStr::getKeyFromDatOffset(long ioffset, char **buf) const
135 {
136  int size;
137  char ch;
138  if (datfd && datfd->getFd() >= 0) {
139  datfd->seek(ioffset, SEEK_SET);
140  for (size = 0; datfd->read(&ch, 1) == 1; size++) {
141  if ((ch == '\\') || (ch == 10) || (ch == 13))
142  break;
143  }
144  *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
145  if (size) {
146  datfd->seek(ioffset, SEEK_SET);
147  datfd->read(*buf, size);
148  }
149  (*buf)[size] = 0;
150  if (!caseSensitive) toupperstr_utf8(*buf, size*2);
151  }
152  else {
153  *buf = (*buf) ? (char *)realloc(*buf, 1) : (char *)malloc(1);
154  **buf = 0;
155  }
156 }
157 
158 
159 /******************************************************************************
160  * zStr::getidxbuf - Gets the index string at the given idx offset
161  * NOTE: buf is calloc'd, or if not null, realloc'd
162  * and must be freed by calling function
163  *
164  * ENT: ioffset - offset in idx file to lookup
165  * buf - address of pointer to allocate for storage of string
166  */
167 
168 void zStr::getKeyFromIdxOffset(long ioffset, char **buf) const
169 {
170  SW_u32 offset;
171 
172  if (idxfd && idxfd->getFd() >= 0) {
173  idxfd->seek(ioffset, SEEK_SET);
174  idxfd->read(&offset, 4);
175  offset = swordtoarch32(offset);
176  getKeyFromDatOffset(offset, buf);
177  }
178 }
179 
180 
181 /******************************************************************************
182  * zStr::findoffset - Finds the offset of the key string from the indexes
183  *
184  * ENT: key - key string to lookup
185  * offset - address to store the starting offset
186  * size - address to store the size of the entry
187  * away - number of entries before of after to jump
188  * (default = 0)
189  *
190  * RET: error status
191  */
192 
193 signed char zStr::findKeyIndex(const char *ikey, long *idxoff, long away) const
194 {
195  char *maxbuf = 0, *trybuf = 0, *key = 0, quitflag = 0;
196  signed char retval = 0;
197  SW_s32 headoff, tailoff, tryoff = 0, maxoff = 0;
198  SW_u32 start, size;
199  int diff = 0;
200  bool awayFromSubstrCheck = false;
201 
202  if (idxfd->getFd() >= 0) {
203  tailoff = maxoff = (SW_s32)idxfd->seek(0, SEEK_END) - IDXENTRYSIZE;
204  if (*ikey) {
205  headoff = 0;
206  stdstr(&key, ikey, 3);
207  if (!caseSensitive) toupperstr_utf8(key, (unsigned int)(strlen(key)*3));
208 
209  int keylen = (int)strlen(key);
210  bool substr = false;
211 
212  getKeyFromIdxOffset(maxoff, &maxbuf);
213 
214  while (headoff < tailoff) {
215  tryoff = ((SW_s32)lastoff == -1) ? headoff + (((((tailoff / IDXENTRYSIZE) - (headoff / IDXENTRYSIZE))) / 2) * IDXENTRYSIZE) : (SW_s32)lastoff;
216  lastoff = -1;
217 
218  getKeyFromIdxOffset(tryoff, &trybuf);
219 
220  if (!*trybuf && tryoff) { // In case of extra entry at end of idx (not first entry)
221  tryoff += (tryoff > (maxoff / 2))?-IDXENTRYSIZE:IDXENTRYSIZE;
222  retval = -1;
223  break;
224  }
225 
226  diff = strcmp(key, trybuf);
227 
228  if (!diff)
229  break;
230 
231  if (!strncmp(trybuf, key, keylen)) substr = true;
232 
233  if (diff < 0)
234  tailoff = (tryoff == headoff) ? headoff : tryoff;
235  else headoff = tryoff;
236 
237  if (tailoff == headoff + IDXENTRYSIZE) {
238  if (quitflag++)
239  headoff = tailoff;
240  }
241  }
242 
243  // didn't find exact match
244  if (headoff >= tailoff) {
245  tryoff = headoff;
246  if (!substr && ((tryoff != maxoff)||(strncmp(key, maxbuf, keylen)<0))) {
247  awayFromSubstrCheck = true;
248  away--; // if our entry doesn't startwith our key, prefer the previous entry over the next
249  }
250  }
251  if (trybuf)
252  free(trybuf);
253  delete [] key;
254  if (maxbuf)
255  free(maxbuf);
256  }
257  else { tryoff = 0; }
258 
259  idxfd->seek(tryoff, SEEK_SET);
260 
261  start = size = 0;
262  retval = (idxfd->read(&start, 4) == 4) ? retval : -1;
263  retval = (idxfd->read(&size, 4) == 4) ? retval : -1;
264  start = swordtoarch32(start);
265  size = swordtoarch32(size);
266 
267  if (idxoff)
268  *idxoff = tryoff;
269 
270  while (away) {
271  SW_u32 laststart = start;
272  SW_u32 lastsize = size;
273  SW_s32 lasttry = tryoff;
274  tryoff += (away > 0) ? IDXENTRYSIZE : -IDXENTRYSIZE;
275 
276  bool bad = false;
277  if (((long)(tryoff + (away*IDXENTRYSIZE)) < -IDXENTRYSIZE) || (tryoff + (away*IDXENTRYSIZE) > (maxoff+IDXENTRYSIZE)))
278  bad = true;
279  else if (idxfd->seek(tryoff, SEEK_SET) < 0)
280  bad = true;
281  if (bad) {
282  if(!awayFromSubstrCheck)
283  retval = -1;
284  start = laststart;
285  size = lastsize;
286  tryoff = lasttry;
287  if (idxoff)
288  *idxoff = tryoff;
289  break;
290  }
291  idxfd->read(&start, 4);
292  idxfd->read(&size, 4);
293  start = swordtoarch32(start);
294  size = swordtoarch32(size);
295 
296  if (idxoff)
297  *idxoff = tryoff;
298 
299 
300  if (((laststart != start) || (lastsize != size)) && size)
301  away += (away < 0) ? 1 : -1;
302  }
303 
304  lastoff = tryoff;
305  }
306  else {
307  if (idxoff)
308  *idxoff = 0;
309  retval = -1;
310  }
311  return retval;
312 }
313 
314 
315 /******************************************************************************
316  * zStr::getText - gets text at a given offset
317  *
318  * ENT:
319  * offset - idxoffset where the key is located.
320  * buf - buffer to store text
321  * idxbuf - buffer to store index key
322  * NOTE: buffer will be alloc'd / realloc'd and
323  * should be free'd by the client
324  *
325  */
326 
327 void zStr::getText(long offset, char **idxbuf, char **buf) const {
328  char *ch;
329  char *idxbuflocal = 0;
330  getKeyFromIdxOffset(offset, &idxbuflocal);
331  SW_u32 start;
332  SW_u32 size;
333 
334  do {
335  idxfd->seek(offset, SEEK_SET);
336  idxfd->read(&start, 4);
337  idxfd->read(&size, 4);
338  start = swordtoarch32(start);
339  size = swordtoarch32(size);
340 
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);
345  datfd->seek(start, SEEK_SET);
346  datfd->read(*buf, (int)(size));
347 
348  for (ch = *buf; *ch; ch++) { // skip over index string
349  if (*ch == 10) {
350  ch++;
351  break;
352  }
353  }
354  memmove(*buf, ch, size - (unsigned long)(ch-*buf));
355 
356  // resolve link
357  if (!strncmp(*buf, "@LINK", 5)) {
358  for (ch = *buf; *ch; ch++) { // null before nl
359  if (*ch == 10) {
360  *ch = 0;
361  break;
362  }
363  }
364  findKeyIndex(*buf + 6, &offset);
365  }
366  else break;
367  }
368  while (true); // while we're resolving links
369 
370  if (idxbuflocal) {
371  SW_u32 localsize = (SW_u32)strlen(idxbuflocal);
372  localsize = (localsize < (size - 1)) ? localsize : (size - 1);
373  strncpy(*idxbuf, idxbuflocal, localsize);
374  (*idxbuf)[localsize] = 0;
375  free(idxbuflocal);
376  }
377  SW_u32 block = 0;
378  SW_u32 entry = 0;
379  memmove(&block, *buf, sizeof(SW_u32));
380  memmove(&entry, *buf + sizeof(SW_u32), sizeof(SW_u32));
381  block = swordtoarch32(block);
382  entry = swordtoarch32(entry);
383  getCompressedText(block, entry, buf);
384 }
385 
386 
387 /******************************************************************************
388  * zStr::getCompressedText - Get text entry from a compressed index / zdata
389  * file.
390  */
391 
392 void zStr::getCompressedText(long block, long entry, char **buf) const {
393 
394  SW_u32 size = 0;
395 
396  if (cacheBlockIndex != block) {
397  SW_u32 start = 0;
398 
399  zdxfd->seek(block * ZDXENTRYSIZE, SEEK_SET);
400  zdxfd->read(&start, 4);
401  zdxfd->read(&size, 4);
402  start = swordtoarch32(start);
403  size = swordtoarch32(size);
404 
405  SWBuf buf;
406  buf.setSize(size + 5);
407  zdtfd->seek(start, SEEK_SET);
408  zdtfd->read(buf.getRawData(), size);
409 
410  flushCache();
411 
412  unsigned long len = size;
413  buf.setSize(size);
414  rawZFilter(buf, 0); // 0 = decipher
415 
416  compressor->setCompressedBuf(&len, buf.getRawData());
417  char *rawBuf = compressor->getUncompressedBuf(&len);
418  cacheBlock = new EntriesBlock(rawBuf, len);
419  cacheBlockIndex = block;
420  }
421  size = (SW_u32)cacheBlock->getEntrySize(entry);
422  *buf = (*buf) ? (char *)realloc(*buf, size*2 + 1) : (char *)malloc(size*2 + 1);
423  strcpy(*buf, cacheBlock->getEntry(entry));
424 }
425 
426 
427 /******************************************************************************
428  * zLD::settext - Sets text for current offset
429  *
430  * ENT: key - key for this entry
431  * buf - buffer to store
432  * len - length of buffer (0 - null terminated)
433  */
434 
435 void zStr::setText(const char *ikey, const char *buf, long len) {
436 
437  static const char nl[] = {13, 10};
438 
439  SW_u32 start, outstart;
440  SW_u32 size, outsize;
441  SW_s32 endoff;
442  long idxoff = 0;
443  SW_s32 shiftSize;
444  char *tmpbuf = 0;
445  char *key = 0;
446  char *dbKey = 0;
447  char *idxBytes = 0;
448  char *outbuf = 0;
449  char *ch = 0;
450 
451  len = (len < 0) ? strlen(buf) : len;
452  stdstr(&key, ikey, 3);
453  if (!caseSensitive) toupperstr_utf8(key, (unsigned int)(strlen(key)*3));
454 
455  char notFound = findKeyIndex(ikey, &idxoff, 0);
456  if (!notFound) {
457  getKeyFromIdxOffset(idxoff, &dbKey);
458  int diff = strcmp(key, dbKey);
459  if (diff < 0) {
460  }
461  else if (diff > 0) {
462  idxoff += IDXENTRYSIZE;
463  }
464  else if ((!diff) && (len > 0 /*we're not deleting*/)) { // got absolute entry
465  do {
466  idxfd->seek(idxoff, SEEK_SET);
467  idxfd->read(&start, 4);
468  idxfd->read(&size, 4);
469  start = swordtoarch32(start);
470  size = swordtoarch32(size);
471 
472  tmpbuf = new char [ size + 2 ];
473  memset(tmpbuf, 0, size + 2);
474  datfd->seek(start, SEEK_SET);
475  datfd->read(tmpbuf, size);
476 
477  for (ch = tmpbuf; *ch; ch++) { // skip over index string
478  if (*ch == 10) {
479  ch++;
480  break;
481  }
482  }
483  memmove(tmpbuf, ch, size - (unsigned long)(ch-tmpbuf));
484 
485  // resolve link
486  if (!strncmp(tmpbuf, "@LINK", 5) && (len)) {
487  for (ch = tmpbuf; *ch; ch++) { // null before nl
488  if (*ch == 10) {
489  *ch = 0;
490  break;
491  }
492  }
493  findKeyIndex(tmpbuf + IDXENTRYSIZE, &idxoff);
494  delete [] tmpbuf;
495  }
496  else break;
497  }
498  while (true); // while we're resolving links
499  }
500  }
501 
502  endoff = (SW_s32)idxfd->seek(0, SEEK_END);
503 
504  shiftSize = endoff - (SW_s32)idxoff;
505 
506  if (shiftSize > 0) {
507  idxBytes = new char [ shiftSize ];
508  idxfd->seek(idxoff, SEEK_SET);
509  idxfd->read(idxBytes, shiftSize);
510  }
511 
512  outbuf = new char [ len + strlen(key) + 5 ];
513  sprintf(outbuf, "%s%c%c", key, 13, 10);
514  size = (SW_u32)strlen(outbuf);
515  if (len > 0) { // NOT a link
516  if (!cacheBlock) {
517  flushCache();
518  cacheBlock = new EntriesBlock();
520  }
521  else if (cacheBlock->getCount() >= blockCount) {
522  flushCache();
523  cacheBlock = new EntriesBlock();
525  }
526  SW_u32 entry = cacheBlock->addEntry(buf);
527  cacheDirty = true;
528  outstart = (SW_u32)archtosword32(cacheBlockIndex);
529  outsize = archtosword32(entry);
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);
533  }
534  else { // link
535  memcpy(outbuf + size, buf, len);
536  size += len;
537  }
538 
539  start = (SW_u32)datfd->seek(0, SEEK_END);
540 
541  outstart = archtosword32(start);
542  outsize = archtosword32(size);
543 
544  idxfd->seek(idxoff, SEEK_SET);
545  if (len > 0) {
546  datfd->seek(start, SEEK_SET);
547  datfd->write(outbuf, size);
548 
549  // add a new line to make data file easier to read in an editor
550  datfd->write(&nl, 2);
551 
552  idxfd->write(&outstart, 4);
553  idxfd->write(&outsize, 4);
554  if (idxBytes) {
555  idxfd->write(idxBytes, shiftSize);
556  }
557  }
558  else { // delete entry
559  if (idxBytes) {
560  idxfd->write(idxBytes+IDXENTRYSIZE, shiftSize-IDXENTRYSIZE);
561  idxfd->seek(-1, SEEK_CUR); // last valid byte
562  FileMgr::getSystemFileMgr()->trunc(idxfd); // truncate index
563  }
564  }
565 
566  if (idxBytes)
567  delete [] idxBytes;
568  delete [] key;
569  delete [] outbuf;
570  free(dbKey);
571 }
572 
573 
574 /******************************************************************************
575  * zLD::linkentry - links one entry to another
576  *
577  * ENT: testmt - testament to find (0 - Bible/module introduction)
578  * destidxoff - dest offset into .vss
579  * srcidxoff - source offset into .vss
580  */
581 
582 void zStr::linkEntry(const char *destkey, const char *srckey) {
583  char *text = new char [ strlen(destkey) + 7 ];
584  sprintf(text, "@LINK %s", destkey);
585  setText(srckey, text);
586  delete [] text;
587 }
588 
589 
590 void zStr::flushCache() const {
591 
592  static const char nl[] = {13, 10};
593 
594  if (cacheBlock) {
595  if (cacheDirty) {
596  SW_u32 start = 0;
597  unsigned long size = 0;
598  SW_u32 outstart = 0, outsize = 0;
599 
600  const char *rawBuf = cacheBlock->getRawData(&size);
601  compressor->setUncompressedBuf(rawBuf, &size);
603 
604  SWBuf buf;
605  buf.setSize(size + 5);
606  memcpy(buf.getRawData(), compressor->getCompressedBuf(&size), size); // 1 = encipher
607  buf.setSize(size);
608  rawZFilter(buf, 1); // 1 = encipher
609 
610  long zdxSize = zdxfd->seek(0, SEEK_END);
611  unsigned long zdtSize = zdtfd->seek(0, SEEK_END);
612 
613  if ((cacheBlockIndex * ZDXENTRYSIZE) > (zdxSize - ZDXENTRYSIZE)) { // New Block
614  start = (SW_u32)zdtSize;
615  }
616  else {
617  zdxfd->seek(cacheBlockIndex * ZDXENTRYSIZE, SEEK_SET);
618  zdxfd->read(&start, 4);
619  zdxfd->read(&outsize, 4);
620  start = swordtoarch32(start);
621  outsize = swordtoarch32(outsize);
622  if (start + outsize >= zdtSize) { // last entry, just overwrite
623  // start is already set
624  }
625  else if (size < outsize) { // middle entry, but smaller, that's fine and let's preserve bigger size
626  size = outsize;
627  }
628  else { // middle and bigger-- we have serious problems, for now let's put it at the end = lots of wasted space
629  start = (SW_u32)zdtSize;
630  }
631  }
632 
633 
634 
635  outstart = archtosword32(start);
636  outsize = archtosword32((SW_u32)size);
637 
638  zdxfd->seek(cacheBlockIndex * ZDXENTRYSIZE, SEEK_SET);
639  zdtfd->seek(start, SEEK_SET);
640  zdtfd->write(buf, size);
641 
642  // add a new line to make data file easier to read in an editor
643  zdtfd->write(&nl, 2);
644 
645  zdxfd->write(&outstart, 4);
646  zdxfd->write(&outsize, 4);
647  }
648  delete cacheBlock;
649  cacheBlock = 0;
650  }
651  cacheBlockIndex = -1;
652  cacheDirty = false;
653 }
654 
655 
656 /******************************************************************************
657  * zLD::CreateModule - Creates new module files
658  *
659  * ENT: path - directory to store module files
660  * RET: error status
661  */
662 
663 signed char zStr::createModule(const char *ipath) {
664  char *path = 0;
665  char *buf = new char [ strlen (ipath) + 20 ];
666  FileDesc *fd, *fd2;
667 
668  stdstr(&path, ipath);
669 
670  if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\'))
671  path[strlen(path)-1] = 0;
672 
673  sprintf(buf, "%s.dat", path);
674  FileMgr::removeFile(buf);
676  fd->getFd();
678 
679  sprintf(buf, "%s.idx", path);
680  FileMgr::removeFile(buf);
682  fd2->getFd();
684 
685  sprintf(buf, "%s.zdt", path);
686  FileMgr::removeFile(buf);
688  fd2->getFd();
690 
691  sprintf(buf, "%s.zdx", path);
692  FileMgr::removeFile(buf);
694  fd2->getFd();
696 
697  delete [] path;
698 
699  return 0;
700 }
701 
FileDesc * datfd
Definition: zstr.h:51
#define SWORD_NAMESPACE_START
Definition: defs.h:39
long seek(long offset, int whence)
Definition: filemgr.cpp:143
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
Definition: swbuf.h:47
#define SEEK_CUR
Definition: zconf.h:245
#define archtosword32(x)
Definition: sysdata.h:97
void getKeyFromIdxOffset(long ioffset, char **buf) const
Definition: zstr.cpp:168
virtual void setCompressedBuf(unsigned long *len, char *buf=0)
Definition: swcomprs.cpp:101
SWCompress * compressor
Definition: zstr.h:47
#define SEEK_END
Definition: zconf.h:246
static unsigned int RDWR
Definition: filemgr.h:76
signed int SW_s32
Definition: sysdata.h:40
virtual char * getCompressedBuf(unsigned long *len=0)
Definition: swcomprs.cpp:111
FileDesc * idxfd
Definition: zstr.h:50
void flushCache() const
Definition: zstr.cpp:590
int addEntry(const char *entry)
Definition: entriesblk.cpp:113
int getFd()
Definition: filemgr.h:231
const char * getEntry(int entryIndex)
Definition: entriesblk.cpp:147
long write(const void *buf, long count)
Definition: filemgr.cpp:153
virtual char * getUncompressedBuf(unsigned long *len=0)
Definition: swcomprs.cpp:90
signed char findKeyIndex(const char *ikey, long *idxoff, long away=0) const
Definition: zstr.cpp:193
signed char trunc(FileDesc *file)
Definition: filemgr.cpp:256
char * toupperstr_utf8(char *t, unsigned int max=0)
Definition: stringmgr.h:118
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
virtual void setUncompressedBuf(const char *buf=0, unsigned long *len=0)
Definition: swcomprs.cpp:75
void close(FileDesc *file)
Definition: filemgr.cpp:196
char * malloc()
void getCompressedText(long block, long entry, char **buf) const
Definition: zstr.cpp:392
char * getRawData()
Definition: swbuf.h:379
long cacheBlockIndex
Definition: zstr.h:41
free(preg->fastmap)
const char * c_str() const
Definition: swbuf.h:158
virtual ~zStr()
Definition: zstr.cpp:104
const char * getRawData(unsigned long *size)
Definition: entriesblk.cpp:99
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
void setText(const char *ikey, const char *buf, long len=-1)
Definition: zstr.cpp:435
char * realloc()
static int instance
Definition: zstr.h:39
#define swordtoarch32(x)
Definition: sysdata.h:94
bool cacheDirty
Definition: zstr.h:42
void getKeyFromDatOffset(long ioffset, char **buf) const
Definition: zstr.cpp:134
static const int ZDXENTRYSIZE
Definition: zstr.h:55
char * path
Definition: zstr.h:43
void getText(long index, char **idxbuf, char **buf) const
Definition: zstr.cpp:327
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043
static const int IDXENTRYSIZE
Definition: zstr.h:54
FileDesc * zdxfd
Definition: zstr.h:52
static unsigned int CREAT
Definition: filemgr.h:72
long lastoff
Definition: zstr.h:45
virtual void rawZFilter(SWBuf &buf, char direction=0) const
Definition: zstr.h:69
static signed char createModule(const char *path)
Definition: zstr.cpp:663
long blockCount
Definition: zstr.h:46
unsigned int SW_u32
Definition: sysdata.h:41
unsigned long getEntrySize(int entryIndex)
Definition: entriesblk.cpp:157
static unsigned int IWRITE
Definition: filemgr.h:79
static unsigned int WRONLY
Definition: filemgr.h:77
void linkEntry(const char *destkey, const char *srckey)
Definition: zstr.cpp:582
long read(void *buf, long count)
Definition: filemgr.cpp:148
FileDesc * zdtfd
Definition: zstr.h:53
static unsigned int IREAD
Definition: filemgr.h:78
#define SWORD_NAMESPACE_END
Definition: defs.h:40
zStr(const char *ipath, int fileMode=-1, long blockCount=100, SWCompress *icomp=0, bool caseSensitive=false)
Definition: zstr.cpp:59
#define SWLOGD(...)
Definition: defs.h:187
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
EntriesBlock * cacheBlock
Definition: zstr.h:40
bool caseSensitive
Definition: zstr.h:44
void setSize(unsigned long len)
Definition: swbuf.h:255
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
int getCount()
Definition: entriesblk.cpp:61