Back to index

tetex-bin  3.0
inflate.h
Go to the documentation of this file.
00001 /* inflate.h -- internal inflate state definition
00002  * Copyright (C) 1995-2003 Mark Adler
00003  * For conditions of distribution and use, see copyright notice in zlib.h
00004  */
00005 
00006 /* WARNING: this file should *not* be used by applications. It is
00007    part of the implementation of the compression library and is
00008    subject to change. Applications should only use zlib.h.
00009  */
00010 
00011 /* define NO_GZIP when compiling if you want to disable gzip header and
00012    trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
00013    the crc code when it is not needed.  For shared libraries, gzip decoding
00014    should be left enabled. */
00015 #ifndef NO_GZIP
00016 #  define GUNZIP
00017 #endif
00018 
00019 /* Possible inflate modes between inflate() calls */
00020 typedef enum {
00021     HEAD,       /* i: waiting for magic header */
00022 #ifdef GUNZIP
00023     FLAGS,      /* i: waiting for method and flags (gzip) */
00024     TIME,       /* i: waiting for modification time (gzip) */
00025     OS,         /* i: waiting for extra flags and operating system (gzip) */
00026     EXLEN,      /* i: waiting for extra length (gzip) */
00027     EXTRA,      /* i: waiting for extra bytes (gzip) */
00028     NAME,       /* i: waiting for end of file name (gzip) */
00029     COMMENT,    /* i: waiting for end of comment (gzip) */
00030     HCRC,       /* i: waiting for header crc (gzip) */
00031 #endif
00032     DICTID,     /* i: waiting for dictionary check value */
00033     DICT,       /* waiting for inflateSetDictionary() call */
00034         TYPE,       /* i: waiting for type bits, including last-flag bit */
00035         TYPEDO,     /* i: same, but skip check to exit inflate on new block */
00036         STORED,     /* i: waiting for stored size (length and complement) */
00037         COPY,       /* i/o: waiting for input or output to copy stored block */
00038         TABLE,      /* i: waiting for dynamic block table lengths */
00039         LENLENS,    /* i: waiting for code length code lengths */
00040         CODELENS,   /* i: waiting for length/lit and distance code lengths */
00041             LEN,        /* i: waiting for length/lit code */
00042             LENEXT,     /* i: waiting for length extra bits */
00043             DIST,       /* i: waiting for distance code */
00044             DISTEXT,    /* i: waiting for distance extra bits */
00045             MATCH,      /* o: waiting for output space to copy string */
00046             LIT,        /* o: waiting for output space to write literal */
00047     CHECK,      /* i: waiting for 32-bit check value */
00048 #ifdef GUNZIP
00049     LENGTH,     /* i: waiting for 32-bit length (gzip) */
00050 #endif
00051     DONE,       /* finished check, done -- remain here until reset */
00052     BAD,        /* got a data error -- remain here until reset */
00053     MEM,        /* got an inflate() memory error -- remain here until reset */
00054     SYNC        /* looking for synchronization bytes to restart inflate() */
00055 } inflate_mode;
00056 
00057 /*
00058     State transitions between above modes -
00059 
00060     (most modes can go to the BAD or MEM mode -- not shown for clarity)
00061 
00062     Process header:
00063         HEAD -> (gzip) or (zlib)
00064         (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
00065         NAME -> COMMENT -> HCRC -> TYPE
00066         (zlib) -> DICTID or TYPE
00067         DICTID -> DICT -> TYPE
00068     Read deflate blocks:
00069             TYPE -> STORED or TABLE or LEN or CHECK
00070             STORED -> COPY -> TYPE
00071             TABLE -> LENLENS -> CODELENS -> LEN
00072     Read deflate codes:
00073                 LEN -> LENEXT or LIT or TYPE
00074                 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
00075                 LIT -> LEN
00076     Process trailer:
00077         CHECK -> LENGTH -> DONE
00078  */
00079 
00080 /* state maintained between inflate() calls.  Approximately 7K bytes. */
00081 struct inflate_state {
00082     inflate_mode mode;          /* current inflate mode */
00083     int last;                   /* true if processing last block */
00084     int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
00085     int havedict;               /* true if dictionary provided */
00086     int flags;                  /* gzip header method and flags (0 if zlib) */
00087     unsigned long check;        /* protected copy of check value */
00088     unsigned long total;        /* protected copy of output count */
00089         /* sliding window */
00090     unsigned wbits;             /* log base 2 of requested window size */
00091     unsigned wsize;             /* window size or zero if not using window */
00092     unsigned whave;             /* valid bytes in the window */
00093     unsigned write;             /* window write index */
00094     unsigned char FAR *window;  /* allocated sliding window, if needed */
00095         /* bit accumulator */
00096     unsigned long hold;         /* input bit accumulator */
00097     unsigned bits;              /* number of bits in "in" */
00098         /* for string and stored block copying */
00099     unsigned length;            /* literal or length of data to copy */
00100     unsigned offset;            /* distance back to copy string from */
00101         /* for table and code decoding */
00102     unsigned extra;             /* extra bits needed */
00103         /* fixed and dynamic code tables */
00104     code const FAR *lencode;    /* starting table for length/literal codes */
00105     code const FAR *distcode;   /* starting table for distance codes */
00106     unsigned lenbits;           /* index bits for lencode */
00107     unsigned distbits;          /* index bits for distcode */
00108         /* dynamic table building */
00109     unsigned ncode;             /* number of code length code lengths */
00110     unsigned nlen;              /* number of length code lengths */
00111     unsigned ndist;             /* number of distance code lengths */
00112     unsigned have;              /* number of code lengths in lens[] */
00113     code FAR *next;             /* next available space in codes[] */
00114     unsigned short lens[320];   /* temporary storage for code lengths */
00115     unsigned short work[288];   /* work area for code table building */
00116     code codes[ENOUGH];         /* space for code tables */
00117 };