Back to index

plt-scheme  4.2.1
Classes | Defines | Enumerations | Functions
infcodes.c File Reference
#include "zutil.h"
#include "inftrees.h"
#include "infblock.h"
#include "infcodes.h"
#include "infutil.h"
#include "inffast.h"

Go to the source code of this file.

Classes

struct  inflate_codes_state
union  inflate_codes_state.sub
struct  inflate_codes_state.sub.code
struct  inflate_codes_state.sub.copy

Defines

#define exop   word.what.Exop
#define bits   word.what.Bits

Enumerations

enum  inflate_codes_mode {
  START, LEN, LENEXT, DIST,
  DISTEXT, COPY, LIT, WASH,
  END, BADCODE, START, LEN,
  LENEXT, DIST, DISTEXT, COPY,
  LIT, WASH, END, BADCODE
}

Functions

inflate_codes_statef * inflate_codes_new (uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, z_streamp z)
int inflate_codes (inflate_blocks_statef *s, z_streamp z, int r)
void inflate_codes_free (inflate_codes_statef *c, z_streamp z)

Class Documentation

struct inflate_codes_state

Definition at line 12 of file infblock.c.

Class Members
Byte dbits
inflate_huft * dtree
int dummy
Byte lbits
uInt len
inflate_huft * ltree
inflate_codes_mode mode
union inflate_codes_state sub
union inflate_codes_state sub
union inflate_codes_state.sub

Definition at line 38 of file infcodes.c.

Class Members
sub code
sub copy
uInt lit
struct inflate_codes_state.sub.code

Definition at line 39 of file infcodes.c.

Class Members
uInt need
inflate_huft * tree
struct inflate_codes_state.sub.copy

Definition at line 44 of file infcodes.c.

Class Members
uInt dist
uInt get

Define Documentation

#define bits   word.what.Bits

Definition at line 15 of file infcodes.c.

#define exop   word.what.Exop

Definition at line 14 of file infcodes.c.


Enumeration Type Documentation

Enumerator:
START 
LEN 
LENEXT 
DIST 
DISTEXT 
COPY 
LIT 
WASH 
END 
BADCODE 
START 
LEN 
LENEXT 
DIST 
DISTEXT 
COPY 
LIT 
WASH 
END 
BADCODE 

Definition at line 17 of file infcodes.c.

             {        /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
      START,    /* x: set up for LEN */
      LEN,      /* i: get length/literal/eob next */
      LENEXT,   /* i: getting length extra (have base) */
      DIST,     /* i: get distance next */
      DISTEXT,  /* i: getting distance extra */
      COPY,     /* o: copying bytes in window, waiting for space */
      LIT,      /* o: got literal, waiting for output space */
      WASH,     /* o: got eob, possibly still output waiting */
      END,      /* x: got eob and all data flushed */
      BADCODE}  /* x: got error */

Function Documentation

int inflate_codes ( inflate_blocks_statef *  s,
z_streamp  z,
int  r 
)

Definition at line 81 of file infcodes.c.

