nuclear@1: /* inflate.h -- internal inflate state definition nuclear@1: * Copyright (C) 1995-2004 Mark Adler nuclear@1: * For conditions of distribution and use, see copyright notice in zlib.h nuclear@1: */ nuclear@1: nuclear@1: /* WARNING: this file should *not* be used by applications. It is nuclear@1: part of the implementation of the compression library and is nuclear@1: subject to change. Applications should only use zlib.h. nuclear@1: */ nuclear@1: nuclear@1: /* define NO_GZIP when compiling if you want to disable gzip header and nuclear@1: trailer decoding by inflate(). NO_GZIP would be used to avoid linking in nuclear@1: the crc code when it is not needed. For shared libraries, gzip decoding nuclear@1: should be left enabled. */ nuclear@1: #ifndef NO_GZIP nuclear@1: # define GUNZIP nuclear@1: #endif nuclear@1: nuclear@1: /* Possible inflate modes between inflate() calls */ nuclear@1: typedef enum { nuclear@1: HEAD, /* i: waiting for magic header */ nuclear@1: FLAGS, /* i: waiting for method and flags (gzip) */ nuclear@1: TIME, /* i: waiting for modification time (gzip) */ nuclear@1: OS, /* i: waiting for extra flags and operating system (gzip) */ nuclear@1: EXLEN, /* i: waiting for extra length (gzip) */ nuclear@1: EXTRA, /* i: waiting for extra bytes (gzip) */ nuclear@1: NAME, /* i: waiting for end of file name (gzip) */ nuclear@1: COMMENT, /* i: waiting for end of comment (gzip) */ nuclear@1: HCRC, /* i: waiting for header crc (gzip) */ nuclear@1: DICTID, /* i: waiting for dictionary check value */ nuclear@1: DICT, /* waiting for inflateSetDictionary() call */ nuclear@1: TYPE, /* i: waiting for type bits, including last-flag bit */ nuclear@1: TYPEDO, /* i: same, but skip check to exit inflate on new block */ nuclear@1: STORED, /* i: waiting for stored size (length and complement) */ nuclear@1: COPY, /* i/o: waiting for input or output to copy stored block */ nuclear@1: TABLE, /* i: waiting for dynamic block table lengths */ nuclear@1: LENLENS, /* i: waiting for code length code lengths */ nuclear@1: CODELENS, /* i: waiting for length/lit and distance code lengths */ nuclear@1: LEN, /* i: waiting for length/lit code */ nuclear@1: LENEXT, /* i: waiting for length extra bits */ nuclear@1: DIST, /* i: waiting for distance code */ nuclear@1: DISTEXT, /* i: waiting for distance extra bits */ nuclear@1: MATCH, /* o: waiting for output space to copy string */ nuclear@1: LIT, /* o: waiting for output space to write literal */ nuclear@1: CHECK, /* i: waiting for 32-bit check value */ nuclear@1: LENGTH, /* i: waiting for 32-bit length (gzip) */ nuclear@1: DONE, /* finished check, done -- remain here until reset */ nuclear@1: BAD, /* got a data error -- remain here until reset */ nuclear@1: MEM, /* got an inflate() memory error -- remain here until reset */ nuclear@1: SYNC /* looking for synchronization bytes to restart inflate() */ nuclear@1: } inflate_mode; nuclear@1: nuclear@1: /* nuclear@1: State transitions between above modes - nuclear@1: nuclear@1: (most modes can go to the BAD or MEM mode -- not shown for clarity) nuclear@1: nuclear@1: Process header: nuclear@1: HEAD -> (gzip) or (zlib) nuclear@1: (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME nuclear@1: NAME -> COMMENT -> HCRC -> TYPE nuclear@1: (zlib) -> DICTID or TYPE nuclear@1: DICTID -> DICT -> TYPE nuclear@1: Read deflate blocks: nuclear@1: TYPE -> STORED or TABLE or LEN or CHECK nuclear@1: STORED -> COPY -> TYPE nuclear@1: TABLE -> LENLENS -> CODELENS -> LEN nuclear@1: Read deflate codes: nuclear@1: LEN -> LENEXT or LIT or TYPE nuclear@1: LENEXT -> DIST -> DISTEXT -> MATCH -> LEN nuclear@1: LIT -> LEN nuclear@1: Process trailer: nuclear@1: CHECK -> LENGTH -> DONE nuclear@1: */ nuclear@1: nuclear@1: /* state maintained between inflate() calls. Approximately 7K bytes. */ nuclear@1: struct inflate_state { nuclear@1: inflate_mode mode; /* current inflate mode */ nuclear@1: int last; /* true if processing last block */ nuclear@1: int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ nuclear@1: int havedict; /* true if dictionary provided */ nuclear@1: int flags; /* gzip header method and flags (0 if zlib) */ nuclear@1: unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ nuclear@1: unsigned long check; /* protected copy of check value */ nuclear@1: unsigned long total; /* protected copy of output count */ nuclear@1: gz_headerp head; /* where to save gzip header information */ nuclear@1: /* sliding window */ nuclear@1: unsigned wbits; /* log base 2 of requested window size */ nuclear@1: unsigned wsize; /* window size or zero if not using window */ nuclear@1: unsigned whave; /* valid bytes in the window */ nuclear@1: unsigned write; /* window write index */ nuclear@1: unsigned char FAR *window; /* allocated sliding window, if needed */ nuclear@1: /* bit accumulator */ nuclear@1: unsigned long hold; /* input bit accumulator */ nuclear@1: unsigned bits; /* number of bits in "in" */ nuclear@1: /* for string and stored block copying */ nuclear@1: unsigned length; /* literal or length of data to copy */ nuclear@1: unsigned offset; /* distance back to copy string from */ nuclear@1: /* for table and code decoding */ nuclear@1: unsigned extra; /* extra bits needed */ nuclear@1: /* fixed and dynamic code tables */ nuclear@1: code const FAR *lencode; /* starting table for length/literal codes */ nuclear@1: code const FAR *distcode; /* starting table for distance codes */ nuclear@1: unsigned lenbits; /* index bits for lencode */ nuclear@1: unsigned distbits; /* index bits for distcode */ nuclear@1: /* dynamic table building */ nuclear@1: unsigned ncode; /* number of code length code lengths */ nuclear@1: unsigned nlen; /* number of length code lengths */ nuclear@1: unsigned ndist; /* number of distance code lengths */ nuclear@1: unsigned have; /* number of code lengths in lens[] */ nuclear@1: code FAR *next; /* next available space in codes[] */ nuclear@1: unsigned short lens[320]; /* temporary storage for code lengths */ nuclear@1: unsigned short work[288]; /* work area for code table building */ nuclear@1: code codes[ENOUGH]; /* space for code tables */ nuclear@1: };