xref: /illumos-gate/usr/src/contrib/zlib/inftrees.h (revision b8382935)
1*b8382935SToomas Soome /* inftrees.h -- header to use inftrees.c
2*b8382935SToomas Soome  * Copyright (C) 1995-2005, 2010 Mark Adler
3*b8382935SToomas Soome  * For conditions of distribution and use, see copyright notice in zlib.h
4*b8382935SToomas Soome  */
5*b8382935SToomas Soome 
6*b8382935SToomas Soome /* WARNING: this file should *not* be used by applications. It is
7*b8382935SToomas Soome    part of the implementation of the compression library and is
8*b8382935SToomas Soome    subject to change. Applications should only use zlib.h.
9*b8382935SToomas Soome  */
10*b8382935SToomas Soome 
11*b8382935SToomas Soome /* Structure for decoding tables.  Each entry provides either the
12*b8382935SToomas Soome    information needed to do the operation requested by the code that
13*b8382935SToomas Soome    indexed that table entry, or it provides a pointer to another
14*b8382935SToomas Soome    table that indexes more bits of the code.  op indicates whether
15*b8382935SToomas Soome    the entry is a pointer to another table, a literal, a length or
16*b8382935SToomas Soome    distance, an end-of-block, or an invalid code.  For a table
17*b8382935SToomas Soome    pointer, the low four bits of op is the number of index bits of
18*b8382935SToomas Soome    that table.  For a length or distance, the low four bits of op
19*b8382935SToomas Soome    is the number of extra bits to get after the code.  bits is
20*b8382935SToomas Soome    the number of bits in this code or part of the code to drop off
21*b8382935SToomas Soome    of the bit buffer.  val is the actual byte to output in the case
22*b8382935SToomas Soome    of a literal, the base length or distance, or the offset from
23*b8382935SToomas Soome    the current table to the next table.  Each entry is four bytes. */
24*b8382935SToomas Soome typedef struct {
25*b8382935SToomas Soome     unsigned char op;           /* operation, extra bits, table bits */
26*b8382935SToomas Soome     unsigned char bits;         /* bits in this part of the code */
27*b8382935SToomas Soome     unsigned short val;         /* offset in table or code value */
28*b8382935SToomas Soome } code;
29*b8382935SToomas Soome 
30*b8382935SToomas Soome /* op values as set by inflate_table():
31*b8382935SToomas Soome     00000000 - literal
32*b8382935SToomas Soome     0000tttt - table link, tttt != 0 is the number of table index bits
33*b8382935SToomas Soome     0001eeee - length or distance, eeee is the number of extra bits
34*b8382935SToomas Soome     01100000 - end of block
35*b8382935SToomas Soome     01000000 - invalid code
36*b8382935SToomas Soome  */
37*b8382935SToomas Soome 
38*b8382935SToomas Soome /* Maximum size of the dynamic table.  The maximum number of code structures is
39*b8382935SToomas Soome    1444, which is the sum of 852 for literal/length codes and 592 for distance
40*b8382935SToomas Soome    codes.  These values were found by exhaustive searches using the program
41*b8382935SToomas Soome    examples/enough.c found in the zlib distribtution.  The arguments to that
42*b8382935SToomas Soome    program are the number of symbols, the initial root table size, and the
43*b8382935SToomas Soome    maximum bit length of a code.  "enough 286 9 15" for literal/length codes
44*b8382935SToomas Soome    returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45*b8382935SToomas Soome    The initial root table size (9 or 6) is found in the fifth argument of the
46*b8382935SToomas Soome    inflate_table() calls in inflate.c and infback.c.  If the root table size is
47*b8382935SToomas Soome    changed, then these maximum sizes would be need to be recalculated and
48*b8382935SToomas Soome    updated. */
49*b8382935SToomas Soome #define ENOUGH_LENS 852
50*b8382935SToomas Soome #define ENOUGH_DISTS 592
51*b8382935SToomas Soome #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52*b8382935SToomas Soome 
53*b8382935SToomas Soome /* Type of code to build for inflate_table() */
54*b8382935SToomas Soome typedef enum {
55*b8382935SToomas Soome     CODES,
56*b8382935SToomas Soome     LENS,
57*b8382935SToomas Soome     DISTS
58*b8382935SToomas Soome } codetype;
59*b8382935SToomas Soome 
60*b8382935SToomas Soome int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61*b8382935SToomas Soome                              unsigned codes, code FAR * FAR *table,
62*b8382935SToomas Soome                              unsigned FAR *bits, unsigned short FAR *work));
63