annotate zlib/infutil.h @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* infutil.h -- types and macros common to blocks and codes
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2 * Copyright (C) 1995 Mark Adler
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 /* WARNING: this file should *not* be used by applications. It is
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7 part of the implementation of the compression library and is
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 subject to change. Applications should only use zlib.h.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 /* inflate blocks semi-private state */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 struct inflate_blocks_state {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 /* mode */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 enum {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 TYPE, /* get type bits (3, including end bit) */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 LENS, /* get lengths for stored */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 STORED, /* processing stored block */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 TABLE, /* get table lengths */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 BTREE, /* get bit lengths tree for a dynamic block */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21 DTREE, /* get length, distance trees for a dynamic block */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 CODES, /* processing fixed or dynamic block */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 DRY, /* output remaining window bytes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 DONE, /* finished last block, done */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 BAD} /* got a data error--stuck here */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 mode; /* current inflate_block mode */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 /* mode dependent information */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 union {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 uInt left; /* if STORED, bytes left to copy */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 struct {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 uInt table; /* table lengths (14 bits) */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 uInt index; /* index into blens (or border) */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 uInt *blens; /* bit lengths of codes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 uInt bb; /* bit length tree depth */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 inflate_huft *tb; /* bit length decoding tree */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 } trees; /* if DTREE, decoding info for trees */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 struct inflate_codes_state
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 *codes; /* if CODES, current state */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 } sub; /* submode */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 uInt last; /* true if this block is the last block */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 /* mode independent information */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 uInt bitk; /* bits in bit buffer */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 uLong bitb; /* bit buffer */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 Byte *window; /* sliding window */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 Byte *end; /* one byte after sliding window */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 Byte *read; /* window read pointer */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 Byte *write; /* window write pointer */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 check_func checkfn; /* check function */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 uLong check; /* check on output */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 };
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55 /* defines for inflate input/output */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 /* update pointers and return */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 #define UPDBITS {s->bitb=b;s->bitk=k;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 #define UPDOUT {s->write=q;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 #define UPDATE {UPDBITS UPDIN UPDOUT}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 #define LEAVE {UPDATE return inflate_flush(s,z,r);}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62 /* get bytes and bits */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 #define NEXTBYTE (n--,*p++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 #define DUMPBITS(j) {b>>=(j);k-=(j);}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 /* output bytes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 #define WAVAIL (q<s->read?s->read-q-1:s->end-q)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 #define LOADOUT {q=s->write;m=WAVAIL;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=WAVAIL;}}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72 #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 /* load local pointers */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 #define LOAD {LOADIN LOADOUT}
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 /* masks for lower bits */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 extern uInt inflate_mask[];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 /* copy as much as possible from the sliding window to the output area */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 extern int inflate_flush __P((
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 struct inflate_blocks_state *,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 z_stream *,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 int));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 struct internal_state {int dummy;}; /* for buggy compilers */