1
/* zlib.h -- interface of the 'zlib' general purpose compression library
2
version 1.1.3, July 9th, 1998
4
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
6
This software is provided 'as-is', without any express or implied
7
warranty. In no event will the authors be held liable for any damages
8
arising from the use of this software.
10
Permission is granted to anyone to use this software for any purpose,
11
including commercial applications, and to alter it and redistribute it
12
freely, subject to the following restrictions:
14
1. The origin of this software must not be misrepresented; you must not
15
claim that you wrote the original software. If you use this software
16
in a product, an acknowledgment in the product documentation would be
17
appreciated but is not required.
18
2. Altered source versions must be plainly marked as such, and must not be
19
misrepresented as being the original software.
20
3. This notice may not be removed or altered from any source distribution.
22
Jean-loup Gailly Mark Adler
23
jloup@gzip.org madler@alumni.caltech.edu
31
#include "nsis_zconf.h"
32
#include "nsis_zutil.h"
39
typedef struct inflate_huft_s FAR inflate_huft;
43
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
44
CODES_START, /* x: set up for LEN */
45
CODES_LEN, /* i: get length/literal/eob next */
46
CODES_LENEXT, /* i: getting length extra (have base) */
47
CODES_DIST, /* i: get distance next */
48
CODES_DISTEXT, /* i: getting distance extra */
49
CODES_COPY, /* o: copying bytes in window, waiting for space */
50
CODES_LIT, /* o: got literal, waiting for output space */
51
CODES_WASH, /* o: got eob, possibly still output waiting */
52
/* CODES_END, x: got eob and all data flushed */
53
/* CODES_BADCODE, x: got error */
55
TYPE, /* get type bits (3, including end bit) */
56
LENS, /* get lengths for stored */
57
STORED, /* processing stored block */
58
TABLE, /* get table lengths */
59
BTREE, /* get bit lengths tree for a dynamic block */
60
DTREE, /* get length, distance trees for a dynamic block */
61
CODES, /* processing fixed or dynamic block */
62
DRY, /* output remaining window bytes */
63
DONE, /* finished last block, done */
64
NZ_BAD /* got a data error--stuck here */
67
/* inflate codes private state */
68
struct inflate_codes_state {
71
/* inflate_mode mode; current inflate_codes mode */
73
/* mode dependent information */
77
inflate_huft *tree; /* pointer into tree */
78
uInt need; /* bits needed */
79
} code; /* if LEN or DIST, where in tree */
80
uInt lit; /* if LIT, literal */
82
uInt get; /* bits to get for extra */
83
uInt dist; /* distance back to copy from */
84
} copy; /* if EXT or COPY, where and how much */
87
/* mode independent information */
88
Byte lbits; /* ltree bits decoded per branch */
89
Byte dbits; /* dtree bits decoder per branch */
90
inflate_huft *ltree; /* literal/length/eob tree */
91
inflate_huft *dtree; /* distance tree */
95
struct inflate_huft_s {
98
Byte Exop; /* number of extra bits or operation */
99
Byte Bits; /* number of bits in this code or subcode */
102
unsigned short base; /* literal, length base, distance base,
108
typedef struct inflate_codes_state inflate_codes_statef;
110
#define FIXEDH 544 /* number of hufts used by fixed tables */
114
inflate_huft fixed_mem[FIXEDH];
117
inflate_huft *fixed_tl;
118
inflate_huft *fixed_td;
123
struct inflate_blocks_state {
128
inflate_mode mode; /* current inflate_block mode */
130
/* mode dependent information */
132
uInt left; /* if STORED, bytes left to copy */
134
uInt table; /* table lengths (14 bits) */
135
uInt index; /* index into blens (or border) */
136
uIntf t_blens[258+31+31]; /* bit lengths of codes */
137
uInt bb; /* bit length tree depth */
138
inflate_huft *tb; /* bit length decoding tree */
139
} trees; /* if DTREE, decoding info for trees */
141
inflate_codes_statef t_codes;
142
} decode; /* if CODES, current state */
145
uInt last; /* DRY if this block is the last block, TYPE otherwise */
147
/* mode independent information */
148
uInt bitk; /* bits in bit buffer */
149
uLong bitb; /* bit buffer */
150
inflate_huft hufts[MANY]; /* single malloc for tree space */
151
Bytef window[1 << MAX_WBITS]; /* sliding window */
152
Bytef *end; /* one byte after sliding window */
153
Bytef *read; /* window read pointer */
154
Bytef *write; /* window write pointer */
155
uLong check; /* check on output */
159
typedef struct nsis_z_stream_s {
160
Bytef *next_in; /* next input byte */
161
uInt avail_in; /* number of bytes available at next_in */
162
uLong total_in; /* total nb of input bytes read so far */
164
Bytef *next_out; /* next output byte should be put there */
165
uInt avail_out; /* remaining free space at next_out */
167
/* char *msg; last error message, NULL if no error */
168
/* struct internal_state FAR *state; not visible by applications */
169
struct inflate_blocks_state blocks;
173
typedef nsis_z_stream FAR *nsis_z_streamp;
177
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
178
#define Z_SYNC_FLUSH 2
179
#define Z_FULL_FLUSH 3
181
/* Allowed flush values; see deflate() below for details */
184
#define Z_STREAM_END 1
185
#define Z_NEED_DICT 2
188
/* EXEHEAD doesn't need a specific return code, just < 0 */
189
#define Z_STREAM_ERROR (-2)
190
#define Z_DATA_ERROR (-3)
191
#define Z_MEM_ERROR (-4)
192
#define Z_BUF_ERROR (-5)
193
#define Z_VERSION_ERROR (-6)
195
/* Return codes for the compression/decompression functions. Negative
196
* values are errors, positive values are used for special but normal events.
199
#define Z_NO_COMPRESSION 0
200
#define Z_BEST_SPEED 1
201
#define Z_BEST_COMPRESSION 9
202
#define Z_DEFAULT_COMPRESSION (-1)
203
/* compression levels */
206
#define Z_HUFFMAN_ONLY 2
207
#define Z_DEFAULT_STRATEGY 0
208
/* compression strategy; see deflateInit2() below for details */
210
/* Possible values of the data_type field */
213
/* The deflate compression method (the only one supported in this version) */
215
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
218
#define nsis_inflateInit(z) \
220
(z)->blocks.zs.fixed_built = 0; \
221
(z)->blocks.zs.fixed_bl = 9; \
222
(z)->blocks.zs.fixed_bd = 5; \
225
int ZEXPORT nsis_inflate(nsis_z_streamp z);
226
#define inflateReset(z) \
228
(z)->blocks.mode = TYPE; \
229
(z)->blocks.bitk = (z)->blocks.bitb = 0; \
230
(z)->blocks.read = (z)->blocks.write = (z)->blocks.window; \
231
(z)->blocks.end = (z)->blocks.window + (1 << DEF_WBITS); \