jdk/src/share/native/java/util/zip/zlib-1.1.3/inftrees.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * file and, per its terms, should not be removed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * inftrees.c -- generate Huffman trees for efficient decoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Copyright (C) 1995-1998 Mark Adler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * For conditions of distribution and use, see copyright notice in zlib.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "zutil.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "inftrees.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#if !defined(BUILDFIXED) && !defined(STDC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#  define BUILDFIXED   /* non ANSI compilers may not accept inffixed.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
const char inflate_copyright[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   " inflate 1.1.3.f-jdk Copyright 1995-1998 Mark Adler ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  If you use the zlib library in a product, an acknowledgment is welcome
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  in the documentation of your product. If for some reason you cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  include such an acknowledgment, I would appreciate that you keep this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  copyright string in the executable of your product.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
struct internal_state  {int dummy;}; /* for buggy compilers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* simplify the use of the inflate_huft type with some defines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define exop word.what.Exop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define bits word.what.Bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
local int huft_build OF((
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    uIntf *,            /* code lengths in bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    uInt,               /* number of codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    uInt,               /* number of "simple" codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    const uIntf *,      /* list of base values for non-simple codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    const uIntf *,      /* list of extra bits for non-simple codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    inflate_huft * FAR*,/* result: starting table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    uIntf *,            /* maximum lookup bits (returns actual) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    inflate_huft *,     /* space for trees */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    uInt *,             /* hufts used in space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    uIntf * ));         /* space for values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/* Tables for deflate from PKZIP's appnote.txt. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        /* see note #13 above about 258 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        8193, 12289, 16385, 24577};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
local const uInt cpdext[30] = { /* Extra bits for distance codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        12, 12, 13, 13};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   Huffman code decoding is performed using a multi-level table lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   The fastest way to decode is to simply build a lookup table whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
   size is determined by the longest code.  However, the time it takes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
   to build this table can also be a factor if the data being decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
   is not very long.  The most common codes are necessarily the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   shortest codes, so those codes dominate the decoding time, and hence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   the speed.  The idea is you can have a shorter table that decodes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   shorter, more probable codes, and then point to subsidiary tables for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   the longer codes.  The time it costs to decode the longer codes is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   then traded against the time it takes to make longer tables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   This results of this trade are in the variables lbits and dbits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   below.  lbits is the number of bits the first level table for literal/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   length codes can decode in one step, and dbits is the same thing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   the distance codes.  Subsequent tables are also less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   those sizes.  These values may be adjusted either when all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   codes are shorter than that, in which case the longest code length in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   bits is used, or when the shortest code is *longer* than the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   table size, in which case the length of the shortest code in bits is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
   used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
   There are two different values for the two tables, since they code a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
   different number of possibilities each.  The literal/length table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   codes 286 possible values, or in a flat code, a little over eight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
   bits.  The distance table codes 30 possible values, or a little less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   than five bits, flat.  The optimum values for speed end up being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   The optimum values may differ though from machine to machine, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
   possibly even between compilers.  Your mileage may vary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#define BMAX 15         /* maximum bit length of any code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
uInt n;                 /* number of codes (assumed <= 288) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
uInt s;                 /* number of simple-valued codes (0..s-1) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
const uIntf *d;         /* list of base values for non-simple codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
const uIntf *e;         /* list of extra bits for non-simple codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
inflate_huft * FAR *t;  /* result: starting table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
uIntf *m;               /* maximum lookup bits, returns actual */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
inflate_huft *hp;       /* space for trees */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
uInt *hn;               /* hufts used in space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
uIntf *v;               /* working area: values in order of bit length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
/* Given a list of code lengths and a maximum table size, make a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   if the given code set is incomplete (the tables are still built in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
   lengths), or Z_MEM_ERROR if not enough memory. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  uInt a;                       /* counter for codes of length k */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  uInt c[BMAX+1];               /* bit length count table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  uInt f;                       /* i repeats in table every f entries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  int g;                        /* maximum code length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  int h;                        /* table level */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  register uInt i;              /* counter, current code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  register uInt j;              /* counter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  register int k;               /* number of bits in current code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  int l;                        /* bits per table (returned in m) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  uInt mask;                    /* (1 << w) - 1, to avoid cc -O bug on HP */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  register uIntf *p;            /* pointer into c[], b[], or v[] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  inflate_huft *q;              /* points to current table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  struct inflate_huft_s r;      /* table entry for structure assignment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  inflate_huft *u[BMAX];        /* table stack */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  register int w;               /* bits before this table == (l * h) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  uInt x[BMAX+1];               /* bit offsets, then code stack */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  uIntf *xp;                    /* pointer into x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  int y;                        /* number of dummy codes added */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  uInt z;                       /* number of entries in current table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  /* Generate counts for each bit length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  p = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#define C0 *p++ = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#define C2 C0 C0 C0 C0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#define C4 C2 C2 C2 C2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  C4                            /* clear c[]--assume BMAX+1 is 16 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  p = b;  i = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    c[*p++]++;                  /* assume all entries <= BMAX */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  } while (--i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  if (c[0] == n)                /* null input--all zero length codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    *t = (inflate_huft *)Z_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    *m = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    return Z_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  /* Find minimum and maximum length, bound *m by those */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  l = *m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  for (j = 1; j <= BMAX; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (c[j])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  k = j;                        /* minimum code length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  if ((uInt)l < j)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    l = j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  for (i = BMAX; i; i--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if (c[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  g = i;                        /* maximum code length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  if ((uInt)l > i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    l = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  *m = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  /* Adjust last length count to fill out codes, if needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  for (y = 1 << j; j < i; j++, y <<= 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    if ((y -= c[j]) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      return Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  if ((y -= c[i]) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    return Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  c[i] += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  /* Generate starting offsets into the value table for each length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  x[1] = j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  p = c + 1;  xp = x + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  while (--i) {                 /* note that i == g from above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    *xp++ = (j += *p++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  /* Make a table of values in order of bit lengths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  p = b;  i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if ((j = *p++) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      v[x[j]++] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  } while (++i < n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  n = x[g];                     /* set n to length of v */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  /* Generate the Huffman codes and for each, make the table entries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
  x[0] = i = 0;                 /* first Huffman code is zero */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  p = v;                        /* grab values in bit order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  h = -1;                       /* no tables yet--level -1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  w = -l;                       /* bits decoded == (l * h) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  q = (inflate_huft *)Z_NULL;   /* ditto */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  z = 0;                        /* ditto */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  /* go through the bit lengths (k already is bits in shortest code) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  for (; k <= g; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    a = c[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    while (a--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      /* here i is the Huffman code of length k bits for value *p */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      /* make tables up to required level */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      while (k > w + l)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        h++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        w += l;                 /* previous table always l bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        /* compute minimum size table less than or equal to l bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        z = g - w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        z = z > (uInt)l ? (uInt)l : z;  /* table size upper limit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        {                       /* too few codes for k-w bit table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
          f -= a + 1;           /* deduct codes from patterns left */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
          xp = c + k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
          if (j < z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            while (++j < z)     /* try smaller tables up to z bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
              if ((f <<= 1) <= *++xp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                break;          /* enough codes to use up j bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
              f -= *xp;         /* else deduct codes from patterns */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        z = 1 << j;             /* table entries for j-bit table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        /* allocate new table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
          return Z_MEM_ERROR;   /* not enough memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        u[h] = q = hp + *hn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        *hn += z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        /* connect to last table, if there is one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
          x[h] = i;             /* save pattern for backing up */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
          r.bits = (Byte)l;     /* bits to dump before this table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
          r.exop = (Byte)j;     /* bits in this table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
          j = i >> (w - l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
          u[h-1][j] = r;        /* connect to last table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
          *t = q;               /* first table is returned result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      /* set up table entry in r */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      r.bits = (Byte)(k - w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      if (p >= v + n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        r.exop = 128 + 64;      /* out of values--invalid code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      else if (*p < s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        r.base = *p++;          /* simple code is just the value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        r.base = d[*p++ - s];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      /* fill code-like entries with r */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      f = 1 << (k - w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      for (j = i >> w; j < z; j += f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        q[j] = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      /* backwards increment the k-bit code i */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
      for (j = 1 << (k - 1); i & j; j >>= 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        i ^= j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      i ^= j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      /* backup over finished tables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
      while ((i & mask) != x[h])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        h--;                    /* don't need to update q */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        w -= l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        mask = (1 << w) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  /* Return Z_BUF_ERROR if we were given an incomplete table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
int inflate_trees_bits(c, bb, tb, hp, z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
uIntf *c;               /* 19 code lengths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
uIntf *bb;              /* bits tree desired/actual depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
inflate_huft * FAR *tb; /* bits tree result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
inflate_huft *hp;       /* space for trees */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
z_streamp z;            /* for messages */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  uInt hn = 0;          /* hufts used in space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
  uIntf *v;             /* work area for huft_build */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
  if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    return Z_MEM_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                 tb, bb, hp, &hn, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
  if (r == Z_DATA_ERROR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  else if (r == Z_BUF_ERROR || *bb == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    z->msg = (char*)"incomplete dynamic bit lengths tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    r = Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
  ZFREE(z, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
uInt nl;                /* number of literal/length codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
uInt nd;                /* number of distance codes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
uIntf *c;               /* that many (total) code lengths */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
uIntf *bl;              /* literal desired/actual bit depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
uIntf *bd;              /* distance desired/actual bit depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
inflate_huft * FAR *tl; /* literal/length tree result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
inflate_huft * FAR *td; /* distance tree result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
inflate_huft *hp;       /* space for trees */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
z_streamp z;            /* for messages */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  uInt hn = 0;          /* hufts used in space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  uIntf *v;             /* work area for huft_build */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  /* allocate work area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
  if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    return Z_MEM_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
  /* build literal/length tree */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  if (r != Z_OK || *bl == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (r == Z_DATA_ERROR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      z->msg = (char*)"oversubscribed literal/length tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    else if (r != Z_MEM_ERROR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
      z->msg = (char*)"incomplete literal/length tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
      r = Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    ZFREE(z, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
  /* build distance tree */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
  if (r != Z_OK || (*bd == 0 && nl > 257))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if (r == Z_DATA_ERROR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      z->msg = (char*)"oversubscribed distance tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    else if (r == Z_BUF_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
#ifdef PKZIP_BUG_WORKAROUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      r = Z_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
      z->msg = (char*)"incomplete distance tree";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
      r = Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    else if (r != Z_MEM_ERROR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
      z->msg = (char*)"empty distance tree with lengths";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      r = Z_DATA_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    ZFREE(z, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  /* done */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
  ZFREE(z, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  return Z_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
/* build fixed tables only once--keep them here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
#ifdef BUILDFIXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
local int fixed_built = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
#define FIXEDH 544      /* number of hufts used by fixed tables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
local inflate_huft fixed_mem[FIXEDH];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
local uInt fixed_bl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
local uInt fixed_bd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
local inflate_huft *fixed_tl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
local inflate_huft *fixed_td;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#include "inffixed.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
int inflate_trees_fixed(bl, bd, tl, td, z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
uIntf *bl;               /* literal desired/actual bit depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
uIntf *bd;               /* distance desired/actual bit depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
inflate_huft * FAR *tl;  /* literal/length tree result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
inflate_huft * FAR *td;  /* distance tree result */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
z_streamp z;             /* for memory allocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
#ifdef BUILDFIXED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
  /* build fixed tables if not already */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  if (!fixed_built)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    int k;              /* temporary variable */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    uInt f = 0;         /* number of hufts used in fixed_mem */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    uIntf *c;           /* length list for huft_build */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    uIntf *v;           /* work area for huft_build */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /* allocate memory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      return Z_MEM_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
      ZFREE(z, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      return Z_MEM_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /* literal table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    for (k = 0; k < 144; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
      c[k] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    for (; k < 256; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      c[k] = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    for (; k < 280; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
      c[k] = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    for (; k < 288; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      c[k] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    fixed_bl = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
               fixed_mem, &f, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /* distance table */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    for (k = 0; k < 30; k++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      c[k] = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    fixed_bd = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
               fixed_mem, &f, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /* done */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    ZFREE(z, v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    ZFREE(z, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    fixed_built = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
  *bl = fixed_bl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
  *bd = fixed_bd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  *tl = fixed_tl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
  *td = fixed_td;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
  return Z_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
}