annotate src/zlib-1.2.7/inflate.h @ 83:ae30d91d2ffe

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