diff options
Diffstat (limited to 'inftrees.c')
-rw-r--r-- | inftrees.c | 69 |
1 files changed, 35 insertions, 34 deletions
@@ -15,22 +15,22 @@ struct internal_state {int dummy;}; /* for buggy compilers */ | |||
15 | #define bits word.what.Bits | 15 | #define bits word.what.Bits |
16 | 16 | ||
17 | 17 | ||
18 | local int huft_build __P(( | 18 | local int huft_build OF(( |
19 | uInt *, /* code lengths in bits */ | 19 | uIntf *, /* code lengths in bits */ |
20 | uInt, /* number of codes */ | 20 | uInt, /* number of codes */ |
21 | uInt, /* number of "simple" codes */ | 21 | uInt, /* number of "simple" codes */ |
22 | uInt *, /* list of base values for non-simple codes */ | 22 | uIntf *, /* list of base values for non-simple codes */ |
23 | uInt *, /* list of extra bits for non-simple codes */ | 23 | uIntf *, /* list of extra bits for non-simple codes */ |
24 | inflate_huft **, /* result: starting table */ | 24 | inflate_huft * FAR*,/* result: starting table */ |
25 | uInt *, /* maximum lookup bits (returns actual) */ | 25 | uIntf *, /* maximum lookup bits (returns actual) */ |
26 | z_stream *)); /* for zalloc function */ | 26 | z_stream *)); /* for zalloc function */ |
27 | 27 | ||
28 | local voidp falloc __P(( | 28 | local voidp falloc OF(( |
29 | voidp, /* opaque pointer (not used) */ | 29 | voidp, /* opaque pointer (not used) */ |
30 | uInt, /* number of items */ | 30 | uInt, /* number of items */ |
31 | uInt)); /* size of item */ | 31 | uInt)); /* size of item */ |
32 | 32 | ||
33 | local void ffree __P(( | 33 | local void ffree OF(( |
34 | voidp q, /* opaque pointer (not used) */ | 34 | voidp q, /* opaque pointer (not used) */ |
35 | voidp p)); /* what to free (not used) */ | 35 | voidp p)); /* what to free (not used) */ |
36 | 36 | ||
@@ -93,13 +93,13 @@ local uInt cpdext[] = { /* Extra bits for distance codes */ | |||
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | local int huft_build(b, n, s, d, e, t, m, zs) | 95 | local int huft_build(b, n, s, d, e, t, m, zs) |
96 | uInt *b; /* code lengths in bits (all assumed <= BMAX) */ | 96 | uIntf *b; /* code lengths in bits (all assumed <= BMAX) */ |
97 | uInt n; /* number of codes (assumed <= N_MAX) */ | 97 | uInt n; /* number of codes (assumed <= N_MAX) */ |
98 | uInt s; /* number of simple-valued codes (0..s-1) */ | 98 | uInt s; /* number of simple-valued codes (0..s-1) */ |
99 | uInt *d; /* list of base values for non-simple codes */ | 99 | uIntf *d; /* list of base values for non-simple codes */ |
100 | uInt *e; /* list of extra bits for non-simple codes */ | 100 | uIntf *e; /* list of extra bits for non-simple codes */ |
101 | inflate_huft **t; /* result: starting table */ | 101 | inflate_huft * FAR *t; /* result: starting table */ |
102 | uInt *m; /* maximum lookup bits, returns actual */ | 102 | uIntf *m; /* maximum lookup bits, returns actual */ |
103 | z_stream *zs; /* for zalloc function */ | 103 | z_stream *zs; /* for zalloc function */ |
104 | /* Given a list of code lengths and a maximum table size, make a set of | 104 | /* Given a list of code lengths and a maximum table size, make a set of |
105 | tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR | 105 | tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR |
@@ -107,6 +107,7 @@ z_stream *zs; /* for zalloc function */ | |||
107 | case), Z_DATA_ERROR if the input is invalid (all zero length codes or an | 107 | case), Z_DATA_ERROR if the input is invalid (all zero length codes or an |
108 | over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */ | 108 | over-subscribed set of lengths), or Z_MEM_ERROR if not enough memory. */ |
109 | { | 109 | { |
110 | |||
110 | uInt a; /* counter for codes of length k */ | 111 | uInt a; /* counter for codes of length k */ |
111 | uInt c[BMAX+1]; /* bit length count table */ | 112 | uInt c[BMAX+1]; /* bit length count table */ |
112 | uInt f; /* i repeats in table every f entries */ | 113 | uInt f; /* i repeats in table every f entries */ |
@@ -116,14 +117,14 @@ z_stream *zs; /* for zalloc function */ | |||
116 | register uInt j; /* counter */ | 117 | register uInt j; /* counter */ |
117 | register int k; /* number of bits in current code */ | 118 | register int k; /* number of bits in current code */ |
118 | int l; /* bits per table (returned in m) */ | 119 | int l; /* bits per table (returned in m) */ |
119 | register uInt *p; /* pointer into c[], b[], or v[] */ | 120 | register uIntf *p; /* pointer into c[], b[], or v[] */ |
120 | register inflate_huft *q; /* points to current table */ | 121 | inflate_huft *q; /* points to current table */ |
121 | inflate_huft r; /* table entry for structure assignment */ | 122 | struct inflate_huft_s r; /* table entry for structure assignment */ |
122 | inflate_huft *u[BMAX]; /* table stack */ | 123 | inflate_huft *u[BMAX]; /* table stack */ |
123 | uInt v[N_MAX]; /* values in order of bit length */ | 124 | uInt v[N_MAX]; /* values in order of bit length */ |
124 | register int w; /* bits before this table == (l * h) */ | 125 | register int w; /* bits before this table == (l * h) */ |
125 | uInt x[BMAX+1]; /* bit offsets, then code stack */ | 126 | uInt x[BMAX+1]; /* bit offsets, then code stack */ |
126 | uInt *xp; /* pointer into x */ | 127 | uIntf *xp; /* pointer into x */ |
127 | int y; /* number of dummy codes added */ | 128 | int y; /* number of dummy codes added */ |
128 | uInt z; /* number of entries in current table */ | 129 | uInt z; /* number of entries in current table */ |
129 | 130 | ||
@@ -238,7 +239,7 @@ z_stream *zs; /* for zalloc function */ | |||
238 | inflate_hufts += z + 1; | 239 | inflate_hufts += z + 1; |
239 | #endif | 240 | #endif |
240 | *t = q + 1; /* link to list for huft_free() */ | 241 | *t = q + 1; /* link to list for huft_free() */ |
241 | *(t = &(q->next)) = (inflate_huft *)Z_NULL; | 242 | *(t = &(q->next)) = Z_NULL; |
242 | u[h] = ++q; /* table starts after link */ | 243 | u[h] = ++q; /* table starts after link */ |
243 | 244 | ||
244 | /* connect to last table, if there is one */ | 245 | /* connect to last table, if there is one */ |
@@ -246,7 +247,7 @@ z_stream *zs; /* for zalloc function */ | |||
246 | { | 247 | { |
247 | x[h] = i; /* save pattern for backing up */ | 248 | x[h] = i; /* save pattern for backing up */ |
248 | r.bits = (Byte)l; /* bits to dump before this table */ | 249 | r.bits = (Byte)l; /* bits to dump before this table */ |
249 | r.exop = j; /* bits in this table */ | 250 | r.exop = (Byte)j; /* bits in this table */ |
250 | r.next = q; /* pointer to this table */ | 251 | r.next = q; /* pointer to this table */ |
251 | j = i >> (w - l); /* (get around Turbo C bug) */ | 252 | j = i >> (w - l); /* (get around Turbo C bug) */ |
252 | u[h-1][j] = r; /* connect to last table */ | 253 | u[h-1][j] = r; /* connect to last table */ |
@@ -259,12 +260,12 @@ z_stream *zs; /* for zalloc function */ | |||
259 | r.exop = 128 + 64; /* out of values--invalid code */ | 260 | r.exop = 128 + 64; /* out of values--invalid code */ |
260 | else if (*p < s) | 261 | else if (*p < s) |
261 | { | 262 | { |
262 | r.exop = (*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ | 263 | r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */ |
263 | r.base = *p++; /* simple code is just the value */ | 264 | r.base = *p++; /* simple code is just the value */ |
264 | } | 265 | } |
265 | else | 266 | else |
266 | { | 267 | { |
267 | r.exop = e[*p - s] + 16 + 64; /* non-simple--look up in lists */ | 268 | r.exop = (Byte)e[*p - s] + 16 + 64; /* non-simple--look up in lists */ |
268 | r.base = d[*p++ - s]; | 269 | r.base = d[*p++ - s]; |
269 | } | 270 | } |
270 | 271 | ||
@@ -294,14 +295,14 @@ z_stream *zs; /* for zalloc function */ | |||
294 | 295 | ||
295 | 296 | ||
296 | int inflate_trees_bits(c, bb, tb, z) | 297 | int inflate_trees_bits(c, bb, tb, z) |
297 | uInt *c; /* 19 code lengths */ | 298 | uIntf *c; /* 19 code lengths */ |
298 | uInt *bb; /* bits tree desired/actual depth */ | 299 | uIntf *bb; /* bits tree desired/actual depth */ |
299 | inflate_huft **tb; /* bits tree result */ | 300 | inflate_huft * FAR *tb; /* bits tree result */ |
300 | z_stream *z; /* for zfree function */ | 301 | z_stream *z; /* for zfree function */ |
301 | { | 302 | { |
302 | int r; | 303 | int r; |
303 | 304 | ||
304 | r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL, tb, bb, z); | 305 | r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL, tb, bb, z); |
305 | if (r == Z_DATA_ERROR) | 306 | if (r == Z_DATA_ERROR) |
306 | z->msg = "oversubscribed dynamic bit lengths tree"; | 307 | z->msg = "oversubscribed dynamic bit lengths tree"; |
307 | else if (r == Z_BUF_ERROR) | 308 | else if (r == Z_BUF_ERROR) |
@@ -317,11 +318,11 @@ z_stream *z; /* for zfree function */ | |||
317 | int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z) | 318 | int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, z) |
318 | uInt nl; /* number of literal/length codes */ | 319 | uInt nl; /* number of literal/length codes */ |
319 | uInt nd; /* number of distance codes */ | 320 | uInt nd; /* number of distance codes */ |
320 | uInt *c; /* that many (total) code lengths */ | 321 | uIntf *c; /* that many (total) code lengths */ |
321 | uInt *bl; /* literal desired/actual bit depth */ | 322 | uIntf *bl; /* literal desired/actual bit depth */ |
322 | uInt *bd; /* distance desired/actual bit depth */ | 323 | uIntf *bd; /* distance desired/actual bit depth */ |
323 | inflate_huft **tl; /* literal/length tree result */ | 324 | inflate_huft * FAR *tl; /* literal/length tree result */ |
324 | inflate_huft **td; /* distance tree result */ | 325 | inflate_huft * FAR *td; /* distance tree result */ |
325 | z_stream *z; /* for zfree function */ | 326 | z_stream *z; /* for zfree function */ |
326 | { | 327 | { |
327 | int r; | 328 | int r; |
@@ -399,10 +400,10 @@ voidp p; | |||
399 | 400 | ||
400 | 401 | ||
401 | int inflate_trees_fixed(bl, bd, tl, td) | 402 | int inflate_trees_fixed(bl, bd, tl, td) |
402 | uInt *bl; /* literal desired/actual bit depth */ | 403 | uIntf *bl; /* literal desired/actual bit depth */ |
403 | uInt *bd; /* distance desired/actual bit depth */ | 404 | uIntf *bd; /* distance desired/actual bit depth */ |
404 | inflate_huft **tl; /* literal/length tree result */ | 405 | inflate_huft * FAR *tl; /* literal/length tree result */ |
405 | inflate_huft **td; /* distance tree result */ | 406 | inflate_huft * FAR *td; /* distance tree result */ |
406 | { | 407 | { |
407 | /* build fixed tables if not built already--lock out other instances */ | 408 | /* build fixed tables if not built already--lock out other instances */ |
408 | while (++fixed_lock > 1) | 409 | while (++fixed_lock > 1) |