11 const char inflate_copyright[] =
 
   12    " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
 
   32 int inflate_table(
type, lens, codes, 
table, bits, work)
 
   34 unsigned short FAR *lens;
 
   38 unsigned short FAR *work;
 
   55     const unsigned short FAR *base;     
 
   56     const unsigned short FAR *
extra;    
 
   58     unsigned short count[MAXBITS+1];    
 
   59     unsigned short offs[MAXBITS+1];     
 
   60     static const unsigned short lbase[31] = { 
 
   61         3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
 
   62         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
 
   63     static const unsigned short lext[31] = { 
 
   64         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
 
   65         19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
 
   66     static const unsigned short dbase[32] = { 
 
   67         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
 
   68         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
 
   69         8193, 12289, 16385, 24577, 0, 0};
 
   70     static const unsigned short dext[32] = { 
 
   71         16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
 
   72         23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
 
   73         28, 28, 29, 29, 64, 64};
 
  107     for (len = 0; len <= MAXBITS; len++)
 
  109     for (sym = 0; sym < codes; sym++)
 
  114     for (max = MAXBITS; max >= 1; max--)
 
  115         if (count[max] != 0) 
break;
 
  116     if (root > max) root = max;
 
  118         this.op = (
unsigned char)64;    
 
  119         this.bits = (
unsigned char)1;
 
  120         this.val = (
unsigned short)0;
 
  126     for (min = 1; min <= MAXBITS; min++)
 
  127         if (count[min] != 0) 
break;
 
  128     if (root < min) root = min;
 
  132     for (len = 1; len <= MAXBITS; len++) {
 
  135         if (left < 0) 
return -1;        
 
  137     if (left > 0 && (type == CODES || max != 1))
 
  142     for (len = 1; len < MAXBITS; len++)
 
  143         offs[len + 1] = offs[len] + count[len];
 
  146     for (sym = 0; sym < codes; sym++)
 
  147         if (lens[sym] != 0) work[offs[lens[sym]]++] = (
unsigned short)sym;
 
  207     low = (unsigned)(-1);       
 
  212     if (type == LENS && used >= ENOUGH - MAXD)
 
  218         this.bits = (
unsigned char)(len - drop);
 
  219         if ((
int)(work[sym]) < end) {
 
  220             this.op = (
unsigned char)0;
 
  221             this.val = work[sym];
 
  223         else if ((
int)(work[sym]) > end) {
 
  224             this.op = (
unsigned char)(extra[work[sym]]);
 
  225             this.val = base[work[sym]];
 
  228             this.op = (
unsigned char)(32 + 64);         
 
  233         incr = 1
U << (len - drop);
 
  238             next[(huff >> drop) + fill] = 
this;
 
  242         incr = 1
U << (len - 1);
 
  254         if (--(count[len]) == 0) {
 
  255             if (len == max) 
break;
 
  256             len = lens[work[sym]];
 
  260         if (len > root && (huff & mask) != low) {
 
  270             left = (int)(1 << curr);
 
  271             while (curr + drop < max) {
 
  272                 left -= count[curr + drop];
 
  273                 if (left <= 0) 
break;
 
  280             if (type == LENS && used >= ENOUGH - MAXD)
 
  285             (*table)[low].op = (
unsigned char)curr;
 
  286             (*table)[low].bits = (
unsigned char)root;
 
  287             (*table)[low].val = (
unsigned short)(next - *table);
 
  298     this.op = (
unsigned char)64;                
 
  299     this.bits = (
unsigned char)(len - drop);
 
  300     this.val = (
unsigned short)0;
 
  303         if (drop != 0 && (huff & mask) != low) {
 
  307             this.bits = (
unsigned char)len;
 
  311         next[huff >> drop] = 
this;
 
  314         incr = 1
U << (len - 1);