Blame deps/zlib/inflate.h

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