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