misc/libfreetype/src/gzip/inflate.c
author koda
Tue, 04 Jun 2013 21:59:01 +0200
branch0.9.19
changeset 9123 19c57656460f
parent 5172 88f2e05288ba
permissions -rw-r--r--
trying to appease almighty unC0Rr
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
/* inflate.c -- zlib interface to inflate modules
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 "infblock.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
#define  DONE  INFLATE_DONE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
#define  BAD   INFLATE_BAD
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
typedef enum {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
      METHOD,   /* waiting for method byte */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
      FLAG,     /* waiting for flag byte */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
      DICT4,    /* four dictionary check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
      DICT3,    /* three dictionary check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
      DICT2,    /* two dictionary check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
      DICT1,    /* one dictionary check byte to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
      DICT0,    /* waiting for inflateSetDictionary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
      BLOCKS,   /* decompressing blocks */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
      CHECK4,   /* four check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
      CHECK3,   /* three check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
      CHECK2,   /* two check bytes to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
      CHECK1,   /* one check byte to go */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
      DONE,     /* finished check, done */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
      BAD}      /* got an error--stay here */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
inflate_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 private state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
struct internal_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_mode  mode;   /* current inflate 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
  union {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    uInt method;        /* if FLAGS, method byte */
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
      uLong was;                /* computed check value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
      uLong need;               /* stream check value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    } check;            /* if CHECK, check values to compare */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
    uInt marker;        /* if BAD, inflateSync's marker bytes count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  } sub;        /* submode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  /* mode independent information */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  int  nowrap;          /* flag for no wrapper */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  uInt wbits;           /* log2(window size)  (8..15, defaults to 15) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  inflate_blocks_statef
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    *blocks;            /* current inflate_blocks state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
};
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
ZEXPORT(int) inflateReset( /* z) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
z_streamp z )
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
  if (z == Z_NULL || z->state == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  z->total_in = z->total_out = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
  z->msg = Z_NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  inflate_blocks_reset(z->state->blocks, z, Z_NULL);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  Tracev((stderr, "inflate: reset\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  return Z_OK;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
ZEXPORT(int) inflateEnd( /* z) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
z_streamp z )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  if (z->state->blocks != Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    inflate_blocks_free(z->state->blocks, z);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  ZFREE(z, z->state);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
  z->state = Z_NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  Tracev((stderr, "inflate: end\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  return Z_OK;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
ZEXPORT(int) inflateInit2_( /* z, w, version, stream_size) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
z_streamp z,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
int w,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
const char *version,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
int stream_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      stream_size != sizeof(z_stream))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      return Z_VERSION_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  /* initialize state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  if (z == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
  z->msg = Z_NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
  if (z->zalloc == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    z->zalloc = zcalloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    z->opaque = (voidpf)0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  if (z->zfree == Z_NULL) z->zfree = zcfree;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  if ((z->state = (struct internal_state FAR *)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    return Z_MEM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  z->state->blocks = Z_NULL;
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
  /* handle undocumented nowrap option (no zlib header or check) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  z->state->nowrap = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  if (w < 0)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    w = - w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    z->state->nowrap = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  }
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
  /* set window size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
  if (w < 8 || w > 15)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    inflateEnd(z);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  z->state->wbits = (uInt)w;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
  /* create inflate_blocks state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  if ((z->state->blocks =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      == Z_NULL)
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
    inflateEnd(z);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    return Z_MEM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  Tracev((stderr, "inflate: allocated\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
  /* reset state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  inflateReset(z);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  return Z_OK;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
#undef  NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
#undef  NEXTBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
ZEXPORT(int) inflate( /* z, f) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
z_streamp z,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
int f )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
{
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  int r;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  uInt b;
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
  if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  r = Z_BUF_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  while (1) switch (z->state->mode)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    case METHOD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
        z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
        z->msg = (char*)"unknown compression method";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
        z->state->sub.marker = 5;       /* can't try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
        z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
        z->msg = (char*)"invalid window size";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
        z->state->sub.marker = 5;       /* can't try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      z->state->mode = FLAG;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    case FLAG:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      b = NEXTBYTE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      if (((z->state->sub.method << 8) + b) % 31)
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
        z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        z->msg = (char*)"incorrect header check";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        z->state->sub.marker = 5;       /* can't try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      Tracev((stderr, "inflate: zlib header ok\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
      if (!(b & PRESET_DICT))
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
        z->state->mode = BLOCKS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      z->state->mode = DICT4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    case DICT4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      z->state->mode = DICT3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    case DICT3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      z->state->mode = DICT2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    case DICT2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
      z->state->mode = DICT1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    case DICT1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      z->state->sub.check.need += (uLong)NEXTBYTE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      z->adler = z->state->sub.check.need;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      z->state->mode = DICT0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      return Z_NEED_DICT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    case DICT0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
      z->msg = (char*)"need dictionary";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
      z->state->sub.marker = 0;       /* can try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    case BLOCKS:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      r = inflate_blocks(z->state->blocks, z, r);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      if (r == Z_DATA_ERROR)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
        z->state->sub.marker = 0;       /* can try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      if (r == Z_OK)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
        r = f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      if (r != Z_STREAM_END)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
        return r;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      r = f;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      if (z->state->nowrap)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
        z->state->mode = DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      z->state->mode = CHECK4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    case CHECK4:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      z->state->mode = CHECK3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    case CHECK3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      z->state->mode = CHECK2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    case CHECK2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
      z->state->mode = CHECK1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    case CHECK1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
      NEEDBYTE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
      z->state->sub.check.need += (uLong)NEXTBYTE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      if (z->state->sub.check.was != z->state->sub.check.need)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        z->state->mode = BAD;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
        z->msg = (char*)"incorrect data check";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        z->state->sub.marker = 5;       /* can't try inflateSync */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      Tracev((stderr, "inflate: zlib check ok\n"));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      z->state->mode = DONE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    case DONE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      return Z_STREAM_END;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    case BAD:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
      return Z_DATA_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      return Z_STREAM_ERROR;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
#ifdef NEED_DUMMY_RETURN
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  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
   271
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273