annotate packages/services/compress/zlib/current/src/inflate.h @ 1777:c16341b1bac6 default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Mon, 12 Oct 2009 02:26:09 +0100
parents 2321e7aae37c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1654
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
1 /* inflate.h -- internal inflate state definition
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
2 * Copyright (C) 1995-2003 Mark Adler
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
3 * For conditions of distribution and use, see copyright notice in zlib.h
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
4 */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
5
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
6 /* WARNING: this file should *not* be used by applications. It is
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
7 part of the implementation of the compression library and is
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
8 subject to change. Applications should only use zlib.h.
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
9 */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
10
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
11 /* define NO_GZIP when compiling if you want to disable gzip header and
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
12 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
13 the crc code when it is not needed. For shared libraries, gzip decoding
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
14 should be left enabled. */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
15 #ifndef NO_GZIP
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
16 # define GUNZIP
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
17 #endif
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
18
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
19 /* Possible inflate modes between inflate() calls */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
20 typedef enum {
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
21 HEAD, /* i: waiting for magic header */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
22 #ifdef GUNZIP
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
23 FLAGS, /* i: waiting for method and flags (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
24 TIME, /* i: waiting for modification time (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
25 OS, /* i: waiting for extra flags and operating system (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
26 EXLEN, /* i: waiting for extra length (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
27 EXTRA, /* i: waiting for extra bytes (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
28 NAME, /* i: waiting for end of file name (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
29 COMMENT, /* i: waiting for end of comment (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
30 HCRC, /* i: waiting for header crc (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
31 #endif
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
32 DICTID, /* i: waiting for dictionary check value */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
33 DICT, /* waiting for inflateSetDictionary() call */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
34 TYPE, /* i: waiting for type bits, including last-flag bit */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
35 TYPEDO, /* i: same, but skip check to exit inflate on new block */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
36 STORED, /* i: waiting for stored size (length and complement) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
37 COPY, /* i/o: waiting for input or output to copy stored block */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
38 TABLE, /* i: waiting for dynamic block table lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
39 LENLENS, /* i: waiting for code length code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
40 CODELENS, /* i: waiting for length/lit and distance code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
41 LEN, /* i: waiting for length/lit code */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
42 LENEXT, /* i: waiting for length extra bits */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
43 DIST, /* i: waiting for distance code */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
44 DISTEXT, /* i: waiting for distance extra bits */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
45 MATCH, /* o: waiting for output space to copy string */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
46 LIT, /* o: waiting for output space to write literal */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
47 CHECK, /* i: waiting for 32-bit check value */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
48 #ifdef GUNZIP
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
49 LENGTH, /* i: waiting for 32-bit length (gzip) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
50 #endif
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
51 DONE, /* finished check, done -- remain here until reset */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
52 BAD, /* got a data error -- remain here until reset */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
53 MEM, /* got an inflate() memory error -- remain here until reset */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
54 SYNC /* looking for synchronization bytes to restart inflate() */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
55 } inflate_mode;
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
56
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
57 /*
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
58 State transitions between above modes -
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
59
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
60 (most modes can go to the BAD or MEM mode -- not shown for clarity)
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
61
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
62 Process header:
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
63 HEAD -> (gzip) or (zlib)
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
64 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
65 NAME -> COMMENT -> HCRC -> TYPE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
66 (zlib) -> DICTID or TYPE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
67 DICTID -> DICT -> TYPE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
68 Read deflate blocks:
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
69 TYPE -> STORED or TABLE or LEN or CHECK
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
70 STORED -> COPY -> TYPE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
71 TABLE -> LENLENS -> CODELENS -> LEN
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
72 Read deflate codes:
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
73 LEN -> LENEXT or LIT or TYPE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
74 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
75 LIT -> LEN
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
76 Process trailer:
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
77 CHECK -> LENGTH -> DONE
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
78 */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
79
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
80 /* state maintained between inflate() calls. Approximately 7K bytes. */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
81 struct inflate_state {
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
82 inflate_mode mode; /* current inflate mode */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
83 int last; /* true if processing last block */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
84 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
85 int havedict; /* true if dictionary provided */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
86 int flags; /* gzip header method and flags (0 if zlib) */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
87 unsigned long check; /* protected copy of check value */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
88 unsigned long total; /* protected copy of output count */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
89 /* sliding window */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
90 unsigned wbits; /* log base 2 of requested window size */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
91 unsigned wsize; /* window size or zero if not using window */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
92 unsigned whave; /* valid bytes in the window */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
93 unsigned write; /* window write index */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
94 unsigned char FAR *window; /* allocated sliding window, if needed */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
95 /* bit accumulator */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
96 unsigned long hold; /* input bit accumulator */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
97 unsigned bits; /* number of bits in "in" */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
98 /* for string and stored block copying */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
99 unsigned length; /* literal or length of data to copy */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
100 unsigned offset; /* distance back to copy string from */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
101 /* for table and code decoding */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
102 unsigned extra; /* extra bits needed */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
103 /* fixed and dynamic code tables */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
104 code const FAR *lencode; /* starting table for length/literal codes */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
105 code const FAR *distcode; /* starting table for distance codes */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
106 unsigned lenbits; /* index bits for lencode */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
107 unsigned distbits; /* index bits for distcode */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
108 /* dynamic table building */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
109 unsigned ncode; /* number of code length code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
110 unsigned nlen; /* number of length code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
111 unsigned ndist; /* number of distance code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
112 unsigned have; /* number of code lengths in lens[] */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
113 code FAR *next; /* next available space in codes[] */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
114 unsigned short lens[320]; /* temporary storage for code lengths */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
115 unsigned short work[288]; /* work area for code table building */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
116 code codes[ENOUGH]; /* space for code tables */
2321e7aae37c New files from zlib-1.2.1
gthomas
parents:
diff changeset
117 };