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