init
[qstardict] / plugins / stardict / dictziplib.hpp
1 #ifndef __DICT_ZIP_LIB_H__
2 #define __DICT_ZIP_LIB_H__
3
4 #include <ctime>
5 #include <string>
6 #include <zlib.h>
7
8 #include "mapfile.hpp"
9
10
11 #define DICT_CACHE_SIZE 5
12
13 struct dictCache
14 {
15     int chunk;
16     char *inBuffer;
17     int stamp;
18     int count;
19 };
20
21 struct dictData
22 {
23     dictData()
24     {}
25     bool open(const std::string& filename, int computeCRC);
26     void close();
27     void read(char *buffer, unsigned long start, unsigned long size);
28     ~dictData()
29     {
30         close();
31     }
32 private:
33     const char *start;  /* start of mmap'd area */
34     const char *end;            /* end of mmap'd area */
35     unsigned long size;         /* size of mmap */
36
37     int type;
38     z_stream zStream;
39     int initialized;
40
41     int headerLength;
42     int method;
43     int flags;
44     time_t mtime;
45     int extraFlags;
46     int os;
47     int version;
48     int chunkLength;
49     int chunkCount;
50     int *chunks;
51     unsigned long *offsets;     /* Sum-scan of chunks. */
52     std::string origFilename;
53     std::string comment;
54     unsigned long crc;
55     unsigned long length;
56     unsigned long compressedLength;
57     dictCache cache[DICT_CACHE_SIZE];
58     MapFile mapfile;
59
60     int read_header(const std::string &filename, int computeCRC);
61 };
62
63 #endif//!__DICT_ZIP_LIB_H__