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