misc/libfreetype/src/gzip/infcodes.c
author koda
Mon, 31 Oct 2011 01:44:32 +0100
changeset 6246 6b2d19ed521a
parent 5172 88f2e05288ba
permissions -rw-r--r--
just moving ios server stuff around
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/* infcodes.c -- process literals and length/distance pairs
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
 * Copyright (C) 1995-2002 Mark Adler
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
 * For conditions of distribution and use, see copyright notice in zlib.h
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
#include "zutil.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
#include "inftrees.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
#include "infblock.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
#include "infcodes.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
#include "infutil.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/* simplify the use of the inflate_huft type with some defines */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
#define exop word.what.Exop
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
#define bits word.what.Bits
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
typedef enum {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
      START,    /* x: set up for LEN */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
      LEN,      /* i: get length/literal/eob next */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
      LENEXT,   /* i: getting length extra (have base) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
      DIST,     /* i: get distance next */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
      DISTEXT,  /* i: getting distance extra */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
      COPY,     /* o: copying bytes in window, waiting for space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
      LIT,      /* o: got literal, waiting for output space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
      WASH,     /* o: got eob, possibly still output waiting */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
      END,      /* x: got eob and all data flushed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
      BADCODE}  /* x: got error */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
inflate_codes_mode;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
/* inflate codes private state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
struct inflate_codes_state {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* mode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  inflate_codes_mode mode;      /* current inflate_codes mode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* mode dependent information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  uInt len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  union {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
    struct {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
      inflate_huft *tree;       /* pointer into tree */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
      uInt need;                /* bits needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    } code;             /* if LEN or DIST, where in tree */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    uInt lit;           /* if LIT, literal */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
    struct {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
      uInt get;                 /* bits to get for extra */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
      uInt dist;                /* distance back to copy from */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    } copy;             /* if EXT or COPY, where and how much */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  } sub;                /* submode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  /* mode independent information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  Byte lbits;           /* ltree bits decoded per branch */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
  Byte dbits;           /* dtree bits decoder per branch */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  inflate_huft *ltree;          /* literal/length/eob tree */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
  inflate_huft *dtree;          /* distance tree */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
};
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
local inflate_codes_statef *inflate_codes_new( /* bl, bd, tl, td, z) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
uInt bl, uInt bd,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
inflate_huft *tl,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
inflate_huft *td, /* need separate declaration for Borland C++ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
z_streamp z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  inflate_codes_statef *c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  if ((c = (inflate_codes_statef *)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    c->mode = START;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    c->lbits = (Byte)bl;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    c->dbits = (Byte)bd;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    c->ltree = tl;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    c->dtree = td;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    Tracev((stderr, "inflate:       codes new\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  return c;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
local int inflate_codes( /* s, z, r) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
inflate_blocks_statef *s,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
z_streamp z,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
int r )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  uInt j;               /* temporary storage */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  inflate_huft *t;      /* temporary pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  uInt e;               /* extra bits or operation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  uLong b;              /* bit buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  uInt k;               /* bits in bit buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  Bytef *p;             /* input data pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  uInt n;               /* bytes available there */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  Bytef *q;             /* output window write pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  uInt m;               /* bytes to end of window or read pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  Bytef *f;             /* pointer to copy strings from */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  /* copy input/output information to locals (UPDATE macro restores) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
  LOAD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  /* process input and output based on current state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  while (1) switch (c->mode)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    case START:         /* x: set up for LEN */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
#ifndef SLOW
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
      if (m >= 258 && n >= 10)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
        UPDATE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
        LOAD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
        if (r != Z_OK)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
#endif /* !SLOW */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      c->sub.code.need = c->lbits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
      c->sub.code.tree = c->ltree;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      c->mode = LEN;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    case LEN:           /* i: get length/literal/eob next */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      j = c->sub.code.need;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      NEEDBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      DUMPBITS(t->bits)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      e = (uInt)(t->exop);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      if (e == 0)               /* literal */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
        c->sub.lit = t->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
                 "inflate:         literal '%c'\n" :
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
                 "inflate:         literal 0x%02x\n", t->base));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
        c->mode = LIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      if (e & 16)               /* length */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
        c->sub.copy.get = e & 15;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
        c->len = t->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
        c->mode = LENEXT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      if ((e & 64) == 0)        /* next table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
        c->sub.code.need = e;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
        c->sub.code.tree = t + t->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      if (e & 32)               /* end of block */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
        Tracevv((stderr, "inflate:         end of block\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
        c->mode = WASH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      c->mode = BADCODE;        /* invalid code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
      z->msg = (char*)"invalid literal/length code";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      r = Z_DATA_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
      LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    case LENEXT:        /* i: getting length extra (have base) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      j = c->sub.copy.get;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
      NEEDBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      c->len += (uInt)b & inflate_mask[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      DUMPBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      c->sub.code.need = c->dbits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      c->sub.code.tree = c->dtree;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      Tracevv((stderr, "inflate:         length %u\n", c->len));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      c->mode = DIST;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    case DIST:          /* i: get distance next */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      j = c->sub.code.need;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      NEEDBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      DUMPBITS(t->bits)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      e = (uInt)(t->exop);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
      if (e & 16)               /* distance */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
        c->sub.copy.get = e & 15;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
        c->sub.copy.dist = t->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
        c->mode = DISTEXT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      if ((e & 64) == 0)        /* next table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
        c->sub.code.need = e;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        c->sub.code.tree = t + t->base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      c->mode = BADCODE;        /* invalid code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      z->msg = (char*)"invalid distance code";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      r = Z_DATA_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
      LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    case DISTEXT:       /* i: getting distance extra */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
      j = c->sub.copy.get;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      NEEDBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      c->sub.copy.dist += (uInt)b & inflate_mask[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      DUMPBITS(j)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      c->mode = COPY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    case COPY:          /* o: copying bytes in window, waiting for space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      f = q - c->sub.copy.dist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      while (f < s->window)             /* modulo window size-"while" instead */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
        f += s->end - s->window;        /* of "if" handles invalid distances */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      while (c->len)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
        NEEDOUT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
        OUTBYTE(*f++)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
        if (f == s->end)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          f = s->window;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        c->len--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      c->mode = START;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
    case LIT:           /* o: got literal, waiting for output space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
      NEEDOUT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      OUTBYTE(c->sub.lit)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      c->mode = START;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    case WASH:          /* o: got eob, possibly more output */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      if (k > 7)        /* return unused byte, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
        Assert(k < 16, "inflate_codes grabbed too many bytes")
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
        k -= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        n++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
        p--;            /* can always return one */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      FLUSH
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      if (s->read != s->write)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
        LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      c->mode = END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    case END:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      r = Z_STREAM_END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    case BADCODE:       /* x: got error */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
      r = Z_DATA_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      r = Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      LEAVE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
#ifdef NEED_DUMMY_RETURN
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
local void inflate_codes_free( /* c, z) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
inflate_codes_statef *c,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
z_streamp z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  ZFREE(z, c);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  Tracev((stderr, "inflate:       codes free\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
}