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