]> git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/infutil.h
Security-29.tar.gz
[apple/security.git] / SecurityServer / MacYarrow / zlib / infutil.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /* infutil.h -- types and macros common to blocks and codes
20 * Copyright (C) 1995-1998 Mark Adler
21 * For conditions of distribution and use, see copyright notice in zlib.h
22 */
23
24 /* WARNING: this file should *not* be used by applications. It is
25 part of the implementation of the compression library and is
26 subject to change. Applications should only use zlib.h.
27 */
28
29 #ifndef _INFUTIL_H
30 #define _INFUTIL_H
31
32 typedef enum {
33 TYPE, /* get type bits (3, including end bit) */
34 LENS, /* get lengths for stored */
35 STORED, /* processing stored block */
36 TABLE, /* get table lengths */
37 BTREE, /* get bit lengths tree for a dynamic block */
38 DTREE, /* get length, distance trees for a dynamic block */
39 CODES, /* processing fixed or dynamic block */
40 DRY, /* output remaining window bytes */
41 DONE, /* finished last block, done */
42 BAD} /* got a data error--stuck here */
43 inflate_block_mode;
44
45 /* inflate blocks semi-private state */
46 struct inflate_blocks_state {
47
48 /* mode */
49 inflate_block_mode mode; /* current inflate_block mode */
50
51 /* mode dependent information */
52 union {
53 uInt left; /* if STORED, bytes left to copy */
54 struct {
55 uInt table; /* table lengths (14 bits) */
56 uInt index; /* index into blens (or border) */
57 uIntf *blens; /* bit lengths of codes */
58 uInt bb; /* bit length tree depth */
59 inflate_huft *tb; /* bit length decoding tree */
60 } trees; /* if DTREE, decoding info for trees */
61 struct {
62 inflate_codes_statef
63 *codes;
64 } decode; /* if CODES, current state */
65 } sub; /* submode */
66 uInt last; /* true if this block is the last block */
67
68 /* mode independent information */
69 uInt bitk; /* bits in bit buffer */
70 uLong bitb; /* bit buffer */
71 inflate_huft *hufts; /* single malloc for tree space */
72 Bytef *window; /* sliding window */
73 Bytef *end; /* one byte after sliding window */
74 Bytef *read; /* window read pointer */
75 Bytef *write; /* window write pointer */
76 check_func checkfn; /* check function */
77 uLong check; /* check on output */
78
79 };
80
81
82 /* defines for inflate input/output */
83 /* update pointers and return */
84 #define UPDBITS {s->bitb=b;s->bitk=k;}
85 #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
86 #define UPDOUT {s->write=q;}
87 #define UPDATE {UPDBITS UPDIN UPDOUT}
88 #define LEAVE {UPDATE return inflate_flush(s,z,r);}
89 /* get bytes and bits */
90 #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
91 #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
92 #define NEXTBYTE (n--,*p++)
93 #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
94 #define DUMPBITS(j) {b>>=(j);k-=(j);}
95 /* output bytes */
96 #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
97 #define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
98 #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
99 #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
100 #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
101 #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
102 /* load local pointers */
103 #define LOAD {LOADIN LOADOUT}
104
105 /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
106 extern uInt inflate_mask[17];
107
108 /* copy as much as possible from the sliding window to the output area */
109 extern int inflate_flush OF((
110 inflate_blocks_statef *,
111 z_streamp ,
112 int));
113
114 struct internal_state {int dummy;}; /* for buggy compilers */
115
116 #endif