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