Build a set of tables to decode the provided canonical Huffman code. The code lengths are lens[0..codes-1]. The result starts at *table, whose indices are 0..2^bits-1. work is a writable array of at least lens shorts, which is used as a work area. type is the type of code to be generated, CODES, LENS, or DISTS. On return, zero is success, -1 is an invalid code, and +1 means that
| 30 | longest code or if it is less than the shortest code. |
| 31 | */ |
| 32 | int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, |
| 33 | unsigned codes, code FAR * FAR *table, unsigned FAR *bits, |
| 34 | unsigned short FAR *work) |
| 35 | { |
| 36 | unsigned len; /* a code's length in bits */ |
| 37 | unsigned sym; /* index of code symbols */ |
| 38 | unsigned min, max; /* minimum and maximum code lengths */ |
| 39 | unsigned root; /* number of index bits for root table */ |
| 40 | unsigned curr; /* number of index bits for current table */ |
| 41 | unsigned drop; /* code bits to drop for sub-table */ |
| 42 | int left; /* number of prefix codes available */ |
| 43 | unsigned used; /* code entries in table used */ |
| 44 | unsigned huff; /* Huffman code */ |
| 45 | unsigned incr; /* for incrementing code, index */ |
| 46 | unsigned fill; /* index for replicating entries */ |
| 47 | unsigned low; /* low bits for current root entry */ |
| 48 | unsigned mask; /* mask for low root bits */ |
| 49 | code here; /* table entry for duplication */ |
| 50 | code FAR *next; /* next available space in table */ |
| 51 | const unsigned short FAR *base; /* base value table to use */ |
| 52 | const unsigned short FAR *extra; /* extra bits table to use */ |
| 53 | unsigned match; /* use base and extra for symbol >= match */ |
| 54 | unsigned short count[MAXBITS+1]; /* number of codes of each length */ |
| 55 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ |
| 56 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */ |
| 57 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, |
| 58 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; |
| 59 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
| 60 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, |
| 61 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; |
| 62 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ |
| 63 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
| 64 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
| 65 | 8193, 12289, 16385, 24577, 0, 0}; |
| 66 | static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ |
| 67 | 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, |
| 68 | 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, |
| 69 | 28, 28, 29, 29, 64, 64}; |
| 70 | |
| 71 | /* |
| 72 | Process a set of code lengths to create a canonical Huffman code. The |
| 73 | code lengths are lens[0..codes-1]. Each length corresponds to the |
| 74 | symbols 0..codes-1. The Huffman code is generated by first sorting the |
| 75 | symbols by length from short to long, and retaining the symbol order |
| 76 | for codes with equal lengths. Then the code starts with all zero bits |
| 77 | for the first code of the shortest length, and the codes are integer |
| 78 | increments for the same length, and zeros are appended as the length |
| 79 | increases. For the deflate format, these bits are stored backwards |
| 80 | from their more natural integer increment ordering, and so when the |
| 81 | decoding tables are built in the large loop below, the integer codes |
| 82 | are incremented backwards. |
| 83 | |
| 84 | This routine assumes, but does not check, that all of the entries in |
| 85 | lens[] are in the range 0..MAXBITS. The caller must assure this. |
| 86 | 1..MAXBITS is interpreted as that code length. zero means that that |
| 87 | symbol does not occur in this code. |
| 88 | |
| 89 | The codes are sorted by computing a count of codes for each length, |
no outgoing calls
no test coverage detected