1 /* infutil.h -- types and macros common to blocks and codes
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
6 /* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h.
14 #ifdef BAD /* For AIX */
19 TYPE, /* get type bits (3, including end bit) */
20 LENS, /* get lengths for stored */
21 STORED, /* processing stored block */
22 TABLE, /* get table lengths */
23 BTREE, /* get bit lengths tree for a dynamic block */
24 DTREE, /* get length, distance trees for a dynamic block */
25 CODES, /* processing fixed or dynamic block */
26 DRY, /* output remaining window bytes */
27 DONE, /* finished last block, done */
28 BAD} /* got a data error--stuck here */
31 /* inflate blocks semi-private state */
32 struct inflate_blocks_state {
35 inflate_block_mode mode; /* current inflate_block mode */
37 /* mode dependent information */
39 uInt left; /* if STORED, bytes left to copy */
41 uInt table; /* table lengths (14 bits) */
42 uInt index; /* index into blens (or border) */
43 uIntf *blens; /* bit lengths of codes */
44 uInt bb; /* bit length tree depth */
45 inflate_huft *tb; /* bit length decoding tree */
46 } trees; /* if DTREE, decoding info for trees */
50 } decode; /* if CODES, current state */
52 uInt last; /* true if this block is the last block */
54 /* mode independent information */
55 uInt bitk; /* bits in bit buffer */
56 uLong bitb; /* bit buffer */
57 inflate_huft *hufts; /* single malloc for tree space */
58 Bytef *window; /* sliding window */
59 Bytef *end; /* one byte after sliding window */
60 Bytef *read; /* window read pointer */
61 Bytef *write; /* window write pointer */
62 check_func checkfn; /* check function */
63 uLong check; /* check on output */
68 /* defines for inflate input/output */
69 /* update pointers and return */
70 #define UPDBITS {s->bitb=b;s->bitk=k;}
71 #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
72 #define UPDOUT {s->write=q;}
73 #define UPDATE {UPDBITS UPDIN UPDOUT}
74 #define LEAVE {UPDATE return inflate_flush(s,z,r);}
75 /* get bytes and bits */
76 #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
77 #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
78 #define NEXTBYTE (n--,*p++)
79 #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
80 #define DUMPBITS(j) {b>>=(j);k-=(j);}
82 #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
83 #define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
84 #define ZWRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
85 #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
86 #define NEEDOUT {if(m==0){ZWRAP if(m==0){FLUSH ZWRAP if(m==0) LEAVE}}r=Z_OK;}
87 #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
88 /* load local pointers */
89 #define LOAD {LOADIN LOADOUT}
91 /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
92 extern uInt inflate_mask[17];
94 /* copy as much as possible from the sliding window to the output area */
95 extern int inflate_flush OF((
96 inflate_blocks_statef *,
100 struct internal_state {int dummy;}; /* for buggy compilers */