OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [lib/] [zlib_inflate/] [inftrees.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/* inftrees.c -- generate Huffman trees for efficient decoding
/* inftrees.c -- generate Huffman trees for efficient decoding
 * Copyright (C) 1995-1998 Mark Adler
 * Copyright (C) 1995-1998 Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 * For conditions of distribution and use, see copyright notice in zlib.h
 */
 */
 
 
#include <linux/zutil.h>
#include <linux/zutil.h>
#include "inftrees.h"
#include "inftrees.h"
#include "infutil.h"
#include "infutil.h"
 
 
static const char inflate_copyright[] =
static const char inflate_copyright[] =
   " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
   " inflate 1.1.3 Copyright 1995-1998 Mark Adler ";
/*
/*
  If you use the zlib library in a product, an acknowledgment is welcome
  If you use the zlib library in a product, an acknowledgment is welcome
  in the documentation of your product. If for some reason you cannot
  in the documentation of your product. If for some reason you cannot
  include such an acknowledgment, I would appreciate that you keep this
  include such an acknowledgment, I would appreciate that you keep this
  copyright string in the executable of your product.
  copyright string in the executable of your product.
 */
 */
struct internal_state;
struct internal_state;
 
 
/* simplify the use of the inflate_huft type with some defines */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define exop word.what.Exop
#define bits word.what.Bits
#define bits word.what.Bits
 
 
 
 
local int huft_build OF((
local int huft_build OF((
    uIntf *,            /* code lengths in bits */
    uIntf *,            /* code lengths in bits */
    uInt,               /* number of codes */
    uInt,               /* number of codes */
    uInt,               /* number of "simple" codes */
    uInt,               /* number of "simple" codes */
    const uIntf *,      /* list of base values for non-simple codes */
    const uIntf *,      /* list of base values for non-simple codes */
    const uIntf *,      /* list of extra bits for non-simple codes */
    const uIntf *,      /* list of extra bits for non-simple codes */
    inflate_huft * FAR*,/* result: starting table */
    inflate_huft * FAR*,/* result: starting table */
    uIntf *,            /* maximum lookup bits (returns actual) */
    uIntf *,            /* maximum lookup bits (returns actual) */
    inflate_huft *,     /* space for trees */
    inflate_huft *,     /* space for trees */
    uInt *,             /* hufts used in space */
    uInt *,             /* hufts used in space */
    uIntf * ));         /* space for values */
    uIntf * ));         /* space for values */
 
 
/* Tables for deflate from PKZIP's appnote.txt. */
/* Tables for deflate from PKZIP's appnote.txt. */
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
        /* see note #13 above about 258 */
        /* see note #13 above about 258 */
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
        0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
        3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
        8193, 12289, 16385, 24577};
        8193, 12289, 16385, 24577};
local const uInt cpdext[30] = { /* Extra bits for distance codes */
local const uInt cpdext[30] = { /* Extra bits for distance codes */
        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
        0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
        7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
        12, 12, 13, 13};
        12, 12, 13, 13};
 
 
