blob: e5154d7f6268442832003f0a4a16d66cbe5e11ca [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Sun designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Sun in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 */
24
25/*
26 * This file is available under and governed by the GNU General Public
27 * License version 2 only, as published by the Free Software Foundation.
28 * However, the following notice accompanied the original version of this
29 * file and, per its terms, should not be removed:
30 *
31 * infutil.h -- types and macros common to blocks and codes
32 * Copyright (C) 1995-1998 Mark Adler
33 * For conditions of distribution and use, see copyright notice in zlib.h
34 */
35
36/* WARNING: this file should *not* be used by applications. It is
37 part of the implementation of the compression library and is
38 subject to change. Applications should only use zlib.h.
39 */
40
41#ifndef _INFUTIL_H
42#define _INFUTIL_H
43
44typedef enum {
45 TYPE, /* get type bits (3, including end bit) */
46 LENS, /* get lengths for stored */
47 STORED, /* processing stored block */
48 TABLE, /* get table lengths */
49 BTREE, /* get bit lengths tree for a dynamic block */
50 DTREE, /* get length, distance trees for a dynamic block */
51 CODES, /* processing fixed or dynamic block */
52 DRY, /* output remaining window bytes */
53 DONE, /* finished last block, done */
54 BAD} /* got a data error--stuck here */
55inflate_block_mode;
56
57/* inflate blocks semi-private state */
58struct inflate_blocks_state {
59
60 /* mode */
61 inflate_block_mode mode; /* current inflate_block mode */
62
63 /* mode dependent information */
64 union {
65 uInt left; /* if STORED, bytes left to copy */
66 struct {
67 uInt table; /* table lengths (14 bits) */
68 uInt index; /* index into blens (or border) */
69 uIntf *blens; /* bit lengths of codes */
70 uInt bb; /* bit length tree depth */
71 inflate_huft *tb; /* bit length decoding tree */
72 } trees; /* if DTREE, decoding info for trees */
73 struct {
74 inflate_codes_statef
75 *codes;
76 } decode; /* if CODES, current state */
77 } sub; /* submode */
78 uInt last; /* true if this block is the last block */
79
80 /* mode independent information */
81 uInt bitk; /* bits in bit buffer */
82 uLong bitb; /* bit buffer */
83 inflate_huft *hufts; /* single malloc for tree space */
84 Bytef *window; /* sliding window */
85 Bytef *end; /* one byte after sliding window */
86 Bytef *read; /* window read pointer */
87 Bytef *write; /* window write pointer */
88 check_func checkfn; /* check function */
89 uLong check; /* check on output */
90
91};
92
93
94/* defines for inflate input/output */
95/* update pointers and return */
96#define UPDBITS {s->bitb=b;s->bitk=k;}
97#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
98#define UPDOUT {s->write=q;}
99#define UPDATE {UPDBITS UPDIN UPDOUT}
100#define LEAVE {UPDATE return inflate_flush(s,z,r);}
101/* get bytes and bits */
102#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
103#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
104#define NEXTBYTE (n--,*p++)
105#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
106#define DUMPBITS(j) {b>>=(j);k-=(j);}
107/* output bytes */
108#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
109#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
110#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
111#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
112#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
113#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
114/* load local pointers */
115#define LOAD {LOADIN LOADOUT}
116
117/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
118extern uInt inflate_mask[17];
119
120/* copy as much as possible from the sliding window to the output area */
121extern int inflate_flush OF((
122 inflate_blocks_statef *,
123 z_streamp ,
124 int));
125
126struct internal_state {int dummy;}; /* for buggy compilers */
127
128#endif