{
  uInt j;               /* temporary storage */
  inflate_huft *t;      /* temporary pointer */
  uInt e;               /* extra bits or operation */
  uLong b;              /* bit buffer */
  uInt k;               /* bits in bit buffer */
  Bytef *p;             /* input data pointer */
  uInt n;               /* bytes available there */
  Bytef *q;             /* output window write pointer */
  uInt m;               /* bytes to end of window or read pointer */
  Bytef *f;             /* pointer to copy strings from */
  inflate_codes_statef *c = s->sub.decode.codes;  /* codes state */

  /* copy input/output information to locals (UPDATE macro restores) */
  LOAD

  /* process input and output based on current state */
  while (1) switch (c->mode)
  {             /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
    case START:         /* x: set up for LEN */
#ifndef SLOW
      if (m >= 258 && n >= 10)
      {
        UPDATE
        r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
        LOAD
        if (r != Z_OK)
        {
          c->mode = r == Z_STREAM_END ? WASH : BADCODE;
          break;
        }
      }
#endif /* !SLOW */
      c->sub.code.need = c->lbits;
      c->sub.code.tree = c->ltree;
      c->mode = LEN;
    case LEN:           /* i: get length/literal/eob next */
      j = c->sub.code.need;
      NEEDBITS(j)
      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
      DUMPBITS(t->bits)
      e = (uInt)(t->exop);
      if (e == 0)               /* literal */
      {
        c->sub.lit = t->base;
        Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
                 "inflate:         literal '%c'\n" :
                 "inflate:         literal 0x%02x\n", t->base));
        c->mode = LIT;
        break;
      }
      if (e & 16)               /* length */
      {
        c->sub.copy.get = e & 15;
        c->len = t->base;
        c->mode = LENEXT;
        break;
      }
      if ((e & 64) == 0)        /* next table */
      {
        c->sub.code.need = e;
        c->sub.code.tree = t + t->base;
        break;
      }
      if (e & 32)               /* end of block */
      {
        Tracevv((stderr, "inflate:         end of block\n"));
        c->mode = WASH;
        break;
      }
      c->mode = BADCODE;        /* invalid code */
      z->msg = (char*)"invalid literal/length code";
      r = Z_DATA_ERROR;
      LEAVE
    case LENEXT:        /* i: getting length extra (have base) */
      j = c->sub.copy.get;
      NEEDBITS(j)
      c->len += (uInt)b & inflate_mask[j];
      DUMPBITS(j)
      c->sub.code.need = c->dbits;
      c->sub.code.tree = c->dtree;
      Tracevv((stderr, "inflate:         length %u\n", c->len));
      c->mode = DIST;
    case DIST:          /* i: get distance next */
      j = c->sub.code.need;
      NEEDBITS(j)
      t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
      DUMPBITS(t->bits)
      e = (uInt)(t->exop);
      if (e & 16)               /* distance */
      {
        c->sub.copy.get = e & 15;
        c->sub.copy.dist = t->base;
        c->mode = DISTEXT;
        break;
      }
      if ((e & 64) == 0)        /* next table */
      {
        c->sub.code.need = e;
        c->sub.code.tree = t + t->base;
        break;
      }
      c->mode = BADCODE;        /* invalid code */
      z->msg = (char*)"invalid distance code";
      r = Z_DATA_ERROR;
      LEAVE
    case DISTEXT:       /* i: getting distance extra */
      j = c->sub.copy.get;
      NEEDBITS(j)
      c->sub.copy.dist += (uInt)b & inflate_mask[j];
      DUMPBITS(j)
      Tracevv((stderr, "inflate:         distance %u\n", c->sub.copy.dist));
      c->mode = COPY;
    case COPY:          /* o: copying bytes in window, waiting for space */
      f = q - c->sub.copy.dist;
      while (f < s->window)             /* modulo window size-"while" instead */
        f += s->end - s->window;        /* of "if" handles invalid distances */
      while (c->len)
      {
        NEEDOUT
        OUTBYTE(*f++)
        if (f == s->end)
          f = s->window;
        c->len--;
      }
      c->mode = START;
      break;
    case LIT:           /* o: got literal, waiting for output space */
      NEEDOUT
      OUTBYTE(c->sub.lit)
      c->mode = START;
      break;
    case WASH:          /* o: got eob, possibly more output */
      if (k > 7)        /* return unused byte, if any */
      {
        Assert(k < 16, "inflate_codes grabbed too many bytes")
        k -= 8;
        n++;
        p--;            /* can always return one */
      }
      FLUSH
      if (s->read != s->write)
        LEAVE
      c->mode = END;
    case END:
      r = Z_STREAM_END;
      LEAVE
    case BADCODE:       /* x: got error */
      r = Z_DATA_ERROR;
      LEAVE
    default:
      r = Z_STREAM_ERROR;
      LEAVE
  }
#ifdef NEED_DUMMY_RETURN
  return Z_STREAM_ERROR;  /* Some dumb compilers complain without this */
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void inflate_codes_free ( inflate_codes_statef *  c,
z_streamp  z 
)

Definition at line 245 of file infcodes.c.

{
  ZFREE(z, c);
  Tracev((stderr, "inflate:       codes free\n"));
}

Here is the caller graph for this function:

inflate_codes_statef* inflate_codes_new ( uInt  bl,
uInt  bd,
inflate_huft *  tl,
inflate_huft *  td,
z_streamp  z 
)

Definition at line 59 of file infcodes.c.

{
  inflate_codes_statef *c;

  if ((c = (inflate_codes_statef *)
       ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
  {
    c->mode = START;
    c->lbits = (Byte)bl;
    c->dbits = (Byte)bd;
    c->ltree = tl;
    c->dtree = td;
    Tracev((stderr, "inflate:       codes new\n"));
  }
  return c;
}

Here is the caller graph for this function: