Initial commit
[wrt350n-kernel.git] / lib / zlib_inflate / inflate.h
blobdf8a6c92052df2c49888504af7277e1cfdfecfd6
1 /* inflate.h -- internal inflate state definition
2 * Copyright (C) 1995-2004 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
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.
9 */
11 /* Possible inflate modes between inflate() calls */
12 typedef enum {
13 HEAD, /* i: waiting for magic header */
14 FLAGS, /* i: waiting for method and flags (gzip) */
15 TIME, /* i: waiting for modification time (gzip) */
16 OS, /* i: waiting for extra flags and operating system (gzip) */
17 EXLEN, /* i: waiting for extra length (gzip) */
18 EXTRA, /* i: waiting for extra bytes (gzip) */
19 NAME, /* i: waiting for end of file name (gzip) */
20 COMMENT, /* i: waiting for end of comment (gzip) */
21 HCRC, /* i: waiting for header crc (gzip) */
22 DICTID, /* i: waiting for dictionary check value */
23 DICT, /* waiting for inflateSetDictionary() call */
24 TYPE, /* i: waiting for type bits, including last-flag bit */
25 TYPEDO, /* i: same, but skip check to exit inflate on new block */
26 STORED, /* i: waiting for stored size (length and complement) */
27 COPY, /* i/o: waiting for input or output to copy stored block */
28 TABLE, /* i: waiting for dynamic block table lengths */
29 LENLENS, /* i: waiting for code length code lengths */
30 CODELENS, /* i: waiting for length/lit and distance code lengths */
31 LEN, /* i: waiting for length/lit code */
32 LENEXT, /* i: waiting for length extra bits */
33 DIST, /* i: waiting for distance code */
34 DISTEXT, /* i: waiting for distance extra bits */
35 MATCH, /* o: waiting for output space to copy string */
36 LIT, /* o: waiting for output space to write literal */
37 CHECK, /* i: waiting for 32-bit check value */
38 LENGTH, /* i: waiting for 32-bit length (gzip) */
39 DONE, /* finished check, done -- remain here until reset */
40 BAD, /* got a data error -- remain here until reset */
41 MEM, /* got an inflate() memory error -- remain here until reset */
42 SYNC /* looking for synchronization bytes to restart inflate() */
43 } inflate_mode;
46 State transitions between above modes -
48 (most modes can go to the BAD or MEM mode -- not shown for clarity)
50 Process header:
51 HEAD -> (gzip) or (zlib)
52 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
53 NAME -> COMMENT -> HCRC -> TYPE
54 (zlib) -> DICTID or TYPE
55 DICTID -> DICT -> TYPE
56 Read deflate blocks:
57 TYPE -> STORED or TABLE or LEN or CHECK
58 STORED -> COPY -> TYPE
59 TABLE -> LENLENS -> CODELENS -> LEN
60 Read deflate codes:
61 LEN -> LENEXT or LIT or TYPE
62 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
63 LIT -> LEN
64 Process trailer:
65 CHECK -> LENGTH -> DONE
68 /* state maintained between inflate() calls. Approximately 7K bytes. */
69 struct inflate_state {
70 inflate_mode mode; /* current inflate mode */
71 int last; /* true if processing last block */
72 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
73 int havedict; /* true if dictionary provided */
74 int flags; /* gzip header method and flags (0 if zlib) */
75 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
76 unsigned long check; /* protected copy of check value */
77 unsigned long total; /* protected copy of output count */
78 /* gz_headerp head; */ /* where to save gzip header information */
79 /* sliding window */
80 unsigned wbits; /* log base 2 of requested window size */
81 unsigned wsize; /* window size or zero if not using window */
82 unsigned whave; /* valid bytes in the window */
83 unsigned write; /* window write index */
84 unsigned char *window; /* allocated sliding window, if needed */
85 /* bit accumulator */
86 unsigned long hold; /* input bit accumulator */
87 unsigned bits; /* number of bits in "in" */
88 /* for string and stored block copying */
89 unsigned length; /* literal or length of data to copy */
90 unsigned offset; /* distance back to copy string from */
91 /* for table and code decoding */
92 unsigned extra; /* extra bits needed */
93 /* fixed and dynamic code tables */
94 code const *lencode; /* starting table for length/literal codes */
95 code const *distcode; /* starting table for distance codes */
96 unsigned lenbits; /* index bits for lencode */
97 unsigned distbits; /* index bits for distcode */
98 /* dynamic table building */
99 unsigned ncode; /* number of code length code lengths */
100 unsigned nlen; /* number of length code lengths */
101 unsigned ndist; /* number of distance code lengths */
102 unsigned have; /* number of code lengths in lens[] */
103 code *next; /* next available space in codes[] */
104 unsigned short lens[320]; /* temporary storage for code lengths */
105 unsigned short work[288]; /* work area for code table building */
106 code codes[ENOUGH]; /* space for code tables */