1 /* $NetBSD: inflate.h,v 1.1.1.1 2006/01/14 20:10:31 christos Exp $ */
3 /* inflate.h -- internal inflate state definition
4 * Copyright (C) 1995-2004 Mark Adler
5 * For conditions of distribution and use, see copyright notice in zlib.h
8 /* WARNING: this file should *not* be used by applications. It is
9 part of the implementation of the compression library and is
10 subject to change. Applications should only use zlib.h.
13 /* define NO_GZIP when compiling if you want to disable gzip header and
14 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
15 the crc code when it is not needed. For shared libraries, gzip decoding
16 should be left enabled. */
21 /* Possible inflate modes between inflate() calls */
23 HEAD
, /* i: waiting for magic header */
24 FLAGS
, /* i: waiting for method and flags (gzip) */
25 TIME
, /* i: waiting for modification time (gzip) */
26 OS
, /* i: waiting for extra flags and operating system (gzip) */
27 EXLEN
, /* i: waiting for extra length (gzip) */
28 EXTRA
, /* i: waiting for extra bytes (gzip) */
29 NAME
, /* i: waiting for end of file name (gzip) */
30 COMMENT
, /* i: waiting for end of comment (gzip) */
31 HCRC
, /* i: waiting for header crc (gzip) */
32 DICTID
, /* i: waiting for dictionary check value */
33 DICT
, /* waiting for inflateSetDictionary() call */
34 TYPE
, /* i: waiting for type bits, including last-flag bit */
35 TYPEDO
, /* i: same, but skip check to exit inflate on new block */
36 STORED
, /* i: waiting for stored size (length and complement) */
37 COPY
, /* i/o: waiting for input or output to copy stored block */
38 TABLE
, /* i: waiting for dynamic block table lengths */
39 LENLENS
, /* i: waiting for code length code lengths */
40 CODELENS
, /* i: waiting for length/lit and distance code lengths */
41 LEN
, /* i: waiting for length/lit code */
42 LENEXT
, /* i: waiting for length extra bits */
43 DIST
, /* i: waiting for distance code */
44 DISTEXT
, /* i: waiting for distance extra bits */
45 MATCH
, /* o: waiting for output space to copy string */
46 LIT
, /* o: waiting for output space to write literal */
47 CHECK
, /* i: waiting for 32-bit check value */
48 LENGTH
, /* i: waiting for 32-bit length (gzip) */
49 DONE
, /* finished check, done -- remain here until reset */
50 BAD
, /* got a data error -- remain here until reset */
51 MEM
, /* got an inflate() memory error -- remain here until reset */
52 SYNC
/* looking for synchronization bytes to restart inflate() */
56 State transitions between above modes -
58 (most modes can go to the BAD or MEM mode -- not shown for clarity)
61 HEAD -> (gzip) or (zlib)
62 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
63 NAME -> COMMENT -> HCRC -> TYPE
64 (zlib) -> DICTID or TYPE
65 DICTID -> DICT -> TYPE
67 TYPE -> STORED or TABLE or LEN or CHECK
68 STORED -> COPY -> TYPE
69 TABLE -> LENLENS -> CODELENS -> LEN
71 LEN -> LENEXT or LIT or TYPE
72 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
75 CHECK -> LENGTH -> DONE
78 /* state maintained between inflate() calls. Approximately 7K bytes. */
79 struct inflate_state
{
80 inflate_mode mode
; /* current inflate mode */
81 int last
; /* true if processing last block */
82 int wrap
; /* bit 0 true for zlib, bit 1 true for gzip */
83 int havedict
; /* true if dictionary provided */
84 int flags
; /* gzip header method and flags (0 if zlib) */
85 unsigned dmax
; /* zlib header max distance (INFLATE_STRICT) */
86 unsigned long check
; /* protected copy of check value */
87 unsigned long total
; /* protected copy of output count */
88 gz_headerp head
; /* where to save gzip header information */
90 unsigned wbits
; /* log base 2 of requested window size */
91 unsigned wsize
; /* window size or zero if not using window */
92 unsigned whave
; /* valid bytes in the window */
93 unsigned write
; /* window write index */
94 unsigned char FAR
*window
; /* allocated sliding window, if needed */
96 unsigned long hold
; /* input bit accumulator */
97 unsigned bits
; /* number of bits in "in" */
98 /* for string and stored block copying */
99 unsigned length
; /* literal or length of data to copy */
100 unsigned offset
; /* distance back to copy string from */
101 /* for table and code decoding */
102 unsigned extra
; /* extra bits needed */
103 /* fixed and dynamic code tables */
104 code
const FAR
*lencode
; /* starting table for length/literal codes */
105 code
const FAR
*distcode
; /* starting table for distance codes */
106 unsigned lenbits
; /* index bits for lencode */
107 unsigned distbits
; /* index bits for distcode */
108 /* dynamic table building */
109 unsigned ncode
; /* number of code length code lengths */
110 unsigned nlen
; /* number of length code lengths */
111 unsigned ndist
; /* number of distance code lengths */
112 unsigned have
; /* number of code lengths in lens[] */
113 code FAR
*next
; /* next available space in codes[] */
114 unsigned short lens
[320]; /* temporary storage for code lengths */
115 unsigned short work
[288]; /* work area for code table building */
116 code codes
[ENOUGH
]; /* space for code tables */