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