Back to index

plt-scheme  4.2.1
Classes | Defines | Enumerations | Functions
inflate.c File Reference
#include "zutil.h"
#include "infblock.h"

Go to the source code of this file.

Classes

struct  inflate_blocks_state
struct  internal_state
union  internal_state.sub
struct  internal_state.sub.check

Defines

#define NEEDBYTE   {if(z->avail_in==0)return r;r=f;}
#define NEXTBYTE   (z->avail_in--,z->total_in++,*z->next_in++)

Enumerations

enum  inflate_mode {
  METHOD, FLAG, DICT4, DICT3,
  DICT2, DICT1, DICT0, BLOCKS,
  CHECK4, CHECK3, CHECK2, CHECK1,
  DONE, BAD, METHOD, FLAG,
  DICT4, DICT3, DICT2, DICT1,
  DICT0, BLOCKS, CHECK4, CHECK3,
  CHECK2, CHECK1, DONE, BAD
}

Functions

int ZEXPORT inflateReset (z_streamp z)
int ZEXPORT inflateEnd (z_streamp z)
int ZEXPORT inflateInit2_ (z_streamp z, int w, const char *version, int stream_size)
int ZEXPORT inflateInit_ (z_streamp z, const char *version, int stream_size)
int ZEXPORT inflate (z_streamp z, int f)
int ZEXPORT inflateSetDictionary (z_streamp z, const Bytef *dictionary, uInt dictLength)
int ZEXPORT inflateSync (z_streamp z)
int ZEXPORT inflateSyncPoint (z_streamp z)

Class Documentation

struct inflate_blocks_state

Definition at line 9 of file inflate.c.

Class Members
uLong bitb
uInt bitk
uLong check
check_func checkfn
int dummy
Bytef * end
inflate_huft * hufts
uInt last
inflate_block_mode mode
Bytef * read
union inflate_blocks_state sub
union inflate_blocks_state sub
Bytef * window
Bytef * write
struct internal_state

Definition at line 82 of file deflate.h.

Collaboration diagram for internal_state:
Class Members
ush bi_buf
int bi_valid
ush bl_count
long block_start
inflate_blocks_statef * blocks
ushf * d_buf
Byte data_type
uch depth
int dummy
uInt good_match
uInt hash_bits
uInt hash_mask
uInt hash_shift
uInt hash_size
Posf * head
int heap
int heap_len
int heap_max
uInt ins_h
uchf * l_buf
int last_eob_len
int last_flush
uInt last_lit
int level
uInt lit_bufsize
uInt lookahead
int match_available
uInt match_length
uInt match_start
uInt matches
uInt max_chain_length
uInt max_lazy_match
Byte method
inflate_mode mode
int nice_match
int noheader
int nowrap
ulg opt_len
int pending
Bytef * pending_buf
ulg pending_buf_size
Bytef * pending_out
Posf * prev
uInt prev_length
IPos prev_match
ulg static_len
int status
int strategy
z_streamp strm
uInt strstart
union internal_state sub
union internal_state sub
uInt w_bits
uInt w_mask
uInt w_size
uInt wbits
Bytef * window
ulg window_size
union internal_state.sub

Definition at line 35 of file inflate.c.

Class Members
sub check
uInt marker
uInt method
struct internal_state.sub.check

Definition at line 37 of file inflate.c.

Class Members
uLong need
uLong was

Define Documentation

#define NEEDBYTE   {if(z->avail_in==0)return r;r=f;}

Definition at line 147 of file inflate.c.

#define NEXTBYTE   (z->avail_in--,z->total_in++,*z->next_in++)

Definition at line 148 of file inflate.c.


Enumeration Type Documentation

Enumerator:
METHOD 
FLAG 
DICT4 
DICT3 
DICT2 
DICT1 
DICT0 
BLOCKS 
CHECK4 
CHECK3 
CHECK2 
CHECK1 
DONE 
BAD 
METHOD 
FLAG 
DICT4 
DICT3 
DICT2 
DICT1 
DICT0 
BLOCKS 
CHECK4 
CHECK3 
CHECK2 
CHECK1 
DONE 
BAD 

