Back to home page

OSCL-LXR

 
 

    


0001 #ifndef INFLATE_H
0002 #define INFLATE_H
0003 
0004 /* inflate.h -- internal inflate state definition
0005  * Copyright (C) 1995-2004 Mark Adler
0006  * For conditions of distribution and use, see copyright notice in zlib.h
0007  */
0008 
0009 /* WARNING: this file should *not* be used by applications. It is
0010    part of the implementation of the compression library and is
0011    subject to change. Applications should only use zlib.h.
0012  */
0013 
0014 #include "inftrees.h"
0015 
0016 /* Possible inflate modes between inflate() calls */
0017 typedef enum {
0018     HEAD,       /* i: waiting for magic header */
0019     FLAGS,      /* i: waiting for method and flags (gzip) */
0020     TIME,       /* i: waiting for modification time (gzip) */
0021     OS,         /* i: waiting for extra flags and operating system (gzip) */
0022     EXLEN,      /* i: waiting for extra length (gzip) */
0023     EXTRA,      /* i: waiting for extra bytes (gzip) */
0024     NAME,       /* i: waiting for end of file name (gzip) */
0025     COMMENT,    /* i: waiting for end of comment (gzip) */
0026     HCRC,       /* i: waiting for header crc (gzip) */
0027     DICTID,     /* i: waiting for dictionary check value */
0028     DICT,       /* waiting for inflateSetDictionary() call */
0029         TYPE,       /* i: waiting for type bits, including last-flag bit */
0030         TYPEDO,     /* i: same, but skip check to exit inflate on new block */
0031         STORED,     /* i: waiting for stored size (length and complement) */
0032         COPY,       /* i/o: waiting for input or output to copy stored block */
0033         TABLE,      /* i: waiting for dynamic block table lengths */
0034         LENLENS,    /* i: waiting for code length code lengths */
0035         CODELENS,   /* i: waiting for length/lit and distance code lengths */
0036             LEN,        /* i: waiting for length/lit code */
0037             LENEXT,     /* i: waiting for length extra bits */
0038             DIST,       /* i: waiting for distance code */
0039             DISTEXT,    /* i: waiting for distance extra bits */
0040             MATCH,      /* o: waiting for output space to copy string */
0041             LIT,        /* o: waiting for output space to write literal */
0042     CHECK,      /* i: waiting for 32-bit check value */
0043     LENGTH,     /* i: waiting for 32-bit length (gzip) */
0044     DONE,       /* finished check, done -- remain here until reset */
0045     BAD,        /* got a data error -- remain here until reset */
0046     MEM,        /* got an inflate() memory error -- remain here until reset */
0047     SYNC        /* looking for synchronization bytes to restart inflate() */
0048 } inflate_mode;
0049 
0050 /*
0051     State transitions between above modes -
0052 
0053     (most modes can go to the BAD or MEM mode -- not shown for clarity)
0054 
0055     Process header:
0056         HEAD -> (gzip) or (zlib)
0057         (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
0058         NAME -> COMMENT -> HCRC -> TYPE
0059         (zlib) -> DICTID or TYPE
0060         DICTID -> DICT -> TYPE
0061     Read deflate blocks:
0062             TYPE -> STORED or TABLE or LEN or CHECK
0063             STORED -> COPY -> TYPE
0064             TABLE -> LENLENS -> CODELENS -> LEN
0065     Read deflate codes:
0066                 LEN -> LENEXT or LIT or TYPE
0067                 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
0068                 LIT -> LEN
0069     Process trailer:
0070         CHECK -> LENGTH -> DONE
0071  */
0072 
0073 /* state maintained between inflate() calls.  Approximately 7K bytes. */
0074 struct inflate_state {
0075     inflate_mode mode;          /* current inflate mode */
0076     int last;                   /* true if processing last block */
0077     int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
0078     int havedict;               /* true if dictionary provided */
0079     int flags;                  /* gzip header method and flags (0 if zlib) */
0080     unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */
0081     unsigned long check;        /* protected copy of check value */
0082     unsigned long total;        /* protected copy of output count */
0083  /*   gz_headerp head; */           /* where to save gzip header information */
0084         /* sliding window */
0085     unsigned wbits;             /* log base 2 of requested window size */
0086     unsigned wsize;             /* window size or zero if not using window */
0087     unsigned whave;             /* valid bytes in the window */
0088     unsigned write;             /* window write index */
0089     unsigned char *window;  /* allocated sliding window, if needed */
0090         /* bit accumulator */
0091     unsigned long hold;         /* input bit accumulator */
0092     unsigned bits;              /* number of bits in "in" */
0093         /* for string and stored block copying */
0094     unsigned length;            /* literal or length of data to copy */
0095     unsigned offset;            /* distance back to copy string from */
0096         /* for table and code decoding */
0097     unsigned extra;             /* extra bits needed */
0098         /* fixed and dynamic code tables */
0099     code const *lencode;    /* starting table for length/literal codes */
0100     code const *distcode;   /* starting table for distance codes */
0101     unsigned lenbits;           /* index bits for lencode */
0102     unsigned distbits;          /* index bits for distcode */
0103         /* dynamic table building */
0104     unsigned ncode;             /* number of code length code lengths */
0105     unsigned nlen;              /* number of length code lengths */
0106     unsigned ndist;             /* number of distance code lengths */
0107     unsigned have;              /* number of code lengths in lens[] */
0108     code *next;             /* next available space in codes[] */
0109     unsigned short lens[320];   /* temporary storage for code lengths */
0110     unsigned short work[288];   /* work area for code table building */
0111     code codes[ENOUGH];         /* space for code tables */
0112 };
0113 
0114 /* Reverse the bytes in a 32-bit value */
0115 #define REVERSE(q) \
0116     ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
0117      (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
0118 
0119 #endif