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