/*
/*
   Huffman code decoding is performed using a multi-level table lookup.
   Huffman code decoding is performed using a multi-level table lookup.
   The fastest way to decode is to simply build a lookup table whose
   The fastest way to decode is to simply build a lookup table whose
   size is determined by the longest code.  However, the time it takes
   size is determined by the longest code.  However, the time it takes
   to build this table can also be a factor if the data being decoded
   to build this table can also be a factor if the data being decoded
   is not very long.  The most common codes are necessarily the
   is not very long.  The most common codes are necessarily the
   shortest codes, so those codes dominate the decoding time, and hence
   shortest codes, so those codes dominate the decoding time, and hence
   the speed.  The idea is you can have a shorter table that decodes the
   the speed.  The idea is you can have a shorter table that decodes the
   shorter, more probable codes, and then point to subsidiary tables for
   shorter, more probable codes, and then point to subsidiary tables for
   the longer codes.  The time it costs to decode the longer codes is
   the longer codes.  The time it costs to decode the longer codes is
   then traded against the time it takes to make longer tables.
   then traded against the time it takes to make longer tables.
 
 
   This results of this trade are in the variables lbits and dbits
   This results of this trade are in the variables lbits and dbits
   below.  lbits is the number of bits the first level table for literal/
   below.  lbits is the number of bits the first level table for literal/
   length codes can decode in one step, and dbits is the same thing for
   length codes can decode in one step, and dbits is the same thing for
   the distance codes.  Subsequent tables are also less than or equal to
   the distance codes.  Subsequent tables are also less than or equal to
   those sizes.  These values may be adjusted either when all of the
   those sizes.  These values may be adjusted either when all of the
   codes are shorter than that, in which case the longest code length in
   codes are shorter than that, in which case the longest code length in
   bits is used, or when the shortest code is *longer* than the requested
   bits is used, or when the shortest code is *longer* than the requested
   table size, in which case the length of the shortest code in bits is
   table size, in which case the length of the shortest code in bits is
   used.
   used.
 
 
   There are two different values for the two tables, since they code a
   There are two different values for the two tables, since they code a
   different number of possibilities each.  The literal/length table
   different number of possibilities each.  The literal/length table
   codes 286 possible values, or in a flat code, a little over eight
   codes 286 possible values, or in a flat code, a little over eight
   bits.  The distance table codes 30 possible values, or a little less
   bits.  The distance table codes 30 possible values, or a little less
   than five bits, flat.  The optimum values for speed end up being
   than five bits, flat.  The optimum values for speed end up being
   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
   about one bit more than those, so lbits is 8+1 and dbits is 5+1.
   The optimum values may differ though from machine to machine, and
   The optimum values may differ though from machine to machine, and
   possibly even between compilers.  Your mileage may vary.
   possibly even between compilers.  Your mileage may vary.
 */
 */
 
 
 
 
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15         /* maximum bit length of any code */
#define BMAX 15         /* maximum bit length of any code */
 
 
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
uIntf *b;               /* code lengths in bits (all assumed <= BMAX) */
uInt n;                 /* number of codes (assumed <= 288) */
uInt n;                 /* number of codes (assumed <= 288) */
uInt s;                 /* number of simple-valued codes (0..s-1) */
uInt s;                 /* number of simple-valued codes (0..s-1) */
const uIntf *d;         /* list of base values for non-simple codes */
const uIntf *d;         /* list of base values for non-simple codes */
const uIntf *e;         /* list of extra bits for non-simple codes */
const uIntf *e;         /* list of extra bits for non-simple codes */
inflate_huft * FAR *t;  /* result: starting table */
inflate_huft * FAR *t;  /* result: starting table */
uIntf *m;               /* maximum lookup bits, returns actual */
uIntf *m;               /* maximum lookup bits, returns actual */
inflate_huft *hp;       /* space for trees */
inflate_huft *hp;       /* space for trees */
uInt *hn;               /* hufts used in space */
uInt *hn;               /* hufts used in space */
uIntf *v;               /* working area: values in order of bit length */
uIntf *v;               /* working area: values in order of bit length */
/* Given a list of code lengths and a maximum table size, make a set of
/* Given a list of code lengths and a maximum table size, make a set of
   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
   tables to decode that set of codes.  Return Z_OK on success, Z_BUF_ERROR
   if the given code set is incomplete (the tables are still built in this
   if the given code set is incomplete (the tables are still built in this
   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
   case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
   lengths), or Z_MEM_ERROR if not enough memory. */
   lengths), or Z_MEM_ERROR if not enough memory. */
{
{
 
 
  uInt a;                       /* counter for codes of length k */
  uInt a;                       /* counter for codes of length k */
  uInt c[BMAX+1];               /* bit length count table */
  uInt c[BMAX+1];               /* bit length count table */
  uInt f;                       /* i repeats in table every f entries */
  uInt f;                       /* i repeats in table every f entries */
  int g;                        /* maximum code length */
  int g;                        /* maximum code length */
  int h;                        /* table level */
  int h;                        /* table level */
  register uInt i;              /* counter, current code */
  register uInt i;              /* counter, current code */
  register uInt j;              /* counter */
  register uInt j;              /* counter */
  register int k;               /* number of bits in current code */
  register int k;               /* number of bits in current code */
  int l;                        /* bits per table (returned in m) */
  int l;                        /* bits per table (returned in m) */
  uInt mask;                    /* (1 << w) - 1, to avoid cc -O bug on HP */
  uInt mask;                    /* (1 << w) - 1, to avoid cc -O bug on HP */
  register uIntf *p;            /* pointer into c[], b[], or v[] */
  register uIntf *p;            /* pointer into c[], b[], or v[] */
  inflate_huft *q;              /* points to current table */
  inflate_huft *q;              /* points to current table */
  struct inflate_huft_s r;      /* table entry for structure assignment */
  struct inflate_huft_s r;      /* table entry for structure assignment */
  inflate_huft *u[BMAX];        /* table stack */
  inflate_huft *u[BMAX];        /* table stack */
  register int w;               /* bits before this table == (l * h) */
  register int w;               /* bits before this table == (l * h) */
  uInt x[BMAX+1];               /* bit offsets, then code stack */
  uInt x[BMAX+1];               /* bit offsets, then code stack */
  uIntf *xp;                    /* pointer into x */
  uIntf *xp;                    /* pointer into x */
  int y;                        /* number of dummy codes added */
  int y;                        /* number of dummy codes added */
  uInt z;                       /* number of entries in current table */
  uInt z;                       /* number of entries in current table */
 
 
 
 
  /* Generate counts for each bit length */
  /* Generate counts for each bit length */
  p = c;
  p = c;
#define C0 *p++ = 0;
#define C0 *p++ = 0;
#define C2 C0 C0 C0 C0
#define C2 C0 C0 C0 C0
#define C4 C2 C2 C2 C2
#define C4 C2 C2 C2 C2
  C4                            /* clear c[]--assume BMAX+1 is 16 */
  C4                            /* clear c[]--assume BMAX+1 is 16 */
  p = b;  i = n;
  p = b;  i = n;
  do {
  do {
    c[*p++]++;                  /* assume all entries <= BMAX */
    c[*p++]++;                  /* assume all entries <= BMAX */
  } while (--i);
  } while (--i);
  if (c[0] == n)                /* null input--all zero length codes */
  if (c[0] == n)                /* null input--all zero length codes */
  {
  {
    *t = (inflate_huft *)Z_NULL;
    *t = (inflate_huft *)Z_NULL;
    *m = 0;
    *m = 0;
    return Z_OK;
    return Z_OK;
  }
  }
 
 
 
 
  /* Find minimum and maximum length, bound *m by those */
  /* Find minimum and maximum length, bound *m by those */
  l = *m;
  l = *m;
  for (j = 1; j <= BMAX; j++)
  for (j = 1; j <= BMAX; j++)
    if (c[j])
    if (c[j])
      break;
      break;
  k = j;                        /* minimum code length */
  k = j;                        /* minimum code length */
  if ((uInt)l < j)
  if ((uInt)l < j)
    l = j;
    l = j;
  for (i = BMAX; i; i--)
  for (i = BMAX; i; i--)
    if (c[i])
    if (c[i])
      break;
      break;
  g = i;                        /* maximum code length */
  g = i;                        /* maximum code length */
  if ((uInt)l > i)
  if ((uInt)l > i)
    l = i;
    l = i;
  *m = l;
  *m = l;
 
 
 
 
  /* Adjust last length count to fill out codes, if needed */
  /* Adjust last length count to fill out codes, if needed */
  for (y = 1 << j; j < i; j++, y <<= 1)
  for (y = 1 << j; j < i; j++, y <<= 1)
    if ((y -= c[j]) < 0)
    if ((y -= c[j]) < 0)
      return Z_DATA_ERROR;
      return Z_DATA_ERROR;
  if ((y -= c[i]) < 0)
  if ((y -= c[i]) < 0)
    return Z_DATA_ERROR;
    return Z_DATA_ERROR;
  c[i] += y;
  c[i] += y;
 
 
 
 
  /* Generate starting offsets into the value table for each length */
  /* Generate starting offsets into the value table for each length */
  x[1] = j = 0;
  x[1] = j = 0;
  p = c + 1;  xp = x + 2;
  p = c + 1;  xp = x + 2;
  while (--i) {                 /* note that i == g from above */
  while (--i) {                 /* note that i == g from above */
    *xp++ = (j += *p++);
    *xp++ = (j += *p++);
  }
  }
 
 
 
 
  /* Make a table of values in order of bit lengths */
  /* Make a table of values in order of bit lengths */
  p = b;  i = 0;
  p = b;  i = 0;
  do {
  do {
    if ((j = *p++) != 0)
    if ((j = *p++) != 0)
      v[x[j]++] = i;
      v[x[j]++] = i;
  } while (++i < n);
  } while (++i < n);
  n = x[g];                     /* set n to length of v */
  n = x[g];                     /* set n to length of v */
 
 
 
 
  /* Generate the Huffman codes and for each, make the table entries */
  /* Generate the Huffman codes and for each, make the table entries */
  x[0] = i = 0;                 /* first Huffman code is zero */
  x[0] = i = 0;                 /* first Huffman code is zero */
  p = v;                        /* grab values in bit order */
  p = v;                        /* grab values in bit order */
  h = -1;                       /* no tables yet--level -1 */
  h = -1;                       /* no tables yet--level -1 */
  w = -l;                       /* bits decoded == (l * h) */
  w = -l;                       /* bits decoded == (l * h) */
  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
  u[0] = (inflate_huft *)Z_NULL;        /* just to keep compilers happy */
  q = (inflate_huft *)Z_NULL;   /* ditto */
  q = (inflate_huft *)Z_NULL;   /* ditto */
  z = 0;                        /* ditto */
  z = 0;                        /* ditto */
 
 
  /* go through the bit lengths (k already is bits in shortest code) */
  /* go through the bit lengths (k already is bits in shortest code) */
  for (; k <= g; k++)
  for (; k <= g; k++)
  {
  {
    a = c[k];
    a = c[k];
    while (a--)
    while (a--)
    {
    {
      /* here i is the Huffman code of length k bits for value *p */
      /* here i is the Huffman code of length k bits for value *p */
      /* make tables up to required level */
      /* make tables up to required level */
      while (k > w + l)
      while (k > w + l)
      {
      {
        h++;
        h++;
        w += l;                 /* previous table always l bits */
        w += l;                 /* previous table always l bits */
 
 
        /* compute minimum size table less than or equal to l bits */
        /* compute minimum size table less than or equal to l bits */
        z = g - w;
        z = g - w;
        z = z > (uInt)l ? l : z;        /* table size upper limit */
        z = z > (uInt)l ? l : z;        /* table size upper limit */
        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
        if ((f = 1 << (j = k - w)) > a + 1)     /* try a k-w bit table */
        {                       /* too few codes for k-w bit table */
        {                       /* too few codes for k-w bit table */
          f -= a + 1;           /* deduct codes from patterns left */
          f -= a + 1;           /* deduct codes from patterns left */
          xp = c + k;
          xp = c + k;
          if (j < z)
          if (j < z)
            while (++j < z)     /* try smaller tables up to z bits */
            while (++j < z)     /* try smaller tables up to z bits */
            {
            {
              if ((f <<= 1) <= *++xp)
              if ((f <<= 1) <= *++xp)
                break;          /* enough codes to use up j bits */
                break;          /* enough codes to use up j bits */
              f -= *xp;         /* else deduct codes from patterns */
              f -= *xp;         /* else deduct codes from patterns */
            }
            }
        }
        }
        z = 1 << j;             /* table entries for j-bit table */
        z = 1 << j;             /* table entries for j-bit table */
 
 
        /* allocate new table */
        /* allocate new table */
        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
        if (*hn + z > MANY)     /* (note: doesn't matter for fixed) */
          return Z_MEM_ERROR;   /* not enough memory */
          return Z_MEM_ERROR;   /* not enough memory */
        u[h] = q = hp + *hn;
        u[h] = q = hp + *hn;
        *hn += z;
        *hn += z;
 
 
        /* connect to last table, if there is one */
        /* connect to last table, if there is one */
        if (h)
        if (h)
        {
        {
          x[h] = i;             /* save pattern for backing up */
          x[h] = i;             /* save pattern for backing up */
          r.bits = (Byte)l;     /* bits to dump before this table */
          r.bits = (Byte)l;     /* bits to dump before this table */
          r.exop = (Byte)j;     /* bits in this table */
          r.exop = (Byte)j;     /* bits in this table */
          j = i >> (w - l);
          j = i >> (w - l);
          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
          r.base = (uInt)(q - u[h-1] - j);   /* offset to this table */
          u[h-1][j] = r;        /* connect to last table */
          u[h-1][j] = r;        /* connect to last table */
        }
        }
        else
        else
          *t = q;               /* first table is returned result */
          *t = q;               /* first table is returned result */
      }
      }
 
 
      /* set up table entry in r */
      /* set up table entry in r */
      r.bits = (Byte)(k - w);
      r.bits = (Byte)(k - w);
      if (p >= v + n)
      if (p >= v + n)
        r.exop = 128 + 64;      /* out of values--invalid code */
        r.exop = 128 + 64;      /* out of values--invalid code */
      else if (*p < s)
      else if (*p < s)
      {
      {
        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
        r.exop = (Byte)(*p < 256 ? 0 : 32 + 64);     /* 256 is end-of-block */
        r.base = *p++;          /* simple code is just the value */
        r.base = *p++;          /* simple code is just the value */
      }
      }
      else
      else
      {
      {
        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
        r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
        r.base = d[*p++ - s];
        r.base = d[*p++ - s];
      }
      }
 
 
      /* fill code-like entries with r */
      /* fill code-like entries with r */
      f = 1 << (k - w);
      f = 1 << (k - w);
      for (j = i >> w; j < z; j += f)
      for (j = i >> w; j < z; j += f)
        q[j] = r;
        q[j] = r;
 
 
      /* backwards increment the k-bit code i */
      /* backwards increment the k-bit code i */
      for (j = 1 << (k - 1); i & j; j >>= 1)
      for (j = 1 << (k - 1); i & j; j >>= 1)
        i ^= j;
        i ^= j;
      i ^= j;
      i ^= j;
 
 
      /* backup over finished tables */
      /* backup over finished tables */
      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
      mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
      while ((i & mask) != x[h])
      while ((i & mask) != x[h])
      {
      {
        h--;                    /* don't need to update q */
        h--;                    /* don't need to update q */
        w -= l;
        w -= l;
        mask = (1 << w) - 1;
        mask = (1 << w) - 1;
      }
      }
    }
    }
  }
  }
 
 
 
 
  /* Return Z_BUF_ERROR if we were given an incomplete table */
  /* Return Z_BUF_ERROR if we were given an incomplete table */
  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
  return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}
}
 
 
 
 
int zlib_inflate_trees_bits(c, bb, tb, hp, z)
int zlib_inflate_trees_bits(c, bb, tb, hp, z)
uIntf *c;               /* 19 code lengths */
uIntf *c;               /* 19 code lengths */
uIntf *bb;              /* bits tree desired/actual depth */
uIntf *bb;              /* bits tree desired/actual depth */
inflate_huft * FAR *tb; /* bits tree result */
inflate_huft * FAR *tb; /* bits tree result */
inflate_huft *hp;       /* space for trees */
inflate_huft *hp;       /* space for trees */
z_streamp z;            /* for messages */
z_streamp z;            /* for messages */
{
{
  int r;
  int r;
  uInt hn = 0;          /* hufts used in space */
  uInt hn = 0;          /* hufts used in space */
  uIntf *v;             /* work area for huft_build */
  uIntf *v;             /* work area for huft_build */
 
 
  v = WS(z)->tree_work_area_1;
  v = WS(z)->tree_work_area_1;
  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
  r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
                 tb, bb, hp, &hn, v);
                 tb, bb, hp, &hn, v);
  if (r == Z_DATA_ERROR)
  if (r == Z_DATA_ERROR)
    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
    z->msg = (char*)"oversubscribed dynamic bit lengths tree";
  else if (r == Z_BUF_ERROR || *bb == 0)
  else if (r == Z_BUF_ERROR || *bb == 0)
  {
  {
    z->msg = (char*)"incomplete dynamic bit lengths tree";
    z->msg = (char*)"incomplete dynamic bit lengths tree";
    r = Z_DATA_ERROR;
    r = Z_DATA_ERROR;
  }
  }
  return r;
  return r;
}
}
 
 
int zlib_inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
int zlib_inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
uInt nl;                /* number of literal/length codes */
uInt nl;                /* number of literal/length codes */
uInt nd;                /* number of distance codes */
uInt nd;                /* number of distance codes */
uIntf *c;               /* that many (total) code lengths */
uIntf *c;               /* that many (total) code lengths */
uIntf *bl;              /* literal desired/actual bit depth */
uIntf *bl;              /* literal desired/actual bit depth */
uIntf *bd;              /* distance desired/actual bit depth */
uIntf *bd;              /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */
inflate_huft * FAR *td; /* distance tree result */
inflate_huft *hp;       /* space for trees */
inflate_huft *hp;       /* space for trees */
z_streamp z;            /* for messages */
z_streamp z;            /* for messages */
{
{
  int r;
  int r;
  uInt hn = 0;          /* hufts used in space */
  uInt hn = 0;          /* hufts used in space */
  uIntf *v;             /* work area for huft_build */
  uIntf *v;             /* work area for huft_build */
 
 
  /* allocate work area */
  /* allocate work area */
  v = WS(z)->tree_work_area_2;
  v = WS(z)->tree_work_area_2;
 
 
  /* build literal/length tree */
  /* build literal/length tree */
  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
  r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
  if (r != Z_OK || *bl == 0)
  if (r != Z_OK || *bl == 0)
  {
  {
    if (r == Z_DATA_ERROR)
    if (r == Z_DATA_ERROR)
      z->msg = (char*)"oversubscribed literal/length tree";
      z->msg = (char*)"oversubscribed literal/length tree";
    else if (r != Z_MEM_ERROR)
    else if (r != Z_MEM_ERROR)
    {
    {
      z->msg = (char*)"incomplete literal/length tree";
      z->msg = (char*)"incomplete literal/length tree";
      r = Z_DATA_ERROR;
      r = Z_DATA_ERROR;
    }
    }
    return r;
    return r;
  }
  }
 
 
  /* build distance tree */
  /* build distance tree */
  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
  r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
  if (r != Z_OK || (*bd == 0 && nl > 257))
  if (r != Z_OK || (*bd == 0 && nl > 257))
  {
  {
    if (r == Z_DATA_ERROR)
    if (r == Z_DATA_ERROR)
      z->msg = (char*)"oversubscribed distance tree";
      z->msg = (char*)"oversubscribed distance tree";
    else if (r == Z_BUF_ERROR) {
    else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
#ifdef PKZIP_BUG_WORKAROUND
      r = Z_OK;
      r = Z_OK;
    }
    }
#else
#else
      z->msg = (char*)"incomplete distance tree";
      z->msg = (char*)"incomplete distance tree";
      r = Z_DATA_ERROR;
      r = Z_DATA_ERROR;
    }
    }
    else if (r != Z_MEM_ERROR)
    else if (r != Z_MEM_ERROR)
    {
    {
      z->msg = (char*)"empty distance tree with lengths";
      z->msg = (char*)"empty distance tree with lengths";
      r = Z_DATA_ERROR;
      r = Z_DATA_ERROR;
    }
    }
    return r;
    return r;
#endif
#endif
  }
  }
 
 
  /* done */
  /* done */
  return Z_OK;
  return Z_OK;
}
}
 
 
 
 
/* build fixed tables only once--keep them here */
/* build fixed tables only once--keep them here */
#include "inffixed.h"
#include "inffixed.h"
 
 
 
 
int zlib_inflate_trees_fixed(bl, bd, tl, td, z)
int zlib_inflate_trees_fixed(bl, bd, tl, td, z)
uIntf *bl;               /* literal desired/actual bit depth */
uIntf *bl;               /* literal desired/actual bit depth */
uIntf *bd;               /* distance desired/actual bit depth */
uIntf *bd;               /* distance desired/actual bit depth */
inflate_huft * FAR *tl;  /* literal/length tree result */
inflate_huft * FAR *tl;  /* literal/length tree result */
inflate_huft * FAR *td;  /* distance tree result */
inflate_huft * FAR *td;  /* distance tree result */
z_streamp z;             /* for memory allocation */
z_streamp z;             /* for memory allocation */
{
{
  *bl = fixed_bl;
  *bl = fixed_bl;
  *bd = fixed_bd;
  *bd = fixed_bd;
  *tl = fixed_tl;
  *tl = fixed_tl;
  *td = fixed_td;
  *td = fixed_td;
  return Z_OK;
  return Z_OK;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.