zlib/infutil.h

100 lines
3.6 KiB
C
Raw Normal View History

2011-09-10 01:36:31 -04:00
/* infutil.h -- types and macros common to blocks and codes
2011-09-10 02:14:39 -04:00
* Copyright (C) 1995-1996 Mark Adler
2011-09-10 01:36:31 -04:00
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
2011-09-10 02:14:39 -04:00
#ifndef _INFUTIL_H
#define _INFUTIL_H
2011-09-10 01:36:31 -04:00
2011-09-10 02:14:39 -04:00
typedef enum {
2011-09-10 02:08:07 -04:00
TYPE, /* get type bits (3, including end bit) */
LENS, /* get lengths for stored */
STORED, /* processing stored block */
TABLE, /* get table lengths */
BTREE, /* get bit lengths tree for a dynamic block */
DTREE, /* get length, distance trees for a dynamic block */
CODES, /* processing fixed or dynamic block */
DRY, /* output remaining window bytes */
DONE, /* finished last block, done */
BAD} /* got a data error--stuck here */
2011-09-10 02:14:39 -04:00
inflate_block_mode;
/* inflate blocks semi-private state */
struct inflate_blocks_state {
/* mode */
inflate_block_mode mode; /* current inflate_block mode */
2011-09-10 01:36:31 -04:00
/* mode dependent information */
union {
2011-09-10 02:08:07 -04:00
uInt left; /* if STORED, bytes left to copy */
2011-09-10 01:36:31 -04:00
struct {
2011-09-10 02:08:07 -04:00
uInt table; /* table lengths (14 bits) */
uInt index; /* index into blens (or border) */
2011-09-10 02:09:18 -04:00
uIntf *blens; /* bit lengths of codes */
2011-09-10 02:08:07 -04:00
uInt bb; /* bit length tree depth */
inflate_huft *tb; /* bit length decoding tree */
} trees; /* if DTREE, decoding info for trees */
2011-09-10 02:08:28 -04:00
struct {
2011-09-10 02:14:39 -04:00
inflate_huft *tl;
inflate_huft *td; /* trees to free */
2011-09-10 02:09:18 -04:00
inflate_codes_statef
*codes;
2011-09-10 02:08:28 -04:00
} decode; /* if CODES, current state */
2011-09-10 02:08:07 -04:00
} sub; /* submode */
uInt last; /* true if this block is the last block */
2011-09-10 01:36:31 -04:00
/* mode independent information */
2011-09-10 02:08:07 -04:00
uInt bitk; /* bits in bit buffer */
uLong bitb; /* bit buffer */
2011-09-10 02:09:18 -04:00
Bytef *window; /* sliding window */
Bytef *end; /* one byte after sliding window */
Bytef *read; /* window read pointer */
Bytef *write; /* window write pointer */
2011-09-10 01:52:17 -04:00
check_func checkfn; /* check function */
2011-09-10 02:08:07 -04:00
uLong check; /* check on output */
2011-09-10 01:36:31 -04:00
};
2011-09-10 02:09:18 -04:00
2011-09-10 01:36:31 -04:00
/* defines for inflate input/output */
/* update pointers and return */
#define UPDBITS {s->bitb=b;s->bitk=k;}
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
#define UPDOUT {s->write=q;}
#define UPDATE {UPDBITS UPDIN UPDOUT}
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
/* get bytes and bits */
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
#define NEXTBYTE (n--,*p++)
2011-09-10 02:06:52 -04:00
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
2011-09-10 01:36:31 -04:00
#define DUMPBITS(j) {b>>=(j);k-=(j);}
/* output bytes */
2011-09-10 02:11:37 -04:00
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
2011-09-10 02:14:39 -04:00
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
2011-09-10 01:36:31 -04:00
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
/* load local pointers */
#define LOAD {LOADIN LOADOUT}
2011-09-10 02:14:39 -04:00
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
extern uInt inflate_mask[17];
2011-09-10 01:36:31 -04:00
/* copy as much as possible from the sliding window to the output area */
2011-09-10 02:09:18 -04:00
extern int inflate_flush OF((
inflate_blocks_statef *,
2011-09-10 02:17:02 -04:00
z_streamp ,
2011-09-10 01:36:31 -04:00
int));
struct internal_state {int dummy;}; /* for buggy compilers */
2011-09-10 02:14:39 -04:00
#endif