xref: /plan9/sys/src/cmd/gs/zlib/inftrees.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
17dd7cddfSDavid du Colombier /* inftrees.h -- header to use inftrees.c
2*593dc095SDavid du Colombier  * Copyright (C) 1995-2003 Mark Adler
37dd7cddfSDavid du Colombier  * For conditions of distribution and use, see copyright notice in zlib.h
47dd7cddfSDavid du Colombier  */
57dd7cddfSDavid du Colombier 
67dd7cddfSDavid du Colombier /* WARNING: this file should *not* be used by applications. It is
77dd7cddfSDavid du Colombier    part of the implementation of the compression library and is
87dd7cddfSDavid du Colombier    subject to change. Applications should only use zlib.h.
97dd7cddfSDavid du Colombier  */
107dd7cddfSDavid du Colombier 
11*593dc095SDavid du Colombier /* Structure for decoding tables.  Each entry provides either the
12*593dc095SDavid du Colombier    information needed to do the operation requested by the code that
13*593dc095SDavid du Colombier    indexed that table entry, or it provides a pointer to another
14*593dc095SDavid du Colombier    table that indexes more bits of the code.  op indicates whether
15*593dc095SDavid du Colombier    the entry is a pointer to another table, a literal, a length or
16*593dc095SDavid du Colombier    distance, an end-of-block, or an invalid code.  For a table
17*593dc095SDavid du Colombier    pointer, the low four bits of op is the number of index bits of
18*593dc095SDavid du Colombier    that table.  For a length or distance, the low four bits of op
19*593dc095SDavid du Colombier    is the number of extra bits to get after the code.  bits is
20*593dc095SDavid du Colombier    the number of bits in this code or part of the code to drop off
21*593dc095SDavid du Colombier    of the bit buffer.  val is the actual byte to output in the case
22*593dc095SDavid du Colombier    of a literal, the base length or distance, or the offset from
23*593dc095SDavid du Colombier    the current table to the next table.  Each entry is four bytes. */
24*593dc095SDavid du Colombier typedef struct {
25*593dc095SDavid du Colombier     unsigned char op;           /* operation, extra bits, table bits */
26*593dc095SDavid du Colombier     unsigned char bits;         /* bits in this part of the code */
27*593dc095SDavid du Colombier     unsigned short val;         /* offset in table or code value */
28*593dc095SDavid du Colombier } code;
297dd7cddfSDavid du Colombier 
30*593dc095SDavid du Colombier /* op values as set by inflate_table():
31*593dc095SDavid du Colombier     00000000 - literal
32*593dc095SDavid du Colombier     0000tttt - table link, tttt != 0 is the number of table index bits
33*593dc095SDavid du Colombier     0001eeee - length or distance, eeee is the number of extra bits
34*593dc095SDavid du Colombier     01100000 - end of block
35*593dc095SDavid du Colombier     01000000 - invalid code
36*593dc095SDavid du Colombier  */
377dd7cddfSDavid du Colombier 
38*593dc095SDavid du Colombier /* Maximum size of dynamic tree.  The maximum found in a long but non-
39*593dc095SDavid du Colombier    exhaustive search was 1004 code structures (850 for length/literals
40*593dc095SDavid du Colombier    and 154 for distances, the latter actually the result of an
41*593dc095SDavid du Colombier    exhaustive search).  The true maximum is not known, but the value
42*593dc095SDavid du Colombier    below is more than safe. */
43*593dc095SDavid du Colombier #define ENOUGH 1440
44*593dc095SDavid du Colombier #define MAXD 154
457dd7cddfSDavid du Colombier 
46*593dc095SDavid du Colombier /* Type of code to build for inftable() */
47*593dc095SDavid du Colombier typedef enum {
48*593dc095SDavid du Colombier     CODES,
49*593dc095SDavid du Colombier     LENS,
50*593dc095SDavid du Colombier     DISTS
51*593dc095SDavid du Colombier } codetype;
527dd7cddfSDavid du Colombier 
53*593dc095SDavid du Colombier extern int inflate_table OF((codetype type, unsigned short FAR *lens,
54*593dc095SDavid du Colombier                              unsigned codes, code FAR * FAR *table,
55*593dc095SDavid du Colombier                              unsigned FAR *bits, unsigned short FAR *work));
56