Definition at line 11 of file inflate.c.

             {
      METHOD,   /* waiting for method byte */
      FLAG,     /* waiting for flag byte */
      DICT4,    /* four dictionary check bytes to go */
      DICT3,    /* three dictionary check bytes to go */
      DICT2,    /* two dictionary check bytes to go */
      DICT1,    /* one dictionary check byte to go */
      DICT0,    /* waiting for inflateSetDictionary */
      BLOCKS,   /* decompressing blocks */
      CHECK4,   /* four check bytes to go */
      CHECK3,   /* three check bytes to go */
      CHECK2,   /* two check bytes to go */
      CHECK1,   /* one check byte to go */
      DONE,     /* finished check, done */
      BAD}      /* got an error--stay here */

Function Documentation

int ZEXPORT inflate ( z_streamp  z,
int  f 
)

Definition at line 150 of file inflate.c.

{
  int r;
  uInt b;

  if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
    return Z_STREAM_ERROR;
  f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
  r = Z_BUF_ERROR;
  while (1) switch (z->state->mode)
  {
    case METHOD:
      NEEDBYTE
      if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
      {
        z->state->mode = BAD;
        z->msg = (char*)"unknown compression method";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
      {
        z->state->mode = BAD;
        z->msg = (char*)"invalid window size";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      z->state->mode = FLAG;
    case FLAG:
      NEEDBYTE
      b = NEXTBYTE;
      if (((z->state->sub.method << 8) + b) % 31)
      {
        z->state->mode = BAD;
        z->msg = (char*)"incorrect header check";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      Tracev((stderr, "inflate: zlib header ok\n"));
      if (!(b & PRESET_DICT))
      {
        z->state->mode = BLOCKS;
        break;
      }
      z->state->mode = DICT4;
    case DICT4:
      NEEDBYTE
      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
      z->state->mode = DICT3;
    case DICT3:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
      z->state->mode = DICT2;
    case DICT2:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
      z->state->mode = DICT1;
    case DICT1:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE;
      z->adler = z->state->sub.check.need;
      z->state->mode = DICT0;
      return Z_NEED_DICT;
    case DICT0:
      z->state->mode = BAD;
      z->msg = (char*)"need dictionary";
      z->state->sub.marker = 0;       /* can try inflateSync */
      return Z_STREAM_ERROR;
    case BLOCKS:
      r = inflate_blocks(z->state->blocks, z, r);
      if (r == Z_DATA_ERROR)
      {
        z->state->mode = BAD;
        z->state->sub.marker = 0;       /* can try inflateSync */
        break;
      }
      if (r == Z_OK)
        r = f;
      if (r != Z_STREAM_END)
        return r;
      r = f;
      inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
      if (z->state->nowrap)
      {
        z->state->mode = DONE;
        break;
      }
      z->state->mode = CHECK4;
    case CHECK4:
      NEEDBYTE
      z->state->sub.check.need = (uLong)NEXTBYTE << 24;
      z->state->mode = CHECK3;
    case CHECK3:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 16;
      z->state->mode = CHECK2;
    case CHECK2:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE << 8;
      z->state->mode = CHECK1;
    case CHECK1:
      NEEDBYTE
      z->state->sub.check.need += (uLong)NEXTBYTE;

      if (z->state->sub.check.was != z->state->sub.check.need)
      {
        z->state->mode = BAD;
        z->msg = (char*)"incorrect data check";
        z->state->sub.marker = 5;       /* can't try inflateSync */
        break;
      }
      Tracev((stderr, "inflate: zlib check ok\n"));
      z->state->mode = DONE;
    case DONE:
      return Z_STREAM_END;
    case BAD:
      return Z_DATA_ERROR;
    default:
      return Z_STREAM_ERROR;
  }
#ifdef NEED_DUMMY_RETURN
  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
#endif
}

Here is the call graph for this function:

Definition at line 67 of file inflate.c.

{
  if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
    return Z_STREAM_ERROR;
  if (z->state->blocks != Z_NULL)
    inflate_blocks_free(z->state->blocks, z);
  ZFREE(z, z->state);
  z->state = Z_NULL;
  Tracev((stderr, "inflate: end\n"));
  return Z_OK;
}

Here is the call graph for this function:

int ZEXPORT inflateInit2_ ( z_streamp  z,
int  w,
const char *  version,
int  stream_size 
)

Definition at line 81 of file inflate.c.

{
  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
      stream_size != sizeof(z_stream))
      return Z_VERSION_ERROR;

  /* initialize state */
  if (z == Z_NULL)
    return Z_STREAM_ERROR;
  z->msg = Z_NULL;
  if (z->zalloc == Z_NULL)
  {
    z->zalloc = zcalloc;
    z->opaque = (voidpf)0;
  }
  if (z->zfree == Z_NULL) z->zfree = zcfree;
  if ((z->state = (struct internal_state FAR *)
       ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
    return Z_MEM_ERROR;
  z->state->blocks = Z_NULL;

  /* handle undocumented nowrap option (no zlib header or check) */
  z->state->nowrap = 0;
  if (w < 0)
  {
    w = - w;
    z->state->nowrap = 1;
  }

  /* set window size */
  if (w < 8 || w > 15)
  {
    inflateEnd(z);
    return Z_STREAM_ERROR;
  }
  z->state->wbits = (uInt)w;

  /* create inflate_blocks state */
  if ((z->state->blocks =
      inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
      == Z_NULL)
  {
    inflateEnd(z);
    return Z_MEM_ERROR;
  }
  Tracev((stderr, "inflate: allocated\n"));

  /* reset state */
  inflateReset(z);
  return Z_OK;
}

Here is the call graph for this function:

int ZEXPORT inflateInit_ ( z_streamp  z,
const char *  version,
int  stream_size 
)

Definition at line 138 of file inflate.c.

{
  return inflateInit2_(z, DEF_WBITS, version, stream_size);
}

Here is the call graph for this function:

Definition at line 53 of file inflate.c.

{
  if (z == Z_NULL || z->state == Z_NULL)
    return Z_STREAM_ERROR;
  z->total_in = z->total_out = 0;
  z->msg = Z_NULL;
  z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
  inflate_blocks_reset(z->state->blocks, z, Z_NULL);
  Tracev((stderr, "inflate: reset\n"));
  return Z_OK;
}

Here is the call graph for this function:

int ZEXPORT inflateSetDictionary ( z_streamp  z,
const Bytef dictionary,
uInt  dictLength 
)

Definition at line 278 of file inflate.c.

{
  uInt length = dictLength;

  if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
    return Z_STREAM_ERROR;

  if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
  z->adler = 1L;

  if (length >= ((uInt)1<<z->state->wbits))
  {
    length = (1<<z->state->wbits)-1;
    dictionary += dictLength - length;
  }
  inflate_set_dictionary(z->state->blocks, dictionary, length);
  z->state->mode = BLOCKS;
  return Z_OK;
}

Here is the call graph for this function:

Definition at line 302 of file inflate.c.

{
  uInt n;       /* number of bytes to look at */
  Bytef *p;     /* pointer to bytes */
  uInt m;       /* number of marker bytes found in a row */
  uLong r, w;   /* temporaries to save total_in and total_out */

  /* set up */
  if (z == Z_NULL || z->state == Z_NULL)
    return Z_STREAM_ERROR;
  if (z->state->mode != BAD)
  {
    z->state->mode = BAD;
    z->state->sub.marker = 0;
  }
  if ((n = z->avail_in) == 0)
    return Z_BUF_ERROR;
  p = z->next_in;
  m = z->state->sub.marker;

  /* search */
  while (n && m < 4)
  {
    static const Byte mark[4] = {0, 0, 0xff, 0xff};
    if (*p == mark[m])
      m++;
    else if (*p)
      m = 0;
    else
      m = 4 - m;
    p++, n--;
  }

  /* restore */
  z->total_in += p - z->next_in;
  z->next_in = p;
  z->avail_in = n;
  z->state->sub.marker = m;

  /* return no joy or set up to restart on a new block */
  if (m != 4)
    return Z_DATA_ERROR;
  r = z->total_in;  w = z->total_out;
  inflateReset(z);
  z->total_in = r;  z->total_out = w;
  z->state->mode = BLOCKS;
  return Z_OK;
}

Here is the call graph for this function:

Definition at line 360 of file inflate.c.

{
  if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
    return Z_STREAM_ERROR;
  return inflate_blocks_sync_point(z->state->blocks);
}

Here is the call graph for this function: