199767f8919635c4928607450d9e0abb932109ceToomas Soome/* inftrees.h -- header to use inftrees.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995-2005, 2010 Mark Adler
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For conditions of distribution and use, see copyright notice in zlib.h
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* WARNING: this file should *not* be used by applications. It is
199767f8919635c4928607450d9e0abb932109ceToomas Soome part of the implementation of the compression library and is
199767f8919635c4928607450d9e0abb932109ceToomas Soome subject to change. Applications should only use zlib.h.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Structure for decoding tables. Each entry provides either the
199767f8919635c4928607450d9e0abb932109ceToomas Soome information needed to do the operation requested by the code that
199767f8919635c4928607450d9e0abb932109ceToomas Soome indexed that table entry, or it provides a pointer to another
199767f8919635c4928607450d9e0abb932109ceToomas Soome table that indexes more bits of the code. op indicates whether
199767f8919635c4928607450d9e0abb932109ceToomas Soome the entry is a pointer to another table, a literal, a length or
199767f8919635c4928607450d9e0abb932109ceToomas Soome distance, an end-of-block, or an invalid code. For a table
199767f8919635c4928607450d9e0abb932109ceToomas Soome pointer, the low four bits of op is the number of index bits of
199767f8919635c4928607450d9e0abb932109ceToomas Soome that table. For a length or distance, the low four bits of op
199767f8919635c4928607450d9e0abb932109ceToomas Soome is the number of extra bits to get after the code. bits is
199767f8919635c4928607450d9e0abb932109ceToomas Soome the number of bits in this code or part of the code to drop off
199767f8919635c4928607450d9e0abb932109ceToomas Soome of the bit buffer. val is the actual byte to output in the case
199767f8919635c4928607450d9e0abb932109ceToomas Soome of a literal, the base length or distance, or the offset from
199767f8919635c4928607450d9e0abb932109ceToomas Soome the current table to the next table. Each entry is four bytes. */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned char op; /* operation, extra bits, table bits */
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned char bits; /* bits in this part of the code */
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned short val; /* offset in table or code value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} code;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* op values as set by inflate_table():
199767f8919635c4928607450d9e0abb932109ceToomas Soome 00000000 - literal
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0000tttt - table link, tttt != 0 is the number of table index bits
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0001eeee - length or distance, eeee is the number of extra bits
199767f8919635c4928607450d9e0abb932109ceToomas Soome 01100000 - end of block
199767f8919635c4928607450d9e0abb932109ceToomas Soome 01000000 - invalid code
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Maximum size of the dynamic table. The maximum number of code structures is
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1444, which is the sum of 852 for literal/length codes and 592 for distance
199767f8919635c4928607450d9e0abb932109ceToomas Soome codes. These values were found by exhaustive searches using the program
199767f8919635c4928607450d9e0abb932109ceToomas Soome examples/enough.c found in the zlib distribtution. The arguments to that
199767f8919635c4928607450d9e0abb932109ceToomas Soome program are the number of symbols, the initial root table size, and the
199767f8919635c4928607450d9e0abb932109ceToomas Soome maximum bit length of a code. "enough 286 9 15" for literal/length codes
199767f8919635c4928607450d9e0abb932109ceToomas Soome returns returns 852, and "enough 30 6 15" for distance codes returns 592.
199767f8919635c4928607450d9e0abb932109ceToomas Soome The initial root table size (9 or 6) is found in the fifth argument of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome inflate_table() calls in inflate.c and infback.c. If the root table size is
199767f8919635c4928607450d9e0abb932109ceToomas Soome changed, then these maximum sizes would be need to be recalculated and
199767f8919635c4928607450d9e0abb932109ceToomas Soome updated. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ENOUGH_LENS 852
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ENOUGH_DISTS 592
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Type of code to build for inflate_table() */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum {
199767f8919635c4928607450d9e0abb932109ceToomas Soome CODES,
199767f8919635c4928607450d9e0abb932109ceToomas Soome LENS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DISTS
199767f8919635c4928607450d9e0abb932109ceToomas Soome} codetype;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned codes, code FAR * FAR *table,
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned FAR *bits, unsigned short FAR *work));