ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

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