inftrees.h revision 206924
1193326Sed/* inftrees.h -- header to use inftrees.c
2193326Sed * Copyright (C) 1995-2005, 2010 Mark Adler
3193326Sed * For conditions of distribution and use, see copyright notice in zlib.h
4193326Sed */
5193326Sed
6193326Sed/* WARNING: this file should *not* be used by applications. It is
7193326Sed   part of the implementation of the compression library and is
8193326Sed   subject to change. Applications should only use zlib.h.
9193326Sed */
10193326Sed
11193326Sed/* Structure for decoding tables.  Each entry provides either the
12193326Sed   information needed to do the operation requested by the code that
13193326Sed   indexed that table entry, or it provides a pointer to another
14193326Sed   table that indexes more bits of the code.  op indicates whether
15212904Sdim   the entry is a pointer to another table, a literal, a length or
16252723Sdim   distance, an end-of-block, or an invalid code.  For a table
17198092Srdivacky   pointer, the low four bits of op is the number of index bits of
18193326Sed   that table.  For a length or distance, the low four bits of op
19193326Sed   is the number of extra bits to get after the code.  bits is
20193326Sed   the number of bits in this code or part of the code to drop off
21193326Sed   of the bit buffer.  val is the actual byte to output in the case
22193326Sed   of a literal, the base length or distance, or the offset from
23193326Sed   the current table to the next table.  Each entry is four bytes. */
24252723Sdimtypedef struct {
25252723Sdim    unsigned char op;           /* operation, extra bits, table bits */
26252723Sdim    unsigned char bits;         /* bits in this part of the code */
27252723Sdim    unsigned short val;         /* offset in table or code value */
28252723Sdim} code;
29252723Sdim
30252723Sdim/* op values as set by inflate_table():
31193326Sed    00000000 - literal
32193326Sed    0000tttt - table link, tttt != 0 is the number of table index bits
33193326Sed    0001eeee - length or distance, eeee is the number of extra bits
34193326Sed    01100000 - end of block
35193326Sed    01000000 - invalid code
36193326Sed */
37193326Sed
38193326Sed/* Maximum size of the dynamic table.  The maximum number of code structures is
39193326Sed   1444, which is the sum of 852 for literal/length codes and 592 for distance
40193326Sed   codes.  These values were found by exhaustive searches using the program
41193326Sed   examples/enough.c found in the zlib distribtution.  The arguments to that
42218893Sdim   program are the number of symbols, the initial root table size, and the
43193326Sed   maximum bit length of a code.  "enough 286 9 15" for literal/length codes
44193326Sed   returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45193326Sed   The initial root table size (9 or 6) is found in the fifth argument of the
46193326Sed   inflate_table() calls in inflate.c and infback.c.  If the root table size is
47210299Sed   changed, then these maximum sizes would be need to be recalculated and
48245431Sdim   updated. */
49210299Sed#define ENOUGH_LENS 852
50193326Sed#define ENOUGH_DISTS 592
51193326Sed#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52218893Sdim
53218893Sdim/* Type of code to build for inflate_table() */
54218893Sdimtypedef enum {
55218893Sdim    CODES,
56218893Sdim    LENS,
57218893Sdim    DISTS
58218893Sdim} codetype;
59199990Srdivacky
60193326Sedint ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61193326Sed                             unsigned codes, code FAR * FAR *table,
62193326Sed                             unsigned FAR *bits, unsigned short FAR *work));
63193326Sed