162306a36Sopenharmony_ci#ifndef INFLATE_H 262306a36Sopenharmony_ci#define INFLATE_H 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* inflate.h -- internal inflate state definition 562306a36Sopenharmony_ci * Copyright (C) 1995-2004 Mark Adler 662306a36Sopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* WARNING: this file should *not* be used by applications. It is 1062306a36Sopenharmony_ci part of the implementation of the compression library and is 1162306a36Sopenharmony_ci subject to change. Applications should only use zlib.h. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include "inftrees.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* Possible inflate modes between inflate() calls */ 1762306a36Sopenharmony_citypedef enum { 1862306a36Sopenharmony_ci HEAD, /* i: waiting for magic header */ 1962306a36Sopenharmony_ci FLAGS, /* i: waiting for method and flags (gzip) */ 2062306a36Sopenharmony_ci TIME, /* i: waiting for modification time (gzip) */ 2162306a36Sopenharmony_ci OS, /* i: waiting for extra flags and operating system (gzip) */ 2262306a36Sopenharmony_ci EXLEN, /* i: waiting for extra length (gzip) */ 2362306a36Sopenharmony_ci EXTRA, /* i: waiting for extra bytes (gzip) */ 2462306a36Sopenharmony_ci NAME, /* i: waiting for end of file name (gzip) */ 2562306a36Sopenharmony_ci COMMENT, /* i: waiting for end of comment (gzip) */ 2662306a36Sopenharmony_ci HCRC, /* i: waiting for header crc (gzip) */ 2762306a36Sopenharmony_ci DICTID, /* i: waiting for dictionary check value */ 2862306a36Sopenharmony_ci DICT, /* waiting for inflateSetDictionary() call */ 2962306a36Sopenharmony_ci TYPE, /* i: waiting for type bits, including last-flag bit */ 3062306a36Sopenharmony_ci TYPEDO, /* i: same, but skip check to exit inflate on new block */ 3162306a36Sopenharmony_ci STORED, /* i: waiting for stored size (length and complement) */ 3262306a36Sopenharmony_ci COPY, /* i/o: waiting for input or output to copy stored block */ 3362306a36Sopenharmony_ci TABLE, /* i: waiting for dynamic block table lengths */ 3462306a36Sopenharmony_ci LENLENS, /* i: waiting for code length code lengths */ 3562306a36Sopenharmony_ci CODELENS, /* i: waiting for length/lit and distance code lengths */ 3662306a36Sopenharmony_ci LEN, /* i: waiting for length/lit code */ 3762306a36Sopenharmony_ci LENEXT, /* i: waiting for length extra bits */ 3862306a36Sopenharmony_ci DIST, /* i: waiting for distance code */ 3962306a36Sopenharmony_ci DISTEXT, /* i: waiting for distance extra bits */ 4062306a36Sopenharmony_ci MATCH, /* o: waiting for output space to copy string */ 4162306a36Sopenharmony_ci LIT, /* o: waiting for output space to write literal */ 4262306a36Sopenharmony_ci CHECK, /* i: waiting for 32-bit check value */ 4362306a36Sopenharmony_ci LENGTH, /* i: waiting for 32-bit length (gzip) */ 4462306a36Sopenharmony_ci DONE, /* finished check, done -- remain here until reset */ 4562306a36Sopenharmony_ci BAD, /* got a data error -- remain here until reset */ 4662306a36Sopenharmony_ci MEM, /* got an inflate() memory error -- remain here until reset */ 4762306a36Sopenharmony_ci SYNC /* looking for synchronization bytes to restart inflate() */ 4862306a36Sopenharmony_ci} inflate_mode; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* 5162306a36Sopenharmony_ci State transitions between above modes - 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci (most modes can go to the BAD or MEM mode -- not shown for clarity) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci Process header: 5662306a36Sopenharmony_ci HEAD -> (gzip) or (zlib) 5762306a36Sopenharmony_ci (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 5862306a36Sopenharmony_ci NAME -> COMMENT -> HCRC -> TYPE 5962306a36Sopenharmony_ci (zlib) -> DICTID or TYPE 6062306a36Sopenharmony_ci DICTID -> DICT -> TYPE 6162306a36Sopenharmony_ci Read deflate blocks: 6262306a36Sopenharmony_ci TYPE -> STORED or TABLE or LEN or CHECK 6362306a36Sopenharmony_ci STORED -> COPY -> TYPE 6462306a36Sopenharmony_ci TABLE -> LENLENS -> CODELENS -> LEN 6562306a36Sopenharmony_ci Read deflate codes: 6662306a36Sopenharmony_ci LEN -> LENEXT or LIT or TYPE 6762306a36Sopenharmony_ci LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 6862306a36Sopenharmony_ci LIT -> LEN 6962306a36Sopenharmony_ci Process trailer: 7062306a36Sopenharmony_ci CHECK -> LENGTH -> DONE 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* state maintained between inflate() calls. Approximately 7K bytes. */ 7462306a36Sopenharmony_cistruct inflate_state { 7562306a36Sopenharmony_ci inflate_mode mode; /* current inflate mode */ 7662306a36Sopenharmony_ci int last; /* true if processing last block */ 7762306a36Sopenharmony_ci int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 7862306a36Sopenharmony_ci int havedict; /* true if dictionary provided */ 7962306a36Sopenharmony_ci int flags; /* gzip header method and flags (0 if zlib) */ 8062306a36Sopenharmony_ci unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 8162306a36Sopenharmony_ci unsigned long check; /* protected copy of check value */ 8262306a36Sopenharmony_ci unsigned long total; /* protected copy of output count */ 8362306a36Sopenharmony_ci /* gz_headerp head; */ /* where to save gzip header information */ 8462306a36Sopenharmony_ci /* sliding window */ 8562306a36Sopenharmony_ci unsigned wbits; /* log base 2 of requested window size */ 8662306a36Sopenharmony_ci unsigned wsize; /* window size or zero if not using window */ 8762306a36Sopenharmony_ci unsigned whave; /* valid bytes in the window */ 8862306a36Sopenharmony_ci unsigned write; /* window write index */ 8962306a36Sopenharmony_ci unsigned char *window; /* allocated sliding window, if needed */ 9062306a36Sopenharmony_ci /* bit accumulator */ 9162306a36Sopenharmony_ci unsigned long hold; /* input bit accumulator */ 9262306a36Sopenharmony_ci unsigned bits; /* number of bits in "in" */ 9362306a36Sopenharmony_ci /* for string and stored block copying */ 9462306a36Sopenharmony_ci unsigned length; /* literal or length of data to copy */ 9562306a36Sopenharmony_ci unsigned offset; /* distance back to copy string from */ 9662306a36Sopenharmony_ci /* for table and code decoding */ 9762306a36Sopenharmony_ci unsigned extra; /* extra bits needed */ 9862306a36Sopenharmony_ci /* fixed and dynamic code tables */ 9962306a36Sopenharmony_ci code const *lencode; /* starting table for length/literal codes */ 10062306a36Sopenharmony_ci code const *distcode; /* starting table for distance codes */ 10162306a36Sopenharmony_ci unsigned lenbits; /* index bits for lencode */ 10262306a36Sopenharmony_ci unsigned distbits; /* index bits for distcode */ 10362306a36Sopenharmony_ci /* dynamic table building */ 10462306a36Sopenharmony_ci unsigned ncode; /* number of code length code lengths */ 10562306a36Sopenharmony_ci unsigned nlen; /* number of length code lengths */ 10662306a36Sopenharmony_ci unsigned ndist; /* number of distance code lengths */ 10762306a36Sopenharmony_ci unsigned have; /* number of code lengths in lens[] */ 10862306a36Sopenharmony_ci code *next; /* next available space in codes[] */ 10962306a36Sopenharmony_ci unsigned short lens[320]; /* temporary storage for code lengths */ 11062306a36Sopenharmony_ci unsigned short work[288]; /* work area for code table building */ 11162306a36Sopenharmony_ci code codes[ENOUGH]; /* space for code tables */ 11262306a36Sopenharmony_ci}; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* Reverse the bytes in a 32-bit value */ 11562306a36Sopenharmony_ci#define REVERSE(q) \ 11662306a36Sopenharmony_ci ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 11762306a36Sopenharmony_ci (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#endif 120