added compression flags into header, compiler now finalized dvander
authorDavid Anderson <dvander@alliedmods.net>
Sat Jul 15 04:51:28 2006 +0000 (2006-07-15)
branchdvander
changeset 223a0b11141fa9
parent 21 a00fa0c94a6d
child 23 040a84cd0eee
added compression flags into header, compiler now finalized
compiler-init/pawncc.c
compiler-init/sp_file.h
compiler-init/spcomp.vcproj
compiler-init/zlib/adler32.c
compiler-init/zlib/compress.c
compiler-init/zlib/crc32.c
compiler-init/zlib/crc32.h
compiler-init/zlib/deflate.c
compiler-init/zlib/deflate.h
compiler-init/zlib/gzio.c
compiler-init/zlib/infback.c
compiler-init/zlib/inffast.c
compiler-init/zlib/inffast.h
compiler-init/zlib/inffixed.h
compiler-init/zlib/inflate.c
compiler-init/zlib/inflate.h
compiler-init/zlib/inftrees.c
compiler-init/zlib/inftrees.h
compiler-init/zlib/trees.c
compiler-init/zlib/trees.h
compiler-init/zlib/uncompr.c
compiler-init/zlib/zconf.h
compiler-init/zlib/zlib.h
compiler-init/zlib/zutil.c
compiler-init/zlib/zutil.h
     1.1 --- a/compiler-init/pawncc.c	Sat Jul 15 03:24:45 2006 +0000
     1.2 +++ b/compiler-init/pawncc.c	Sat Jul 15 04:51:28 2006 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  #include "sp_file.h"
     1.5  #include "amx.h"
     1.6  #include "osdefs.h"
     1.7 +#include "zlib/zlib.h"
     1.8  
     1.9  #define NUM_SECTIONS	6
    1.10  
    1.11 @@ -328,6 +329,8 @@
    1.12  				}
    1.13  			}
    1.14  			cod.codesize = (uint32_t)(tptr - tbase);
    1.15 +			cod.disksize = cod.codesize;
    1.16 +			cod.compression = SPFILE_COMPRESSION_NONE;
    1.17  			sfwrite(&cod, sizeof(cod), 1, fp);
    1.18  			sfwrite(tbase, cod.codesize, 1, fp);
    1.19  			free(tbase);
    1.20 @@ -346,24 +349,58 @@
    1.21  		{
    1.22  			sp_file_data_t dat;
    1.23  			unsigned char *dbase;
    1.24 +			Bytef *cmp_dbase;
    1.25 +			uLong disksize;
    1.26 +			int err;
    1.27  
    1.28  			dat.datasize = hdr->hea - hdr->dat;
    1.29  			dat.memsize = hdr->stp;
    1.30  			dat.data = sizeof(dat);
    1.31 -			dbase = (unsigned char *)hdr + hdr->dat;
    1.32 +			dat.compression = SPFILE_COMPRESSION_GZ;
    1.33  
    1.34 -			sfwrite(&dat, sizeof(dat), 1, fp);
    1.35  			if (dat.datasize)
    1.36  			{
    1.37 -				sfwrite(dbase, dat.datasize, 1, fp);
    1.38 +				dat.disksize = (uint32_t)compressBound((uLong)dat.datasize);
    1.39 +
    1.40 +				dbase = (unsigned char *)hdr + hdr->dat;
    1.41 +				cmp_dbase = (Bytef *)malloc(dat.disksize);
    1.42 +
    1.43 +				/* compress */
    1.44 +				err = compress2(cmp_dbase, &disksize, (Bytef *)dbase, dat.datasize, Z_BEST_COMPRESSION);
    1.45 +
    1.46 +				if (err != Z_OK)
    1.47 +				{
    1.48 +					pc_printf("Failed to compress DAT section with error: %d\n", err);
    1.49 +					pc_printf("Defaulting to no compression.\n");
    1.50 +					dat.compression = SPFILE_COMPRESSION_NONE;
    1.51 +					dat.disksize = dat.datasize;
    1.52 +
    1.53 +					/* write header */
    1.54 +					sfwrite(&dat, sizeof(dat), 1, fp);
    1.55 +					/* write data */
    1.56 +					sfwrite(&dbase, dat.datasize, 1, fp);
    1.57 +				} else {
    1.58 +					dat.disksize = (uint32_t)disksize;
    1.59 +
    1.60 +					/* write header */
    1.61 +					sfwrite(&dat, sizeof(dat), 1, fp);
    1.62 +					/* write data */
    1.63 +					sfwrite(&cmp_dbase, dat.disksize, 1, fp);
    1.64 +				}
    1.65 +				
    1.66 +				free(cmp_dbase);
    1.67 +			} else {
    1.68 +				/* should be 0 */
    1.69 +				dat.disksize = dat.datasize;
    1.70 +				sfwrite(&dat, sizeof(dat), 1, fp);
    1.71  			}
    1.72  
    1.73  			/* backtrack and write this section's header info */
    1.74  			curoffs = ftell(fp);
    1.75  			fseek(fp, offsets[1], SEEK_SET);
    1.76  			sfwrite(&lastsection, sizeof(uint32_t), 1, fp);
    1.77 -			dat.datasize += sizeof(dat);
    1.78 -			sfwrite(&dat.datasize, sizeof(uint32_t),1, fp);
    1.79 +			disksize += sizeof(dat);
    1.80 +			sfwrite(&disksize, sizeof(uint32_t),1, fp);
    1.81  			fseek(fp, curoffs, SEEK_SET);
    1.82  			lastsection = curoffs;
    1.83  		}
     2.1 --- a/compiler-init/sp_file.h	Sat Jul 15 03:24:45 2006 +0000
     2.2 +++ b/compiler-init/sp_file.h	Sat Jul 15 04:51:28 2006 +0000
     2.3 @@ -59,14 +59,21 @@
     2.4  	uint8_t		codeversion;	/* version of opcodes supported */
     2.5  	uint16_t	flags;			/* flags */
     2.6  	uint32_t	main;			/* address to "main" if any */
     2.7 +	uint32_t	disksize;		/* disksize in bytes */
     2.8 +	uint32_t	compression;	/* compression */
     2.9  	uint32_t	code;			/* rel offset to code */
    2.10  } sp_file_code_t;
    2.11  
    2.12 +#define SPFILE_COMPRESSION_NONE		0
    2.13 +#define SPFILE_COMPRESSION_GZ		1
    2.14 +
    2.15  /* section is .data */
    2.16  typedef struct sp_file_data_s
    2.17  {
    2.18 -	uint32_t	datasize;		/* size of data section */
    2.19 +	uint32_t	datasize;		/* size of data section in memory */
    2.20  	uint32_t	memsize;		/* total mem required (includes data) */
    2.21 +	uint32_t	disksize;		/* size of data on disk (compressed) */
    2.22 +	uint8_t		compression;	/* compression */
    2.23  	uint32_t	data;			/* file offset to data (helper) */
    2.24  } sp_file_data_t;
    2.25  
     3.1 --- a/compiler-init/spcomp.vcproj	Sat Jul 15 03:24:45 2006 +0000
     3.2 +++ b/compiler-init/spcomp.vcproj	Sat Jul 15 04:51:28 2006 +0000
     3.3 @@ -115,7 +115,7 @@
     3.4  			/>
     3.5  			<Tool
     3.6  				Name="VCCLCompilerTool"
     3.7 -				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
     3.8 +				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;ZEXPORT"
     3.9  				RuntimeLibrary="2"
    3.10  				UsePrecompiledHeader="0"
    3.11  				WarningLevel="3"
    3.12 @@ -250,10 +250,6 @@
    3.13  				RelativePath=".\scvars.c"
    3.14  				>
    3.15  			</File>
    3.16 -			<File
    3.17 -				RelativePath=".\sp_file.c"
    3.18 -				>
    3.19 -			</File>
    3.20  		</Filter>
    3.21  		<Filter
    3.22  			Name="Header Files"
    3.23 @@ -307,6 +303,106 @@
    3.24  				>
    3.25  			</File>
    3.26  		</Filter>
    3.27 +		<Filter
    3.28 +			Name="zlib"
    3.29 +			>
    3.30 +			<Filter
    3.31 +				Name="Source Files"
    3.32 +				>
    3.33 +				<File
    3.34 +					RelativePath=".\zlib\adler32.c"
    3.35 +					>
    3.36 +				</File>
    3.37 +				<File
    3.38 +					RelativePath=".\zlib\compress.c"
    3.39 +					>
    3.40 +				</File>
    3.41 +				<File
    3.42 +					RelativePath=".\zlib\crc32.c"
    3.43 +					>
    3.44 +				</File>
    3.45 +				<File
    3.46 +					RelativePath=".\zlib\deflate.c"
    3.47 +					>
    3.48 +				</File>
    3.49 +				<File
    3.50 +					RelativePath=".\zlib\gzio.c"
    3.51 +					>
    3.52 +				</File>
    3.53 +				<File
    3.54 +					RelativePath=".\zlib\infback.c"
    3.55 +					>
    3.56 +				</File>
    3.57 +				<File
    3.58 +					RelativePath=".\zlib\inffast.c"
    3.59 +					>
    3.60 +				</File>
    3.61 +				<File
    3.62 +					RelativePath=".\zlib\inflate.c"
    3.63 +					>
    3.64 +				</File>
    3.65 +				<File
    3.66 +					RelativePath=".\zlib\inftrees.c"
    3.67 +					>
    3.68 +				</File>
    3.69 +				<File
    3.70 +					RelativePath=".\zlib\trees.c"
    3.71 +					>
    3.72 +				</File>
    3.73 +				<File
    3.74 +					RelativePath=".\zlib\uncompr.c"
    3.75 +					>
    3.76 +				</File>
    3.77 +				<File
    3.78 +					RelativePath=".\zlib\zutil.c"
    3.79 +					>
    3.80 +				</File>
    3.81 +			</Filter>
    3.82 +			<Filter
    3.83 +				Name="Header Files"
    3.84 +				>
    3.85 +				<File
    3.86 +					RelativePath=".\zlib\crc32.h"
    3.87 +					>
    3.88 +				</File>
    3.89 +				<File
    3.90 +					RelativePath=".\zlib\deflate.h"
    3.91 +					>
    3.92 +				</File>
    3.93 +				<File
    3.94 +					RelativePath=".\zlib\inffast.h"
    3.95 +					>
    3.96 +				</File>
    3.97 +				<File
    3.98 +					RelativePath=".\zlib\inffixed.h"
    3.99 +					>
   3.100 +				</File>
   3.101 +				<File
   3.102 +					RelativePath=".\zlib\inflate.h"
   3.103 +					>
   3.104 +				</File>
   3.105 +				<File
   3.106 +					RelativePath=".\zlib\inftrees.h"
   3.107 +					>
   3.108 +				</File>
   3.109 +				<File
   3.110 +					RelativePath=".\zlib\trees.h"
   3.111 +					>
   3.112 +				</File>
   3.113 +				<File
   3.114 +					RelativePath=".\zlib\zconf.h"
   3.115 +					>
   3.116 +				</File>
   3.117 +				<File
   3.118 +					RelativePath=".\zlib\zlib.h"
   3.119 +					>
   3.120 +				</File>
   3.121 +				<File
   3.122 +					RelativePath=".\zlib\zutil.h"
   3.123 +					>
   3.124 +				</File>
   3.125 +			</Filter>
   3.126 +		</Filter>
   3.127  	</Files>
   3.128  	<Globals>
   3.129  	</Globals>
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/compiler-init/zlib/adler32.c	Sat Jul 15 04:51:28 2006 +0000
     4.3 @@ -0,0 +1,149 @@
     4.4 +/* adler32.c -- compute the Adler-32 checksum of a data stream
     4.5 + * Copyright (C) 1995-2004 Mark Adler
     4.6 + * For conditions of distribution and use, see copyright notice in zlib.h
     4.7 + */
     4.8 +
     4.9 +/* @(#) $Id$ */
    4.10 +
    4.11 +#define ZLIB_INTERNAL
    4.12 +#include "zlib.h"
    4.13 +
    4.14 +#define BASE 65521UL    /* largest prime smaller than 65536 */
    4.15 +#define NMAX 5552
    4.16 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
    4.17 +
    4.18 +#define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
    4.19 +#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
    4.20 +#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
    4.21 +#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
    4.22 +#define DO16(buf)   DO8(buf,0); DO8(buf,8);
    4.23 +
    4.24 +/* use NO_DIVIDE if your processor does not do division in hardware */
    4.25 +#ifdef NO_DIVIDE
    4.26 +#  define MOD(a) \
    4.27 +    do { \
    4.28 +        if (a >= (BASE << 16)) a -= (BASE << 16); \
    4.29 +        if (a >= (BASE << 15)) a -= (BASE << 15); \
    4.30 +        if (a >= (BASE << 14)) a -= (BASE << 14); \
    4.31 +        if (a >= (BASE << 13)) a -= (BASE << 13); \
    4.32 +        if (a >= (BASE << 12)) a -= (BASE << 12); \
    4.33 +        if (a >= (BASE << 11)) a -= (BASE << 11); \
    4.34 +        if (a >= (BASE << 10)) a -= (BASE << 10); \
    4.35 +        if (a >= (BASE << 9)) a -= (BASE << 9); \
    4.36 +        if (a >= (BASE << 8)) a -= (BASE << 8); \
    4.37 +        if (a >= (BASE << 7)) a -= (BASE << 7); \
    4.38 +        if (a >= (BASE << 6)) a -= (BASE << 6); \
    4.39 +        if (a >= (BASE << 5)) a -= (BASE << 5); \
    4.40 +        if (a >= (BASE << 4)) a -= (BASE << 4); \
    4.41 +        if (a >= (BASE << 3)) a -= (BASE << 3); \
    4.42 +        if (a >= (BASE << 2)) a -= (BASE << 2); \
    4.43 +        if (a >= (BASE << 1)) a -= (BASE << 1); \
    4.44 +        if (a >= BASE) a -= BASE; \
    4.45 +    } while (0)
    4.46 +#  define MOD4(a) \
    4.47 +    do { \
    4.48 +        if (a >= (BASE << 4)) a -= (BASE << 4); \
    4.49 +        if (a >= (BASE << 3)) a -= (BASE << 3); \
    4.50 +        if (a >= (BASE << 2)) a -= (BASE << 2); \
    4.51 +        if (a >= (BASE << 1)) a -= (BASE << 1); \
    4.52 +        if (a >= BASE) a -= BASE; \
    4.53 +    } while (0)
    4.54 +#else
    4.55 +#  define MOD(a) a %= BASE
    4.56 +#  define MOD4(a) a %= BASE
    4.57 +#endif
    4.58 +
    4.59 +/* ========================================================================= */
    4.60 +uLong ZEXPORT adler32(adler, buf, len)
    4.61 +    uLong adler;
    4.62 +    const Bytef *buf;
    4.63 +    uInt len;
    4.64 +{
    4.65 +    unsigned long sum2;
    4.66 +    unsigned n;
    4.67 +
    4.68 +    /* split Adler-32 into component sums */
    4.69 +    sum2 = (adler >> 16) & 0xffff;
    4.70 +    adler &= 0xffff;
    4.71 +
    4.72 +    /* in case user likes doing a byte at a time, keep it fast */
    4.73 +    if (len == 1) {
    4.74 +        adler += buf[0];
    4.75 +        if (adler >= BASE)
    4.76 +            adler -= BASE;
    4.77 +        sum2 += adler;
    4.78 +        if (sum2 >= BASE)
    4.79 +            sum2 -= BASE;
    4.80 +        return adler | (sum2 << 16);
    4.81 +    }
    4.82 +
    4.83 +    /* initial Adler-32 value (deferred check for len == 1 speed) */
    4.84 +    if (buf == Z_NULL)
    4.85 +        return 1L;
    4.86 +
    4.87 +    /* in case short lengths are provided, keep it somewhat fast */
    4.88 +    if (len < 16) {
    4.89 +        while (len--) {
    4.90 +            adler += *buf++;
    4.91 +            sum2 += adler;
    4.92 +        }
    4.93 +        if (adler >= BASE)
    4.94 +            adler -= BASE;
    4.95 +        MOD4(sum2);             /* only added so many BASE's */
    4.96 +        return adler | (sum2 << 16);
    4.97 +    }
    4.98 +
    4.99 +    /* do length NMAX blocks -- requires just one modulo operation */
   4.100 +    while (len >= NMAX) {
   4.101 +        len -= NMAX;
   4.102 +        n = NMAX / 16;          /* NMAX is divisible by 16 */
   4.103 +        do {
   4.104 +            DO16(buf);          /* 16 sums unrolled */
   4.105 +            buf += 16;
   4.106 +        } while (--n);
   4.107 +        MOD(adler);
   4.108 +        MOD(sum2);
   4.109 +    }
   4.110 +
   4.111 +    /* do remaining bytes (less than NMAX, still just one modulo) */
   4.112 +    if (len) {                  /* avoid modulos if none remaining */
   4.113 +        while (len >= 16) {
   4.114 +            len -= 16;
   4.115 +            DO16(buf);
   4.116 +            buf += 16;
   4.117 +        }
   4.118 +        while (len--) {
   4.119 +            adler += *buf++;
   4.120 +            sum2 += adler;
   4.121 +        }
   4.122 +        MOD(adler);
   4.123 +        MOD(sum2);
   4.124 +    }
   4.125 +
   4.126 +    /* return recombined sums */
   4.127 +    return adler | (sum2 << 16);
   4.128 +}
   4.129 +
   4.130 +/* ========================================================================= */
   4.131 +uLong ZEXPORT adler32_combine(adler1, adler2, len2)
   4.132 +    uLong adler1;
   4.133 +    uLong adler2;
   4.134 +    z_off_t len2;
   4.135 +{
   4.136 +    unsigned long sum1;
   4.137 +    unsigned long sum2;
   4.138 +    unsigned rem;
   4.139 +
   4.140 +    /* the derivation of this formula is left as an exercise for the reader */
   4.141 +    rem = (unsigned)(len2 % BASE);
   4.142 +    sum1 = adler1 & 0xffff;
   4.143 +    sum2 = rem * sum1;
   4.144 +    MOD(sum2);
   4.145 +    sum1 += (adler2 & 0xffff) + BASE - 1;
   4.146 +    sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
   4.147 +    if (sum1 > BASE) sum1 -= BASE;
   4.148 +    if (sum1 > BASE) sum1 -= BASE;
   4.149 +    if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
   4.150 +    if (sum2 > BASE) sum2 -= BASE;
   4.151 +    return sum1 | (sum2 << 16);
   4.152 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/compiler-init/zlib/compress.c	Sat Jul 15 04:51:28 2006 +0000
     5.3 @@ -0,0 +1,79 @@
     5.4 +/* compress.c -- compress a memory buffer
     5.5 + * Copyright (C) 1995-2003 Jean-loup Gailly.
     5.6 + * For conditions of distribution and use, see copyright notice in zlib.h
     5.7 + */
     5.8 +
     5.9 +/* @(#) $Id$ */
    5.10 +
    5.11 +#define ZLIB_INTERNAL
    5.12 +#include "zlib.h"
    5.13 +
    5.14 +/* ===========================================================================
    5.15 +     Compresses the source buffer into the destination buffer. The level
    5.16 +   parameter has the same meaning as in deflateInit.  sourceLen is the byte
    5.17 +   length of the source buffer. Upon entry, destLen is the total size of the
    5.18 +   destination buffer, which must be at least 0.1% larger than sourceLen plus
    5.19 +   12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
    5.20 +
    5.21 +     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
    5.22 +   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
    5.23 +   Z_STREAM_ERROR if the level parameter is invalid.
    5.24 +*/
    5.25 +int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
    5.26 +    Bytef *dest;
    5.27 +    uLongf *destLen;
    5.28 +    const Bytef *source;
    5.29 +    uLong sourceLen;
    5.30 +    int level;
    5.31 +{
    5.32 +    z_stream stream;
    5.33 +    int err;
    5.34 +
    5.35 +    stream.next_in = (Bytef*)source;
    5.36 +    stream.avail_in = (uInt)sourceLen;
    5.37 +#ifdef MAXSEG_64K
    5.38 +    /* Check for source > 64K on 16-bit machine: */
    5.39 +    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
    5.40 +#endif
    5.41 +    stream.next_out = dest;
    5.42 +    stream.avail_out = (uInt)*destLen;
    5.43 +    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
    5.44 +
    5.45 +    stream.zalloc = (alloc_func)0;
    5.46 +    stream.zfree = (free_func)0;
    5.47 +    stream.opaque = (voidpf)0;
    5.48 +
    5.49 +    err = deflateInit(&stream, level);
    5.50 +    if (err != Z_OK) return err;
    5.51 +
    5.52 +    err = deflate(&stream, Z_FINISH);
    5.53 +    if (err != Z_STREAM_END) {
    5.54 +        deflateEnd(&stream);
    5.55 +        return err == Z_OK ? Z_BUF_ERROR : err;
    5.56 +    }
    5.57 +    *destLen = stream.total_out;
    5.58 +
    5.59 +    err = deflateEnd(&stream);
    5.60 +    return err;
    5.61 +}
    5.62 +
    5.63 +/* ===========================================================================
    5.64 + */
    5.65 +int ZEXPORT compress (dest, destLen, source, sourceLen)
    5.66 +    Bytef *dest;
    5.67 +    uLongf *destLen;
    5.68 +    const Bytef *source;
    5.69 +    uLong sourceLen;
    5.70 +{
    5.71 +    return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
    5.72 +}
    5.73 +
    5.74 +/* ===========================================================================
    5.75 +     If the default memLevel or windowBits for deflateInit() is changed, then
    5.76 +   this function needs to be updated.
    5.77 + */
    5.78 +uLong ZEXPORT compressBound (sourceLen)
    5.79 +    uLong sourceLen;
    5.80 +{
    5.81 +    return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
    5.82 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/compiler-init/zlib/crc32.c	Sat Jul 15 04:51:28 2006 +0000
     6.3 @@ -0,0 +1,423 @@
     6.4 +/* crc32.c -- compute the CRC-32 of a data stream
     6.5 + * Copyright (C) 1995-2005 Mark Adler
     6.6 + * For conditions of distribution and use, see copyright notice in zlib.h
     6.7 + *
     6.8 + * Thanks to Rodney Brown <[email protected]> for his contribution of faster
     6.9 + * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
    6.10 + * tables for updating the shift register in one step with three exclusive-ors
    6.11 + * instead of four steps with four exclusive-ors.  This results in about a
    6.12 + * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
    6.13 + */
    6.14 +
    6.15 +/* @(#) $Id$ */
    6.16 +
    6.17 +/*
    6.18 +  Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
    6.19 +  protection on the static variables used to control the first-use generation
    6.20 +  of the crc tables.  Therefore, if you #define DYNAMIC_CRC_TABLE, you should
    6.21 +  first call get_crc_table() to initialize the tables before allowing more than
    6.22 +  one thread to use crc32().
    6.23 + */
    6.24 +
    6.25 +#ifdef MAKECRCH
    6.26 +#  include <stdio.h>
    6.27 +#  ifndef DYNAMIC_CRC_TABLE
    6.28 +#    define DYNAMIC_CRC_TABLE
    6.29 +#  endif /* !DYNAMIC_CRC_TABLE */
    6.30 +#endif /* MAKECRCH */
    6.31 +
    6.32 +#include "zutil.h"      /* for STDC and FAR definitions */
    6.33 +
    6.34 +#define local static
    6.35 +
    6.36 +/* Find a four-byte integer type for crc32_little() and crc32_big(). */
    6.37 +#ifndef NOBYFOUR
    6.38 +#  ifdef STDC           /* need ANSI C limits.h to determine sizes */
    6.39 +#    include <limits.h>
    6.40 +#    define BYFOUR
    6.41 +#    if (UINT_MAX == 0xffffffffUL)
    6.42 +       typedef unsigned int u4;
    6.43 +#    else
    6.44 +#      if (ULONG_MAX == 0xffffffffUL)
    6.45 +         typedef unsigned long u4;
    6.46 +#      else
    6.47 +#        if (USHRT_MAX == 0xffffffffUL)
    6.48 +           typedef unsigned short u4;
    6.49 +#        else
    6.50 +#          undef BYFOUR     /* can't find a four-byte integer type! */
    6.51 +#        endif
    6.52 +#      endif
    6.53 +#    endif
    6.54 +#  endif /* STDC */
    6.55 +#endif /* !NOBYFOUR */
    6.56 +
    6.57 +/* Definitions for doing the crc four data bytes at a time. */
    6.58 +#ifdef BYFOUR
    6.59 +#  define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
    6.60 +                (((w)&0xff00)<<8)+(((w)&0xff)<<24))
    6.61 +   local unsigned long crc32_little OF((unsigned long,
    6.62 +                        const unsigned char FAR *, unsigned));
    6.63 +   local unsigned long crc32_big OF((unsigned long,
    6.64 +                        const unsigned char FAR *, unsigned));
    6.65 +#  define TBLS 8
    6.66 +#else
    6.67 +#  define TBLS 1
    6.68 +#endif /* BYFOUR */
    6.69 +
    6.70 +/* Local functions for crc concatenation */
    6.71 +local unsigned long gf2_matrix_times OF((unsigned long *mat,
    6.72 +                                         unsigned long vec));
    6.73 +local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
    6.74 +
    6.75 +#ifdef DYNAMIC_CRC_TABLE
    6.76 +
    6.77 +local volatile int crc_table_empty = 1;
    6.78 +local unsigned long FAR crc_table[TBLS][256];
    6.79 +local void make_crc_table OF((void));
    6.80 +#ifdef MAKECRCH
    6.81 +   local void write_table OF((FILE *, const unsigned long FAR *));
    6.82 +#endif /* MAKECRCH */
    6.83 +/*
    6.84 +  Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
    6.85 +  x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
    6.86 +
    6.87 +  Polynomials over GF(2) are represented in binary, one bit per coefficient,
    6.88 +  with the lowest powers in the most significant bit.  Then adding polynomials
    6.89 +  is just exclusive-or, and multiplying a polynomial by x is a right shift by
    6.90 +  one.  If we call the above polynomial p, and represent a byte as the
    6.91 +  polynomial q, also with the lowest power in the most significant bit (so the
    6.92 +  byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
    6.93 +  where a mod b means the remainder after dividing a by b.
    6.94 +
    6.95 +  This calculation is done using the shift-register method of multiplying and
    6.96 +  taking the remainder.  The register is initialized to zero, and for each
    6.97 +  incoming bit, x^32 is added mod p to the register if the bit is a one (where
    6.98 +  x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
    6.99 +  x (which is shifting right by one and adding x^32 mod p if the bit shifted
   6.100 +  out is a one).  We start with the highest power (least significant bit) of
   6.101 +  q and repeat for all eight bits of q.
   6.102 +
   6.103 +  The first table is simply the CRC of all possible eight bit values.  This is
   6.104 +  all the information needed to generate CRCs on data a byte at a time for all
   6.105 +  combinations of CRC register values and incoming bytes.  The remaining tables
   6.106 +  allow for word-at-a-time CRC calculation for both big-endian and little-
   6.107 +  endian machines, where a word is four bytes.
   6.108 +*/
   6.109 +local void make_crc_table()
   6.110 +{
   6.111 +    unsigned long c;
   6.112 +    int n, k;
   6.113 +    unsigned long poly;                 /* polynomial exclusive-or pattern */
   6.114 +    /* terms of polynomial defining this crc (except x^32): */
   6.115 +    static volatile int first = 1;      /* flag to limit concurrent making */
   6.116 +    static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
   6.117 +
   6.118 +    /* See if another task is already doing this (not thread-safe, but better
   6.119 +       than nothing -- significantly reduces duration of vulnerability in
   6.120 +       case the advice about DYNAMIC_CRC_TABLE is ignored) */
   6.121 +    if (first) {
   6.122 +        first = 0;
   6.123 +
   6.124 +        /* make exclusive-or pattern from polynomial (0xedb88320UL) */
   6.125 +        poly = 0UL;
   6.126 +        for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
   6.127 +            poly |= 1UL << (31 - p[n]);
   6.128 +
   6.129 +        /* generate a crc for every 8-bit value */
   6.130 +        for (n = 0; n < 256; n++) {
   6.131 +            c = (unsigned long)n;
   6.132 +            for (k = 0; k < 8; k++)
   6.133 +                c = c & 1 ? poly ^ (c >> 1) : c >> 1;
   6.134 +            crc_table[0][n] = c;
   6.135 +        }
   6.136 +
   6.137 +#ifdef BYFOUR
   6.138 +        /* generate crc for each value followed by one, two, and three zeros,
   6.139 +           and then the byte reversal of those as well as the first table */
   6.140 +        for (n = 0; n < 256; n++) {
   6.141 +            c = crc_table[0][n];
   6.142 +            crc_table[4][n] = REV(c);
   6.143 +            for (k = 1; k < 4; k++) {
   6.144 +                c = crc_table[0][c & 0xff] ^ (c >> 8);
   6.145 +                crc_table[k][n] = c;
   6.146 +                crc_table[k + 4][n] = REV(c);
   6.147 +            }
   6.148 +        }
   6.149 +#endif /* BYFOUR */
   6.150 +
   6.151 +        crc_table_empty = 0;
   6.152 +    }
   6.153 +    else {      /* not first */
   6.154 +        /* wait for the other guy to finish (not efficient, but rare) */
   6.155 +        while (crc_table_empty)
   6.156 +            ;
   6.157 +    }
   6.158 +
   6.159 +#ifdef MAKECRCH
   6.160 +    /* write out CRC tables to crc32.h */
   6.161 +    {
   6.162 +        FILE *out;
   6.163 +
   6.164 +        out = fopen("crc32.h", "w");
   6.165 +        if (out == NULL) return;
   6.166 +        fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
   6.167 +        fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
   6.168 +        fprintf(out, "local const unsigned long FAR ");
   6.169 +        fprintf(out, "crc_table[TBLS][256] =\n{\n  {\n");
   6.170 +        write_table(out, crc_table[0]);
   6.171 +#  ifdef BYFOUR
   6.172 +        fprintf(out, "#ifdef BYFOUR\n");
   6.173 +        for (k = 1; k < 8; k++) {
   6.174 +            fprintf(out, "  },\n  {\n");
   6.175 +            write_table(out, crc_table[k]);
   6.176 +        }
   6.177 +        fprintf(out, "#endif\n");
   6.178 +#  endif /* BYFOUR */
   6.179 +        fprintf(out, "  }\n};\n");
   6.180 +        fclose(out);
   6.181 +    }
   6.182 +#endif /* MAKECRCH */
   6.183 +}
   6.184 +
   6.185 +#ifdef MAKECRCH
   6.186 +local void write_table(out, table)
   6.187 +    FILE *out;
   6.188 +    const unsigned long FAR *table;
   6.189 +{
   6.190 +    int n;
   6.191 +
   6.192 +    for (n = 0; n < 256; n++)
   6.193 +        fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : "    ", table[n],
   6.194 +                n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
   6.195 +}
   6.196 +#endif /* MAKECRCH */
   6.197 +
   6.198 +#else /* !DYNAMIC_CRC_TABLE */
   6.199 +/* ========================================================================
   6.200 + * Tables of CRC-32s of all single-byte values, made by make_crc_table().
   6.201 + */
   6.202 +#include "crc32.h"
   6.203 +#endif /* DYNAMIC_CRC_TABLE */
   6.204 +
   6.205 +/* =========================================================================
   6.206 + * This function can be used by asm versions of crc32()
   6.207 + */
   6.208 +const unsigned long FAR * ZEXPORT get_crc_table()
   6.209 +{
   6.210 +#ifdef DYNAMIC_CRC_TABLE
   6.211 +    if (crc_table_empty)
   6.212 +        make_crc_table();
   6.213 +#endif /* DYNAMIC_CRC_TABLE */
   6.214 +    return (const unsigned long FAR *)crc_table;
   6.215 +}
   6.216 +
   6.217 +/* ========================================================================= */
   6.218 +#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
   6.219 +#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
   6.220 +
   6.221 +/* ========================================================================= */
   6.222 +unsigned long ZEXPORT crc32(crc, buf, len)
   6.223 +    unsigned long crc;
   6.224 +    const unsigned char FAR *buf;
   6.225 +    unsigned len;
   6.226 +{
   6.227 +    if (buf == Z_NULL) return 0UL;
   6.228 +
   6.229 +#ifdef DYNAMIC_CRC_TABLE
   6.230 +    if (crc_table_empty)
   6.231 +        make_crc_table();
   6.232 +#endif /* DYNAMIC_CRC_TABLE */
   6.233 +
   6.234 +#ifdef BYFOUR
   6.235 +    if (sizeof(void *) == sizeof(ptrdiff_t)) {
   6.236 +        u4 endian;
   6.237 +
   6.238 +        endian = 1;
   6.239 +        if (*((unsigned char *)(&endian)))
   6.240 +            return crc32_little(crc, buf, len);
   6.241 +        else
   6.242 +            return crc32_big(crc, buf, len);
   6.243 +    }
   6.244 +#endif /* BYFOUR */
   6.245 +    crc = crc ^ 0xffffffffUL;
   6.246 +    while (len >= 8) {
   6.247 +        DO8;
   6.248 +        len -= 8;
   6.249 +    }
   6.250 +    if (len) do {
   6.251 +        DO1;
   6.252 +    } while (--len);
   6.253 +    return crc ^ 0xffffffffUL;
   6.254 +}
   6.255 +
   6.256 +#ifdef BYFOUR
   6.257 +
   6.258 +/* ========================================================================= */
   6.259 +#define DOLIT4 c ^= *buf4++; \
   6.260 +        c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
   6.261 +            crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
   6.262 +#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
   6.263 +
   6.264 +/* ========================================================================= */
   6.265 +local unsigned long crc32_little(crc, buf, len)
   6.266 +    unsigned long crc;
   6.267 +    const unsigned char FAR *buf;
   6.268 +    unsigned len;
   6.269 +{
   6.270 +    register u4 c;
   6.271 +    register const u4 FAR *buf4;
   6.272 +
   6.273 +    c = (u4)crc;
   6.274 +    c = ~c;
   6.275 +    while (len && ((ptrdiff_t)buf & 3)) {
   6.276 +        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
   6.277 +        len--;
   6.278 +    }
   6.279 +
   6.280 +    buf4 = (const u4 FAR *)(const void FAR *)buf;
   6.281 +    while (len >= 32) {
   6.282 +        DOLIT32;
   6.283 +        len -= 32;
   6.284 +    }
   6.285 +    while (len >= 4) {
   6.286 +        DOLIT4;
   6.287 +        len -= 4;
   6.288 +    }
   6.289 +    buf = (const unsigned char FAR *)buf4;
   6.290 +
   6.291 +    if (len) do {
   6.292 +        c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
   6.293 +    } while (--len);
   6.294 +    c = ~c;
   6.295 +    return (unsigned long)c;
   6.296 +}
   6.297 +
   6.298 +/* ========================================================================= */
   6.299 +#define DOBIG4 c ^= *++buf4; \
   6.300 +        c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
   6.301 +            crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
   6.302 +#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
   6.303 +
   6.304 +/* ========================================================================= */
   6.305 +local unsigned long crc32_big(crc, buf, len)
   6.306 +    unsigned long crc;
   6.307 +    const unsigned char FAR *buf;
   6.308 +    unsigned len;
   6.309 +{
   6.310 +    register u4 c;
   6.311 +    register const u4 FAR *buf4;
   6.312 +
   6.313 +    c = REV((u4)crc);
   6.314 +    c = ~c;
   6.315 +    while (len && ((ptrdiff_t)buf & 3)) {
   6.316 +        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
   6.317 +        len--;
   6.318 +    }
   6.319 +
   6.320 +    buf4 = (const u4 FAR *)(const void FAR *)buf;
   6.321 +    buf4--;
   6.322 +    while (len >= 32) {
   6.323 +        DOBIG32;
   6.324 +        len -= 32;
   6.325 +    }
   6.326 +    while (len >= 4) {
   6.327 +        DOBIG4;
   6.328 +        len -= 4;
   6.329 +    }
   6.330 +    buf4++;
   6.331 +    buf = (const unsigned char FAR *)buf4;
   6.332 +
   6.333 +    if (len) do {
   6.334 +        c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
   6.335 +    } while (--len);
   6.336 +    c = ~c;
   6.337 +    return (unsigned long)(REV(c));
   6.338 +}
   6.339 +
   6.340 +#endif /* BYFOUR */
   6.341 +
   6.342 +#define GF2_DIM 32      /* dimension of GF(2) vectors (length of CRC) */
   6.343 +
   6.344 +/* ========================================================================= */
   6.345 +local unsigned long gf2_matrix_times(mat, vec)
   6.346 +    unsigned long *mat;
   6.347 +    unsigned long vec;
   6.348 +{
   6.349 +    unsigned long sum;
   6.350 +
   6.351 +    sum = 0;
   6.352 +    while (vec) {
   6.353 +        if (vec & 1)
   6.354 +            sum ^= *mat;
   6.355 +        vec >>= 1;
   6.356 +        mat++;
   6.357 +    }
   6.358 +    return sum;
   6.359 +}
   6.360 +
   6.361 +/* ========================================================================= */
   6.362 +local void gf2_matrix_square(square, mat)
   6.363 +    unsigned long *square;
   6.364 +    unsigned long *mat;
   6.365 +{
   6.366 +    int n;
   6.367 +
   6.368 +    for (n = 0; n < GF2_DIM; n++)
   6.369 +        square[n] = gf2_matrix_times(mat, mat[n]);
   6.370 +}
   6.371 +
   6.372 +/* ========================================================================= */
   6.373 +uLong ZEXPORT crc32_combine(crc1, crc2, len2)
   6.374 +    uLong crc1;
   6.375 +    uLong crc2;
   6.376 +    z_off_t len2;
   6.377 +{
   6.378 +    int n;
   6.379 +    unsigned long row;
   6.380 +    unsigned long even[GF2_DIM];    /* even-power-of-two zeros operator */
   6.381 +    unsigned long odd[GF2_DIM];     /* odd-power-of-two zeros operator */
   6.382 +
   6.383 +    /* degenerate case */
   6.384 +    if (len2 == 0)
   6.385 +        return crc1;
   6.386 +
   6.387 +    /* put operator for one zero bit in odd */
   6.388 +    odd[0] = 0xedb88320L;           /* CRC-32 polynomial */
   6.389 +    row = 1;
   6.390 +    for (n = 1; n < GF2_DIM; n++) {
   6.391 +        odd[n] = row;
   6.392 +        row <<= 1;
   6.393 +    }
   6.394 +
   6.395 +    /* put operator for two zero bits in even */
   6.396 +    gf2_matrix_square(even, odd);
   6.397 +
   6.398 +    /* put operator for four zero bits in odd */
   6.399 +    gf2_matrix_square(odd, even);
   6.400 +
   6.401 +    /* apply len2 zeros to crc1 (first square will put the operator for one
   6.402 +       zero byte, eight zero bits, in even) */
   6.403 +    do {
   6.404 +        /* apply zeros operator for this bit of len2 */
   6.405 +        gf2_matrix_square(even, odd);
   6.406 +        if (len2 & 1)
   6.407 +            crc1 = gf2_matrix_times(even, crc1);
   6.408 +        len2 >>= 1;
   6.409 +
   6.410 +        /* if no more bits set, then done */
   6.411 +        if (len2 == 0)
   6.412 +            break;
   6.413 +
   6.414 +        /* another iteration of the loop with odd and even swapped */
   6.415 +        gf2_matrix_square(odd, even);
   6.416 +        if (len2 & 1)
   6.417 +            crc1 = gf2_matrix_times(odd, crc1);
   6.418 +        len2 >>= 1;
   6.419 +
   6.420 +        /* if no more bits set, then done */
   6.421 +    } while (len2 != 0);
   6.422 +
   6.423 +    /* return combined crc */
   6.424 +    crc1 ^= crc2;
   6.425 +    return crc1;
   6.426 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/compiler-init/zlib/crc32.h	Sat Jul 15 04:51:28 2006 +0000
     7.3 @@ -0,0 +1,441 @@
     7.4 +/* crc32.h -- tables for rapid CRC calculation
     7.5 + * Generated automatically by crc32.c
     7.6 + */
     7.7 +
     7.8 +local const unsigned long FAR crc_table[TBLS][256] =
     7.9 +{
    7.10 +  {
    7.11 +    0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
    7.12 +    0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
    7.13 +    0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
    7.14 +    0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
    7.15 +    0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
    7.16 +    0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
    7.17 +    0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
    7.18 +    0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
    7.19 +    0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
    7.20 +    0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
    7.21 +    0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
    7.22 +    0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
    7.23 +    0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
    7.24 +    0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
    7.25 +    0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
    7.26 +    0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
    7.27 +    0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
    7.28 +    0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
    7.29 +    0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
    7.30 +    0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
    7.31 +    0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
    7.32 +    0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
    7.33 +    0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
    7.34 +    0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
    7.35 +    0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
    7.36 +    0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
    7.37 +    0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
    7.38 +    0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
    7.39 +    0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
    7.40 +    0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
    7.41 +    0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
    7.42 +    0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
    7.43 +    0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
    7.44 +    0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
    7.45 +    0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
    7.46 +    0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
    7.47 +    0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
    7.48 +    0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
    7.49 +    0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
    7.50 +    0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
    7.51 +    0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
    7.52 +    0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
    7.53 +    0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
    7.54 +    0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
    7.55 +    0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
    7.56 +    0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
    7.57 +    0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
    7.58 +    0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
    7.59 +    0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
    7.60 +    0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
    7.61 +    0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
    7.62 +    0x2d02ef8dUL
    7.63 +#ifdef BYFOUR
    7.64 +  },
    7.65 +  {
    7.66 +    0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
    7.67 +    0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
    7.68 +    0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
    7.69 +    0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
    7.70 +    0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
    7.71 +    0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
    7.72 +    0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
    7.73 +    0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
    7.74 +    0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
    7.75 +    0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
    7.76 +    0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
    7.77 +    0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
    7.78 +    0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
    7.79 +    0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
    7.80 +    0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
    7.81 +    0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
    7.82 +    0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
    7.83 +    0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
    7.84 +    0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
    7.85 +    0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
    7.86 +    0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
    7.87 +    0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
    7.88 +    0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
    7.89 +    0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
    7.90 +    0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
    7.91 +    0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
    7.92 +    0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
    7.93 +    0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
    7.94 +    0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
    7.95 +    0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
    7.96 +    0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
    7.97 +    0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
    7.98 +    0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
    7.99 +    0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
   7.100 +    0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
   7.101 +    0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
   7.102 +    0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
   7.103 +    0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
   7.104 +    0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
   7.105 +    0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
   7.106 +    0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
   7.107 +    0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
   7.108 +    0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
   7.109 +    0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
   7.110 +    0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
   7.111 +    0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
   7.112 +    0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
   7.113 +    0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
   7.114 +    0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
   7.115 +    0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
   7.116 +    0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
   7.117 +    0x9324fd72UL
   7.118 +  },
   7.119 +  {
   7.120 +    0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
   7.121 +    0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
   7.122 +    0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
   7.123 +    0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
   7.124 +    0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
   7.125 +    0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
   7.126 +    0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
   7.127 +    0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
   7.128 +    0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
   7.129 +    0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
   7.130 +    0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
   7.131 +    0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
   7.132 +    0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
   7.133 +    0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
   7.134 +    0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
   7.135 +    0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
   7.136 +    0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
   7.137 +    0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
   7.138 +    0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
   7.139 +    0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
   7.140 +    0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
   7.141 +    0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
   7.142 +    0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
   7.143 +    0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
   7.144 +    0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
   7.145 +    0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
   7.146 +    0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
   7.147 +    0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
   7.148 +    0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
   7.149 +    0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
   7.150 +    0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
   7.151 +    0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
   7.152 +    0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
   7.153 +    0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
   7.154 +    0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
   7.155 +    0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
   7.156 +    0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
   7.157 +    0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
   7.158 +    0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
   7.159 +    0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
   7.160 +    0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
   7.161 +    0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
   7.162 +    0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
   7.163 +    0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
   7.164 +    0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
   7.165 +    0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
   7.166 +    0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
   7.167 +    0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
   7.168 +    0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
   7.169 +    0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
   7.170 +    0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
   7.171 +    0xbe9834edUL
   7.172 +  },
   7.173 +  {
   7.174 +    0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
   7.175 +    0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
   7.176 +    0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
   7.177 +    0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
   7.178 +    0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
   7.179 +    0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
   7.180 +    0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
   7.181 +    0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
   7.182 +    0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
   7.183 +    0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
   7.184 +    0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
   7.185 +    0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
   7.186 +    0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
   7.187 +    0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
   7.188 +    0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
   7.189 +    0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
   7.190 +    0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
   7.191 +    0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
   7.192 +    0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
   7.193 +    0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
   7.194 +    0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
   7.195 +    0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
   7.196 +    0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
   7.197 +    0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
   7.198 +    0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
   7.199 +    0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
   7.200 +    0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
   7.201 +    0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
   7.202 +    0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
   7.203 +    0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
   7.204 +    0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
   7.205 +    0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
   7.206 +    0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
   7.207 +    0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
   7.208 +    0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
   7.209 +    0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
   7.210 +    0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
   7.211 +    0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
   7.212 +    0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
   7.213 +    0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
   7.214 +    0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
   7.215 +    0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
   7.216 +    0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
   7.217 +    0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
   7.218 +    0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
   7.219 +    0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
   7.220 +    0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
   7.221 +    0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
   7.222 +    0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
   7.223 +    0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
   7.224 +    0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
   7.225 +    0xde0506f1UL
   7.226 +  },
   7.227 +  {
   7.228 +    0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
   7.229 +    0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
   7.230 +    0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
   7.231 +    0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
   7.232 +    0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
   7.233 +    0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
   7.234 +    0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
   7.235 +    0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
   7.236 +    0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
   7.237 +    0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
   7.238 +    0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
   7.239 +    0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
   7.240 +    0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
   7.241 +    0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
   7.242 +    0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
   7.243 +    0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
   7.244 +    0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
   7.245 +    0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
   7.246 +    0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
   7.247 +    0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
   7.248 +    0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
   7.249 +    0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
   7.250 +    0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
   7.251 +    0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
   7.252 +    0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
   7.253 +    0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
   7.254 +    0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
   7.255 +    0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
   7.256 +    0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
   7.257 +    0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
   7.258 +    0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
   7.259 +    0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
   7.260 +    0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
   7.261 +    0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
   7.262 +    0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
   7.263 +    0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
   7.264 +    0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
   7.265 +    0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
   7.266 +    0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
   7.267 +    0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
   7.268 +    0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
   7.269 +    0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
   7.270 +    0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
   7.271 +    0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
   7.272 +    0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
   7.273 +    0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
   7.274 +    0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
   7.275 +    0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
   7.276 +    0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
   7.277 +    0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
   7.278 +    0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
   7.279 +    0x8def022dUL
   7.280 +  },
   7.281 +  {
   7.282 +    0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
   7.283 +    0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
   7.284 +    0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
   7.285 +    0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
   7.286 +    0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
   7.287 +    0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
   7.288 +    0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
   7.289 +    0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
   7.290 +    0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
   7.291 +    0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
   7.292 +    0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
   7.293 +    0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
   7.294 +    0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
   7.295 +    0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
   7.296 +    0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
   7.297 +    0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
   7.298 +    0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
   7.299 +    0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
   7.300 +    0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
   7.301 +    0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
   7.302 +    0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
   7.303 +    0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
   7.304 +    0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
   7.305 +    0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
   7.306 +    0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
   7.307 +    0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
   7.308 +    0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
   7.309 +    0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
   7.310 +    0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
   7.311 +    0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
   7.312 +    0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
   7.313 +    0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
   7.314 +    0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
   7.315 +    0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
   7.316 +    0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
   7.317 +    0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
   7.318 +    0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
   7.319 +    0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
   7.320 +    0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
   7.321 +    0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
   7.322 +    0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
   7.323 +    0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
   7.324 +    0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
   7.325 +    0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
   7.326 +    0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
   7.327 +    0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
   7.328 +    0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
   7.329 +    0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
   7.330 +    0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
   7.331 +    0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
   7.332 +    0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
   7.333 +    0x72fd2493UL
   7.334 +  },
   7.335 +  {
   7.336 +    0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
   7.337 +    0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
   7.338 +    0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
   7.339 +    0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
   7.340 +    0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
   7.341 +    0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
   7.342 +    0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
   7.343 +    0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
   7.344 +    0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
   7.345 +    0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
   7.346 +    0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
   7.347 +    0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
   7.348 +    0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
   7.349 +    0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
   7.350 +    0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
   7.351 +    0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
   7.352 +    0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
   7.353 +    0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
   7.354 +    0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
   7.355 +    0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
   7.356 +    0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
   7.357 +    0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
   7.358 +    0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
   7.359 +    0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
   7.360 +    0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
   7.361 +    0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
   7.362 +    0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
   7.363 +    0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
   7.364 +    0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
   7.365 +    0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
   7.366 +    0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
   7.367 +    0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
   7.368 +    0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
   7.369 +    0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
   7.370 +    0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
   7.371 +    0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
   7.372 +    0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
   7.373 +    0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
   7.374 +    0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
   7.375 +    0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
   7.376 +    0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
   7.377 +    0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
   7.378 +    0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
   7.379 +    0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
   7.380 +    0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
   7.381 +    0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
   7.382 +    0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
   7.383 +    0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
   7.384 +    0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
   7.385 +    0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
   7.386 +    0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
   7.387 +    0xed3498beUL
   7.388 +  },
   7.389 +  {
   7.390 +    0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
   7.391 +    0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
   7.392 +    0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
   7.393 +    0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
   7.394 +    0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
   7.395 +    0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
   7.396 +    0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
   7.397 +    0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
   7.398 +    0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
   7.399 +    0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
   7.400 +    0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
   7.401 +    0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
   7.402 +    0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
   7.403 +    0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
   7.404 +    0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
   7.405 +    0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
   7.406 +    0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
   7.407 +    0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
   7.408 +    0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
   7.409 +    0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
   7.410 +    0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
   7.411 +    0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
   7.412 +    0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
   7.413 +    0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
   7.414 +    0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
   7.415 +    0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
   7.416 +    0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
   7.417 +    0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
   7.418 +    0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
   7.419 +    0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
   7.420 +    0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
   7.421 +    0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
   7.422 +    0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
   7.423 +    0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
   7.424 +    0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
   7.425 +    0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
   7.426 +    0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
   7.427 +    0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
   7.428 +    0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
   7.429 +    0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
   7.430 +    0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
   7.431 +    0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
   7.432 +    0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
   7.433 +    0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
   7.434 +    0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
   7.435 +    0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
   7.436 +    0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
   7.437 +    0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
   7.438 +    0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
   7.439 +    0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
   7.440 +    0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
   7.441 +    0xf10605deUL
   7.442 +#endif
   7.443 +  }
   7.444 +};
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/compiler-init/zlib/deflate.c	Sat Jul 15 04:51:28 2006 +0000
     8.3 @@ -0,0 +1,1736 @@
     8.4 +/* deflate.c -- compress data using the deflation algorithm
     8.5 + * Copyright (C) 1995-2005 Jean-loup Gailly.
     8.6 + * For conditions of distribution and use, see copyright notice in zlib.h
     8.7 + */
     8.8 +
     8.9 +/*
    8.10 + *  ALGORITHM
    8.11 + *
    8.12 + *      The "deflation" process depends on being able to identify portions
    8.13 + *      of the input text which are identical to earlier input (within a
    8.14 + *      sliding window trailing behind the input currently being processed).
    8.15 + *
    8.16 + *      The most straightforward technique turns out to be the fastest for
    8.17 + *      most input files: try all possible matches and select the longest.
    8.18 + *      The key feature of this algorithm is that insertions into the string
    8.19 + *      dictionary are very simple and thus fast, and deletions are avoided
    8.20 + *      completely. Insertions are performed at each input character, whereas
    8.21 + *      string matches are performed only when the previous match ends. So it
    8.22 + *      is preferable to spend more time in matches to allow very fast string
    8.23 + *      insertions and avoid deletions. The matching algorithm for small
    8.24 + *      strings is inspired from that of Rabin & Karp. A brute force approach
    8.25 + *      is used to find longer strings when a small match has been found.
    8.26 + *      A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
    8.27 + *      (by Leonid Broukhis).
    8.28 + *         A previous version of this file used a more sophisticated algorithm
    8.29 + *      (by Fiala and Greene) which is guaranteed to run in linear amortized
    8.30 + *      time, but has a larger average cost, uses more memory and is patented.
    8.31 + *      However the F&G algorithm may be faster for some highly redundant
    8.32 + *      files if the parameter max_chain_length (described below) is too large.
    8.33 + *
    8.34 + *  ACKNOWLEDGEMENTS
    8.35 + *
    8.36 + *      The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
    8.37 + *      I found it in 'freeze' written by Leonid Broukhis.
    8.38 + *      Thanks to many people for bug reports and testing.
    8.39 + *
    8.40 + *  REFERENCES
    8.41 + *
    8.42 + *      Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
    8.43 + *      Available in http://www.ietf.org/rfc/rfc1951.txt
    8.44 + *
    8.45 + *      A description of the Rabin and Karp algorithm is given in the book
    8.46 + *         "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
    8.47 + *
    8.48 + *      Fiala,E.R., and Greene,D.H.
    8.49 + *         Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
    8.50 + *
    8.51 + */
    8.52 +
    8.53 +/* @(#) $Id$ */
    8.54 +
    8.55 +#include "deflate.h"
    8.56 +
    8.57 +const char deflate_copyright[] =
    8.58 +   " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
    8.59 +/*
    8.60 +  If you use the zlib library in a product, an acknowledgment is welcome
    8.61 +  in the documentation of your product. If for some reason you cannot
    8.62 +  include such an acknowledgment, I would appreciate that you keep this
    8.63 +  copyright string in the executable of your product.
    8.64 + */
    8.65 +
    8.66 +/* ===========================================================================
    8.67 + *  Function prototypes.
    8.68 + */
    8.69 +typedef enum {
    8.70 +    need_more,      /* block not completed, need more input or more output */
    8.71 +    block_done,     /* block flush performed */
    8.72 +    finish_started, /* finish started, need only more output at next deflate */
    8.73 +    finish_done     /* finish done, accept no more input or output */
    8.74 +} block_state;
    8.75 +
    8.76 +typedef block_state (*compress_func) OF((deflate_state *s, int flush));
    8.77 +/* Compression function. Returns the block state after the call. */
    8.78 +
    8.79 +local void fill_window    OF((deflate_state *s));
    8.80 +local block_state deflate_stored OF((deflate_state *s, int flush));
    8.81 +local block_state deflate_fast   OF((deflate_state *s, int flush));
    8.82 +#ifndef FASTEST
    8.83 +local block_state deflate_slow   OF((deflate_state *s, int flush));
    8.84 +#endif
    8.85 +local void lm_init        OF((deflate_state *s));
    8.86 +local void putShortMSB    OF((deflate_state *s, uInt b));
    8.87 +local void flush_pending  OF((z_streamp strm));
    8.88 +local int read_buf        OF((z_streamp strm, Bytef *buf, unsigned size));
    8.89 +#ifndef FASTEST
    8.90 +#ifdef ASMV
    8.91 +      void match_init OF((void)); /* asm code initialization */
    8.92 +      uInt longest_match  OF((deflate_state *s, IPos cur_match));
    8.93 +#else
    8.94 +local uInt longest_match  OF((deflate_state *s, IPos cur_match));
    8.95 +#endif
    8.96 +#endif
    8.97 +local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
    8.98 +
    8.99 +#ifdef DEBUG
   8.100 +local  void check_match OF((deflate_state *s, IPos start, IPos match,
   8.101 +                            int length));
   8.102 +#endif
   8.103 +
   8.104 +/* ===========================================================================
   8.105 + * Local data
   8.106 + */
   8.107 +
   8.108 +#define NIL 0
   8.109 +/* Tail of hash chains */
   8.110 +
   8.111 +#ifndef TOO_FAR
   8.112 +#  define TOO_FAR 4096
   8.113 +#endif
   8.114 +/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
   8.115 +
   8.116 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
   8.117 +/* Minimum amount of lookahead, except at the end of the input file.
   8.118 + * See deflate.c for comments about the MIN_MATCH+1.
   8.119 + */
   8.120 +
   8.121 +/* Values for max_lazy_match, good_match and max_chain_length, depending on
   8.122 + * the desired pack level (0..9). The values given below have been tuned to
   8.123 + * exclude worst case performance for pathological files. Better values may be
   8.124 + * found for specific files.
   8.125 + */
   8.126 +typedef struct config_s {
   8.127 +   ush good_length; /* reduce lazy search above this match length */
   8.128 +   ush max_lazy;    /* do not perform lazy search above this match length */
   8.129 +   ush nice_length; /* quit search above this match length */
   8.130 +   ush max_chain;
   8.131 +   compress_func func;
   8.132 +} config;
   8.133 +
   8.134 +#ifdef FASTEST
   8.135 +local const config configuration_table[2] = {
   8.136 +/*      good lazy nice chain */
   8.137 +/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
   8.138 +/* 1 */ {4,    4,  8,    4, deflate_fast}}; /* max speed, no lazy matches */
   8.139 +#else
   8.140 +local const config configuration_table[10] = {
   8.141 +/*      good lazy nice chain */
   8.142 +/* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
   8.143 +/* 1 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
   8.144 +/* 2 */ {4,    5, 16,    8, deflate_fast},
   8.145 +/* 3 */ {4,    6, 32,   32, deflate_fast},
   8.146 +
   8.147 +/* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
   8.148 +/* 5 */ {8,   16, 32,   32, deflate_slow},
   8.149 +/* 6 */ {8,   16, 128, 128, deflate_slow},
   8.150 +/* 7 */ {8,   32, 128, 256, deflate_slow},
   8.151 +/* 8 */ {32, 128, 258, 1024, deflate_slow},
   8.152 +/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
   8.153 +#endif
   8.154 +
   8.155 +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
   8.156 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
   8.157 + * meaning.
   8.158 + */
   8.159 +
   8.160 +#define EQUAL 0
   8.161 +/* result of memcmp for equal strings */
   8.162 +
   8.163 +#ifndef NO_DUMMY_DECL
   8.164 +struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
   8.165 +#endif
   8.166 +
   8.167 +/* ===========================================================================
   8.168 + * Update a hash value with the given input byte
   8.169 + * IN  assertion: all calls to to UPDATE_HASH are made with consecutive
   8.170 + *    input characters, so that a running hash key can be computed from the
   8.171 + *    previous key instead of complete recalculation each time.
   8.172 + */
   8.173 +#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
   8.174 +
   8.175 +
   8.176 +/* ===========================================================================
   8.177 + * Insert string str in the dictionary and set match_head to the previous head
   8.178 + * of the hash chain (the most recent string with same hash key). Return
   8.179 + * the previous length of the hash chain.
   8.180 + * If this file is compiled with -DFASTEST, the compression level is forced
   8.181 + * to 1, and no hash chains are maintained.
   8.182 + * IN  assertion: all calls to to INSERT_STRING are made with consecutive
   8.183 + *    input characters and the first MIN_MATCH bytes of str are valid
   8.184 + *    (except for the last MIN_MATCH-1 bytes of the input file).
   8.185 + */
   8.186 +#ifdef FASTEST
   8.187 +#define INSERT_STRING(s, str, match_head) \
   8.188 +   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
   8.189 +    match_head = s->head[s->ins_h], \
   8.190 +    s->head[s->ins_h] = (Pos)(str))
   8.191 +#else
   8.192 +#define INSERT_STRING(s, str, match_head) \
   8.193 +   (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
   8.194 +    match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
   8.195 +    s->head[s->ins_h] = (Pos)(str))
   8.196 +#endif
   8.197 +
   8.198 +/* ===========================================================================
   8.199 + * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
   8.200 + * prev[] will be initialized on the fly.
   8.201 + */
   8.202 +#define CLEAR_HASH(s) \
   8.203 +    s->head[s->hash_size-1] = NIL; \
   8.204 +    zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
   8.205 +
   8.206 +/* ========================================================================= */
   8.207 +int ZEXPORT deflateInit_(strm, level, version, stream_size)
   8.208 +    z_streamp strm;
   8.209 +    int level;
   8.210 +    const char *version;
   8.211 +    int stream_size;
   8.212 +{
   8.213 +    return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
   8.214 +                         Z_DEFAULT_STRATEGY, version, stream_size);
   8.215 +    /* To do: ignore strm->next_in if we use it as window */
   8.216 +}
   8.217 +
   8.218 +/* ========================================================================= */
   8.219 +int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
   8.220 +                  version, stream_size)
   8.221 +    z_streamp strm;
   8.222 +    int  level;
   8.223 +    int  method;
   8.224 +    int  windowBits;
   8.225 +    int  memLevel;
   8.226 +    int  strategy;
   8.227 +    const char *version;
   8.228 +    int stream_size;
   8.229 +{
   8.230 +    deflate_state *s;
   8.231 +    int wrap = 1;
   8.232 +    static const char my_version[] = ZLIB_VERSION;
   8.233 +
   8.234 +    ushf *overlay;
   8.235 +    /* We overlay pending_buf and d_buf+l_buf. This works since the average
   8.236 +     * output size for (length,distance) codes is <= 24 bits.
   8.237 +     */
   8.238 +
   8.239 +    if (version == Z_NULL || version[0] != my_version[0] ||
   8.240 +        stream_size != sizeof(z_stream)) {
   8.241 +        return Z_VERSION_ERROR;
   8.242 +    }
   8.243 +    if (strm == Z_NULL) return Z_STREAM_ERROR;
   8.244 +
   8.245 +    strm->msg = Z_NULL;
   8.246 +    if (strm->zalloc == (alloc_func)0) {
   8.247 +        strm->zalloc = zcalloc;
   8.248 +        strm->opaque = (voidpf)0;
   8.249 +    }
   8.250 +    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
   8.251 +
   8.252 +#ifdef FASTEST
   8.253 +    if (level != 0) level = 1;
   8.254 +#else
   8.255 +    if (level == Z_DEFAULT_COMPRESSION) level = 6;
   8.256 +#endif
   8.257 +
   8.258 +    if (windowBits < 0) { /* suppress zlib wrapper */
   8.259 +        wrap = 0;
   8.260 +        windowBits = -windowBits;
   8.261 +    }
   8.262 +#ifdef GZIP
   8.263 +    else if (windowBits > 15) {
   8.264 +        wrap = 2;       /* write gzip wrapper instead */
   8.265 +        windowBits -= 16;
   8.266 +    }
   8.267 +#endif
   8.268 +    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
   8.269 +        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
   8.270 +        strategy < 0 || strategy > Z_FIXED) {
   8.271 +        return Z_STREAM_ERROR;
   8.272 +    }
   8.273 +    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
   8.274 +    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
   8.275 +    if (s == Z_NULL) return Z_MEM_ERROR;
   8.276 +    strm->state = (struct internal_state FAR *)s;
   8.277 +    s->strm = strm;
   8.278 +
   8.279 +    s->wrap = wrap;
   8.280 +    s->gzhead = Z_NULL;
   8.281 +    s->w_bits = windowBits;
   8.282 +    s->w_size = 1 << s->w_bits;
   8.283 +    s->w_mask = s->w_size - 1;
   8.284 +
   8.285 +    s->hash_bits = memLevel + 7;
   8.286 +    s->hash_size = 1 << s->hash_bits;
   8.287 +    s->hash_mask = s->hash_size - 1;
   8.288 +    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
   8.289 +
   8.290 +    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
   8.291 +    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
   8.292 +    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));
   8.293 +
   8.294 +    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
   8.295 +
   8.296 +    overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
   8.297 +    s->pending_buf = (uchf *) overlay;
   8.298 +    s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
   8.299 +
   8.300 +    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
   8.301 +        s->pending_buf == Z_NULL) {
   8.302 +        s->status = FINISH_STATE;
   8.303 +        strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
   8.304 +        deflateEnd (strm);
   8.305 +        return Z_MEM_ERROR;
   8.306 +    }
   8.307 +    s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
   8.308 +    s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
   8.309 +
   8.310 +    s->level = level;
   8.311 +    s->strategy = strategy;
   8.312 +    s->method = (Byte)method;
   8.313 +
   8.314 +    return deflateReset(strm);
   8.315 +}
   8.316 +
   8.317 +/* ========================================================================= */
   8.318 +int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
   8.319 +    z_streamp strm;
   8.320 +    const Bytef *dictionary;
   8.321 +    uInt  dictLength;
   8.322 +{
   8.323 +    deflate_state *s;
   8.324 +    uInt length = dictLength;
   8.325 +    uInt n;
   8.326 +    IPos hash_head = 0;
   8.327 +
   8.328 +    if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
   8.329 +        strm->state->wrap == 2 ||
   8.330 +        (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
   8.331 +        return Z_STREAM_ERROR;
   8.332 +
   8.333 +    s = strm->state;
   8.334 +    if (s->wrap)
   8.335 +        strm->adler = adler32(strm->adler, dictionary, dictLength);
   8.336 +
   8.337 +    if (length < MIN_MATCH) return Z_OK;
   8.338 +    if (length > MAX_DIST(s)) {
   8.339 +        length = MAX_DIST(s);
   8.340 +        dictionary += dictLength - length; /* use the tail of the dictionary */
   8.341 +    }
   8.342 +    zmemcpy(s->window, dictionary, length);
   8.343 +    s->strstart = length;
   8.344 +    s->block_start = (long)length;
   8.345 +
   8.346 +    /* Insert all strings in the hash table (except for the last two bytes).
   8.347 +     * s->lookahead stays null, so s->ins_h will be recomputed at the next
   8.348 +     * call of fill_window.
   8.349 +     */
   8.350 +    s->ins_h = s->window[0];
   8.351 +    UPDATE_HASH(s, s->ins_h, s->window[1]);
   8.352 +    for (n = 0; n <= length - MIN_MATCH; n++) {
   8.353 +        INSERT_STRING(s, n, hash_head);
   8.354 +    }
   8.355 +    if (hash_head) hash_head = 0;  /* to make compiler happy */
   8.356 +    return Z_OK;
   8.357 +}
   8.358 +
   8.359 +/* ========================================================================= */
   8.360 +int ZEXPORT deflateReset (strm)
   8.361 +    z_streamp strm;
   8.362 +{
   8.363 +    deflate_state *s;
   8.364 +
   8.365 +    if (strm == Z_NULL || strm->state == Z_NULL ||
   8.366 +        strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
   8.367 +        return Z_STREAM_ERROR;
   8.368 +    }
   8.369 +
   8.370 +    strm->total_in = strm->total_out = 0;
   8.371 +    strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
   8.372 +    strm->data_type = Z_UNKNOWN;
   8.373 +
   8.374 +    s = (deflate_state *)strm->state;
   8.375 +    s->pending = 0;
   8.376 +    s->pending_out = s->pending_buf;
   8.377 +
   8.378 +    if (s->wrap < 0) {
   8.379 +        s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
   8.380 +    }
   8.381 +    s->status = s->wrap ? INIT_STATE : BUSY_STATE;
   8.382 +    strm->adler =
   8.383 +#ifdef GZIP
   8.384 +        s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
   8.385 +#endif
   8.386 +        adler32(0L, Z_NULL, 0);
   8.387 +    s->last_flush = Z_NO_FLUSH;
   8.388 +
   8.389 +    _tr_init(s);
   8.390 +    lm_init(s);
   8.391 +
   8.392 +    return Z_OK;
   8.393 +}
   8.394 +
   8.395 +/* ========================================================================= */
   8.396 +int ZEXPORT deflateSetHeader (strm, head)
   8.397 +    z_streamp strm;
   8.398 +    gz_headerp head;
   8.399 +{
   8.400 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
   8.401 +    if (strm->state->wrap != 2) return Z_STREAM_ERROR;
   8.402 +    strm->state->gzhead = head;
   8.403 +    return Z_OK;
   8.404 +}
   8.405 +
   8.406 +/* ========================================================================= */
   8.407 +int ZEXPORT deflatePrime (strm, bits, value)
   8.408 +    z_streamp strm;
   8.409 +    int bits;
   8.410 +    int value;
   8.411 +{
   8.412 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
   8.413 +    strm->state->bi_valid = bits;
   8.414 +    strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
   8.415 +    return Z_OK;
   8.416 +}
   8.417 +
   8.418 +/* ========================================================================= */
   8.419 +int ZEXPORT deflateParams(strm, level, strategy)
   8.420 +    z_streamp strm;
   8.421 +    int level;
   8.422 +    int strategy;
   8.423 +{
   8.424 +    deflate_state *s;
   8.425 +    compress_func func;
   8.426 +    int err = Z_OK;
   8.427 +
   8.428 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
   8.429 +    s = strm->state;
   8.430 +
   8.431 +#ifdef FASTEST
   8.432 +    if (level != 0) level = 1;
   8.433 +#else
   8.434 +    if (level == Z_DEFAULT_COMPRESSION) level = 6;
   8.435 +#endif
   8.436 +    if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
   8.437 +        return Z_STREAM_ERROR;
   8.438 +    }
   8.439 +    func = configuration_table[s->level].func;
   8.440 +
   8.441 +    if (func != configuration_table[level].func && strm->total_in != 0) {
   8.442 +        /* Flush the last buffer: */
   8.443 +        err = deflate(strm, Z_PARTIAL_FLUSH);
   8.444 +    }
   8.445 +    if (s->level != level) {
   8.446 +        s->level = level;
   8.447 +        s->max_lazy_match   = configuration_table[level].max_lazy;
   8.448 +        s->good_match       = configuration_table[level].good_length;
   8.449 +        s->nice_match       = configuration_table[level].nice_length;
   8.450 +        s->max_chain_length = configuration_table[level].max_chain;
   8.451 +    }
   8.452 +    s->strategy = strategy;
   8.453 +    return err;
   8.454 +}
   8.455 +
   8.456 +/* ========================================================================= */
   8.457 +int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
   8.458 +    z_streamp strm;
   8.459 +    int good_length;
   8.460 +    int max_lazy;
   8.461 +    int nice_length;
   8.462 +    int max_chain;
   8.463 +{
   8.464 +    deflate_state *s;
   8.465 +
   8.466 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
   8.467 +    s = strm->state;
   8.468 +    s->good_match = good_length;
   8.469 +    s->max_lazy_match = max_lazy;
   8.470 +    s->nice_match = nice_length;
   8.471 +    s->max_chain_length = max_chain;
   8.472 +    return Z_OK;
   8.473 +}
   8.474 +
   8.475 +/* =========================================================================
   8.476 + * For the default windowBits of 15 and memLevel of 8, this function returns
   8.477 + * a close to exact, as well as small, upper bound on the compressed size.
   8.478 + * They are coded as constants here for a reason--if the #define's are
   8.479 + * changed, then this function needs to be changed as well.  The return
   8.480 + * value for 15 and 8 only works for those exact settings.
   8.481 + *
   8.482 + * For any setting other than those defaults for windowBits and memLevel,
   8.483 + * the value returned is a conservative worst case for the maximum expansion
   8.484 + * resulting from using fixed blocks instead of stored blocks, which deflate
   8.485 + * can emit on compressed data for some combinations of the parameters.
   8.486 + *
   8.487 + * This function could be more sophisticated to provide closer upper bounds
   8.488 + * for every combination of windowBits and memLevel, as well as wrap.
   8.489 + * But even the conservative upper bound of about 14% expansion does not
   8.490 + * seem onerous for output buffer allocation.
   8.491 + */
   8.492 +uLong ZEXPORT deflateBound(strm, sourceLen)
   8.493 +    z_streamp strm;
   8.494 +    uLong sourceLen;
   8.495 +{
   8.496 +    deflate_state *s;
   8.497 +    uLong destLen;
   8.498 +
   8.499 +    /* conservative upper bound */
   8.500 +    destLen = sourceLen +
   8.501 +              ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
   8.502 +
   8.503 +    /* if can't get parameters, return conservative bound */
   8.504 +    if (strm == Z_NULL || strm->state == Z_NULL)
   8.505 +        return destLen;
   8.506 +
   8.507 +    /* if not default parameters, return conservative bound */
   8.508 +    s = strm->state;
   8.509 +    if (s->w_bits != 15 || s->hash_bits != 8 + 7)
   8.510 +        return destLen;
   8.511 +
   8.512 +    /* default settings: return tight bound for that case */
   8.513 +    return compressBound(sourceLen);
   8.514 +}
   8.515 +
   8.516 +/* =========================================================================
   8.517 + * Put a short in the pending buffer. The 16-bit value is put in MSB order.
   8.518 + * IN assertion: the stream state is correct and there is enough room in
   8.519 + * pending_buf.
   8.520 + */
   8.521 +local void putShortMSB (s, b)
   8.522 +    deflate_state *s;
   8.523 +    uInt b;
   8.524 +{
   8.525 +    put_byte(s, (Byte)(b >> 8));
   8.526 +    put_byte(s, (Byte)(b & 0xff));
   8.527 +}
   8.528 +
   8.529 +/* =========================================================================
   8.530 + * Flush as much pending output as possible. All deflate() output goes
   8.531 + * through this function so some applications may wish to modify it
   8.532 + * to avoid allocating a large strm->next_out buffer and copying into it.
   8.533 + * (See also read_buf()).
   8.534 + */
   8.535 +local void flush_pending(strm)
   8.536 +    z_streamp strm;
   8.537 +{
   8.538 +    unsigned len = strm->state->pending;
   8.539 +
   8.540 +    if (len > strm->avail_out) len = strm->avail_out;
   8.541 +    if (len == 0) return;
   8.542 +
   8.543 +    zmemcpy(strm->next_out, strm->state->pending_out, len);
   8.544 +    strm->next_out  += len;
   8.545 +    strm->state->pending_out  += len;
   8.546 +    strm->total_out += len;
   8.547 +    strm->avail_out  -= len;
   8.548 +    strm->state->pending -= len;
   8.549 +    if (strm->state->pending == 0) {
   8.550 +        strm->state->pending_out = strm->state->pending_buf;
   8.551 +    }
   8.552 +}
   8.553 +
   8.554 +/* ========================================================================= */
   8.555 +int ZEXPORT deflate (strm, flush)
   8.556 +    z_streamp strm;
   8.557 +    int flush;
   8.558 +{
   8.559 +    int old_flush; /* value of flush param for previous deflate call */
   8.560 +    deflate_state *s;
   8.561 +
   8.562 +    if (strm == Z_NULL || strm->state == Z_NULL ||
   8.563 +        flush > Z_FINISH || flush < 0) {
   8.564 +        return Z_STREAM_ERROR;
   8.565 +    }
   8.566 +    s = strm->state;
   8.567 +
   8.568 +    if (strm->next_out == Z_NULL ||
   8.569 +        (strm->next_in == Z_NULL && strm->avail_in != 0) ||
   8.570 +        (s->status == FINISH_STATE && flush != Z_FINISH)) {
   8.571 +        ERR_RETURN(strm, Z_STREAM_ERROR);
   8.572 +    }
   8.573 +    if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
   8.574 +
   8.575 +    s->strm = strm; /* just in case */
   8.576 +    old_flush = s->last_flush;
   8.577 +    s->last_flush = flush;
   8.578 +
   8.579 +    /* Write the header */
   8.580 +    if (s->status == INIT_STATE) {
   8.581 +#ifdef GZIP
   8.582 +        if (s->wrap == 2) {
   8.583 +            strm->adler = crc32(0L, Z_NULL, 0);
   8.584 +            put_byte(s, 31);
   8.585 +            put_byte(s, 139);
   8.586 +            put_byte(s, 8);
   8.587 +            if (s->gzhead == NULL) {
   8.588 +                put_byte(s, 0);
   8.589 +                put_byte(s, 0);
   8.590 +                put_byte(s, 0);
   8.591 +                put_byte(s, 0);
   8.592 +                put_byte(s, 0);
   8.593 +                put_byte(s, s->level == 9 ? 2 :
   8.594 +                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
   8.595 +                             4 : 0));
   8.596 +                put_byte(s, OS_CODE);
   8.597 +                s->status = BUSY_STATE;
   8.598 +            }
   8.599 +            else {
   8.600 +                put_byte(s, (s->gzhead->text ? 1 : 0) +
   8.601 +                            (s->gzhead->hcrc ? 2 : 0) +
   8.602 +                            (s->gzhead->extra == Z_NULL ? 0 : 4) +
   8.603 +                            (s->gzhead->name == Z_NULL ? 0 : 8) +
   8.604 +                            (s->gzhead->comment == Z_NULL ? 0 : 16)
   8.605 +                        );
   8.606 +                put_byte(s, (Byte)(s->gzhead->time & 0xff));
   8.607 +                put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
   8.608 +                put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
   8.609 +                put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
   8.610 +                put_byte(s, s->level == 9 ? 2 :
   8.611 +                            (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
   8.612 +                             4 : 0));
   8.613 +                put_byte(s, s->gzhead->os & 0xff);
   8.614 +                if (s->gzhead->extra != NULL) {
   8.615 +                    put_byte(s, s->gzhead->extra_len & 0xff);
   8.616 +                    put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
   8.617 +                }
   8.618 +                if (s->gzhead->hcrc)
   8.619 +                    strm->adler = crc32(strm->adler, s->pending_buf,
   8.620 +                                        s->pending);
   8.621 +                s->gzindex = 0;
   8.622 +                s->status = EXTRA_STATE;
   8.623 +            }
   8.624 +        }
   8.625 +        else
   8.626 +#endif
   8.627 +        {
   8.628 +            uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
   8.629 +            uInt level_flags;
   8.630 +
   8.631 +            if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
   8.632 +                level_flags = 0;
   8.633 +            else if (s->level < 6)
   8.634 +                level_flags = 1;
   8.635 +            else if (s->level == 6)
   8.636 +                level_flags = 2;
   8.637 +            else
   8.638 +                level_flags = 3;
   8.639 +            header |= (level_flags << 6);
   8.640 +            if (s->strstart != 0) header |= PRESET_DICT;
   8.641 +            header += 31 - (header % 31);
   8.642 +
   8.643 +            s->status = BUSY_STATE;
   8.644 +            putShortMSB(s, header);
   8.645 +
   8.646 +            /* Save the adler32 of the preset dictionary: */
   8.647 +            if (s->strstart != 0) {
   8.648 +                putShortMSB(s, (uInt)(strm->adler >> 16));
   8.649 +                putShortMSB(s, (uInt)(strm->adler & 0xffff));
   8.650 +            }
   8.651 +            strm->adler = adler32(0L, Z_NULL, 0);
   8.652 +        }
   8.653 +    }
   8.654 +#ifdef GZIP
   8.655 +    if (s->status == EXTRA_STATE) {
   8.656 +        if (s->gzhead->extra != NULL) {
   8.657 +            uInt beg = s->pending;  /* start of bytes to update crc */
   8.658 +
   8.659 +            while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
   8.660 +                if (s->pending == s->pending_buf_size) {
   8.661 +                    if (s->gzhead->hcrc && s->pending > beg)
   8.662 +                        strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.663 +                                            s->pending - beg);
   8.664 +                    flush_pending(strm);
   8.665 +                    beg = s->pending;
   8.666 +                    if (s->pending == s->pending_buf_size)
   8.667 +                        break;
   8.668 +                }
   8.669 +                put_byte(s, s->gzhead->extra[s->gzindex]);
   8.670 +                s->gzindex++;
   8.671 +            }
   8.672 +            if (s->gzhead->hcrc && s->pending > beg)
   8.673 +                strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.674 +                                    s->pending - beg);
   8.675 +            if (s->gzindex == s->gzhead->extra_len) {
   8.676 +                s->gzindex = 0;
   8.677 +                s->status = NAME_STATE;
   8.678 +            }
   8.679 +        }
   8.680 +        else
   8.681 +            s->status = NAME_STATE;
   8.682 +    }
   8.683 +    if (s->status == NAME_STATE) {
   8.684 +        if (s->gzhead->name != NULL) {
   8.685 +            uInt beg = s->pending;  /* start of bytes to update crc */
   8.686 +            int val;
   8.687 +
   8.688 +            do {
   8.689 +                if (s->pending == s->pending_buf_size) {
   8.690 +                    if (s->gzhead->hcrc && s->pending > beg)
   8.691 +                        strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.692 +                                            s->pending - beg);
   8.693 +                    flush_pending(strm);
   8.694 +                    beg = s->pending;
   8.695 +                    if (s->pending == s->pending_buf_size) {
   8.696 +                        val = 1;
   8.697 +                        break;
   8.698 +                    }
   8.699 +                }
   8.700 +                val = s->gzhead->name[s->gzindex++];
   8.701 +                put_byte(s, val);
   8.702 +            } while (val != 0);
   8.703 +            if (s->gzhead->hcrc && s->pending > beg)
   8.704 +                strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.705 +                                    s->pending - beg);
   8.706 +            if (val == 0) {
   8.707 +                s->gzindex = 0;
   8.708 +                s->status = COMMENT_STATE;
   8.709 +            }
   8.710 +        }
   8.711 +        else
   8.712 +            s->status = COMMENT_STATE;
   8.713 +    }
   8.714 +    if (s->status == COMMENT_STATE) {
   8.715 +        if (s->gzhead->comment != NULL) {
   8.716 +            uInt beg = s->pending;  /* start of bytes to update crc */
   8.717 +            int val;
   8.718 +
   8.719 +            do {
   8.720 +                if (s->pending == s->pending_buf_size) {
   8.721 +                    if (s->gzhead->hcrc && s->pending > beg)
   8.722 +                        strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.723 +                                            s->pending - beg);
   8.724 +                    flush_pending(strm);
   8.725 +                    beg = s->pending;
   8.726 +                    if (s->pending == s->pending_buf_size) {
   8.727 +                        val = 1;
   8.728 +                        break;
   8.729 +                    }
   8.730 +                }
   8.731 +                val = s->gzhead->comment[s->gzindex++];
   8.732 +                put_byte(s, val);
   8.733 +            } while (val != 0);
   8.734 +            if (s->gzhead->hcrc && s->pending > beg)
   8.735 +                strm->adler = crc32(strm->adler, s->pending_buf + beg,
   8.736 +                                    s->pending - beg);
   8.737 +            if (val == 0)
   8.738 +                s->status = HCRC_STATE;
   8.739 +        }
   8.740 +        else
   8.741 +            s->status = HCRC_STATE;
   8.742 +    }
   8.743 +    if (s->status == HCRC_STATE) {
   8.744 +        if (s->gzhead->hcrc) {
   8.745 +            if (s->pending + 2 > s->pending_buf_size)
   8.746 +                flush_pending(strm);
   8.747 +            if (s->pending + 2 <= s->pending_buf_size) {
   8.748 +                put_byte(s, (Byte)(strm->adler & 0xff));
   8.749 +                put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
   8.750 +                strm->adler = crc32(0L, Z_NULL, 0);
   8.751 +                s->status = BUSY_STATE;
   8.752 +            }
   8.753 +        }
   8.754 +        else
   8.755 +            s->status = BUSY_STATE;
   8.756 +    }
   8.757 +#endif
   8.758 +
   8.759 +    /* Flush as much pending output as possible */
   8.760 +    if (s->pending != 0) {
   8.761 +        flush_pending(strm);
   8.762 +        if (strm->avail_out == 0) {
   8.763 +            /* Since avail_out is 0, deflate will be called again with
   8.764 +             * more output space, but possibly with both pending and
   8.765 +             * avail_in equal to zero. There won't be anything to do,
   8.766 +             * but this is not an error situation so make sure we
   8.767 +             * return OK instead of BUF_ERROR at next call of deflate:
   8.768 +             */
   8.769 +            s->last_flush = -1;
   8.770 +            return Z_OK;
   8.771 +        }
   8.772 +
   8.773 +    /* Make sure there is something to do and avoid duplicate consecutive
   8.774 +     * flushes. For repeated and useless calls with Z_FINISH, we keep
   8.775 +     * returning Z_STREAM_END instead of Z_BUF_ERROR.
   8.776 +     */
   8.777 +    } else if (strm->avail_in == 0 && flush <= old_flush &&
   8.778 +               flush != Z_FINISH) {
   8.779 +        ERR_RETURN(strm, Z_BUF_ERROR);
   8.780 +    }
   8.781 +
   8.782 +    /* User must not provide more input after the first FINISH: */
   8.783 +    if (s->status == FINISH_STATE && strm->avail_in != 0) {
   8.784 +        ERR_RETURN(strm, Z_BUF_ERROR);
   8.785 +    }
   8.786 +
   8.787 +    /* Start a new block or continue the current one.
   8.788 +     */
   8.789 +    if (strm->avail_in != 0 || s->lookahead != 0 ||
   8.790 +        (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
   8.791 +        block_state bstate;
   8.792 +
   8.793 +        bstate = (*(configuration_table[s->level].func))(s, flush);
   8.794 +
   8.795 +        if (bstate == finish_started || bstate == finish_done) {
   8.796 +            s->status = FINISH_STATE;
   8.797 +        }
   8.798 +        if (bstate == need_more || bstate == finish_started) {
   8.799 +            if (strm->avail_out == 0) {
   8.800 +                s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
   8.801 +            }
   8.802 +            return Z_OK;
   8.803 +            /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
   8.804 +             * of deflate should use the same flush parameter to make sure
   8.805 +             * that the flush is complete. So we don't have to output an
   8.806 +             * empty block here, this will be done at next call. This also
   8.807 +             * ensures that for a very small output buffer, we emit at most
   8.808 +             * one empty block.
   8.809 +             */
   8.810 +        }
   8.811 +        if (bstate == block_done) {
   8.812 +            if (flush == Z_PARTIAL_FLUSH) {
   8.813 +                _tr_align(s);
   8.814 +            } else { /* FULL_FLUSH or SYNC_FLUSH */
   8.815 +                _tr_stored_block(s, (char*)0, 0L, 0);
   8.816 +                /* For a full flush, this empty block will be recognized
   8.817 +                 * as a special marker by inflate_sync().
   8.818 +                 */
   8.819 +                if (flush == Z_FULL_FLUSH) {
   8.820 +                    CLEAR_HASH(s);             /* forget history */
   8.821 +                }
   8.822 +            }
   8.823 +            flush_pending(strm);
   8.824 +            if (strm->avail_out == 0) {
   8.825 +              s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
   8.826 +              return Z_OK;
   8.827 +            }
   8.828 +        }
   8.829 +    }
   8.830 +    Assert(strm->avail_out > 0, "bug2");
   8.831 +
   8.832 +    if (flush != Z_FINISH) return Z_OK;
   8.833 +    if (s->wrap <= 0) return Z_STREAM_END;
   8.834 +
   8.835 +    /* Write the trailer */
   8.836 +#ifdef GZIP
   8.837 +    if (s->wrap == 2) {
   8.838 +        put_byte(s, (Byte)(strm->adler & 0xff));
   8.839 +        put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
   8.840 +        put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
   8.841 +        put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
   8.842 +        put_byte(s, (Byte)(strm->total_in & 0xff));
   8.843 +        put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
   8.844 +        put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
   8.845 +        put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
   8.846 +    }
   8.847 +    else
   8.848 +#endif
   8.849 +    {
   8.850 +        putShortMSB(s, (uInt)(strm->adler >> 16));
   8.851 +        putShortMSB(s, (uInt)(strm->adler & 0xffff));
   8.852 +    }
   8.853 +    flush_pending(strm);
   8.854 +    /* If avail_out is zero, the application will call deflate again
   8.855 +     * to flush the rest.
   8.856 +     */
   8.857 +    if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
   8.858 +    return s->pending != 0 ? Z_OK : Z_STREAM_END;
   8.859 +}
   8.860 +
   8.861 +/* ========================================================================= */
   8.862 +int ZEXPORT deflateEnd (strm)
   8.863 +    z_streamp strm;
   8.864 +{
   8.865 +    int status;
   8.866 +
   8.867 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
   8.868 +
   8.869 +    status = strm->state->status;
   8.870 +    if (status != INIT_STATE &&
   8.871 +        status != EXTRA_STATE &&
   8.872 +        status != NAME_STATE &&
   8.873 +        status != COMMENT_STATE &&
   8.874 +        status != HCRC_STATE &&
   8.875 +        status != BUSY_STATE &&
   8.876 +        status != FINISH_STATE) {
   8.877 +      return Z_STREAM_ERROR;
   8.878 +    }
   8.879 +
   8.880 +    /* Deallocate in reverse order of allocations: */
   8.881 +    TRY_FREE(strm, strm->state->pending_buf);
   8.882 +    TRY_FREE(strm, strm->state->head);
   8.883 +    TRY_FREE(strm, strm->state->prev);
   8.884 +    TRY_FREE(strm, strm->state->window);
   8.885 +
   8.886 +    ZFREE(strm, strm->state);
   8.887 +    strm->state = Z_NULL;
   8.888 +
   8.889 +    return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
   8.890 +}
   8.891 +
   8.892 +/* =========================================================================
   8.893 + * Copy the source state to the destination state.
   8.894 + * To simplify the source, this is not supported for 16-bit MSDOS (which
   8.895 + * doesn't have enough memory anyway to duplicate compression states).
   8.896 + */
   8.897 +int ZEXPORT deflateCopy (dest, source)
   8.898 +    z_streamp dest;
   8.899 +    z_streamp source;
   8.900 +{
   8.901 +#ifdef MAXSEG_64K
   8.902 +    return Z_STREAM_ERROR;
   8.903 +#else
   8.904 +    deflate_state *ds;
   8.905 +    deflate_state *ss;
   8.906 +    ushf *overlay;
   8.907 +
   8.908 +
   8.909 +    if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
   8.910 +        return Z_STREAM_ERROR;
   8.911 +    }
   8.912 +
   8.913 +    ss = source->state;
   8.914 +
   8.915 +    zmemcpy(dest, source, sizeof(z_stream));
   8.916 +
   8.917 +    ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
   8.918 +    if (ds == Z_NULL) return Z_MEM_ERROR;
   8.919 +    dest->state = (struct internal_state FAR *) ds;
   8.920 +    zmemcpy(ds, ss, sizeof(deflate_state));
   8.921 +    ds->strm = dest;
   8.922 +
   8.923 +    ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
   8.924 +    ds->prev   = (Posf *)  ZALLOC(dest, ds->w_size, sizeof(Pos));
   8.925 +    ds->head   = (Posf *)  ZALLOC(dest, ds->hash_size, sizeof(Pos));
   8.926 +    overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
   8.927 +    ds->pending_buf = (uchf *) overlay;
   8.928 +
   8.929 +    if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
   8.930 +        ds->pending_buf == Z_NULL) {
   8.931 +        deflateEnd (dest);
   8.932 +        return Z_MEM_ERROR;
   8.933 +    }
   8.934 +    /* following zmemcpy do not work for 16-bit MSDOS */
   8.935 +    zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
   8.936 +    zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
   8.937 +    zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
   8.938 +    zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
   8.939 +
   8.940 +    ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
   8.941 +    ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
   8.942 +    ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
   8.943 +
   8.944 +    ds->l_desc.dyn_tree = ds->dyn_ltree;
   8.945 +    ds->d_desc.dyn_tree = ds->dyn_dtree;
   8.946 +    ds->bl_desc.dyn_tree = ds->bl_tree;
   8.947 +
   8.948 +    return Z_OK;
   8.949 +#endif /* MAXSEG_64K */
   8.950 +}
   8.951 +
   8.952 +/* ===========================================================================
   8.953 + * Read a new buffer from the current input stream, update the adler32
   8.954 + * and total number of bytes read.  All deflate() input goes through
   8.955 + * this function so some applications may wish to modify it to avoid
   8.956 + * allocating a large strm->next_in buffer and copying from it.
   8.957 + * (See also flush_pending()).
   8.958 + */
   8.959 +local int read_buf(strm, buf, size)
   8.960 +    z_streamp strm;
   8.961 +    Bytef *buf;
   8.962 +    unsigned size;
   8.963 +{
   8.964 +    unsigned len = strm->avail_in;
   8.965 +
   8.966 +    if (len > size) len = size;
   8.967 +    if (len == 0) return 0;
   8.968 +
   8.969 +    strm->avail_in  -= len;
   8.970 +
   8.971 +    if (strm->state->wrap == 1) {
   8.972 +        strm->adler = adler32(strm->adler, strm->next_in, len);
   8.973 +    }
   8.974 +#ifdef GZIP
   8.975 +    else if (strm->state->wrap == 2) {
   8.976 +        strm->adler = crc32(strm->adler, strm->next_in, len);
   8.977 +    }
   8.978 +#endif
   8.979 +    zmemcpy(buf, strm->next_in, len);
   8.980 +    strm->next_in  += len;
   8.981 +    strm->total_in += len;
   8.982 +
   8.983 +    return (int)len;
   8.984 +}
   8.985 +
   8.986 +/* ===========================================================================
   8.987 + * Initialize the "longest match" routines for a new zlib stream
   8.988 + */
   8.989 +local void lm_init (s)
   8.990 +    deflate_state *s;
   8.991 +{
   8.992 +    s->window_size = (ulg)2L*s->w_size;
   8.993 +
   8.994 +    CLEAR_HASH(s);
   8.995 +
   8.996 +    /* Set the default configuration parameters:
   8.997 +     */
   8.998 +    s->max_lazy_match   = configuration_table[s->level].max_lazy;
   8.999 +    s->good_match       = configuration_table[s->level].good_length;
  8.1000 +    s->nice_match       = configuration_table[s->level].nice_length;
  8.1001 +    s->max_chain_length = configuration_table[s->level].max_chain;
  8.1002 +
  8.1003 +    s->strstart = 0;
  8.1004 +    s->block_start = 0L;
  8.1005 +    s->lookahead = 0;
  8.1006 +    s->match_length = s->prev_length = MIN_MATCH-1;
  8.1007 +    s->match_available = 0;
  8.1008 +    s->ins_h = 0;
  8.1009 +#ifndef FASTEST
  8.1010 +#ifdef ASMV
  8.1011 +    match_init(); /* initialize the asm code */
  8.1012 +#endif
  8.1013 +#endif
  8.1014 +}
  8.1015 +
  8.1016 +#ifndef FASTEST
  8.1017 +/* ===========================================================================
  8.1018 + * Set match_start to the longest match starting at the given string and
  8.1019 + * return its length. Matches shorter or equal to prev_length are discarded,
  8.1020 + * in which case the result is equal to prev_length and match_start is
  8.1021 + * garbage.
  8.1022 + * IN assertions: cur_match is the head of the hash chain for the current
  8.1023 + *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  8.1024 + * OUT assertion: the match length is not greater than s->lookahead.
  8.1025 + */
  8.1026 +#ifndef ASMV
  8.1027 +/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
  8.1028 + * match.S. The code will be functionally equivalent.
  8.1029 + */
  8.1030 +local uInt longest_match(s, cur_match)
  8.1031 +    deflate_state *s;
  8.1032 +    IPos cur_match;                             /* current match */
  8.1033 +{
  8.1034 +    unsigned chain_length = s->max_chain_length;/* max hash chain length */
  8.1035 +    register Bytef *scan = s->window + s->strstart; /* current string */
  8.1036 +    register Bytef *match;                       /* matched string */
  8.1037 +    register int len;                           /* length of current match */
  8.1038 +    int best_len = s->prev_length;              /* best match length so far */
  8.1039 +    int nice_match = s->nice_match;             /* stop if match long enough */
  8.1040 +    IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  8.1041 +        s->strstart - (IPos)MAX_DIST(s) : NIL;
  8.1042 +    /* Stop when cur_match becomes <= limit. To simplify the code,
  8.1043 +     * we prevent matches with the string of window index 0.
  8.1044 +     */
  8.1045 +    Posf *prev = s->prev;
  8.1046 +    uInt wmask = s->w_mask;
  8.1047 +
  8.1048 +#ifdef UNALIGNED_OK
  8.1049 +    /* Compare two bytes at a time. Note: this is not always beneficial.
  8.1050 +     * Try with and without -DUNALIGNED_OK to check.
  8.1051 +     */
  8.1052 +    register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  8.1053 +    register ush scan_start = *(ushf*)scan;
  8.1054 +    register ush scan_end   = *(ushf*)(scan+best_len-1);
  8.1055 +#else
  8.1056 +    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  8.1057 +    register Byte scan_end1  = scan[best_len-1];
  8.1058 +    register Byte scan_end   = scan[best_len];
  8.1059 +#endif
  8.1060 +
  8.1061 +    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  8.1062 +     * It is easy to get rid of this optimization if necessary.
  8.1063 +     */
  8.1064 +    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  8.1065 +
  8.1066 +    /* Do not waste too much time if we already have a good match: */
  8.1067 +    if (s->prev_length >= s->good_match) {
  8.1068 +        chain_length >>= 2;
  8.1069 +    }
  8.1070 +    /* Do not look for matches beyond the end of the input. This is necessary
  8.1071 +     * to make deflate deterministic.
  8.1072 +     */
  8.1073 +    if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  8.1074 +
  8.1075 +    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  8.1076 +
  8.1077 +    do {
  8.1078 +        Assert(cur_match < s->strstart, "no future");
  8.1079 +        match = s->window + cur_match;
  8.1080 +
  8.1081 +        /* Skip to next match if the match length cannot increase
  8.1082 +         * or if the match length is less than 2.  Note that the checks below
  8.1083 +         * for insufficient lookahead only occur occasionally for performance
  8.1084 +         * reasons.  Therefore uninitialized memory will be accessed, and
  8.1085 +         * conditional jumps will be made that depend on those values.
  8.1086 +         * However the length of the match is limited to the lookahead, so
  8.1087 +         * the output of deflate is not affected by the uninitialized values.
  8.1088 +         */
  8.1089 +#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  8.1090 +        /* This code assumes sizeof(unsigned short) == 2. Do not use
  8.1091 +         * UNALIGNED_OK if your compiler uses a different size.
  8.1092 +         */
  8.1093 +        if (*(ushf*)(match+best_len-1) != scan_end ||
  8.1094 +            *(ushf*)match != scan_start) continue;
  8.1095 +
  8.1096 +        /* It is not necessary to compare scan[2] and match[2] since they are
  8.1097 +         * always equal when the other bytes match, given that the hash keys
  8.1098 +         * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
  8.1099 +         * strstart+3, +5, ... up to strstart+257. We check for insufficient
  8.1100 +         * lookahead only every 4th comparison; the 128th check will be made
  8.1101 +         * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
  8.1102 +         * necessary to put more guard bytes at the end of the window, or
  8.1103 +         * to check more often for insufficient lookahead.
  8.1104 +         */
  8.1105 +        Assert(scan[2] == match[2], "scan[2]?");
  8.1106 +        scan++, match++;
  8.1107 +        do {
  8.1108 +        } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  8.1109 +                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  8.1110 +                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  8.1111 +                 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  8.1112 +                 scan < strend);
  8.1113 +        /* The funny "do {}" generates better code on most compilers */
  8.1114 +
  8.1115 +        /* Here, scan <= window+strstart+257 */
  8.1116 +        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  8.1117 +        if (*scan == *match) scan++;
  8.1118 +
  8.1119 +        len = (MAX_MATCH - 1) - (int)(strend-scan);
  8.1120 +        scan = strend - (MAX_MATCH-1);
  8.1121 +
  8.1122 +#else /* UNALIGNED_OK */
  8.1123 +
  8.1124 +        if (match[best_len]   != scan_end  ||
  8.1125 +            match[best_len-1] != scan_end1 ||
  8.1126 +            *match            != *scan     ||
  8.1127 +            *++match          != scan[1])      continue;
  8.1128 +
  8.1129 +        /* The check at best_len-1 can be removed because it will be made
  8.1130 +         * again later. (This heuristic is not always a win.)
  8.1131 +         * It is not necessary to compare scan[2] and match[2] since they
  8.1132 +         * are always equal when the other bytes match, given that
  8.1133 +         * the hash keys are equal and that HASH_BITS >= 8.
  8.1134 +         */
  8.1135 +        scan += 2, match++;
  8.1136 +        Assert(*scan == *match, "match[2]?");
  8.1137 +
  8.1138 +        /* We check for insufficient lookahead only every 8th comparison;
  8.1139 +         * the 256th check will be made at strstart+258.
  8.1140 +         */
  8.1141 +        do {
  8.1142 +        } while (*++scan == *++match && *++scan == *++match &&
  8.1143 +                 *++scan == *++match && *++scan == *++match &&
  8.1144 +                 *++scan == *++match && *++scan == *++match &&
  8.1145 +                 *++scan == *++match && *++scan == *++match &&
  8.1146 +                 scan < strend);
  8.1147 +
  8.1148 +        Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  8.1149 +
  8.1150 +        len = MAX_MATCH - (int)(strend - scan);
  8.1151 +        scan = strend - MAX_MATCH;
  8.1152 +
  8.1153 +#endif /* UNALIGNED_OK */
  8.1154 +
  8.1155 +        if (len > best_len) {
  8.1156 +            s->match_start = cur_match;
  8.1157 +            best_len = len;
  8.1158 +            if (len >= nice_match) break;
  8.1159 +#ifdef UNALIGNED_OK
  8.1160 +            scan_end = *(ushf*)(scan+best_len-1);
  8.1161 +#else
  8.1162 +            scan_end1  = scan[best_len-1];
  8.1163 +            scan_end   = scan[best_len];
  8.1164 +#endif
  8.1165 +        }
  8.1166 +    } while ((cur_match = prev[cur_match & wmask]) > limit
  8.1167 +             && --chain_length != 0);
  8.1168 +
  8.1169 +    if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  8.1170 +    return s->lookahead;
  8.1171 +}
  8.1172 +#endif /* ASMV */
  8.1173 +#endif /* FASTEST */
  8.1174 +
  8.1175 +/* ---------------------------------------------------------------------------
  8.1176 + * Optimized version for level == 1 or strategy == Z_RLE only
  8.1177 + */
  8.1178 +local uInt longest_match_fast(s, cur_match)
  8.1179 +    deflate_state *s;
  8.1180 +    IPos cur_match;                             /* current match */
  8.1181 +{
  8.1182 +    register Bytef *scan = s->window + s->strstart; /* current string */
  8.1183 +    register Bytef *match;                       /* matched string */
  8.1184 +    register int len;                           /* length of current match */
  8.1185 +    register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  8.1186 +
  8.1187 +    /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  8.1188 +     * It is easy to get rid of this optimization if necessary.
  8.1189 +     */
  8.1190 +    Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  8.1191 +
  8.1192 +    Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  8.1193 +
  8.1194 +    Assert(cur_match < s->strstart, "no future");
  8.1195 +
  8.1196 +    match = s->window + cur_match;
  8.1197 +
  8.1198 +    /* Return failure if the match length is less than 2:
  8.1199 +     */
  8.1200 +    if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  8.1201 +
  8.1202 +    /* The check at best_len-1 can be removed because it will be made
  8.1203 +     * again later. (This heuristic is not always a win.)
  8.1204 +     * It is not necessary to compare scan[2] and match[2] since they
  8.1205 +     * are always equal when the other bytes match, given that
  8.1206 +     * the hash keys are equal and that HASH_BITS >= 8.
  8.1207 +     */
  8.1208 +    scan += 2, match += 2;
  8.1209 +    Assert(*scan == *match, "match[2]?");
  8.1210 +
  8.1211 +    /* We check for insufficient lookahead only every 8th comparison;
  8.1212 +     * the 256th check will be made at strstart+258.
  8.1213 +     */
  8.1214 +    do {
  8.1215 +    } while (*++scan == *++match && *++scan == *++match &&
  8.1216 +             *++scan == *++match && *++scan == *++match &&
  8.1217 +             *++scan == *++match && *++scan == *++match &&
  8.1218 +             *++scan == *++match && *++scan == *++match &&
  8.1219 +             scan < strend);
  8.1220 +
  8.1221 +    Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  8.1222 +
  8.1223 +    len = MAX_MATCH - (int)(strend - scan);
  8.1224 +
  8.1225 +    if (len < MIN_MATCH) return MIN_MATCH - 1;
  8.1226 +
  8.1227 +    s->match_start = cur_match;
  8.1228 +    return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  8.1229 +}
  8.1230 +
  8.1231 +#ifdef DEBUG
  8.1232 +/* ===========================================================================
  8.1233 + * Check that the match at match_start is indeed a match.
  8.1234 + */
  8.1235 +local void check_match(s, start, match, length)
  8.1236 +    deflate_state *s;
  8.1237 +    IPos start, match;
  8.1238 +    int length;
  8.1239 +{
  8.1240 +    /* check that the match is indeed a match */
  8.1241 +    if (zmemcmp(s->window + match,
  8.1242 +                s->window + start, length) != EQUAL) {
  8.1243 +        fprintf(stderr, " start %u, match %u, length %d\n",
  8.1244 +                start, match, length);
  8.1245 +        do {
  8.1246 +            fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  8.1247 +        } while (--length != 0);
  8.1248 +        z_error("invalid match");
  8.1249 +    }
  8.1250 +    if (z_verbose > 1) {
  8.1251 +        fprintf(stderr,"\\[%d,%d]", start-match, length);
  8.1252 +        do { putc(s->window[start++], stderr); } while (--length != 0);
  8.1253 +    }
  8.1254 +}
  8.1255 +#else
  8.1256 +#  define check_match(s, start, match, length)
  8.1257 +#endif /* DEBUG */
  8.1258 +
  8.1259 +/* ===========================================================================
  8.1260 + * Fill the window when the lookahead becomes insufficient.
  8.1261 + * Updates strstart and lookahead.
  8.1262 + *
  8.1263 + * IN assertion: lookahead < MIN_LOOKAHEAD
  8.1264 + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  8.1265 + *    At least one byte has been read, or avail_in == 0; reads are
  8.1266 + *    performed for at least two bytes (required for the zip translate_eol
  8.1267 + *    option -- not supported here).
  8.1268 + */
  8.1269 +local void fill_window(s)
  8.1270 +    deflate_state *s;
  8.1271 +{
  8.1272 +    register unsigned n, m;
  8.1273 +    register Posf *p;
  8.1274 +    unsigned more;    /* Amount of free space at the end of the window. */
  8.1275 +    uInt wsize = s->w_size;
  8.1276 +
  8.1277 +    do {
  8.1278 +        more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  8.1279 +
  8.1280 +        /* Deal with !@#$% 64K limit: */
  8.1281 +        if (sizeof(int) <= 2) {
  8.1282 +            if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  8.1283 +                more = wsize;
  8.1284 +
  8.1285 +            } else if (more == (unsigned)(-1)) {
  8.1286 +                /* Very unlikely, but possible on 16 bit machine if
  8.1287 +                 * strstart == 0 && lookahead == 1 (input done a byte at time)
  8.1288 +                 */
  8.1289 +                more--;
  8.1290 +            }
  8.1291 +        }
  8.1292 +
  8.1293 +        /* If the window is almost full and there is insufficient lookahead,
  8.1294 +         * move the upper half to the lower one to make room in the upper half.
  8.1295 +         */
  8.1296 +        if (s->strstart >= wsize+MAX_DIST(s)) {
  8.1297 +
  8.1298 +            zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  8.1299 +            s->match_start -= wsize;
  8.1300 +            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
  8.1301 +            s->block_start -= (long) wsize;
  8.1302 +
  8.1303 +            /* Slide the hash table (could be avoided with 32 bit values
  8.1304 +               at the expense of memory usage). We slide even when level == 0
  8.1305 +               to keep the hash table consistent if we switch back to level > 0
  8.1306 +               later. (Using level 0 permanently is not an optimal usage of
  8.1307 +               zlib, so we don't care about this pathological case.)
  8.1308 +             */
  8.1309 +            /* %%% avoid this when Z_RLE */
  8.1310 +            n = s->hash_size;
  8.1311 +            p = &s->head[n];
  8.1312 +            do {
  8.1313 +                m = *--p;
  8.1314 +                *p = (Pos)(m >= wsize ? m-wsize : NIL);
  8.1315 +            } while (--n);
  8.1316 +
  8.1317 +            n = wsize;
  8.1318 +#ifndef FASTEST
  8.1319 +            p = &s->prev[n];
  8.1320 +            do {
  8.1321 +                m = *--p;
  8.1322 +                *p = (Pos)(m >= wsize ? m-wsize : NIL);
  8.1323 +                /* If n is not on any hash chain, prev[n] is garbage but
  8.1324 +                 * its value will never be used.
  8.1325 +                 */
  8.1326 +            } while (--n);
  8.1327 +#endif
  8.1328 +            more += wsize;
  8.1329 +        }
  8.1330 +        if (s->strm->avail_in == 0) return;
  8.1331 +
  8.1332 +        /* If there was no sliding:
  8.1333 +         *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  8.1334 +         *    more == window_size - lookahead - strstart
  8.1335 +         * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  8.1336 +         * => more >= window_size - 2*WSIZE + 2
  8.1337 +         * In the BIG_MEM or MMAP case (not yet supported),
  8.1338 +         *   window_size == input_size + MIN_LOOKAHEAD  &&
  8.1339 +         *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  8.1340 +         * Otherwise, window_size == 2*WSIZE so more >= 2.
  8.1341 +         * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  8.1342 +         */
  8.1343 +        Assert(more >= 2, "more < 2");
  8.1344 +
  8.1345 +        n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  8.1346 +        s->lookahead += n;
  8.1347 +
  8.1348 +        /* Initialize the hash value now that we have some input: */
  8.1349 +        if (s->lookahead >= MIN_MATCH) {
  8.1350 +            s->ins_h = s->window[s->strstart];
  8.1351 +            UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  8.1352 +#if MIN_MATCH != 3
  8.1353 +            Call UPDATE_HASH() MIN_MATCH-3 more times
  8.1354 +#endif
  8.1355 +        }
  8.1356 +        /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  8.1357 +         * but this is not important since only literal bytes will be emitted.
  8.1358 +         */
  8.1359 +
  8.1360 +    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  8.1361 +}
  8.1362 +
  8.1363 +/* ===========================================================================
  8.1364 + * Flush the current block, with given end-of-file flag.
  8.1365 + * IN assertion: strstart is set to the end of the current match.
  8.1366 + */
  8.1367 +#define FLUSH_BLOCK_ONLY(s, eof) { \
  8.1368 +   _tr_flush_block(s, (s->block_start >= 0L ? \
  8.1369 +                   (charf *)&s->window[(unsigned)s->block_start] : \
  8.1370 +                   (charf *)Z_NULL), \
  8.1371 +                (ulg)((long)s->strstart - s->block_start), \
  8.1372 +                (eof)); \
  8.1373 +   s->block_start = s->strstart; \
  8.1374 +   flush_pending(s->strm); \
  8.1375 +   Tracev((stderr,"[FLUSH]")); \
  8.1376 +}
  8.1377 +
  8.1378 +/* Same but force premature exit if necessary. */
  8.1379 +#define FLUSH_BLOCK(s, eof) { \
  8.1380 +   FLUSH_BLOCK_ONLY(s, eof); \
  8.1381 +   if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  8.1382 +}
  8.1383 +
  8.1384 +/* ===========================================================================
  8.1385 + * Copy without compression as much as possible from the input stream, return
  8.1386 + * the current block state.
  8.1387 + * This function does not insert new strings in the dictionary since
  8.1388 + * uncompressible data is probably not useful. This function is used
  8.1389 + * only for the level=0 compression option.
  8.1390 + * NOTE: this function should be optimized to avoid extra copying from
  8.1391 + * window to pending_buf.
  8.1392 + */
  8.1393 +local block_state deflate_stored(s, flush)
  8.1394 +    deflate_state *s;
  8.1395 +    int flush;
  8.1396 +{
  8.1397 +    /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
  8.1398 +     * to pending_buf_size, and each stored block has a 5 byte header:
  8.1399 +     */
  8.1400 +    ulg max_block_size = 0xffff;
  8.1401 +    ulg max_start;
  8.1402 +
  8.1403 +    if (max_block_size > s->pending_buf_size - 5) {
  8.1404 +        max_block_size = s->pending_buf_size - 5;
  8.1405 +    }
  8.1406 +
  8.1407 +    /* Copy as much as possible from input to output: */
  8.1408 +    for (;;) {
  8.1409 +        /* Fill the window as much as possible: */
  8.1410 +        if (s->lookahead <= 1) {
  8.1411 +
  8.1412 +            Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  8.1413 +                   s->block_start >= (long)s->w_size, "slide too late");
  8.1414 +
  8.1415 +            fill_window(s);
  8.1416 +            if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  8.1417 +
  8.1418 +            if (s->lookahead == 0) break; /* flush the current block */
  8.1419 +        }
  8.1420 +        Assert(s->block_start >= 0L, "block gone");
  8.1421 +
  8.1422 +        s->strstart += s->lookahead;
  8.1423 +        s->lookahead = 0;
  8.1424 +
  8.1425 +        /* Emit a stored block if pending_buf will be full: */
  8.1426 +        max_start = s->block_start + max_block_size;
  8.1427 +        if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  8.1428 +            /* strstart == 0 is possible when wraparound on 16-bit machine */
  8.1429 +            s->lookahead = (uInt)(s->strstart - max_start);
  8.1430 +            s->strstart = (uInt)max_start;
  8.1431 +            FLUSH_BLOCK(s, 0);
  8.1432 +        }
  8.1433 +        /* Flush if we may have to slide, otherwise block_start may become
  8.1434 +         * negative and the data will be gone:
  8.1435 +         */
  8.1436 +        if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  8.1437 +            FLUSH_BLOCK(s, 0);
  8.1438 +        }
  8.1439 +    }
  8.1440 +    FLUSH_BLOCK(s, flush == Z_FINISH);
  8.1441 +    return flush == Z_FINISH ? finish_done : block_done;
  8.1442 +}
  8.1443 +
  8.1444 +/* ===========================================================================
  8.1445 + * Compress as much as possible from the input stream, return the current
  8.1446 + * block state.
  8.1447 + * This function does not perform lazy evaluation of matches and inserts
  8.1448 + * new strings in the dictionary only for unmatched strings or for short
  8.1449 + * matches. It is used only for the fast compression options.
  8.1450 + */
  8.1451 +local block_state deflate_fast(s, flush)
  8.1452 +    deflate_state *s;
  8.1453 +    int flush;
  8.1454 +{
  8.1455 +    IPos hash_head = NIL; /* head of the hash chain */
  8.1456 +    int bflush;           /* set if current block must be flushed */
  8.1457 +
  8.1458 +    for (;;) {
  8.1459 +        /* Make sure that we always have enough lookahead, except
  8.1460 +         * at the end of the input file. We need MAX_MATCH bytes
  8.1461 +         * for the next match, plus MIN_MATCH bytes to insert the
  8.1462 +         * string following the next match.
  8.1463 +         */
  8.1464 +        if (s->lookahead < MIN_LOOKAHEAD) {
  8.1465 +            fill_window(s);
  8.1466 +            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  8.1467 +                return need_more;
  8.1468 +            }
  8.1469 +            if (s->lookahead == 0) break; /* flush the current block */
  8.1470 +        }
  8.1471 +
  8.1472 +        /* Insert the string window[strstart .. strstart+2] in the
  8.1473 +         * dictionary, and set hash_head to the head of the hash chain:
  8.1474 +         */
  8.1475 +        if (s->lookahead >= MIN_MATCH) {
  8.1476 +            INSERT_STRING(s, s->strstart, hash_head);
  8.1477 +        }
  8.1478 +
  8.1479 +        /* Find the longest match, discarding those <= prev_length.
  8.1480 +         * At this point we have always match_length < MIN_MATCH
  8.1481 +         */
  8.1482 +        if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  8.1483 +            /* To simplify the code, we prevent matches with the string
  8.1484 +             * of window index 0 (in particular we have to avoid a match
  8.1485 +             * of the string with itself at the start of the input file).
  8.1486 +             */
  8.1487 +#ifdef FASTEST
  8.1488 +            if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  8.1489 +                (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  8.1490 +                s->match_length = longest_match_fast (s, hash_head);
  8.1491 +            }
  8.1492 +#else
  8.1493 +            if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  8.1494 +                s->match_length = longest_match (s, hash_head);
  8.1495 +            } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  8.1496 +                s->match_length = longest_match_fast (s, hash_head);
  8.1497 +            }
  8.1498 +#endif
  8.1499 +            /* longest_match() or longest_match_fast() sets match_start */
  8.1500 +        }
  8.1501 +        if (s->match_length >= MIN_MATCH) {
  8.1502 +            check_match(s, s->strstart, s->match_start, s->match_length);
  8.1503 +
  8.1504 +            _tr_tally_dist(s, s->strstart - s->match_start,
  8.1505 +                           s->match_length - MIN_MATCH, bflush);
  8.1506 +
  8.1507 +            s->lookahead -= s->match_length;
  8.1508 +
  8.1509 +            /* Insert new strings in the hash table only if the match length
  8.1510 +             * is not too large. This saves time but degrades compression.
  8.1511 +             */
  8.1512 +#ifndef FASTEST
  8.1513 +            if (s->match_length <= s->max_insert_length &&
  8.1514 +                s->lookahead >= MIN_MATCH) {
  8.1515 +                s->match_length--; /* string at strstart already in table */
  8.1516 +                do {
  8.1517 +                    s->strstart++;
  8.1518 +                    INSERT_STRING(s, s->strstart, hash_head);
  8.1519 +                    /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  8.1520 +                     * always MIN_MATCH bytes ahead.
  8.1521 +                     */
  8.1522 +                } while (--s->match_length != 0);
  8.1523 +                s->strstart++;
  8.1524 +            } else
  8.1525 +#endif
  8.1526 +            {
  8.1527 +                s->strstart += s->match_length;
  8.1528 +                s->match_length = 0;
  8.1529 +                s->ins_h = s->window[s->strstart];
  8.1530 +                UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  8.1531 +#if MIN_MATCH != 3
  8.1532 +                Call UPDATE_HASH() MIN_MATCH-3 more times
  8.1533 +#endif
  8.1534 +                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  8.1535 +                 * matter since it will be recomputed at next deflate call.
  8.1536 +                 */
  8.1537 +            }
  8.1538 +        } else {
  8.1539 +            /* No match, output a literal byte */
  8.1540 +            Tracevv((stderr,"%c", s->window[s->strstart]));
  8.1541 +            _tr_tally_lit (s, s->window[s->strstart], bflush);
  8.1542 +            s->lookahead--;
  8.1543 +            s->strstart++;
  8.1544 +        }
  8.1545 +        if (bflush) FLUSH_BLOCK(s, 0);
  8.1546 +    }
  8.1547 +    FLUSH_BLOCK(s, flush == Z_FINISH);
  8.1548 +    return flush == Z_FINISH ? finish_done : block_done;
  8.1549 +}
  8.1550 +
  8.1551 +#ifndef FASTEST
  8.1552 +/* ===========================================================================
  8.1553 + * Same as above, but achieves better compression. We use a lazy
  8.1554 + * evaluation for matches: a match is finally adopted only if there is
  8.1555 + * no better match at the next window position.
  8.1556 + */
  8.1557 +local block_state deflate_slow(s, flush)
  8.1558 +    deflate_state *s;
  8.1559 +    int flush;
  8.1560 +{
  8.1561 +    IPos hash_head = NIL;    /* head of hash chain */
  8.1562 +    int bflush;              /* set if current block must be flushed */
  8.1563 +
  8.1564 +    /* Process the input block. */
  8.1565 +    for (;;) {
  8.1566 +        /* Make sure that we always have enough lookahead, except
  8.1567 +         * at the end of the input file. We need MAX_MATCH bytes
  8.1568 +         * for the next match, plus MIN_MATCH bytes to insert the
  8.1569 +         * string following the next match.
  8.1570 +         */
  8.1571 +        if (s->lookahead < MIN_LOOKAHEAD) {
  8.1572 +            fill_window(s);
  8.1573 +            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  8.1574 +                return need_more;
  8.1575 +            }
  8.1576 +            if (s->lookahead == 0) break; /* flush the current block */
  8.1577 +        }
  8.1578 +
  8.1579 +        /* Insert the string window[strstart .. strstart+2] in the
  8.1580 +         * dictionary, and set hash_head to the head of the hash chain:
  8.1581 +         */
  8.1582 +        if (s->lookahead >= MIN_MATCH) {
  8.1583 +            INSERT_STRING(s, s->strstart, hash_head);
  8.1584 +        }
  8.1585 +
  8.1586 +        /* Find the longest match, discarding those <= prev_length.
  8.1587 +         */
  8.1588 +        s->prev_length = s->match_length, s->prev_match = s->match_start;
  8.1589 +        s->match_length = MIN_MATCH-1;
  8.1590 +
  8.1591 +        if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  8.1592 +            s->strstart - hash_head <= MAX_DIST(s)) {
  8.1593 +            /* To simplify the code, we prevent matches with the string
  8.1594 +             * of window index 0 (in particular we have to avoid a match
  8.1595 +             * of the string with itself at the start of the input file).
  8.1596 +             */
  8.1597 +            if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  8.1598 +                s->match_length = longest_match (s, hash_head);
  8.1599 +            } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  8.1600 +                s->match_length = longest_match_fast (s, hash_head);
  8.1601 +            }
  8.1602 +            /* longest_match() or longest_match_fast() sets match_start */
  8.1603 +
  8.1604 +            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  8.1605 +#if TOO_FAR <= 32767
  8.1606 +                || (s->match_length == MIN_MATCH &&
  8.1607 +                    s->strstart - s->match_start > TOO_FAR)
  8.1608 +#endif
  8.1609 +                )) {
  8.1610 +
  8.1611 +                /* If prev_match is also MIN_MATCH, match_start is garbage
  8.1612 +                 * but we will ignore the current match anyway.
  8.1613 +                 */
  8.1614 +                s->match_length = MIN_MATCH-1;
  8.1615 +            }
  8.1616 +        }
  8.1617 +        /* If there was a match at the previous step and the current
  8.1618 +         * match is not better, output the previous match:
  8.1619 +         */
  8.1620 +        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  8.1621 +            uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  8.1622 +            /* Do not insert strings in hash table beyond this. */
  8.1623 +
  8.1624 +            check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  8.1625 +
  8.1626 +            _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  8.1627 +                           s->prev_length - MIN_MATCH, bflush);
  8.1628 +
  8.1629 +            /* Insert in hash table all strings up to the end of the match.
  8.1630 +             * strstart-1 and strstart are already inserted. If there is not
  8.1631 +             * enough lookahead, the last two strings are not inserted in
  8.1632 +             * the hash table.
  8.1633 +             */
  8.1634 +            s->lookahead -= s->prev_length-1;
  8.1635 +            s->prev_length -= 2;
  8.1636 +            do {
  8.1637 +                if (++s->strstart <= max_insert) {
  8.1638 +                    INSERT_STRING(s, s->strstart, hash_head);
  8.1639 +                }
  8.1640 +            } while (--s->prev_length != 0);
  8.1641 +            s->match_available = 0;
  8.1642 +            s->match_length = MIN_MATCH-1;
  8.1643 +            s->strstart++;
  8.1644 +
  8.1645 +            if (bflush) FLUSH_BLOCK(s, 0);
  8.1646 +
  8.1647 +        } else if (s->match_available) {
  8.1648 +            /* If there was no match at the previous position, output a
  8.1649 +             * single literal. If there was a match but the current match
  8.1650 +             * is longer, truncate the previous match to a single literal.
  8.1651 +             */
  8.1652 +            Tracevv((stderr,"%c", s->window[s->strstart-1]));
  8.1653 +            _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  8.1654 +            if (bflush) {
  8.1655 +                FLUSH_BLOCK_ONLY(s, 0);
  8.1656 +            }
  8.1657 +            s->strstart++;
  8.1658 +            s->lookahead--;
  8.1659 +            if (s->strm->avail_out == 0) return need_more;
  8.1660 +        } else {
  8.1661 +            /* There is no previous match to compare with, wait for
  8.1662 +             * the next step to decide.
  8.1663 +             */
  8.1664 +            s->match_available = 1;
  8.1665 +            s->strstart++;
  8.1666 +            s->lookahead--;
  8.1667 +        }
  8.1668 +    }
  8.1669 +    Assert (flush != Z_NO_FLUSH, "no flush?");
  8.1670 +    if (s->match_available) {
  8.1671 +        Tracevv((stderr,"%c", s->window[s->strstart-1]));
  8.1672 +        _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  8.1673 +        s->match_available = 0;
  8.1674 +    }
  8.1675 +    FLUSH_BLOCK(s, flush == Z_FINISH);
  8.1676 +    return flush == Z_FINISH ? finish_done : block_done;
  8.1677 +}
  8.1678 +#endif /* FASTEST */
  8.1679 +
  8.1680 +#if 0
  8.1681 +/* ===========================================================================
  8.1682 + * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  8.1683 + * one.  Do not maintain a hash table.  (It will be regenerated if this run of
  8.1684 + * deflate switches away from Z_RLE.)
  8.1685 + */
  8.1686 +local block_state deflate_rle(s, flush)
  8.1687 +    deflate_state *s;
  8.1688 +    int flush;
  8.1689 +{
  8.1690 +    int bflush;         /* set if current block must be flushed */
  8.1691 +    uInt run;           /* length of run */
  8.1692 +    uInt max;           /* maximum length of run */
  8.1693 +    uInt prev;          /* byte at distance one to match */
  8.1694 +    Bytef *scan;        /* scan for end of run */
  8.1695 +
  8.1696 +    for (;;) {
  8.1697 +        /* Make sure that we always have enough lookahead, except
  8.1698 +         * at the end of the input file. We need MAX_MATCH bytes
  8.1699 +         * for the longest encodable run.
  8.1700 +         */
  8.1701 +        if (s->lookahead < MAX_MATCH) {
  8.1702 +            fill_window(s);
  8.1703 +            if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  8.1704 +                return need_more;
  8.1705 +            }
  8.1706 +            if (s->lookahead == 0) break; /* flush the current block */
  8.1707 +        }
  8.1708 +
  8.1709 +        /* See how many times the previous byte repeats */
  8.1710 +        run = 0;
  8.1711 +        if (s->strstart > 0) {      /* if there is a previous byte, that is */
  8.1712 +            max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  8.1713 +            scan = s->window + s->strstart - 1;
  8.1714 +            prev = *scan++;
  8.1715 +            do {
  8.1716 +                if (*scan++ != prev)
  8.1717 +                    break;
  8.1718 +            } while (++run < max);
  8.1719 +        }
  8.1720 +
  8.1721 +        /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  8.1722 +        if (run >= MIN_MATCH) {
  8.1723 +            check_match(s, s->strstart, s->strstart - 1, run);
  8.1724 +            _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  8.1725 +            s->lookahead -= run;
  8.1726 +            s->strstart += run;
  8.1727 +        } else {
  8.1728 +            /* No match, output a literal byte */
  8.1729 +            Tracevv((stderr,"%c", s->window[s->strstart]));
  8.1730 +            _tr_tally_lit (s, s->window[s->strstart], bflush);
  8.1731 +            s->lookahead--;
  8.1732 +            s->strstart++;
  8.1733 +        }
  8.1734 +        if (bflush) FLUSH_BLOCK(s, 0);
  8.1735 +    }
  8.1736 +    FLUSH_BLOCK(s, flush == Z_FINISH);
  8.1737 +    return flush == Z_FINISH ? finish_done : block_done;
  8.1738 +}
  8.1739 +#endif
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/compiler-init/zlib/deflate.h	Sat Jul 15 04:51:28 2006 +0000
     9.3 @@ -0,0 +1,331 @@
     9.4 +/* deflate.h -- internal compression state
     9.5 + * Copyright (C) 1995-2004 Jean-loup Gailly
     9.6 + * For conditions of distribution and use, see copyright notice in zlib.h
     9.7 + */
     9.8 +
     9.9 +/* WARNING: this file should *not* be used by applications. It is
    9.10 +   part of the implementation of the compression library and is
    9.11 +   subject to change. Applications should only use zlib.h.
    9.12 + */
    9.13 +
    9.14 +/* @(#) $Id$ */
    9.15 +
    9.16 +#ifndef DEFLATE_H
    9.17 +#define DEFLATE_H
    9.18 +
    9.19 +#include "zutil.h"
    9.20 +
    9.21 +/* define NO_GZIP when compiling if you want to disable gzip header and
    9.22 +   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
    9.23 +   the crc code when it is not needed.  For shared libraries, gzip encoding
    9.24 +   should be left enabled. */
    9.25 +#ifndef NO_GZIP
    9.26 +#  define GZIP
    9.27 +#endif
    9.28 +
    9.29 +/* ===========================================================================
    9.30 + * Internal compression state.
    9.31 + */
    9.32 +
    9.33 +#define LENGTH_CODES 29
    9.34 +/* number of length codes, not counting the special END_BLOCK code */
    9.35 +
    9.36 +#define LITERALS  256
    9.37 +/* number of literal bytes 0..255 */
    9.38 +
    9.39 +#define L_CODES (LITERALS+1+LENGTH_CODES)
    9.40 +/* number of Literal or Length codes, including the END_BLOCK code */
    9.41 +
    9.42 +#define D_CODES   30
    9.43 +/* number of distance codes */
    9.44 +
    9.45 +#define BL_CODES  19
    9.46 +/* number of codes used to transfer the bit lengths */
    9.47 +
    9.48 +#define HEAP_SIZE (2*L_CODES+1)
    9.49 +/* maximum heap size */
    9.50 +
    9.51 +#define MAX_BITS 15
    9.52 +/* All codes must not exceed MAX_BITS bits */
    9.53 +
    9.54 +#define INIT_STATE    42
    9.55 +#define EXTRA_STATE   69
    9.56 +#define NAME_STATE    73
    9.57 +#define COMMENT_STATE 91
    9.58 +#define HCRC_STATE   103
    9.59 +#define BUSY_STATE   113
    9.60 +#define FINISH_STATE 666
    9.61 +/* Stream status */
    9.62 +
    9.63 +
    9.64 +/* Data structure describing a single value and its code string. */
    9.65 +typedef struct ct_data_s {
    9.66 +    union {
    9.67 +        ush  freq;       /* frequency count */
    9.68 +        ush  code;       /* bit string */
    9.69 +    } fc;
    9.70 +    union {
    9.71 +        ush  dad;        /* father node in Huffman tree */
    9.72 +        ush  len;        /* length of bit string */
    9.73 +    } dl;
    9.74 +} FAR ct_data;
    9.75 +
    9.76 +#define Freq fc.freq
    9.77 +#define Code fc.code
    9.78 +#define Dad  dl.dad
    9.79 +#define Len  dl.len
    9.80 +
    9.81 +typedef struct static_tree_desc_s  static_tree_desc;
    9.82 +
    9.83 +typedef struct tree_desc_s {
    9.84 +    ct_data *dyn_tree;           /* the dynamic tree */
    9.85 +    int     max_code;            /* largest code with non zero frequency */
    9.86 +    static_tree_desc *stat_desc; /* the corresponding static tree */
    9.87 +} FAR tree_desc;
    9.88 +
    9.89 +typedef ush Pos;
    9.90 +typedef Pos FAR Posf;
    9.91 +typedef unsigned IPos;
    9.92 +
    9.93 +/* A Pos is an index in the character window. We use short instead of int to
    9.94 + * save space in the various tables. IPos is used only for parameter passing.
    9.95 + */
    9.96 +
    9.97 +typedef struct internal_state {
    9.98 +    z_streamp strm;      /* pointer back to this zlib stream */
    9.99 +    int   status;        /* as the name implies */
   9.100 +    Bytef *pending_buf;  /* output still pending */
   9.101 +    ulg   pending_buf_size; /* size of pending_buf */
   9.102 +    Bytef *pending_out;  /* next pending byte to output to the stream */
   9.103 +    uInt   pending;      /* nb of bytes in the pending buffer */
   9.104 +    int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
   9.105 +    gz_headerp  gzhead;  /* gzip header information to write */
   9.106 +    uInt   gzindex;      /* where in extra, name, or comment */
   9.107 +    Byte  method;        /* STORED (for zip only) or DEFLATED */
   9.108 +    int   last_flush;    /* value of flush param for previous deflate call */
   9.109 +
   9.110 +                /* used by deflate.c: */
   9.111 +
   9.112 +    uInt  w_size;        /* LZ77 window size (32K by default) */
   9.113 +    uInt  w_bits;        /* log2(w_size)  (8..16) */
   9.114 +    uInt  w_mask;        /* w_size - 1 */
   9.115 +
   9.116 +    Bytef *window;
   9.117 +    /* Sliding window. Input bytes are read into the second half of the window,
   9.118 +     * and move to the first half later to keep a dictionary of at least wSize
   9.119 +     * bytes. With this organization, matches are limited to a distance of
   9.120 +     * wSize-MAX_MATCH bytes, but this ensures that IO is always
   9.121 +     * performed with a length multiple of the block size. Also, it limits
   9.122 +     * the window size to 64K, which is quite useful on MSDOS.
   9.123 +     * To do: use the user input buffer as sliding window.
   9.124 +     */
   9.125 +
   9.126 +    ulg window_size;
   9.127 +    /* Actual size of window: 2*wSize, except when the user input buffer
   9.128 +     * is directly used as sliding window.
   9.129 +     */
   9.130 +
   9.131 +    Posf *prev;
   9.132 +    /* Link to older string with same hash index. To limit the size of this
   9.133 +     * array to 64K, this link is maintained only for the last 32K strings.
   9.134 +     * An index in this array is thus a window index modulo 32K.
   9.135 +     */
   9.136 +
   9.137 +    Posf *head; /* Heads of the hash chains or NIL. */
   9.138 +
   9.139 +    uInt  ins_h;          /* hash index of string to be inserted */
   9.140 +    uInt  hash_size;      /* number of elements in hash table */
   9.141 +    uInt  hash_bits;      /* log2(hash_size) */
   9.142 +    uInt  hash_mask;      /* hash_size-1 */
   9.143 +
   9.144 +    uInt  hash_shift;
   9.145 +    /* Number of bits by which ins_h must be shifted at each input
   9.146 +     * step. It must be such that after MIN_MATCH steps, the oldest
   9.147 +     * byte no longer takes part in the hash key, that is:
   9.148 +     *   hash_shift * MIN_MATCH >= hash_bits
   9.149 +     */
   9.150 +
   9.151 +    long block_start;
   9.152 +    /* Window position at the beginning of the current output block. Gets
   9.153 +     * negative when the window is moved backwards.
   9.154 +     */
   9.155 +
   9.156 +    uInt match_length;           /* length of best match */
   9.157 +    IPos prev_match;             /* previous match */
   9.158 +    int match_available;         /* set if previous match exists */
   9.159 +    uInt strstart;               /* start of string to insert */
   9.160 +    uInt match_start;            /* start of matching string */
   9.161 +    uInt lookahead;              /* number of valid bytes ahead in window */
   9.162 +
   9.163 +    uInt prev_length;
   9.164 +    /* Length of the best match at previous step. Matches not greater than this
   9.165 +     * are discarded. This is used in the lazy match evaluation.
   9.166 +     */
   9.167 +
   9.168 +    uInt max_chain_length;
   9.169 +    /* To speed up deflation, hash chains are never searched beyond this
   9.170 +     * length.  A higher limit improves compression ratio but degrades the
   9.171 +     * speed.
   9.172 +     */
   9.173 +
   9.174 +    uInt max_lazy_match;
   9.175 +    /* Attempt to find a better match only when the current match is strictly
   9.176 +     * smaller than this value. This mechanism is used only for compression
   9.177 +     * levels >= 4.
   9.178 +     */
   9.179 +#   define max_insert_length  max_lazy_match
   9.180 +    /* Insert new strings in the hash table only if the match length is not
   9.181 +     * greater than this length. This saves time but degrades compression.
   9.182 +     * max_insert_length is used only for compression levels <= 3.
   9.183 +     */
   9.184 +
   9.185 +    int level;    /* compression level (1..9) */
   9.186 +    int strategy; /* favor or force Huffman coding*/
   9.187 +
   9.188 +    uInt good_match;
   9.189 +    /* Use a faster search when the previous match is longer than this */
   9.190 +
   9.191 +    int nice_match; /* Stop searching when current match exceeds this */
   9.192 +
   9.193 +                /* used by trees.c: */
   9.194 +    /* Didn't use ct_data typedef below to supress compiler warning */
   9.195 +    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
   9.196 +    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
   9.197 +    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
   9.198 +
   9.199 +    struct tree_desc_s l_desc;               /* desc. for literal tree */
   9.200 +    struct tree_desc_s d_desc;               /* desc. for distance tree */
   9.201 +    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
   9.202 +
   9.203 +    ush bl_count[MAX_BITS+1];
   9.204 +    /* number of codes at each bit length for an optimal tree */
   9.205 +
   9.206 +    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
   9.207 +    int heap_len;               /* number of elements in the heap */
   9.208 +    int heap_max;               /* element of largest frequency */
   9.209 +    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
   9.210 +     * The same heap array is used to build all trees.
   9.211 +     */
   9.212 +
   9.213 +    uch depth[2*L_CODES+1];
   9.214 +    /* Depth of each subtree used as tie breaker for trees of equal frequency
   9.215 +     */
   9.216 +
   9.217 +    uchf *l_buf;          /* buffer for literals or lengths */
   9.218 +
   9.219 +    uInt  lit_bufsize;
   9.220 +    /* Size of match buffer for literals/lengths.  There are 4 reasons for
   9.221 +     * limiting lit_bufsize to 64K:
   9.222 +     *   - frequencies can be kept in 16 bit counters
   9.223 +     *   - if compression is not successful for the first block, all input
   9.224 +     *     data is still in the window so we can still emit a stored block even
   9.225 +     *     when input comes from standard input.  (This can also be done for
   9.226 +     *     all blocks if lit_bufsize is not greater than 32K.)
   9.227 +     *   - if compression is not successful for a file smaller than 64K, we can
   9.228 +     *     even emit a stored file instead of a stored block (saving 5 bytes).
   9.229 +     *     This is applicable only for zip (not gzip or zlib).
   9.230 +     *   - creating new Huffman trees less frequently may not provide fast
   9.231 +     *     adaptation to changes in the input data statistics. (Take for
   9.232 +     *     example a binary file with poorly compressible code followed by
   9.233 +     *     a highly compressible string table.) Smaller buffer sizes give
   9.234 +     *     fast adaptation but have of course the overhead of transmitting
   9.235 +     *     trees more frequently.
   9.236 +     *   - I can't count above 4
   9.237 +     */
   9.238 +
   9.239 +    uInt last_lit;      /* running index in l_buf */
   9.240 +
   9.241 +    ushf *d_buf;
   9.242 +    /* Buffer for distances. To simplify the code, d_buf and l_buf have
   9.243 +     * the same number of elements. To use different lengths, an extra flag
   9.244 +     * array would be necessary.
   9.245 +     */
   9.246 +
   9.247 +    ulg opt_len;        /* bit length of current block with optimal trees */
   9.248 +    ulg static_len;     /* bit length of current block with static trees */
   9.249 +    uInt matches;       /* number of string matches in current block */
   9.250 +    int last_eob_len;   /* bit length of EOB code for last block */
   9.251 +
   9.252 +#ifdef DEBUG
   9.253 +    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
   9.254 +    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
   9.255 +#endif
   9.256 +
   9.257 +    ush bi_buf;
   9.258 +    /* Output buffer. bits are inserted starting at the bottom (least
   9.259 +     * significant bits).
   9.260 +     */
   9.261 +    int bi_valid;
   9.262 +    /* Number of valid bits in bi_buf.  All bits above the last valid bit
   9.263 +     * are always zero.
   9.264 +     */
   9.265 +
   9.266 +} FAR deflate_state;
   9.267 +
   9.268 +/* Output a byte on the stream.
   9.269 + * IN assertion: there is enough room in pending_buf.
   9.270 + */
   9.271 +#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
   9.272 +
   9.273 +
   9.274 +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
   9.275 +/* Minimum amount of lookahead, except at the end of the input file.
   9.276 + * See deflate.c for comments about the MIN_MATCH+1.
   9.277 + */
   9.278 +
   9.279 +#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
   9.280 +/* In order to simplify the code, particularly on 16 bit machines, match
   9.281 + * distances are limited to MAX_DIST instead of WSIZE.
   9.282 + */
   9.283 +
   9.284 +        /* in trees.c */
   9.285 +void _tr_init         OF((deflate_state *s));
   9.286 +int  _tr_tally        OF((deflate_state *s, unsigned dist, unsigned lc));
   9.287 +void _tr_flush_block  OF((deflate_state *s, charf *buf, ulg stored_len,
   9.288 +                          int eof));
   9.289 +void _tr_align        OF((deflate_state *s));
   9.290 +void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
   9.291 +                          int eof));
   9.292 +
   9.293 +#define d_code(dist) \
   9.294 +   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
   9.295 +/* Mapping from a distance to a distance code. dist is the distance - 1 and
   9.296 + * must not have side effects. _dist_code[256] and _dist_code[257] are never
   9.297 + * used.
   9.298 + */
   9.299 +
   9.300 +#ifndef DEBUG
   9.301 +/* Inline versions of _tr_tally for speed: */
   9.302 +
   9.303 +#if defined(GEN_TREES_H) || !defined(STDC)
   9.304 +  extern uch _length_code[];
   9.305 +  extern uch _dist_code[];
   9.306 +#else
   9.307 +  extern const uch _length_code[];
   9.308 +  extern const uch _dist_code[];
   9.309 +#endif
   9.310 +
   9.311 +# define _tr_tally_lit(s, c, flush) \
   9.312 +  { uch cc = (c); \
   9.313 +    s->d_buf[s->last_lit] = 0; \
   9.314 +    s->l_buf[s->last_lit++] = cc; \
   9.315 +    s->dyn_ltree[cc].Freq++; \
   9.316 +    flush = (s->last_lit == s->lit_bufsize-1); \
   9.317 +   }
   9.318 +# define _tr_tally_dist(s, distance, length, flush) \
   9.319 +  { uch len = (length); \
   9.320 +    ush dist = (distance); \
   9.321 +    s->d_buf[s->last_lit] = dist; \
   9.322 +    s->l_buf[s->last_lit++] = len; \
   9.323 +    dist--; \
   9.324 +    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
   9.325 +    s->dyn_dtree[d_code(dist)].Freq++; \
   9.326 +    flush = (s->last_lit == s->lit_bufsize-1); \
   9.327 +  }
   9.328 +#else
   9.329 +# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
   9.330 +# define _tr_tally_dist(s, distance, length, flush) \
   9.331 +              flush = _tr_tally(s, distance, length)
   9.332 +#endif
   9.333 +
   9.334 +#endif /* DEFLATE_H */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/compiler-init/zlib/gzio.c	Sat Jul 15 04:51:28 2006 +0000
    10.3 @@ -0,0 +1,1026 @@
    10.4 +/* gzio.c -- IO on .gz files
    10.5 + * Copyright (C) 1995-2005 Jean-loup Gailly.
    10.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    10.7 + *
    10.8 + * Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
    10.9 + */
   10.10 +
   10.11 +/* @(#) $Id$ */
   10.12 +
   10.13 +#include <stdio.h>
   10.14 +
   10.15 +#include "zutil.h"
   10.16 +
   10.17 +#ifdef NO_DEFLATE       /* for compatibility with old definition */
   10.18 +#  define NO_GZCOMPRESS
   10.19 +#endif
   10.20 +
   10.21 +#ifndef NO_DUMMY_DECL
   10.22 +struct internal_state {int dummy;}; /* for buggy compilers */
   10.23 +#endif
   10.24 +
   10.25 +#ifndef Z_BUFSIZE
   10.26 +#  ifdef MAXSEG_64K
   10.27 +#    define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
   10.28 +#  else
   10.29 +#    define Z_BUFSIZE 16384
   10.30 +#  endif
   10.31 +#endif
   10.32 +#ifndef Z_PRINTF_BUFSIZE
   10.33 +#  define Z_PRINTF_BUFSIZE 4096
   10.34 +#endif
   10.35 +
   10.36 +#ifdef __MVS__
   10.37 +#  pragma map (fdopen , "\174\174FDOPEN")
   10.38 +   FILE *fdopen(int, const char *);
   10.39 +#endif
   10.40 +
   10.41 +#ifndef STDC
   10.42 +extern voidp  malloc OF((uInt size));
   10.43 +extern void   free   OF((voidpf ptr));
   10.44 +#endif
   10.45 +
   10.46 +#define ALLOC(size) malloc(size)
   10.47 +#define TRYFREE(p) {if (p) free(p);}
   10.48 +
   10.49 +static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
   10.50 +
   10.51 +/* gzip flag byte */
   10.52 +#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
   10.53 +#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
   10.54 +#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
   10.55 +#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
   10.56 +#define COMMENT      0x10 /* bit 4 set: file comment present */
   10.57 +#define RESERVED     0xE0 /* bits 5..7: reserved */
   10.58 +
   10.59 +typedef struct gz_stream {
   10.60 +    z_stream stream;
   10.61 +    int      z_err;   /* error code for last stream operation */
   10.62 +    int      z_eof;   /* set if end of input file */
   10.63 +    FILE     *file;   /* .gz file */
   10.64 +    Byte     *inbuf;  /* input buffer */
   10.65 +    Byte     *outbuf; /* output buffer */
   10.66 +    uLong    crc;     /* crc32 of uncompressed data */
   10.67 +    char     *msg;    /* error message */
   10.68 +    char     *path;   /* path name for debugging only */
   10.69 +    int      transparent; /* 1 if input file is not a .gz file */
   10.70 +    char     mode;    /* 'w' or 'r' */
   10.71 +    z_off_t  start;   /* start of compressed data in file (header skipped) */
   10.72 +    z_off_t  in;      /* bytes into deflate or inflate */
   10.73 +    z_off_t  out;     /* bytes out of deflate or inflate */
   10.74 +    int      back;    /* one character push-back */
   10.75 +    int      last;    /* true if push-back is last character */
   10.76 +} gz_stream;
   10.77 +
   10.78 +
   10.79 +local gzFile gz_open      OF((const char *path, const char *mode, int  fd));
   10.80 +local int do_flush        OF((gzFile file, int flush));
   10.81 +local int    get_byte     OF((gz_stream *s));
   10.82 +local void   check_header OF((gz_stream *s));
   10.83 +local int    destroy      OF((gz_stream *s));
   10.84 +local void   putLong      OF((FILE *file, uLong x));
   10.85 +local uLong  getLong      OF((gz_stream *s));
   10.86 +
   10.87 +/* ===========================================================================
   10.88 +     Opens a gzip (.gz) file for reading or writing. The mode parameter
   10.89 +   is as in fopen ("rb" or "wb"). The file is given either by file descriptor
   10.90 +   or path name (if fd == -1).
   10.91 +     gz_open returns NULL if the file could not be opened or if there was
   10.92 +   insufficient memory to allocate the (de)compression state; errno
   10.93 +   can be checked to distinguish the two cases (if errno is zero, the
   10.94 +   zlib error is Z_MEM_ERROR).
   10.95 +*/
   10.96 +local gzFile gz_open (path, mode, fd)
   10.97 +    const char *path;
   10.98 +    const char *mode;
   10.99 +    int  fd;
  10.100 +{
  10.101 +    int err;
  10.102 +    int level = Z_DEFAULT_COMPRESSION; /* compression level */
  10.103 +    int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
  10.104 +    char *p = (char*)mode;
  10.105 +    gz_stream *s;
  10.106 +    char fmode[80]; /* copy of mode, without the compression level */
  10.107 +    char *m = fmode;
  10.108 +
  10.109 +    if (!path || !mode) return Z_NULL;
  10.110 +
  10.111 +    s = (gz_stream *)ALLOC(sizeof(gz_stream));
  10.112 +    if (!s) return Z_NULL;
  10.113 +
  10.114 +    s->stream.zalloc = (alloc_func)0;
  10.115 +    s->stream.zfree = (free_func)0;
  10.116 +    s->stream.opaque = (voidpf)0;
  10.117 +    s->stream.next_in = s->inbuf = Z_NULL;
  10.118 +    s->stream.next_out = s->outbuf = Z_NULL;
  10.119 +    s->stream.avail_in = s->stream.avail_out = 0;
  10.120 +    s->file = NULL;
  10.121 +    s->z_err = Z_OK;
  10.122 +    s->z_eof = 0;
  10.123 +    s->in = 0;
  10.124 +    s->out = 0;
  10.125 +    s->back = EOF;
  10.126 +    s->crc = crc32(0L, Z_NULL, 0);
  10.127 +    s->msg = NULL;
  10.128 +    s->transparent = 0;
  10.129 +
  10.130 +    s->path = (char*)ALLOC(strlen(path)+1);
  10.131 +    if (s->path == NULL) {
  10.132 +        return destroy(s), (gzFile)Z_NULL;
  10.133 +    }
  10.134 +    strcpy(s->path, path); /* do this early for debugging */
  10.135 +
  10.136 +    s->mode = '\0';
  10.137 +    do {
  10.138 +        if (*p == 'r') s->mode = 'r';
  10.139 +        if (*p == 'w' || *p == 'a') s->mode = 'w';
  10.140 +        if (*p >= '0' && *p <= '9') {
  10.141 +            level = *p - '0';
  10.142 +        } else if (*p == 'f') {
  10.143 +          strategy = Z_FILTERED;
  10.144 +        } else if (*p == 'h') {
  10.145 +          strategy = Z_HUFFMAN_ONLY;
  10.146 +        } else if (*p == 'R') {
  10.147 +          strategy = Z_RLE;
  10.148 +        } else {
  10.149 +            *m++ = *p; /* copy the mode */
  10.150 +        }
  10.151 +    } while (*p++ && m != fmode + sizeof(fmode));
  10.152 +    if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
  10.153 +
  10.154 +    if (s->mode == 'w') {
  10.155 +#ifdef NO_GZCOMPRESS
  10.156 +        err = Z_STREAM_ERROR;
  10.157 +#else
  10.158 +        err = deflateInit2(&(s->stream), level,
  10.159 +                           Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
  10.160 +        /* windowBits is passed < 0 to suppress zlib header */
  10.161 +
  10.162 +        s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
  10.163 +#endif
  10.164 +        if (err != Z_OK || s->outbuf == Z_NULL) {
  10.165 +            return destroy(s), (gzFile)Z_NULL;
  10.166 +        }
  10.167 +    } else {
  10.168 +        s->stream.next_in  = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
  10.169 +
  10.170 +        err = inflateInit2(&(s->stream), -MAX_WBITS);
  10.171 +        /* windowBits is passed < 0 to tell that there is no zlib header.
  10.172 +         * Note that in this case inflate *requires* an extra "dummy" byte
  10.173 +         * after the compressed stream in order to complete decompression and
  10.174 +         * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
  10.175 +         * present after the compressed stream.
  10.176 +         */
  10.177 +        if (err != Z_OK || s->inbuf == Z_NULL) {
  10.178 +            return destroy(s), (gzFile)Z_NULL;
  10.179 +        }
  10.180 +    }
  10.181 +    s->stream.avail_out = Z_BUFSIZE;
  10.182 +
  10.183 +    errno = 0;
  10.184 +    s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
  10.185 +
  10.186 +    if (s->file == NULL) {
  10.187 +        return destroy(s), (gzFile)Z_NULL;
  10.188 +    }
  10.189 +    if (s->mode == 'w') {
  10.190 +        /* Write a very simple .gz header:
  10.191 +         */
  10.192 +        fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
  10.193 +             Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
  10.194 +        s->start = 10L;
  10.195 +        /* We use 10L instead of ftell(s->file) to because ftell causes an
  10.196 +         * fflush on some systems. This version of the library doesn't use
  10.197 +         * start anyway in write mode, so this initialization is not
  10.198 +         * necessary.
  10.199 +         */
  10.200 +    } else {
  10.201 +        check_header(s); /* skip the .gz header */
  10.202 +        s->start = ftell(s->file) - s->stream.avail_in;
  10.203 +    }
  10.204 +
  10.205 +    return (gzFile)s;
  10.206 +}
  10.207 +
  10.208 +/* ===========================================================================
  10.209 +     Opens a gzip (.gz) file for reading or writing.
  10.210 +*/
  10.211 +gzFile ZEXPORT gzopen (path, mode)
  10.212 +    const char *path;
  10.213 +    const char *mode;
  10.214 +{
  10.215 +    return gz_open (path, mode, -1);
  10.216 +}
  10.217 +
  10.218 +/* ===========================================================================
  10.219 +     Associate a gzFile with the file descriptor fd. fd is not dup'ed here
  10.220 +   to mimic the behavio(u)r of fdopen.
  10.221 +*/
  10.222 +gzFile ZEXPORT gzdopen (fd, mode)
  10.223 +    int fd;
  10.224 +    const char *mode;
  10.225 +{
  10.226 +    char name[46];      /* allow for up to 128-bit integers */
  10.227 +
  10.228 +    if (fd < 0) return (gzFile)Z_NULL;
  10.229 +    sprintf(name, "<fd:%d>", fd); /* for debugging */
  10.230 +
  10.231 +    return gz_open (name, mode, fd);
  10.232 +}
  10.233 +
  10.234 +/* ===========================================================================
  10.235 + * Update the compression level and strategy
  10.236 + */
  10.237 +int ZEXPORT gzsetparams (file, level, strategy)
  10.238 +    gzFile file;
  10.239 +    int level;
  10.240 +    int strategy;
  10.241 +{
  10.242 +    gz_stream *s = (gz_stream*)file;
  10.243 +
  10.244 +    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
  10.245 +
  10.246 +    /* Make room to allow flushing */
  10.247 +    if (s->stream.avail_out == 0) {
  10.248 +
  10.249 +        s->stream.next_out = s->outbuf;
  10.250 +        if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
  10.251 +            s->z_err = Z_ERRNO;
  10.252 +        }
  10.253 +        s->stream.avail_out = Z_BUFSIZE;
  10.254 +    }
  10.255 +
  10.256 +    return deflateParams (&(s->stream), level, strategy);
  10.257 +}
  10.258 +
  10.259 +/* ===========================================================================
  10.260 +     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
  10.261 +   for end of file.
  10.262 +   IN assertion: the stream s has been sucessfully opened for reading.
  10.263 +*/
  10.264 +local int get_byte(s)
  10.265 +    gz_stream *s;
  10.266 +{
  10.267 +    if (s->z_eof) return EOF;
  10.268 +    if (s->stream.avail_in == 0) {
  10.269 +        errno = 0;
  10.270 +        s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
  10.271 +        if (s->stream.avail_in == 0) {
  10.272 +            s->z_eof = 1;
  10.273 +            if (ferror(s->file)) s->z_err = Z_ERRNO;
  10.274 +            return EOF;
  10.275 +        }
  10.276 +        s->stream.next_in = s->inbuf;
  10.277 +    }
  10.278 +    s->stream.avail_in--;
  10.279 +    return *(s->stream.next_in)++;
  10.280 +}
  10.281 +
  10.282 +/* ===========================================================================
  10.283 +      Check the gzip header of a gz_stream opened for reading. Set the stream
  10.284 +    mode to transparent if the gzip magic header is not present; set s->err
  10.285 +    to Z_DATA_ERROR if the magic header is present but the rest of the header
  10.286 +    is incorrect.
  10.287 +    IN assertion: the stream s has already been created sucessfully;
  10.288 +       s->stream.avail_in is zero for the first time, but may be non-zero
  10.289 +       for concatenated .gz files.
  10.290 +*/
  10.291 +local void check_header(s)
  10.292 +    gz_stream *s;
  10.293 +{
  10.294 +    int method; /* method byte */
  10.295 +    int flags;  /* flags byte */
  10.296 +    uInt len;
  10.297 +    int c;
  10.298 +
  10.299 +    /* Assure two bytes in the buffer so we can peek ahead -- handle case
  10.300 +       where first byte of header is at the end of the buffer after the last
  10.301 +       gzip segment */
  10.302 +    len = s->stream.avail_in;
  10.303 +    if (len < 2) {
  10.304 +        if (len) s->inbuf[0] = s->stream.next_in[0];
  10.305 +        errno = 0;
  10.306 +        len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
  10.307 +        if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
  10.308 +        s->stream.avail_in += len;
  10.309 +        s->stream.next_in = s->inbuf;
  10.310 +        if (s->stream.avail_in < 2) {
  10.311 +            s->transparent = s->stream.avail_in;
  10.312 +            return;
  10.313 +        }
  10.314 +    }
  10.315 +
  10.316 +    /* Peek ahead to check the gzip magic header */
  10.317 +    if (s->stream.next_in[0] != gz_magic[0] ||
  10.318 +        s->stream.next_in[1] != gz_magic[1]) {
  10.319 +        s->transparent = 1;
  10.320 +        return;
  10.321 +    }
  10.322 +    s->stream.avail_in -= 2;
  10.323 +    s->stream.next_in += 2;
  10.324 +
  10.325 +    /* Check the rest of the gzip header */
  10.326 +    method = get_byte(s);
  10.327 +    flags = get_byte(s);
  10.328 +    if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
  10.329 +        s->z_err = Z_DATA_ERROR;
  10.330 +        return;
  10.331 +    }
  10.332 +
  10.333 +    /* Discard time, xflags and OS code: */
  10.334 +    for (len = 0; len < 6; len++) (void)get_byte(s);
  10.335 +
  10.336 +    if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
  10.337 +        len  =  (uInt)get_byte(s);
  10.338 +        len += ((uInt)get_byte(s))<<8;
  10.339 +        /* len is garbage if EOF but the loop below will quit anyway */
  10.340 +        while (len-- != 0 && get_byte(s) != EOF) ;
  10.341 +    }
  10.342 +    if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
  10.343 +        while ((c = get_byte(s)) != 0 && c != EOF) ;
  10.344 +    }
  10.345 +    if ((flags & COMMENT) != 0) {   /* skip the .gz file comment */
  10.346 +        while ((c = get_byte(s)) != 0 && c != EOF) ;
  10.347 +    }
  10.348 +    if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
  10.349 +        for (len = 0; len < 2; len++) (void)get_byte(s);
  10.350 +    }
  10.351 +    s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
  10.352 +}
  10.353 +
  10.354 + /* ===========================================================================
  10.355 + * Cleanup then free the given gz_stream. Return a zlib error code.
  10.356 +   Try freeing in the reverse order of allocations.
  10.357 + */
  10.358 +local int destroy (s)
  10.359 +    gz_stream *s;
  10.360 +{
  10.361 +    int err = Z_OK;
  10.362 +
  10.363 +    if (!s) return Z_STREAM_ERROR;
  10.364 +
  10.365 +    TRYFREE(s->msg);
  10.366 +
  10.367 +    if (s->stream.state != NULL) {
  10.368 +        if (s->mode == 'w') {
  10.369 +#ifdef NO_GZCOMPRESS
  10.370 +            err = Z_STREAM_ERROR;
  10.371 +#else
  10.372 +            err = deflateEnd(&(s->stream));
  10.373 +#endif
  10.374 +        } else if (s->mode == 'r') {
  10.375 +            err = inflateEnd(&(s->stream));
  10.376 +        }
  10.377 +    }
  10.378 +    if (s->file != NULL && fclose(s->file)) {
  10.379 +#ifdef ESPIPE
  10.380 +        if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
  10.381 +#endif
  10.382 +            err = Z_ERRNO;
  10.383 +    }
  10.384 +    if (s->z_err < 0) err = s->z_err;
  10.385 +
  10.386 +    TRYFREE(s->inbuf);
  10.387 +    TRYFREE(s->outbuf);
  10.388 +    TRYFREE(s->path);
  10.389 +    TRYFREE(s);
  10.390 +    return err;
  10.391 +}
  10.392 +
  10.393 +/* ===========================================================================
  10.394 +     Reads the given number of uncompressed bytes from the compressed file.
  10.395 +   gzread returns the number of bytes actually read (0 for end of file).
  10.396 +*/
  10.397 +int ZEXPORT gzread (file, buf, len)
  10.398 +    gzFile file;
  10.399 +    voidp buf;
  10.400 +    unsigned len;
  10.401 +{
  10.402 +    gz_stream *s = (gz_stream*)file;
  10.403 +    Bytef *start = (Bytef*)buf; /* starting point for crc computation */
  10.404 +    Byte  *next_out; /* == stream.next_out but not forced far (for MSDOS) */
  10.405 +
  10.406 +    if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
  10.407 +
  10.408 +    if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
  10.409 +    if (s->z_err == Z_STREAM_END) return 0;  /* EOF */
  10.410 +
  10.411 +    next_out = (Byte*)buf;
  10.412 +    s->stream.next_out = (Bytef*)buf;
  10.413 +    s->stream.avail_out = len;
  10.414 +
  10.415 +    if (s->stream.avail_out && s->back != EOF) {
  10.416 +        *next_out++ = s->back;
  10.417 +        s->stream.next_out++;
  10.418 +        s->stream.avail_out--;
  10.419 +        s->back = EOF;
  10.420 +        s->out++;
  10.421 +        start++;
  10.422 +        if (s->last) {
  10.423 +            s->z_err = Z_STREAM_END;
  10.424 +            return 1;
  10.425 +        }
  10.426 +    }
  10.427 +
  10.428 +    while (s->stream.avail_out != 0) {
  10.429 +
  10.430 +        if (s->transparent) {
  10.431 +            /* Copy first the lookahead bytes: */
  10.432 +            uInt n = s->stream.avail_in;
  10.433 +            if (n > s->stream.avail_out) n = s->stream.avail_out;
  10.434 +            if (n > 0) {
  10.435 +                zmemcpy(s->stream.next_out, s->stream.next_in, n);
  10.436 +                next_out += n;
  10.437 +                s->stream.next_out = next_out;
  10.438 +                s->stream.next_in   += n;
  10.439 +                s->stream.avail_out -= n;
  10.440 +                s->stream.avail_in  -= n;
  10.441 +            }
  10.442 +            if (s->stream.avail_out > 0) {
  10.443 +                s->stream.avail_out -=
  10.444 +                    (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
  10.445 +            }
  10.446 +            len -= s->stream.avail_out;
  10.447 +            s->in  += len;
  10.448 +            s->out += len;
  10.449 +            if (len == 0) s->z_eof = 1;
  10.450 +            return (int)len;
  10.451 +        }
  10.452 +        if (s->stream.avail_in == 0 && !s->z_eof) {
  10.453 +
  10.454 +            errno = 0;
  10.455 +            s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
  10.456 +            if (s->stream.avail_in == 0) {
  10.457 +                s->z_eof = 1;
  10.458 +                if (ferror(s->file)) {
  10.459 +                    s->z_err = Z_ERRNO;
  10.460 +                    break;
  10.461 +                }
  10.462 +            }
  10.463 +            s->stream.next_in = s->inbuf;
  10.464 +        }
  10.465 +        s->in += s->stream.avail_in;
  10.466 +        s->out += s->stream.avail_out;
  10.467 +        s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
  10.468 +        s->in -= s->stream.avail_in;
  10.469 +        s->out -= s->stream.avail_out;
  10.470 +
  10.471 +        if (s->z_err == Z_STREAM_END) {
  10.472 +            /* Check CRC and original size */
  10.473 +            s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
  10.474 +            start = s->stream.next_out;
  10.475 +
  10.476 +            if (getLong(s) != s->crc) {
  10.477 +                s->z_err = Z_DATA_ERROR;
  10.478 +            } else {
  10.479 +                (void)getLong(s);
  10.480 +                /* The uncompressed length returned by above getlong() may be
  10.481 +                 * different from s->out in case of concatenated .gz files.
  10.482 +                 * Check for such files:
  10.483 +                 */
  10.484 +                check_header(s);
  10.485 +                if (s->z_err == Z_OK) {
  10.486 +                    inflateReset(&(s->stream));
  10.487 +                    s->crc = crc32(0L, Z_NULL, 0);
  10.488 +                }
  10.489 +            }
  10.490 +        }
  10.491 +        if (s->z_err != Z_OK || s->z_eof) break;
  10.492 +    }
  10.493 +    s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
  10.494 +
  10.495 +    if (len == s->stream.avail_out &&
  10.496 +        (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
  10.497 +        return -1;
  10.498 +    return (int)(len - s->stream.avail_out);
  10.499 +}
  10.500 +
  10.501 +
  10.502 +/* ===========================================================================
  10.503 +      Reads one byte from the compressed file. gzgetc returns this byte
  10.504 +   or -1 in case of end of file or error.
  10.505 +*/
  10.506 +int ZEXPORT gzgetc(file)
  10.507 +    gzFile file;
  10.508 +{
  10.509 +    unsigned char c;
  10.510 +
  10.511 +    return gzread(file, &c, 1) == 1 ? c : -1;
  10.512 +}
  10.513 +
  10.514 +
  10.515 +/* ===========================================================================
  10.516 +      Push one byte back onto the stream.
  10.517 +*/
  10.518 +int ZEXPORT gzungetc(c, file)
  10.519 +    int c;
  10.520 +    gzFile file;
  10.521 +{
  10.522 +    gz_stream *s = (gz_stream*)file;
  10.523 +
  10.524 +    if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
  10.525 +    s->back = c;
  10.526 +    s->out--;
  10.527 +    s->last = (s->z_err == Z_STREAM_END);
  10.528 +    if (s->last) s->z_err = Z_OK;
  10.529 +    s->z_eof = 0;
  10.530 +    return c;
  10.531 +}
  10.532 +
  10.533 +
  10.534 +/* ===========================================================================
  10.535 +      Reads bytes from the compressed file until len-1 characters are
  10.536 +   read, or a newline character is read and transferred to buf, or an
  10.537 +   end-of-file condition is encountered.  The string is then terminated
  10.538 +   with a null character.
  10.539 +      gzgets returns buf, or Z_NULL in case of error.
  10.540 +
  10.541 +      The current implementation is not optimized at all.
  10.542 +*/
  10.543 +char * ZEXPORT gzgets(file, buf, len)
  10.544 +    gzFile file;
  10.545 +    char *buf;
  10.546 +    int len;
  10.547 +{
  10.548 +    char *b = buf;
  10.549 +    if (buf == Z_NULL || len <= 0) return Z_NULL;
  10.550 +
  10.551 +    while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
  10.552 +    *buf = '\0';
  10.553 +    return b == buf && len > 0 ? Z_NULL : b;
  10.554 +}
  10.555 +
  10.556 +
  10.557 +#ifndef NO_GZCOMPRESS
  10.558 +/* ===========================================================================
  10.559 +     Writes the given number of uncompressed bytes into the compressed file.
  10.560 +   gzwrite returns the number of bytes actually written (0 in case of error).
  10.561 +*/
  10.562 +int ZEXPORT gzwrite (file, buf, len)
  10.563 +    gzFile file;
  10.564 +    voidpc buf;
  10.565 +    unsigned len;
  10.566 +{
  10.567 +    gz_stream *s = (gz_stream*)file;
  10.568 +
  10.569 +    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
  10.570 +
  10.571 +    s->stream.next_in = (Bytef*)buf;
  10.572 +    s->stream.avail_in = len;
  10.573 +
  10.574 +    while (s->stream.avail_in != 0) {
  10.575 +
  10.576 +        if (s->stream.avail_out == 0) {
  10.577 +
  10.578 +            s->stream.next_out = s->outbuf;
  10.579 +            if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
  10.580 +                s->z_err = Z_ERRNO;
  10.581 +                break;
  10.582 +            }
  10.583 +            s->stream.avail_out = Z_BUFSIZE;
  10.584 +        }
  10.585 +        s->in += s->stream.avail_in;
  10.586 +        s->out += s->stream.avail_out;
  10.587 +        s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
  10.588 +        s->in -= s->stream.avail_in;
  10.589 +        s->out -= s->stream.avail_out;
  10.590 +        if (s->z_err != Z_OK) break;
  10.591 +    }
  10.592 +    s->crc = crc32(s->crc, (const Bytef *)buf, len);
  10.593 +
  10.594 +    return (int)(len - s->stream.avail_in);
  10.595 +}
  10.596 +
  10.597 +
  10.598 +/* ===========================================================================
  10.599 +     Converts, formats, and writes the args to the compressed file under
  10.600 +   control of the format string, as in fprintf. gzprintf returns the number of
  10.601 +   uncompressed bytes actually written (0 in case of error).
  10.602 +*/
  10.603 +#ifdef STDC
  10.604 +#include <stdarg.h>
  10.605 +
  10.606 +int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
  10.607 +{
  10.608 +    char buf[Z_PRINTF_BUFSIZE];
  10.609 +    va_list va;
  10.610 +    int len;
  10.611 +
  10.612 +    buf[sizeof(buf) - 1] = 0;
  10.613 +    va_start(va, format);
  10.614 +#ifdef NO_vsnprintf
  10.615 +#  ifdef HAS_vsprintf_void
  10.616 +    (void)vsprintf(buf, format, va);
  10.617 +    va_end(va);
  10.618 +    for (len = 0; len < sizeof(buf); len++)
  10.619 +        if (buf[len] == 0) break;
  10.620 +#  else
  10.621 +    len = vsprintf(buf, format, va);
  10.622 +    va_end(va);
  10.623 +#  endif
  10.624 +#else
  10.625 +#  ifdef HAS_vsnprintf_void
  10.626 +    (void)vsnprintf(buf, sizeof(buf), format, va);
  10.627 +    va_end(va);
  10.628 +    len = strlen(buf);
  10.629 +#  else
  10.630 +    len = vsnprintf(buf, sizeof(buf), format, va);
  10.631 +    va_end(va);
  10.632 +#  endif
  10.633 +#endif
  10.634 +    if (len <= 0 || len >= (int)sizeof(buf) || buf[sizeof(buf) - 1] != 0)
  10.635 +        return 0;
  10.636 +    return gzwrite(file, buf, (unsigned)len);
  10.637 +}
  10.638 +#else /* not ANSI C */
  10.639 +
  10.640 +int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
  10.641 +                       a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
  10.642 +    gzFile file;
  10.643 +    const char *format;
  10.644 +    int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
  10.645 +        a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
  10.646 +{
  10.647 +    char buf[Z_PRINTF_BUFSIZE];
  10.648 +    int len;
  10.649 +
  10.650 +    buf[sizeof(buf) - 1] = 0;
  10.651 +#ifdef NO_snprintf
  10.652 +#  ifdef HAS_sprintf_void
  10.653 +    sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
  10.654 +            a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
  10.655 +    for (len = 0; len < sizeof(buf); len++)
  10.656 +        if (buf[len] == 0) break;
  10.657 +#  else
  10.658 +    len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
  10.659 +                a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
  10.660 +#  endif
  10.661 +#else
  10.662 +#  ifdef HAS_snprintf_void
  10.663 +    snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
  10.664 +             a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
  10.665 +    len = strlen(buf);
  10.666 +#  else
  10.667 +    len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
  10.668 +                 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
  10.669 +#  endif
  10.670 +#endif
  10.671 +    if (len <= 0 || len >= sizeof(buf) || buf[sizeof(buf) - 1] != 0)
  10.672 +        return 0;
  10.673 +    return gzwrite(file, buf, len);
  10.674 +}
  10.675 +#endif
  10.676 +
  10.677 +/* ===========================================================================
  10.678 +      Writes c, converted to an unsigned char, into the compressed file.
  10.679 +   gzputc returns the value that was written, or -1 in case of error.
  10.680 +*/
  10.681 +int ZEXPORT gzputc(file, c)
  10.682 +    gzFile file;
  10.683 +    int c;
  10.684 +{
  10.685 +    unsigned char cc = (unsigned char) c; /* required for big endian systems */
  10.686 +
  10.687 +    return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
  10.688 +}
  10.689 +
  10.690 +
  10.691 +/* ===========================================================================
  10.692 +      Writes the given null-terminated string to the compressed file, excluding
  10.693 +   the terminating null character.
  10.694 +      gzputs returns the number of characters written, or -1 in case of error.
  10.695 +*/
  10.696 +int ZEXPORT gzputs(file, s)
  10.697 +    gzFile file;
  10.698 +    const char *s;
  10.699 +{
  10.700 +    return gzwrite(file, (char*)s, (unsigned)strlen(s));
  10.701 +}
  10.702 +
  10.703 +
  10.704 +/* ===========================================================================
  10.705 +     Flushes all pending output into the compressed file. The parameter
  10.706 +   flush is as in the deflate() function.
  10.707 +*/
  10.708 +local int do_flush (file, flush)
  10.709 +    gzFile file;
  10.710 +    int flush;
  10.711 +{
  10.712 +    uInt len;
  10.713 +    int done = 0;
  10.714 +    gz_stream *s = (gz_stream*)file;
  10.715 +
  10.716 +    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
  10.717 +
  10.718 +    s->stream.avail_in = 0; /* should be zero already anyway */
  10.719 +
  10.720 +    for (;;) {
  10.721 +        len = Z_BUFSIZE - s->stream.avail_out;
  10.722 +
  10.723 +        if (len != 0) {
  10.724 +            if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
  10.725 +                s->z_err = Z_ERRNO;
  10.726 +                return Z_ERRNO;
  10.727 +            }
  10.728 +            s->stream.next_out = s->outbuf;
  10.729 +            s->stream.avail_out = Z_BUFSIZE;
  10.730 +        }
  10.731 +        if (done) break;
  10.732 +        s->out += s->stream.avail_out;
  10.733 +        s->z_err = deflate(&(s->stream), flush);
  10.734 +        s->out -= s->stream.avail_out;
  10.735 +
  10.736 +        /* Ignore the second of two consecutive flushes: */
  10.737 +        if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
  10.738 +
  10.739 +        /* deflate has finished flushing only when it hasn't used up
  10.740 +         * all the available space in the output buffer:
  10.741 +         */
  10.742 +        done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
  10.743 +
  10.744 +        if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
  10.745 +    }
  10.746 +    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
  10.747 +}
  10.748 +
  10.749 +int ZEXPORT gzflush (file, flush)
  10.750 +     gzFile file;
  10.751 +     int flush;
  10.752 +{
  10.753 +    gz_stream *s = (gz_stream*)file;
  10.754 +    int err = do_flush (file, flush);
  10.755 +
  10.756 +    if (err) return err;
  10.757 +    fflush(s->file);
  10.758 +    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
  10.759 +}
  10.760 +#endif /* NO_GZCOMPRESS */
  10.761 +
  10.762 +/* ===========================================================================
  10.763 +      Sets the starting position for the next gzread or gzwrite on the given
  10.764 +   compressed file. The offset represents a number of bytes in the
  10.765 +      gzseek returns the resulting offset location as measured in bytes from
  10.766 +   the beginning of the uncompressed stream, or -1 in case of error.
  10.767 +      SEEK_END is not implemented, returns error.
  10.768 +      In this version of the library, gzseek can be extremely slow.
  10.769 +*/
  10.770 +z_off_t ZEXPORT gzseek (file, offset, whence)
  10.771 +    gzFile file;
  10.772 +    z_off_t offset;
  10.773 +    int whence;
  10.774 +{
  10.775 +    gz_stream *s = (gz_stream*)file;
  10.776 +
  10.777 +    if (s == NULL || whence == SEEK_END ||
  10.778 +        s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
  10.779 +        return -1L;
  10.780 +    }
  10.781 +
  10.782 +    if (s->mode == 'w') {
  10.783 +#ifdef NO_GZCOMPRESS
  10.784 +        return -1L;
  10.785 +#else
  10.786 +        if (whence == SEEK_SET) {
  10.787 +            offset -= s->in;
  10.788 +        }
  10.789 +        if (offset < 0) return -1L;
  10.790 +
  10.791 +        /* At this point, offset is the number of zero bytes to write. */
  10.792 +        if (s->inbuf == Z_NULL) {
  10.793 +            s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
  10.794 +            if (s->inbuf == Z_NULL) return -1L;
  10.795 +            zmemzero(s->inbuf, Z_BUFSIZE);
  10.796 +        }
  10.797 +        while (offset > 0)  {
  10.798 +            uInt size = Z_BUFSIZE;
  10.799 +            if (offset < Z_BUFSIZE) size = (uInt)offset;
  10.800 +
  10.801 +            size = gzwrite(file, s->inbuf, size);
  10.802 +            if (size == 0) return -1L;
  10.803 +
  10.804 +            offset -= size;
  10.805 +        }
  10.806 +        return s->in;
  10.807 +#endif
  10.808 +    }
  10.809 +    /* Rest of function is for reading only */
  10.810 +
  10.811 +    /* compute absolute position */
  10.812 +    if (whence == SEEK_CUR) {
  10.813 +        offset += s->out;
  10.814 +    }
  10.815 +    if (offset < 0) return -1L;
  10.816 +
  10.817 +    if (s->transparent) {
  10.818 +        /* map to fseek */
  10.819 +        s->back = EOF;
  10.820 +        s->stream.avail_in = 0;
  10.821 +        s->stream.next_in = s->inbuf;
  10.822 +        if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
  10.823 +
  10.824 +        s->in = s->out = offset;
  10.825 +        return offset;
  10.826 +    }
  10.827 +
  10.828 +    /* For a negative seek, rewind and use positive seek */
  10.829 +    if (offset >= s->out) {
  10.830 +        offset -= s->out;
  10.831 +    } else if (gzrewind(file) < 0) {
  10.832 +        return -1L;
  10.833 +    }
  10.834 +    /* offset is now the number of bytes to skip. */
  10.835 +
  10.836 +    if (offset != 0 && s->outbuf == Z_NULL) {
  10.837 +        s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
  10.838 +        if (s->outbuf == Z_NULL) return -1L;
  10.839 +    }
  10.840 +    if (offset && s->back != EOF) {
  10.841 +        s->back = EOF;
  10.842 +        s->out++;
  10.843 +        offset--;
  10.844 +        if (s->last) s->z_err = Z_STREAM_END;
  10.845 +    }
  10.846 +    while (offset > 0)  {
  10.847 +        int size = Z_BUFSIZE;
  10.848 +        if (offset < Z_BUFSIZE) size = (int)offset;
  10.849 +
  10.850 +        size = gzread(file, s->outbuf, (uInt)size);
  10.851 +        if (size <= 0) return -1L;
  10.852 +        offset -= size;
  10.853 +    }
  10.854 +    return s->out;
  10.855 +}
  10.856 +
  10.857 +/* ===========================================================================
  10.858 +     Rewinds input file.
  10.859 +*/
  10.860 +int ZEXPORT gzrewind (file)
  10.861 +    gzFile file;
  10.862 +{
  10.863 +    gz_stream *s = (gz_stream*)file;
  10.864 +
  10.865 +    if (s == NULL || s->mode != 'r') return -1;
  10.866 +
  10.867 +    s->z_err = Z_OK;
  10.868 +    s->z_eof = 0;
  10.869 +    s->back = EOF;
  10.870 +    s->stream.avail_in = 0;
  10.871 +    s->stream.next_in = s->inbuf;
  10.872 +    s->crc = crc32(0L, Z_NULL, 0);
  10.873 +    if (!s->transparent) (void)inflateReset(&s->stream);
  10.874 +    s->in = 0;
  10.875 +    s->out = 0;
  10.876 +    return fseek(s->file, s->start, SEEK_SET);
  10.877 +}
  10.878 +
  10.879 +/* ===========================================================================
  10.880 +     Returns the starting position for the next gzread or gzwrite on the
  10.881 +   given compressed file. This position represents a number of bytes in the
  10.882 +   uncompressed data stream.
  10.883 +*/
  10.884 +z_off_t ZEXPORT gztell (file)
  10.885 +    gzFile file;
  10.886 +{
  10.887 +    return gzseek(file, 0L, SEEK_CUR);
  10.888 +}
  10.889 +
  10.890 +/* ===========================================================================
  10.891 +     Returns 1 when EOF has previously been detected reading the given
  10.892 +   input stream, otherwise zero.
  10.893 +*/
  10.894 +int ZEXPORT gzeof (file)
  10.895 +    gzFile file;
  10.896 +{
  10.897 +    gz_stream *s = (gz_stream*)file;
  10.898 +
  10.899 +    /* With concatenated compressed files that can have embedded
  10.900 +     * crc trailers, z_eof is no longer the only/best indicator of EOF
  10.901 +     * on a gz_stream. Handle end-of-stream error explicitly here.
  10.902 +     */
  10.903 +    if (s == NULL || s->mode != 'r') return 0;
  10.904 +    if (s->z_eof) return 1;
  10.905 +    return s->z_err == Z_STREAM_END;
  10.906 +}
  10.907 +
  10.908 +/* ===========================================================================
  10.909 +     Returns 1 if reading and doing so transparently, otherwise zero.
  10.910 +*/
  10.911 +int ZEXPORT gzdirect (file)
  10.912 +    gzFile file;
  10.913 +{
  10.914 +    gz_stream *s = (gz_stream*)file;
  10.915 +
  10.916 +    if (s == NULL || s->mode != 'r') return 0;
  10.917 +    return s->transparent;
  10.918 +}
  10.919 +
  10.920 +/* ===========================================================================
  10.921 +   Outputs a long in LSB order to the given file
  10.922 +*/
  10.923 +local void putLong (file, x)
  10.924 +    FILE *file;
  10.925 +    uLong x;
  10.926 +{
  10.927 +    int n;
  10.928 +    for (n = 0; n < 4; n++) {
  10.929 +        fputc((int)(x & 0xff), file);
  10.930 +        x >>= 8;
  10.931 +    }
  10.932 +}
  10.933 +
  10.934 +/* ===========================================================================
  10.935 +   Reads a long in LSB order from the given gz_stream. Sets z_err in case
  10.936 +   of error.
  10.937 +*/
  10.938 +local uLong getLong (s)
  10.939 +    gz_stream *s;
  10.940 +{
  10.941 +    uLong x = (uLong)get_byte(s);
  10.942 +    int c;
  10.943 +
  10.944 +    x += ((uLong)get_byte(s))<<8;
  10.945 +    x += ((uLong)get_byte(s))<<16;
  10.946 +    c = get_byte(s);
  10.947 +    if (c == EOF) s->z_err = Z_DATA_ERROR;
  10.948 +    x += ((uLong)c)<<24;
  10.949 +    return x;
  10.950 +}
  10.951 +
  10.952 +/* ===========================================================================
  10.953 +     Flushes all pending output if necessary, closes the compressed file
  10.954 +   and deallocates all the (de)compression state.
  10.955 +*/
  10.956 +int ZEXPORT gzclose (file)
  10.957 +    gzFile file;
  10.958 +{
  10.959 +    gz_stream *s = (gz_stream*)file;
  10.960 +
  10.961 +    if (s == NULL) return Z_STREAM_ERROR;
  10.962 +
  10.963 +    if (s->mode == 'w') {
  10.964 +#ifdef NO_GZCOMPRESS
  10.965 +        return Z_STREAM_ERROR;
  10.966 +#else
  10.967 +        if (do_flush (file, Z_FINISH) != Z_OK)
  10.968 +            return destroy((gz_stream*)file);
  10.969 +
  10.970 +        putLong (s->file, s->crc);
  10.971 +        putLong (s->file, (uLong)(s->in & 0xffffffff));
  10.972 +#endif
  10.973 +    }
  10.974 +    return destroy((gz_stream*)file);
  10.975 +}
  10.976 +
  10.977 +#ifdef STDC
  10.978 +#  define zstrerror(errnum) strerror(errnum)
  10.979 +#else
  10.980 +#  define zstrerror(errnum) ""
  10.981 +#endif
  10.982 +
  10.983 +/* ===========================================================================
  10.984 +     Returns the error message for the last error which occurred on the
  10.985 +   given compressed file. errnum is set to zlib error number. If an
  10.986 +   error occurred in the file system and not in the compression library,
  10.987 +   errnum is set to Z_ERRNO and the application may consult errno
  10.988 +   to get the exact error code.
  10.989 +*/
  10.990 +const char * ZEXPORT gzerror (file, errnum)
  10.991 +    gzFile file;
  10.992 +    int *errnum;
  10.993 +{
  10.994 +    char *m;
  10.995 +    gz_stream *s = (gz_stream*)file;
  10.996 +
  10.997 +    if (s == NULL) {
  10.998 +        *errnum = Z_STREAM_ERROR;
  10.999 +        return (const char*)ERR_MSG(Z_STREAM_ERROR);
 10.1000 +    }
 10.1001 +    *errnum = s->z_err;
 10.1002 +    if (*errnum == Z_OK) return (const char*)"";
 10.1003 +
 10.1004 +    m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
 10.1005 +
 10.1006 +    if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
 10.1007 +
 10.1008 +    TRYFREE(s->msg);
 10.1009 +    s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
 10.1010 +    if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
 10.1011 +    strcpy(s->msg, s->path);
 10.1012 +    strcat(s->msg, ": ");
 10.1013 +    strcat(s->msg, m);
 10.1014 +    return (const char*)s->msg;
 10.1015 +}
 10.1016 +
 10.1017 +/* ===========================================================================
 10.1018 +     Clear the error and end-of-file flags, and do the same for the real file.
 10.1019 +*/
 10.1020 +void ZEXPORT gzclearerr (file)
 10.1021 +    gzFile file;
 10.1022 +{
 10.1023 +    gz_stream *s = (gz_stream*)file;
 10.1024 +
 10.1025 +    if (s == NULL) return;
 10.1026 +    if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
 10.1027 +    s->z_eof = 0;
 10.1028 +    clearerr(s->file);
 10.1029 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/compiler-init/zlib/infback.c	Sat Jul 15 04:51:28 2006 +0000
    11.3 @@ -0,0 +1,623 @@
    11.4 +/* infback.c -- inflate using a call-back interface
    11.5 + * Copyright (C) 1995-2005 Mark Adler
    11.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    11.7 + */
    11.8 +
    11.9 +/*
   11.10 +   This code is largely copied from inflate.c.  Normally either infback.o or
   11.11 +   inflate.o would be linked into an application--not both.  The interface
   11.12 +   with inffast.c is retained so that optimized assembler-coded versions of
   11.13 +   inflate_fast() can be used with either inflate.c or infback.c.
   11.14 + */
   11.15 +
   11.16 +#include "zutil.h"
   11.17 +#include "inftrees.h"
   11.18 +#include "inflate.h"
   11.19 +#include "inffast.h"
   11.20 +
   11.21 +/* function prototypes */
   11.22 +local void fixedtables OF((struct inflate_state FAR *state));
   11.23 +
   11.24 +/*
   11.25 +   strm provides memory allocation functions in zalloc and zfree, or
   11.26 +   Z_NULL to use the library memory allocation functions.
   11.27 +
   11.28 +   windowBits is in the range 8..15, and window is a user-supplied
   11.29 +   window and output buffer that is 2**windowBits bytes.
   11.30 + */
   11.31 +int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
   11.32 +z_streamp strm;
   11.33 +int windowBits;
   11.34 +unsigned char FAR *window;
   11.35 +const char *version;
   11.36 +int stream_size;
   11.37 +{
   11.38 +    struct inflate_state FAR *state;
   11.39 +
   11.40 +    if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
   11.41 +        stream_size != (int)(sizeof(z_stream)))
   11.42 +        return Z_VERSION_ERROR;
   11.43 +    if (strm == Z_NULL || window == Z_NULL ||
   11.44 +        windowBits < 8 || windowBits > 15)
   11.45 +        return Z_STREAM_ERROR;
   11.46 +    strm->msg = Z_NULL;                 /* in case we return an error */
   11.47 +    if (strm->zalloc == (alloc_func)0) {
   11.48 +        strm->zalloc = zcalloc;
   11.49 +        strm->opaque = (voidpf)0;
   11.50 +    }
   11.51 +    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
   11.52 +    state = (struct inflate_state FAR *)ZALLOC(strm, 1,
   11.53 +                                               sizeof(struct inflate_state));
   11.54 +    if (state == Z_NULL) return Z_MEM_ERROR;
   11.55 +    Tracev((stderr, "inflate: allocated\n"));
   11.56 +    strm->state = (struct internal_state FAR *)state;
   11.57 +    state->dmax = 32768U;
   11.58 +    state->wbits = windowBits;
   11.59 +    state->wsize = 1U << windowBits;
   11.60 +    state->window = window;
   11.61 +    state->write = 0;
   11.62 +    state->whave = 0;
   11.63 +    return Z_OK;
   11.64 +}
   11.65 +
   11.66 +/*
   11.67 +   Return state with length and distance decoding tables and index sizes set to
   11.68 +   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
   11.69 +   If BUILDFIXED is defined, then instead this routine builds the tables the
   11.70 +   first time it's called, and returns those tables the first time and
   11.71 +   thereafter.  This reduces the size of the code by about 2K bytes, in
   11.72 +   exchange for a little execution time.  However, BUILDFIXED should not be
   11.73 +   used for threaded applications, since the rewriting of the tables and virgin
   11.74 +   may not be thread-safe.
   11.75 + */
   11.76 +local void fixedtables(state)
   11.77 +struct inflate_state FAR *state;
   11.78 +{
   11.79 +#ifdef BUILDFIXED
   11.80 +    static int virgin = 1;
   11.81 +    static code *lenfix, *distfix;
   11.82 +    static code fixed[544];
   11.83 +
   11.84 +    /* build fixed huffman tables if first call (may not be thread safe) */
   11.85 +    if (virgin) {
   11.86 +        unsigned sym, bits;
   11.87 +        static code *next;
   11.88 +
   11.89 +        /* literal/length table */
   11.90 +        sym = 0;
   11.91 +        while (sym < 144) state->lens[sym++] = 8;
   11.92 +        while (sym < 256) state->lens[sym++] = 9;
   11.93 +        while (sym < 280) state->lens[sym++] = 7;
   11.94 +        while (sym < 288) state->lens[sym++] = 8;
   11.95 +        next = fixed;
   11.96 +        lenfix = next;
   11.97 +        bits = 9;
   11.98 +        inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
   11.99 +
  11.100 +        /* distance table */
  11.101 +        sym = 0;
  11.102 +        while (sym < 32) state->lens[sym++] = 5;
  11.103 +        distfix = next;
  11.104 +        bits = 5;
  11.105 +        inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  11.106 +
  11.107 +        /* do this just once */
  11.108 +        virgin = 0;
  11.109 +    }
  11.110 +#else /* !BUILDFIXED */
  11.111 +#   include "inffixed.h"
  11.112 +#endif /* BUILDFIXED */
  11.113 +    state->lencode = lenfix;
  11.114 +    state->lenbits = 9;
  11.115 +    state->distcode = distfix;
  11.116 +    state->distbits = 5;
  11.117 +}
  11.118 +
  11.119 +/* Macros for inflateBack(): */
  11.120 +
  11.121 +/* Load returned state from inflate_fast() */
  11.122 +#define LOAD() \
  11.123 +    do { \
  11.124 +        put = strm->next_out; \
  11.125 +        left = strm->avail_out; \
  11.126 +        next = strm->next_in; \
  11.127 +        have = strm->avail_in; \
  11.128 +        hold = state->hold; \
  11.129 +        bits = state->bits; \
  11.130 +    } while (0)
  11.131 +
  11.132 +/* Set state from registers for inflate_fast() */
  11.133 +#define RESTORE() \
  11.134 +    do { \
  11.135 +        strm->next_out = put; \
  11.136 +        strm->avail_out = left; \
  11.137 +        strm->next_in = next; \
  11.138 +        strm->avail_in = have; \
  11.139 +        state->hold = hold; \
  11.140 +        state->bits = bits; \
  11.141 +    } while (0)
  11.142 +
  11.143 +/* Clear the input bit accumulator */
  11.144 +#define INITBITS() \
  11.145 +    do { \
  11.146 +        hold = 0; \
  11.147 +        bits = 0; \
  11.148 +    } while (0)
  11.149 +
  11.150 +/* Assure that some input is available.  If input is requested, but denied,
  11.151 +   then return a Z_BUF_ERROR from inflateBack(). */
  11.152 +#define PULL() \
  11.153 +    do { \
  11.154 +        if (have == 0) { \
  11.155 +            have = in(in_desc, &next); \
  11.156 +            if (have == 0) { \
  11.157 +                next = Z_NULL; \
  11.158 +                ret = Z_BUF_ERROR; \
  11.159 +                goto inf_leave; \
  11.160 +            } \
  11.161 +        } \
  11.162 +    } while (0)
  11.163 +
  11.164 +/* Get a byte of input into the bit accumulator, or return from inflateBack()
  11.165 +   with an error if there is no input available. */
  11.166 +#define PULLBYTE() \
  11.167 +    do { \
  11.168 +        PULL(); \
  11.169 +        have--; \
  11.170 +        hold += (unsigned long)(*next++) << bits; \
  11.171 +        bits += 8; \
  11.172 +    } while (0)
  11.173 +
  11.174 +/* Assure that there are at least n bits in the bit accumulator.  If there is
  11.175 +   not enough available input to do that, then return from inflateBack() with
  11.176 +   an error. */
  11.177 +#define NEEDBITS(n) \
  11.178 +    do { \
  11.179 +        while (bits < (unsigned)(n)) \
  11.180 +            PULLBYTE(); \
  11.181 +    } while (0)
  11.182 +
  11.183 +/* Return the low n bits of the bit accumulator (n < 16) */
  11.184 +#define BITS(n) \
  11.185 +    ((unsigned)hold & ((1U << (n)) - 1))
  11.186 +
  11.187 +/* Remove n bits from the bit accumulator */
  11.188 +#define DROPBITS(n) \
  11.189 +    do { \
  11.190 +        hold >>= (n); \
  11.191 +        bits -= (unsigned)(n); \
  11.192 +    } while (0)
  11.193 +
  11.194 +/* Remove zero to seven bits as needed to go to a byte boundary */
  11.195 +#define BYTEBITS() \
  11.196 +    do { \
  11.197 +        hold >>= bits & 7; \
  11.198 +        bits -= bits & 7; \
  11.199 +    } while (0)
  11.200 +
  11.201 +/* Assure that some output space is available, by writing out the window
  11.202 +   if it's full.  If the write fails, return from inflateBack() with a
  11.203 +   Z_BUF_ERROR. */
  11.204 +#define ROOM() \
  11.205 +    do { \
  11.206 +        if (left == 0) { \
  11.207 +            put = state->window; \
  11.208 +            left = state->wsize; \
  11.209 +            state->whave = left; \
  11.210 +            if (out(out_desc, put, left)) { \
  11.211 +                ret = Z_BUF_ERROR; \
  11.212 +                goto inf_leave; \
  11.213 +            } \
  11.214 +        } \
  11.215 +    } while (0)
  11.216 +
  11.217 +/*
  11.218 +   strm provides the memory allocation functions and window buffer on input,
  11.219 +   and provides information on the unused input on return.  For Z_DATA_ERROR
  11.220 +   returns, strm will also provide an error message.
  11.221 +
  11.222 +   in() and out() are the call-back input and output functions.  When
  11.223 +   inflateBack() needs more input, it calls in().  When inflateBack() has
  11.224 +   filled the window with output, or when it completes with data in the
  11.225 +   window, it calls out() to write out the data.  The application must not
  11.226 +   change the provided input until in() is called again or inflateBack()
  11.227 +   returns.  The application must not change the window/output buffer until
  11.228 +   inflateBack() returns.
  11.229 +
  11.230 +   in() and out() are called with a descriptor parameter provided in the
  11.231 +   inflateBack() call.  This parameter can be a structure that provides the
  11.232 +   information required to do the read or write, as well as accumulated
  11.233 +   information on the input and output such as totals and check values.
  11.234 +
  11.235 +   in() should return zero on failure.  out() should return non-zero on
  11.236 +   failure.  If either in() or out() fails, than inflateBack() returns a
  11.237 +   Z_BUF_ERROR.  strm->next_in can be checked for Z_NULL to see whether it
  11.238 +   was in() or out() that caused in the error.  Otherwise,  inflateBack()
  11.239 +   returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
  11.240 +   error, or Z_MEM_ERROR if it could not allocate memory for the state.
  11.241 +   inflateBack() can also return Z_STREAM_ERROR if the input parameters
  11.242 +   are not correct, i.e. strm is Z_NULL or the state was not initialized.
  11.243 + */
  11.244 +int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
  11.245 +z_streamp strm;
  11.246 +in_func in;
  11.247 +void FAR *in_desc;
  11.248 +out_func out;
  11.249 +void FAR *out_desc;
  11.250 +{
  11.251 +    struct inflate_state FAR *state;
  11.252 +    unsigned char FAR *next;    /* next input */
  11.253 +    unsigned char FAR *put;     /* next output */
  11.254 +    unsigned have, left;        /* available input and output */
  11.255 +    unsigned long hold;         /* bit buffer */
  11.256 +    unsigned bits;              /* bits in bit buffer */
  11.257 +    unsigned copy;              /* number of stored or match bytes to copy */
  11.258 +    unsigned char FAR *from;    /* where to copy match bytes from */
  11.259 +    code this;                  /* current decoding table entry */
  11.260 +    code last;                  /* parent table entry */
  11.261 +    unsigned len;               /* length to copy for repeats, bits to drop */
  11.262 +    int ret;                    /* return code */
  11.263 +    static const unsigned short order[19] = /* permutation of code lengths */
  11.264 +        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  11.265 +
  11.266 +    /* Check that the strm exists and that the state was initialized */
  11.267 +    if (strm == Z_NULL || strm->state == Z_NULL)
  11.268 +        return Z_STREAM_ERROR;
  11.269 +    state = (struct inflate_state FAR *)strm->state;
  11.270 +
  11.271 +    /* Reset the state */
  11.272 +    strm->msg = Z_NULL;
  11.273 +    state->mode = TYPE;
  11.274 +    state->last = 0;
  11.275 +    state->whave = 0;
  11.276 +    next = strm->next_in;
  11.277 +    have = next != Z_NULL ? strm->avail_in : 0;
  11.278 +    hold = 0;
  11.279 +    bits = 0;
  11.280 +    put = state->window;
  11.281 +    left = state->wsize;
  11.282 +
  11.283 +    /* Inflate until end of block marked as last */
  11.284 +    for (;;)
  11.285 +        switch (state->mode) {
  11.286 +        case TYPE:
  11.287 +            /* determine and dispatch block type */
  11.288 +            if (state->last) {
  11.289 +                BYTEBITS();
  11.290 +                state->mode = DONE;
  11.291 +                break;
  11.292 +            }
  11.293 +            NEEDBITS(3);
  11.294 +            state->last = BITS(1);
  11.295 +            DROPBITS(1);
  11.296 +            switch (BITS(2)) {
  11.297 +            case 0:                             /* stored block */
  11.298 +                Tracev((stderr, "inflate:     stored block%s\n",
  11.299 +                        state->last ? " (last)" : ""));
  11.300 +                state->mode = STORED;
  11.301 +                break;
  11.302 +            case 1:                             /* fixed block */
  11.303 +                fixedtables(state);
  11.304 +                Tracev((stderr, "inflate:     fixed codes block%s\n",
  11.305 +                        state->last ? " (last)" : ""));
  11.306 +                state->mode = LEN;              /* decode codes */
  11.307 +                break;
  11.308 +            case 2:                             /* dynamic block */
  11.309 +                Tracev((stderr, "inflate:     dynamic codes block%s\n",
  11.310 +                        state->last ? " (last)" : ""));
  11.311 +                state->mode = TABLE;
  11.312 +                break;
  11.313 +            case 3:
  11.314 +                strm->msg = (char *)"invalid block type";
  11.315 +                state->mode = BAD;
  11.316 +            }
  11.317 +            DROPBITS(2);
  11.318 +            break;
  11.319 +
  11.320 +        case STORED:
  11.321 +            /* get and verify stored block length */
  11.322 +            BYTEBITS();                         /* go to byte boundary */
  11.323 +            NEEDBITS(32);
  11.324 +            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  11.325 +                strm->msg = (char *)"invalid stored block lengths";
  11.326 +                state->mode = BAD;
  11.327 +                break;
  11.328 +            }
  11.329 +            state->length = (unsigned)hold & 0xffff;
  11.330 +            Tracev((stderr, "inflate:       stored length %u\n",
  11.331 +                    state->length));
  11.332 +            INITBITS();
  11.333 +
  11.334 +            /* copy stored block from input to output */
  11.335 +            while (state->length != 0) {
  11.336 +                copy = state->length;
  11.337 +                PULL();
  11.338 +                ROOM();
  11.339 +                if (copy > have) copy = have;
  11.340 +                if (copy > left) copy = left;
  11.341 +                zmemcpy(put, next, copy);
  11.342 +                have -= copy;
  11.343 +                next += copy;
  11.344 +                left -= copy;
  11.345 +                put += copy;
  11.346 +                state->length -= copy;
  11.347 +            }
  11.348 +            Tracev((stderr, "inflate:       stored end\n"));
  11.349 +            state->mode = TYPE;
  11.350 +            break;
  11.351 +
  11.352 +        case TABLE:
  11.353 +            /* get dynamic table entries descriptor */
  11.354 +            NEEDBITS(14);
  11.355 +            state->nlen = BITS(5) + 257;
  11.356 +            DROPBITS(5);
  11.357 +            state->ndist = BITS(5) + 1;
  11.358 +            DROPBITS(5);
  11.359 +            state->ncode = BITS(4) + 4;
  11.360 +            DROPBITS(4);
  11.361 +#ifndef PKZIP_BUG_WORKAROUND
  11.362 +            if (state->nlen > 286 || state->ndist > 30) {
  11.363 +                strm->msg = (char *)"too many length or distance symbols";
  11.364 +                state->mode = BAD;
  11.365 +                break;
  11.366 +            }
  11.367 +#endif
  11.368 +            Tracev((stderr, "inflate:       table sizes ok\n"));
  11.369 +
  11.370 +            /* get code length code lengths (not a typo) */
  11.371 +            state->have = 0;
  11.372 +            while (state->have < state->ncode) {
  11.373 +                NEEDBITS(3);
  11.374 +                state->lens[order[state->have++]] = (unsigned short)BITS(3);
  11.375 +                DROPBITS(3);
  11.376 +            }
  11.377 +            while (state->have < 19)
  11.378 +                state->lens[order[state->have++]] = 0;
  11.379 +            state->next = state->codes;
  11.380 +            state->lencode = (code const FAR *)(state->next);
  11.381 +            state->lenbits = 7;
  11.382 +            ret = inflate_table(CODES, state->lens, 19, &(state->next),
  11.383 +                                &(state->lenbits), state->work);
  11.384 +            if (ret) {
  11.385 +                strm->msg = (char *)"invalid code lengths set";
  11.386 +                state->mode = BAD;
  11.387 +                break;
  11.388 +            }
  11.389 +            Tracev((stderr, "inflate:       code lengths ok\n"));
  11.390 +
  11.391 +            /* get length and distance code code lengths */
  11.392 +            state->have = 0;
  11.393 +            while (state->have < state->nlen + state->ndist) {
  11.394 +                for (;;) {
  11.395 +                    this = state->lencode[BITS(state->lenbits)];
  11.396 +                    if ((unsigned)(this.bits) <= bits) break;
  11.397 +                    PULLBYTE();
  11.398 +                }
  11.399 +                if (this.val < 16) {
  11.400 +                    NEEDBITS(this.bits);
  11.401 +                    DROPBITS(this.bits);
  11.402 +                    state->lens[state->have++] = this.val;
  11.403 +                }
  11.404 +                else {
  11.405 +                    if (this.val == 16) {
  11.406 +                        NEEDBITS(this.bits + 2);
  11.407 +                        DROPBITS(this.bits);
  11.408 +                        if (state->have == 0) {
  11.409 +                            strm->msg = (char *)"invalid bit length repeat";
  11.410 +                            state->mode = BAD;
  11.411 +                            break;
  11.412 +                        }
  11.413 +                        len = (unsigned)(state->lens[state->have - 1]);
  11.414 +                        copy = 3 + BITS(2);
  11.415 +                        DROPBITS(2);
  11.416 +                    }
  11.417 +                    else if (this.val == 17) {
  11.418 +                        NEEDBITS(this.bits + 3);
  11.419 +                        DROPBITS(this.bits);
  11.420 +                        len = 0;
  11.421 +                        copy = 3 + BITS(3);
  11.422 +                        DROPBITS(3);
  11.423 +                    }
  11.424 +                    else {
  11.425 +                        NEEDBITS(this.bits + 7);
  11.426 +                        DROPBITS(this.bits);
  11.427 +                        len = 0;
  11.428 +                        copy = 11 + BITS(7);
  11.429 +                        DROPBITS(7);
  11.430 +                    }
  11.431 +                    if (state->have + copy > state->nlen + state->ndist) {
  11.432 +                        strm->msg = (char *)"invalid bit length repeat";
  11.433 +                        state->mode = BAD;
  11.434 +                        break;
  11.435 +                    }
  11.436 +                    while (copy--)
  11.437 +                        state->lens[state->have++] = (unsigned short)len;
  11.438 +                }
  11.439 +            }
  11.440 +
  11.441 +            /* handle error breaks in while */
  11.442 +            if (state->mode == BAD) break;
  11.443 +
  11.444 +            /* build code tables */
  11.445 +            state->next = state->codes;
  11.446 +            state->lencode = (code const FAR *)(state->next);
  11.447 +            state->lenbits = 9;
  11.448 +            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  11.449 +                                &(state->lenbits), state->work);
  11.450 +            if (ret) {
  11.451 +                strm->msg = (char *)"invalid literal/lengths set";
  11.452 +                state->mode = BAD;
  11.453 +                break;
  11.454 +            }
  11.455 +            state->distcode = (code const FAR *)(state->next);
  11.456 +            state->distbits = 6;
  11.457 +            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  11.458 +                            &(state->next), &(state->distbits), state->work);
  11.459 +            if (ret) {
  11.460 +                strm->msg = (char *)"invalid distances set";
  11.461 +                state->mode = BAD;
  11.462 +                break;
  11.463 +            }
  11.464 +            Tracev((stderr, "inflate:       codes ok\n"));
  11.465 +            state->mode = LEN;
  11.466 +
  11.467 +        case LEN:
  11.468 +            /* use inflate_fast() if we have enough input and output */
  11.469 +            if (have >= 6 && left >= 258) {
  11.470 +                RESTORE();
  11.471 +                if (state->whave < state->wsize)
  11.472 +                    state->whave = state->wsize - left;
  11.473 +                inflate_fast(strm, state->wsize);
  11.474 +                LOAD();
  11.475 +                break;
  11.476 +            }
  11.477 +
  11.478 +            /* get a literal, length, or end-of-block code */
  11.479 +            for (;;) {
  11.480 +                this = state->lencode[BITS(state->lenbits)];
  11.481 +                if ((unsigned)(this.bits) <= bits) break;
  11.482 +                PULLBYTE();
  11.483 +            }
  11.484 +            if (this.op && (this.op & 0xf0) == 0) {
  11.485 +                last = this;
  11.486 +                for (;;) {
  11.487 +                    this = state->lencode[last.val +
  11.488 +                            (BITS(last.bits + last.op) >> last.bits)];
  11.489 +                    if ((unsigned)(last.bits + this.bits) <= bits) break;
  11.490 +                    PULLBYTE();
  11.491 +                }
  11.492 +                DROPBITS(last.bits);
  11.493 +            }
  11.494 +            DROPBITS(this.bits);
  11.495 +            state->length = (unsigned)this.val;
  11.496 +
  11.497 +            /* process literal */
  11.498 +            if (this.op == 0) {
  11.499 +                Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
  11.500 +                        "inflate:         literal '%c'\n" :
  11.501 +                        "inflate:         literal 0x%02x\n", this.val));
  11.502 +                ROOM();
  11.503 +                *put++ = (unsigned char)(state->length);
  11.504 +                left--;
  11.505 +                state->mode = LEN;
  11.506 +                break;
  11.507 +            }
  11.508 +
  11.509 +            /* process end of block */
  11.510 +            if (this.op & 32) {
  11.511 +                Tracevv((stderr, "inflate:         end of block\n"));
  11.512 +                state->mode = TYPE;
  11.513 +                break;
  11.514 +            }
  11.515 +
  11.516 +            /* invalid code */
  11.517 +            if (this.op & 64) {
  11.518 +                strm->msg = (char *)"invalid literal/length code";
  11.519 +                state->mode = BAD;
  11.520 +                break;
  11.521 +            }
  11.522 +
  11.523 +            /* length code -- get extra bits, if any */
  11.524 +            state->extra = (unsigned)(this.op) & 15;
  11.525 +            if (state->extra != 0) {
  11.526 +                NEEDBITS(state->extra);
  11.527 +                state->length += BITS(state->extra);
  11.528 +                DROPBITS(state->extra);
  11.529 +            }
  11.530 +            Tracevv((stderr, "inflate:         length %u\n", state->length));
  11.531 +
  11.532 +            /* get distance code */
  11.533 +            for (;;) {
  11.534 +                this = state->distcode[BITS(state->distbits)];
  11.535 +                if ((unsigned)(this.bits) <= bits) break;
  11.536 +                PULLBYTE();
  11.537 +            }
  11.538 +            if ((this.op & 0xf0) == 0) {
  11.539 +                last = this;
  11.540 +                for (;;) {
  11.541 +                    this = state->distcode[last.val +
  11.542 +                            (BITS(last.bits + last.op) >> last.bits)];
  11.543 +                    if ((unsigned)(last.bits + this.bits) <= bits) break;
  11.544 +                    PULLBYTE();
  11.545 +                }
  11.546 +                DROPBITS(last.bits);
  11.547 +            }
  11.548 +            DROPBITS(this.bits);
  11.549 +            if (this.op & 64) {
  11.550 +                strm->msg = (char *)"invalid distance code";
  11.551 +                state->mode = BAD;
  11.552 +                break;
  11.553 +            }
  11.554 +            state->offset = (unsigned)this.val;
  11.555 +
  11.556 +            /* get distance extra bits, if any */
  11.557 +            state->extra = (unsigned)(this.op) & 15;
  11.558 +            if (state->extra != 0) {
  11.559 +                NEEDBITS(state->extra);
  11.560 +                state->offset += BITS(state->extra);
  11.561 +                DROPBITS(state->extra);
  11.562 +            }
  11.563 +            if (state->offset > state->wsize - (state->whave < state->wsize ?
  11.564 +                                                left : 0)) {
  11.565 +                strm->msg = (char *)"invalid distance too far back";
  11.566 +                state->mode = BAD;
  11.567 +                break;
  11.568 +            }
  11.569 +            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
  11.570 +
  11.571 +            /* copy match from window to output */
  11.572 +            do {
  11.573 +                ROOM();
  11.574 +                copy = state->wsize - state->offset;
  11.575 +                if (copy < left) {
  11.576 +                    from = put + copy;
  11.577 +                    copy = left - copy;
  11.578 +                }
  11.579 +                else {
  11.580 +                    from = put - state->offset;
  11.581 +                    copy = left;
  11.582 +                }
  11.583 +                if (copy > state->length) copy = state->length;
  11.584 +                state->length -= copy;
  11.585 +                left -= copy;
  11.586 +                do {
  11.587 +                    *put++ = *from++;
  11.588 +                } while (--copy);
  11.589 +            } while (state->length != 0);
  11.590 +            break;
  11.591 +
  11.592 +        case DONE:
  11.593 +            /* inflate stream terminated properly -- write leftover output */
  11.594 +            ret = Z_STREAM_END;
  11.595 +            if (left < state->wsize) {
  11.596 +                if (out(out_desc, state->window, state->wsize - left))
  11.597 +                    ret = Z_BUF_ERROR;
  11.598 +            }
  11.599 +            goto inf_leave;
  11.600 +
  11.601 +        case BAD:
  11.602 +            ret = Z_DATA_ERROR;
  11.603 +            goto inf_leave;
  11.604 +
  11.605 +        default:                /* can't happen, but makes compilers happy */
  11.606 +            ret = Z_STREAM_ERROR;
  11.607 +            goto inf_leave;
  11.608 +        }
  11.609 +
  11.610 +    /* Return unused input */
  11.611 +  inf_leave:
  11.612 +    strm->next_in = next;
  11.613 +    strm->avail_in = have;
  11.614 +    return ret;
  11.615 +}
  11.616 +
  11.617 +int ZEXPORT inflateBackEnd(strm)
  11.618 +z_streamp strm;
  11.619 +{
  11.620 +    if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  11.621 +        return Z_STREAM_ERROR;
  11.622 +    ZFREE(strm, strm->state);
  11.623 +    strm->state = Z_NULL;
  11.624 +    Tracev((stderr, "inflate: end\n"));
  11.625 +    return Z_OK;
  11.626 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/compiler-init/zlib/inffast.c	Sat Jul 15 04:51:28 2006 +0000
    12.3 @@ -0,0 +1,318 @@
    12.4 +/* inffast.c -- fast decoding
    12.5 + * Copyright (C) 1995-2004 Mark Adler
    12.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    12.7 + */
    12.8 +
    12.9 +#include "zutil.h"
   12.10 +#include "inftrees.h"
   12.11 +#include "inflate.h"
   12.12 +#include "inffast.h"
   12.13 +
   12.14 +#ifndef ASMINF
   12.15 +
   12.16 +/* Allow machine dependent optimization for post-increment or pre-increment.
   12.17 +   Based on testing to date,
   12.18 +   Pre-increment preferred for:
   12.19 +   - PowerPC G3 (Adler)
   12.20 +   - MIPS R5000 (Randers-Pehrson)
   12.21 +   Post-increment preferred for:
   12.22 +   - none
   12.23 +   No measurable difference:
   12.24 +   - Pentium III (Anderson)
   12.25 +   - M68060 (Nikl)
   12.26 + */
   12.27 +#ifdef POSTINC
   12.28 +#  define OFF 0
   12.29 +#  define PUP(a) *(a)++
   12.30 +#else
   12.31 +#  define OFF 1
   12.32 +#  define PUP(a) *++(a)
   12.33 +#endif
   12.34 +
   12.35 +/*
   12.36 +   Decode literal, length, and distance codes and write out the resulting
   12.37 +   literal and match bytes until either not enough input or output is
   12.38 +   available, an end-of-block is encountered, or a data error is encountered.
   12.39 +   When large enough input and output buffers are supplied to inflate(), for
   12.40 +   example, a 16K input buffer and a 64K output buffer, more than 95% of the
   12.41 +   inflate execution time is spent in this routine.
   12.42 +
   12.43 +   Entry assumptions:
   12.44 +
   12.45 +        state->mode == LEN
   12.46 +        strm->avail_in >= 6
   12.47 +        strm->avail_out >= 258
   12.48 +        start >= strm->avail_out
   12.49 +        state->bits < 8
   12.50 +
   12.51 +   On return, state->mode is one of:
   12.52 +
   12.53 +        LEN -- ran out of enough output space or enough available input
   12.54 +        TYPE -- reached end of block code, inflate() to interpret next block
   12.55 +        BAD -- error in block data
   12.56 +
   12.57 +   Notes:
   12.58 +
   12.59 +    - The maximum input bits used by a length/distance pair is 15 bits for the
   12.60 +      length code, 5 bits for the length extra, 15 bits for the distance code,
   12.61 +      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
   12.62 +      Therefore if strm->avail_in >= 6, then there is enough input to avoid
   12.63 +      checking for available input while decoding.
   12.64 +
   12.65 +    - The maximum bytes that a single length/distance pair can output is 258
   12.66 +      bytes, which is the maximum length that can be coded.  inflate_fast()
   12.67 +      requires strm->avail_out >= 258 for each loop to avoid checking for
   12.68 +      output space.
   12.69 + */
   12.70 +void inflate_fast(strm, start)
   12.71 +z_streamp strm;
   12.72 +unsigned start;         /* inflate()'s starting value for strm->avail_out */
   12.73 +{
   12.74 +    struct inflate_state FAR *state;
   12.75 +    unsigned char FAR *in;      /* local strm->next_in */
   12.76 +    unsigned char FAR *last;    /* while in < last, enough input available */
   12.77 +    unsigned char FAR *out;     /* local strm->next_out */
   12.78 +    unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
   12.79 +    unsigned char FAR *end;     /* while out < end, enough space available */
   12.80 +#ifdef INFLATE_STRICT
   12.81 +    unsigned dmax;              /* maximum distance from zlib header */
   12.82 +#endif
   12.83 +    unsigned wsize;             /* window size or zero if not using window */
   12.84 +    unsigned whave;             /* valid bytes in the window */
   12.85 +    unsigned write;             /* window write index */
   12.86 +    unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
   12.87 +    unsigned long hold;         /* local strm->hold */
   12.88 +    unsigned bits;              /* local strm->bits */
   12.89 +    code const FAR *lcode;      /* local strm->lencode */
   12.90 +    code const FAR *dcode;      /* local strm->distcode */
   12.91 +    unsigned lmask;             /* mask for first level of length codes */
   12.92 +    unsigned dmask;             /* mask for first level of distance codes */
   12.93 +    code this;                  /* retrieved table entry */
   12.94 +    unsigned op;                /* code bits, operation, extra bits, or */
   12.95 +                                /*  window position, window bytes to copy */
   12.96 +    unsigned len;               /* match length, unused bytes */
   12.97 +    unsigned dist;              /* match distance */
   12.98 +    unsigned char FAR *from;    /* where to copy match from */
   12.99 +
  12.100 +    /* copy state to local variables */
  12.101 +    state = (struct inflate_state FAR *)strm->state;
  12.102 +    in = strm->next_in - OFF;
  12.103 +    last = in + (strm->avail_in - 5);
  12.104 +    out = strm->next_out - OFF;
  12.105 +    beg = out - (start - strm->avail_out);
  12.106 +    end = out + (strm->avail_out - 257);
  12.107 +#ifdef INFLATE_STRICT
  12.108 +    dmax = state->dmax;
  12.109 +#endif
  12.110 +    wsize = state->wsize;
  12.111 +    whave = state->whave;
  12.112 +    write = state->write;
  12.113 +    window = state->window;
  12.114 +    hold = state->hold;
  12.115 +    bits = state->bits;
  12.116 +    lcode = state->lencode;
  12.117 +    dcode = state->distcode;
  12.118 +    lmask = (1U << state->lenbits) - 1;
  12.119 +    dmask = (1U << state->distbits) - 1;
  12.120 +
  12.121 +    /* decode literals and length/distances until end-of-block or not enough
  12.122 +       input data or output space */
  12.123 +    do {
  12.124 +        if (bits < 15) {
  12.125 +            hold += (unsigned long)(PUP(in)) << bits;
  12.126 +            bits += 8;
  12.127 +            hold += (unsigned long)(PUP(in)) << bits;
  12.128 +            bits += 8;
  12.129 +        }
  12.130 +        this = lcode[hold & lmask];
  12.131 +      dolen:
  12.132 +        op = (unsigned)(this.bits);
  12.133 +        hold >>= op;
  12.134 +        bits -= op;
  12.135 +        op = (unsigned)(this.op);
  12.136 +        if (op == 0) {                          /* literal */
  12.137 +            Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
  12.138 +                    "inflate:         literal '%c'\n" :
  12.139 +                    "inflate:         literal 0x%02x\n", this.val));
  12.140 +            PUP(out) = (unsigned char)(this.val);
  12.141 +        }
  12.142 +        else if (op & 16) {                     /* length base */
  12.143 +            len = (unsigned)(this.val);
  12.144 +            op &= 15;                           /* number of extra bits */
  12.145 +            if (op) {
  12.146 +                if (bits < op) {
  12.147 +                    hold += (unsigned long)(PUP(in)) << bits;
  12.148 +                    bits += 8;
  12.149 +                }
  12.150 +                len += (unsigned)hold & ((1U << op) - 1);
  12.151 +                hold >>= op;
  12.152 +                bits -= op;
  12.153 +            }
  12.154 +            Tracevv((stderr, "inflate:         length %u\n", len));
  12.155 +            if (bits < 15) {
  12.156 +                hold += (unsigned long)(PUP(in)) << bits;
  12.157 +                bits += 8;
  12.158 +                hold += (unsigned long)(PUP(in)) << bits;
  12.159 +                bits += 8;
  12.160 +            }
  12.161 +            this = dcode[hold & dmask];
  12.162 +          dodist:
  12.163 +            op = (unsigned)(this.bits);
  12.164 +            hold >>= op;
  12.165 +            bits -= op;
  12.166 +            op = (unsigned)(this.op);
  12.167 +            if (op & 16) {                      /* distance base */
  12.168 +                dist = (unsigned)(this.val);
  12.169 +                op &= 15;                       /* number of extra bits */
  12.170 +                if (bits < op) {
  12.171 +                    hold += (unsigned long)(PUP(in)) << bits;
  12.172 +                    bits += 8;
  12.173 +                    if (bits < op) {
  12.174 +                        hold += (unsigned long)(PUP(in)) << bits;
  12.175 +                        bits += 8;
  12.176 +                    }
  12.177 +                }
  12.178 +                dist += (unsigned)hold & ((1U << op) - 1);
  12.179 +#ifdef INFLATE_STRICT
  12.180 +                if (dist > dmax) {
  12.181 +                    strm->msg = (char *)"invalid distance too far back";
  12.182 +                    state->mode = BAD;
  12.183 +                    break;
  12.184 +                }
  12.185 +#endif
  12.186 +                hold >>= op;
  12.187 +                bits -= op;
  12.188 +                Tracevv((stderr, "inflate:         distance %u\n", dist));
  12.189 +                op = (unsigned)(out - beg);     /* max distance in output */
  12.190 +                if (dist > op) {                /* see if copy from window */
  12.191 +                    op = dist - op;             /* distance back in window */
  12.192 +                    if (op > whave) {
  12.193 +                        strm->msg = (char *)"invalid distance too far back";
  12.194 +                        state->mode = BAD;
  12.195 +                        break;
  12.196 +                    }
  12.197 +                    from = window - OFF;
  12.198 +                    if (write == 0) {           /* very common case */
  12.199 +                        from += wsize - op;
  12.200 +                        if (op < len) {         /* some from window */
  12.201 +                            len -= op;
  12.202 +                            do {
  12.203 +                                PUP(out) = PUP(from);
  12.204 +                            } while (--op);
  12.205 +                            from = out - dist;  /* rest from output */
  12.206 +                        }
  12.207 +                    }
  12.208 +                    else if (write < op) {      /* wrap around window */
  12.209 +                        from += wsize + write - op;
  12.210 +                        op -= write;
  12.211 +                        if (op < len) {         /* some from end of window */
  12.212 +                            len -= op;
  12.213 +                            do {
  12.214 +                                PUP(out) = PUP(from);
  12.215 +                            } while (--op);
  12.216 +                            from = window - OFF;
  12.217 +                            if (write < len) {  /* some from start of window */
  12.218 +                                op = write;
  12.219 +                                len -= op;
  12.220 +                                do {
  12.221 +                                    PUP(out) = PUP(from);
  12.222 +                                } while (--op);
  12.223 +                                from = out - dist;      /* rest from output */
  12.224 +                            }
  12.225 +                        }
  12.226 +                    }
  12.227 +                    else {                      /* contiguous in window */
  12.228 +                        from += write - op;
  12.229 +                        if (op < len) {         /* some from window */
  12.230 +                            len -= op;
  12.231 +                            do {
  12.232 +                                PUP(out) = PUP(from);
  12.233 +                            } while (--op);
  12.234 +                            from = out - dist;  /* rest from output */
  12.235 +                        }
  12.236 +                    }
  12.237 +                    while (len > 2) {
  12.238 +                        PUP(out) = PUP(from);
  12.239 +                        PUP(out) = PUP(from);
  12.240 +                        PUP(out) = PUP(from);
  12.241 +                        len -= 3;
  12.242 +                    }
  12.243 +                    if (len) {
  12.244 +                        PUP(out) = PUP(from);
  12.245 +                        if (len > 1)
  12.246 +                            PUP(out) = PUP(from);
  12.247 +                    }
  12.248 +                }
  12.249 +                else {
  12.250 +                    from = out - dist;          /* copy direct from output */
  12.251 +                    do {                        /* minimum length is three */
  12.252 +                        PUP(out) = PUP(from);
  12.253 +                        PUP(out) = PUP(from);
  12.254 +                        PUP(out) = PUP(from);
  12.255 +                        len -= 3;
  12.256 +                    } while (len > 2);
  12.257 +                    if (len) {
  12.258 +                        PUP(out) = PUP(from);
  12.259 +                        if (len > 1)
  12.260 +                            PUP(out) = PUP(from);
  12.261 +                    }
  12.262 +                }
  12.263 +            }
  12.264 +            else if ((op & 64) == 0) {          /* 2nd level distance code */
  12.265 +                this = dcode[this.val + (hold & ((1U << op) - 1))];
  12.266 +                goto dodist;
  12.267 +            }
  12.268 +            else {
  12.269 +                strm->msg = (char *)"invalid distance code";
  12.270 +                state->mode = BAD;
  12.271 +                break;
  12.272 +            }
  12.273 +        }
  12.274 +        else if ((op & 64) == 0) {              /* 2nd level length code */
  12.275 +            this = lcode[this.val + (hold & ((1U << op) - 1))];
  12.276 +            goto dolen;
  12.277 +        }
  12.278 +        else if (op & 32) {                     /* end-of-block */
  12.279 +            Tracevv((stderr, "inflate:         end of block\n"));
  12.280 +            state->mode = TYPE;
  12.281 +            break;
  12.282 +        }
  12.283 +        else {
  12.284 +            strm->msg = (char *)"invalid literal/length code";
  12.285 +            state->mode = BAD;
  12.286 +            break;
  12.287 +        }
  12.288 +    } while (in < last && out < end);
  12.289 +
  12.290 +    /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  12.291 +    len = bits >> 3;
  12.292 +    in -= len;
  12.293 +    bits -= len << 3;
  12.294 +    hold &= (1U << bits) - 1;
  12.295 +
  12.296 +    /* update state and return */
  12.297 +    strm->next_in = in + OFF;
  12.298 +    strm->next_out = out + OFF;
  12.299 +    strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  12.300 +    strm->avail_out = (unsigned)(out < end ?
  12.301 +                                 257 + (end - out) : 257 - (out - end));
  12.302 +    state->hold = hold;
  12.303 +    state->bits = bits;
  12.304 +    return;
  12.305 +}
  12.306 +
  12.307 +/*
  12.308 +   inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
  12.309 +   - Using bit fields for code structure
  12.310 +   - Different op definition to avoid & for extra bits (do & for table bits)
  12.311 +   - Three separate decoding do-loops for direct, window, and write == 0
  12.312 +   - Special case for distance > 1 copies to do overlapped load and store copy
  12.313 +   - Explicit branch predictions (based on measured branch probabilities)
  12.314 +   - Deferring match copy and interspersed it with decoding subsequent codes
  12.315 +   - Swapping literal/length else
  12.316 +   - Swapping window/direct else
  12.317 +   - Larger unrolled copy loops (three is about right)
  12.318 +   - Moving len -= 3 statement into middle of loop
  12.319 + */
  12.320 +
  12.321 +#endif /* !ASMINF */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/compiler-init/zlib/inffast.h	Sat Jul 15 04:51:28 2006 +0000
    13.3 @@ -0,0 +1,11 @@
    13.4 +/* inffast.h -- header to use inffast.c
    13.5 + * Copyright (C) 1995-2003 Mark Adler
    13.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    13.7 + */
    13.8 +
    13.9 +/* WARNING: this file should *not* be used by applications. It is
   13.10 +   part of the implementation of the compression library and is
   13.11 +   subject to change. Applications should only use zlib.h.
   13.12 + */
   13.13 +
   13.14 +void inflate_fast OF((z_streamp strm, unsigned start));
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/compiler-init/zlib/inffixed.h	Sat Jul 15 04:51:28 2006 +0000
    14.3 @@ -0,0 +1,94 @@
    14.4 +    /* inffixed.h -- table for decoding fixed codes
    14.5 +     * Generated automatically by makefixed().
    14.6 +     */
    14.7 +
    14.8 +    /* WARNING: this file should *not* be used by applications. It
    14.9 +       is part of the implementation of the compression library and
   14.10 +       is subject to change. Applications should only use zlib.h.
   14.11 +     */
   14.12 +
   14.13 +    static const code lenfix[512] = {
   14.14 +        {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
   14.15 +        {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
   14.16 +        {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
   14.17 +        {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
   14.18 +        {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
   14.19 +        {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
   14.20 +        {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
   14.21 +        {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
   14.22 +        {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
   14.23 +        {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
   14.24 +        {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
   14.25 +        {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
   14.26 +        {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
   14.27 +        {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
   14.28 +        {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
   14.29 +        {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
   14.30 +        {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
   14.31 +        {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
   14.32 +        {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
   14.33 +        {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
   14.34 +        {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
   14.35 +        {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
   14.36 +        {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
   14.37 +        {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
   14.38 +        {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
   14.39 +        {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
   14.40 +        {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
   14.41 +        {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
   14.42 +        {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
   14.43 +        {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
   14.44 +        {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
   14.45 +        {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
   14.46 +        {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
   14.47 +        {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
   14.48 +        {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
   14.49 +        {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
   14.50 +        {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
   14.51 +        {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
   14.52 +        {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
   14.53 +        {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
   14.54 +        {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
   14.55 +        {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
   14.56 +        {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
   14.57 +        {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
   14.58 +        {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
   14.59 +        {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
   14.60 +        {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
   14.61 +        {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
   14.62 +        {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
   14.63 +        {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
   14.64 +        {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
   14.65 +        {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
   14.66 +        {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
   14.67 +        {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
   14.68 +        {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
   14.69 +        {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
   14.70 +        {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
   14.71 +        {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
   14.72 +        {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
   14.73 +        {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
   14.74 +        {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
   14.75 +        {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
   14.76 +        {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
   14.77 +        {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
   14.78 +        {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
   14.79 +        {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
   14.80 +        {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
   14.81 +        {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
   14.82 +        {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
   14.83 +        {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
   14.84 +        {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
   14.85 +        {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
   14.86 +        {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
   14.87 +        {0,9,255}
   14.88 +    };
   14.89 +
   14.90 +    static const code distfix[32] = {
   14.91 +        {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
   14.92 +        {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
   14.93 +        {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
   14.94 +        {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
   14.95 +        {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
   14.96 +        {22,5,193},{64,5,0}
   14.97 +    };
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/compiler-init/zlib/inflate.c	Sat Jul 15 04:51:28 2006 +0000
    15.3 @@ -0,0 +1,1368 @@
    15.4 +/* inflate.c -- zlib decompression
    15.5 + * Copyright (C) 1995-2005 Mark Adler
    15.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    15.7 + */
    15.8 +
    15.9 +/*
   15.10 + * Change history:
   15.11 + *
   15.12 + * 1.2.beta0    24 Nov 2002
   15.13 + * - First version -- complete rewrite of inflate to simplify code, avoid
   15.14 + *   creation of window when not needed, minimize use of window when it is
   15.15 + *   needed, make inffast.c even faster, implement gzip decoding, and to
   15.16 + *   improve code readability and style over the previous zlib inflate code
   15.17 + *
   15.18 + * 1.2.beta1    25 Nov 2002
   15.19 + * - Use pointers for available input and output checking in inffast.c
   15.20 + * - Remove input and output counters in inffast.c
   15.21 + * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
   15.22 + * - Remove unnecessary second byte pull from length extra in inffast.c
   15.23 + * - Unroll direct copy to three copies per loop in inffast.c
   15.24 + *
   15.25 + * 1.2.beta2    4 Dec 2002
   15.26 + * - Change external routine names to reduce potential conflicts
   15.27 + * - Correct filename to inffixed.h for fixed tables in inflate.c
   15.28 + * - Make hbuf[] unsigned char to match parameter type in inflate.c
   15.29 + * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
   15.30 + *   to avoid negation problem on Alphas (64 bit) in inflate.c
   15.31 + *
   15.32 + * 1.2.beta3    22 Dec 2002
   15.33 + * - Add comments on state->bits assertion in inffast.c
   15.34 + * - Add comments on op field in inftrees.h
   15.35 + * - Fix bug in reuse of allocated window after inflateReset()
   15.36 + * - Remove bit fields--back to byte structure for speed
   15.37 + * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
   15.38 + * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
   15.39 + * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
   15.40 + * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
   15.41 + * - Use local copies of stream next and avail values, as well as local bit
   15.42 + *   buffer and bit count in inflate()--for speed when inflate_fast() not used
   15.43 + *
   15.44 + * 1.2.beta4    1 Jan 2003
   15.45 + * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
   15.46 + * - Move a comment on output buffer sizes from inffast.c to inflate.c
   15.47 + * - Add comments in inffast.c to introduce the inflate_fast() routine
   15.48 + * - Rearrange window copies in inflate_fast() for speed and simplification
   15.49 + * - Unroll last copy for window match in inflate_fast()
   15.50 + * - Use local copies of window variables in inflate_fast() for speed
   15.51 + * - Pull out common write == 0 case for speed in inflate_fast()
   15.52 + * - Make op and len in inflate_fast() unsigned for consistency
   15.53 + * - Add FAR to lcode and dcode declarations in inflate_fast()
   15.54 + * - Simplified bad distance check in inflate_fast()
   15.55 + * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
   15.56 + *   source file infback.c to provide a call-back interface to inflate for
   15.57 + *   programs like gzip and unzip -- uses window as output buffer to avoid
   15.58 + *   window copying
   15.59 + *
   15.60 + * 1.2.beta5    1 Jan 2003
   15.61 + * - Improved inflateBack() interface to allow the caller to provide initial
   15.62 + *   input in strm.
   15.63 + * - Fixed stored blocks bug in inflateBack()
   15.64 + *
   15.65 + * 1.2.beta6    4 Jan 2003
   15.66 + * - Added comments in inffast.c on effectiveness of POSTINC
   15.67 + * - Typecasting all around to reduce compiler warnings
   15.68 + * - Changed loops from while (1) or do {} while (1) to for (;;), again to
   15.69 + *   make compilers happy
   15.70 + * - Changed type of window in inflateBackInit() to unsigned char *
   15.71 + *
   15.72 + * 1.2.beta7    27 Jan 2003
   15.73 + * - Changed many types to unsigned or unsigned short to avoid warnings
   15.74 + * - Added inflateCopy() function
   15.75 + *
   15.76 + * 1.2.0        9 Mar 2003
   15.77 + * - Changed inflateBack() interface to provide separate opaque descriptors
   15.78 + *   for the in() and out() functions
   15.79 + * - Changed inflateBack() argument and in_func typedef to swap the length
   15.80 + *   and buffer address return values for the input function
   15.81 + * - Check next_in and next_out for Z_NULL on entry to inflate()
   15.82 + *
   15.83 + * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
   15.84 + */
   15.85 +
   15.86 +#include "zutil.h"
   15.87 +#include "inftrees.h"
   15.88 +#include "inflate.h"
   15.89 +#include "inffast.h"
   15.90 +
   15.91 +#ifdef MAKEFIXED
   15.92 +#  ifndef BUILDFIXED
   15.93 +#    define BUILDFIXED
   15.94 +#  endif
   15.95 +#endif
   15.96 +
   15.97 +/* function prototypes */
   15.98 +local void fixedtables OF((struct inflate_state FAR *state));
   15.99 +local int updatewindow OF((z_streamp strm, unsigned out));
  15.100 +#ifdef BUILDFIXED
  15.101 +   void makefixed OF((void));
  15.102 +#endif
  15.103 +local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  15.104 +                              unsigned len));
  15.105 +
  15.106 +int ZEXPORT inflateReset(strm)
  15.107 +z_streamp strm;
  15.108 +{
  15.109 +    struct inflate_state FAR *state;
  15.110 +
  15.111 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  15.112 +    state = (struct inflate_state FAR *)strm->state;
  15.113 +    strm->total_in = strm->total_out = state->total = 0;
  15.114 +    strm->msg = Z_NULL;
  15.115 +    strm->adler = 1;        /* to support ill-conceived Java test suite */
  15.116 +    state->mode = HEAD;
  15.117 +    state->last = 0;
  15.118 +    state->havedict = 0;
  15.119 +    state->dmax = 32768U;
  15.120 +    state->head = Z_NULL;
  15.121 +    state->wsize = 0;
  15.122 +    state->whave = 0;
  15.123 +    state->write = 0;
  15.124 +    state->hold = 0;
  15.125 +    state->bits = 0;
  15.126 +    state->lencode = state->distcode = state->next = state->codes;
  15.127 +    Tracev((stderr, "inflate: reset\n"));
  15.128 +    return Z_OK;
  15.129 +}
  15.130 +
  15.131 +int ZEXPORT inflatePrime(strm, bits, value)
  15.132 +z_streamp strm;
  15.133 +int bits;
  15.134 +int value;
  15.135 +{
  15.136 +    struct inflate_state FAR *state;
  15.137 +
  15.138 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  15.139 +    state = (struct inflate_state FAR *)strm->state;
  15.140 +    if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  15.141 +    value &= (1L << bits) - 1;
  15.142 +    state->hold += value << state->bits;
  15.143 +    state->bits += bits;
  15.144 +    return Z_OK;
  15.145 +}
  15.146 +
  15.147 +int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
  15.148 +z_streamp strm;
  15.149 +int windowBits;
  15.150 +const char *version;
  15.151 +int stream_size;
  15.152 +{
  15.153 +    struct inflate_state FAR *state;
  15.154 +
  15.155 +    if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  15.156 +        stream_size != (int)(sizeof(z_stream)))
  15.157 +        return Z_VERSION_ERROR;
  15.158 +    if (strm == Z_NULL) return Z_STREAM_ERROR;
  15.159 +    strm->msg = Z_NULL;                 /* in case we return an error */
  15.160 +    if (strm->zalloc == (alloc_func)0) {
  15.161 +        strm->zalloc = zcalloc;
  15.162 +        strm->opaque = (voidpf)0;
  15.163 +    }
  15.164 +    if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  15.165 +    state = (struct inflate_state FAR *)
  15.166 +            ZALLOC(strm, 1, sizeof(struct inflate_state));
  15.167 +    if (state == Z_NULL) return Z_MEM_ERROR;
  15.168 +    Tracev((stderr, "inflate: allocated\n"));
  15.169 +    strm->state = (struct internal_state FAR *)state;
  15.170 +    if (windowBits < 0) {
  15.171 +        state->wrap = 0;
  15.172 +        windowBits = -windowBits;
  15.173 +    }
  15.174 +    else {
  15.175 +        state->wrap = (windowBits >> 4) + 1;
  15.176 +#ifdef GUNZIP
  15.177 +        if (windowBits < 48) windowBits &= 15;
  15.178 +#endif
  15.179 +    }
  15.180 +    if (windowBits < 8 || windowBits > 15) {
  15.181 +        ZFREE(strm, state);
  15.182 +        strm->state = Z_NULL;
  15.183 +        return Z_STREAM_ERROR;
  15.184 +    }
  15.185 +    state->wbits = (unsigned)windowBits;
  15.186 +    state->window = Z_NULL;
  15.187 +    return inflateReset(strm);
  15.188 +}
  15.189 +
  15.190 +int ZEXPORT inflateInit_(strm, version, stream_size)
  15.191 +z_streamp strm;
  15.192 +const char *version;
  15.193 +int stream_size;
  15.194 +{
  15.195 +    return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  15.196 +}
  15.197 +
  15.198 +/*
  15.199 +   Return state with length and distance decoding tables and index sizes set to
  15.200 +   fixed code decoding.  Normally this returns fixed tables from inffixed.h.
  15.201 +   If BUILDFIXED is defined, then instead this routine builds the tables the
  15.202 +   first time it's called, and returns those tables the first time and
  15.203 +   thereafter.  This reduces the size of the code by about 2K bytes, in
  15.204 +   exchange for a little execution time.  However, BUILDFIXED should not be
  15.205 +   used for threaded applications, since the rewriting of the tables and virgin
  15.206 +   may not be thread-safe.
  15.207 + */
  15.208 +local void fixedtables(state)
  15.209 +struct inflate_state FAR *state;
  15.210 +{
  15.211 +#ifdef BUILDFIXED
  15.212 +    static int virgin = 1;
  15.213 +    static code *lenfix, *distfix;
  15.214 +    static code fixed[544];
  15.215 +
  15.216 +    /* build fixed huffman tables if first call (may not be thread safe) */
  15.217 +    if (virgin) {
  15.218 +        unsigned sym, bits;
  15.219 +        static code *next;
  15.220 +
  15.221 +        /* literal/length table */
  15.222 +        sym = 0;
  15.223 +        while (sym < 144) state->lens[sym++] = 8;
  15.224 +        while (sym < 256) state->lens[sym++] = 9;
  15.225 +        while (sym < 280) state->lens[sym++] = 7;
  15.226 +        while (sym < 288) state->lens[sym++] = 8;
  15.227 +        next = fixed;
  15.228 +        lenfix = next;
  15.229 +        bits = 9;
  15.230 +        inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  15.231 +
  15.232 +        /* distance table */
  15.233 +        sym = 0;
  15.234 +        while (sym < 32) state->lens[sym++] = 5;
  15.235 +        distfix = next;
  15.236 +        bits = 5;
  15.237 +        inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  15.238 +
  15.239 +        /* do this just once */
  15.240 +        virgin = 0;
  15.241 +    }
  15.242 +#else /* !BUILDFIXED */
  15.243 +#   include "inffixed.h"
  15.244 +#endif /* BUILDFIXED */
  15.245 +    state->lencode = lenfix;
  15.246 +    state->lenbits = 9;
  15.247 +    state->distcode = distfix;
  15.248 +    state->distbits = 5;
  15.249 +}
  15.250 +
  15.251 +#ifdef MAKEFIXED
  15.252 +#include <stdio.h>
  15.253 +
  15.254 +/*
  15.255 +   Write out the inffixed.h that is #include'd above.  Defining MAKEFIXED also
  15.256 +   defines BUILDFIXED, so the tables are built on the fly.  makefixed() writes
  15.257 +   those tables to stdout, which would be piped to inffixed.h.  A small program
  15.258 +   can simply call makefixed to do this:
  15.259 +
  15.260 +    void makefixed(void);
  15.261 +
  15.262 +    int main(void)
  15.263 +    {
  15.264 +        makefixed();
  15.265 +        return 0;
  15.266 +    }
  15.267 +
  15.268 +   Then that can be linked with zlib built with MAKEFIXED defined and run:
  15.269 +
  15.270 +    a.out > inffixed.h
  15.271 + */
  15.272 +void makefixed()
  15.273 +{
  15.274 +    unsigned low, size;
  15.275 +    struct inflate_state state;
  15.276 +
  15.277 +    fixedtables(&state);
  15.278 +    puts("    /* inffixed.h -- table for decoding fixed codes");
  15.279 +    puts("     * Generated automatically by makefixed().");
  15.280 +    puts("     */");
  15.281 +    puts("");
  15.282 +    puts("    /* WARNING: this file should *not* be used by applications.");
  15.283 +    puts("       It is part of the implementation of this library and is");
  15.284 +    puts("       subject to change. Applications should only use zlib.h.");
  15.285 +    puts("     */");
  15.286 +    puts("");
  15.287 +    size = 1U << 9;
  15.288 +    printf("    static const code lenfix[%u] = {", size);
  15.289 +    low = 0;
  15.290 +    for (;;) {
  15.291 +        if ((low % 7) == 0) printf("\n        ");
  15.292 +        printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  15.293 +               state.lencode[low].val);
  15.294 +        if (++low == size) break;
  15.295 +        putchar(',');
  15.296 +    }
  15.297 +    puts("\n    };");
  15.298 +    size = 1U << 5;
  15.299 +    printf("\n    static const code distfix[%u] = {", size);
  15.300 +    low = 0;
  15.301 +    for (;;) {
  15.302 +        if ((low % 6) == 0) printf("\n        ");
  15.303 +        printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  15.304 +               state.distcode[low].val);
  15.305 +        if (++low == size) break;
  15.306 +        putchar(',');
  15.307 +    }
  15.308 +    puts("\n    };");
  15.309 +}
  15.310 +#endif /* MAKEFIXED */
  15.311 +
  15.312 +/*
  15.313 +   Update the window with the last wsize (normally 32K) bytes written before
  15.314 +   returning.  If window does not exist yet, create it.  This is only called
  15.315 +   when a window is already in use, or when output has been written during this
  15.316 +   inflate call, but the end of the deflate stream has not been reached yet.
  15.317 +   It is also called to create a window for dictionary data when a dictionary
  15.318 +   is loaded.
  15.319 +
  15.320 +   Providing output buffers larger than 32K to inflate() should provide a speed
  15.321 +   advantage, since only the last 32K of output is copied to the sliding window
  15.322 +   upon return from inflate(), and since all distances after the first 32K of
  15.323 +   output will fall in the output data, making match copies simpler and faster.
  15.324 +   The advantage may be dependent on the size of the processor's data caches.
  15.325 + */
  15.326 +local int updatewindow(strm, out)
  15.327 +z_streamp strm;
  15.328 +unsigned out;
  15.329 +{
  15.330 +    struct inflate_state FAR *state;
  15.331 +    unsigned copy, dist;
  15.332 +
  15.333 +    state = (struct inflate_state FAR *)strm->state;
  15.334 +
  15.335 +    /* if it hasn't been done already, allocate space for the window */
  15.336 +    if (state->window == Z_NULL) {
  15.337 +        state->window = (unsigned char FAR *)
  15.338 +                        ZALLOC(strm, 1U << state->wbits,
  15.339 +                               sizeof(unsigned char));
  15.340 +        if (state->window == Z_NULL) return 1;
  15.341 +    }
  15.342 +
  15.343 +    /* if window not in use yet, initialize */
  15.344 +    if (state->wsize == 0) {
  15.345 +        state->wsize = 1U << state->wbits;
  15.346 +        state->write = 0;
  15.347 +        state->whave = 0;
  15.348 +    }
  15.349 +
  15.350 +    /* copy state->wsize or less output bytes into the circular window */
  15.351 +    copy = out - strm->avail_out;
  15.352 +    if (copy >= state->wsize) {
  15.353 +        zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  15.354 +        state->write = 0;
  15.355 +        state->whave = state->wsize;
  15.356 +    }
  15.357 +    else {
  15.358 +        dist = state->wsize - state->write;
  15.359 +        if (dist > copy) dist = copy;
  15.360 +        zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  15.361 +        copy -= dist;
  15.362 +        if (copy) {
  15.363 +            zmemcpy(state->window, strm->next_out - copy, copy);
  15.364 +            state->write = copy;
  15.365 +            state->whave = state->wsize;
  15.366 +        }
  15.367 +        else {
  15.368 +            state->write += dist;
  15.369 +            if (state->write == state->wsize) state->write = 0;
  15.370 +            if (state->whave < state->wsize) state->whave += dist;
  15.371 +        }
  15.372 +    }
  15.373 +    return 0;
  15.374 +}
  15.375 +
  15.376 +/* Macros for inflate(): */
  15.377 +
  15.378 +/* check function to use adler32() for zlib or crc32() for gzip */
  15.379 +#ifdef GUNZIP
  15.380 +#  define UPDATE(check, buf, len) \
  15.381 +    (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  15.382 +#else
  15.383 +#  define UPDATE(check, buf, len) adler32(check, buf, len)
  15.384 +#endif
  15.385 +
  15.386 +/* check macros for header crc */
  15.387 +#ifdef GUNZIP
  15.388 +#  define CRC2(check, word) \
  15.389 +    do { \
  15.390 +        hbuf[0] = (unsigned char)(word); \
  15.391 +        hbuf[1] = (unsigned char)((word) >> 8); \
  15.392 +        check = crc32(check, hbuf, 2); \
  15.393 +    } while (0)
  15.394 +
  15.395 +#  define CRC4(check, word) \
  15.396 +    do { \
  15.397 +        hbuf[0] = (unsigned char)(word); \
  15.398 +        hbuf[1] = (unsigned char)((word) >> 8); \
  15.399 +        hbuf[2] = (unsigned char)((word) >> 16); \
  15.400 +        hbuf[3] = (unsigned char)((word) >> 24); \
  15.401 +        check = crc32(check, hbuf, 4); \
  15.402 +    } while (0)
  15.403 +#endif
  15.404 +
  15.405 +/* Load registers with state in inflate() for speed */
  15.406 +#define LOAD() \
  15.407 +    do { \
  15.408 +        put = strm->next_out; \
  15.409 +        left = strm->avail_out; \
  15.410 +        next = strm->next_in; \
  15.411 +        have = strm->avail_in; \
  15.412 +        hold = state->hold; \
  15.413 +        bits = state->bits; \
  15.414 +    } while (0)
  15.415 +
  15.416 +/* Restore state from registers in inflate() */
  15.417 +#define RESTORE() \
  15.418 +    do { \
  15.419 +        strm->next_out = put; \
  15.420 +        strm->avail_out = left; \
  15.421 +        strm->next_in = next; \
  15.422 +        strm->avail_in = have; \
  15.423 +        state->hold = hold; \
  15.424 +        state->bits = bits; \
  15.425 +    } while (0)
  15.426 +
  15.427 +/* Clear the input bit accumulator */
  15.428 +#define INITBITS() \
  15.429 +    do { \
  15.430 +        hold = 0; \
  15.431 +        bits = 0; \
  15.432 +    } while (0)
  15.433 +
  15.434 +/* Get a byte of input into the bit accumulator, or return from inflate()
  15.435 +   if there is no input available. */
  15.436 +#define PULLBYTE() \
  15.437 +    do { \
  15.438 +        if (have == 0) goto inf_leave; \
  15.439 +        have--; \
  15.440 +        hold += (unsigned long)(*next++) << bits; \
  15.441 +        bits += 8; \
  15.442 +    } while (0)
  15.443 +
  15.444 +/* Assure that there are at least n bits in the bit accumulator.  If there is
  15.445 +   not enough available input to do that, then return from inflate(). */
  15.446 +#define NEEDBITS(n) \
  15.447 +    do { \
  15.448 +        while (bits < (unsigned)(n)) \
  15.449 +            PULLBYTE(); \
  15.450 +    } while (0)
  15.451 +
  15.452 +/* Return the low n bits of the bit accumulator (n < 16) */
  15.453 +#define BITS(n) \
  15.454 +    ((unsigned)hold & ((1U << (n)) - 1))
  15.455 +
  15.456 +/* Remove n bits from the bit accumulator */
  15.457 +#define DROPBITS(n) \
  15.458 +    do { \
  15.459 +        hold >>= (n); \
  15.460 +        bits -= (unsigned)(n); \
  15.461 +    } while (0)
  15.462 +
  15.463 +/* Remove zero to seven bits as needed to go to a byte boundary */
  15.464 +#define BYTEBITS() \
  15.465 +    do { \
  15.466 +        hold >>= bits & 7; \
  15.467 +        bits -= bits & 7; \
  15.468 +    } while (0)
  15.469 +
  15.470 +/* Reverse the bytes in a 32-bit value */
  15.471 +#define REVERSE(q) \
  15.472 +    ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  15.473 +     (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  15.474 +
  15.475 +/*
  15.476 +   inflate() uses a state machine to process as much input data and generate as
  15.477 +   much output data as possible before returning.  The state machine is
  15.478 +   structured roughly as follows:
  15.479 +
  15.480 +    for (;;) switch (state) {
  15.481 +    ...
  15.482 +    case STATEn:
  15.483 +        if (not enough input data or output space to make progress)
  15.484 +            return;
  15.485 +        ... make progress ...
  15.486 +        state = STATEm;
  15.487 +        break;
  15.488 +    ...
  15.489 +    }
  15.490 +
  15.491 +   so when inflate() is called again, the same case is attempted again, and
  15.492 +   if the appropriate resources are provided, the machine proceeds to the
  15.493 +   next state.  The NEEDBITS() macro is usually the way the state evaluates
  15.494 +   whether it can proceed or should return.  NEEDBITS() does the return if
  15.495 +   the requested bits are not available.  The typical use of the BITS macros
  15.496 +   is:
  15.497 +
  15.498 +        NEEDBITS(n);
  15.499 +        ... do something with BITS(n) ...
  15.500 +        DROPBITS(n);
  15.501 +
  15.502 +   where NEEDBITS(n) either returns from inflate() if there isn't enough
  15.503 +   input left to load n bits into the accumulator, or it continues.  BITS(n)
  15.504 +   gives the low n bits in the accumulator.  When done, DROPBITS(n) drops
  15.505 +   the low n bits off the accumulator.  INITBITS() clears the accumulator
  15.506 +   and sets the number of available bits to zero.  BYTEBITS() discards just
  15.507 +   enough bits to put the accumulator on a byte boundary.  After BYTEBITS()
  15.508 +   and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
  15.509 +
  15.510 +   NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
  15.511 +   if there is no input available.  The decoding of variable length codes uses
  15.512 +   PULLBYTE() directly in order to pull just enough bytes to decode the next
  15.513 +   code, and no more.
  15.514 +
  15.515 +   Some states loop until they get enough input, making sure that enough
  15.516 +   state information is maintained to continue the loop where it left off
  15.517 +   if NEEDBITS() returns in the loop.  For example, want, need, and keep
  15.518 +   would all have to actually be part of the saved state in case NEEDBITS()
  15.519 +   returns:
  15.520 +
  15.521 +    case STATEw:
  15.522 +        while (want < need) {
  15.523 +            NEEDBITS(n);
  15.524 +            keep[want++] = BITS(n);
  15.525 +            DROPBITS(n);
  15.526 +        }
  15.527 +        state = STATEx;
  15.528 +    case STATEx:
  15.529 +
  15.530 +   As shown above, if the next state is also the next case, then the break
  15.531 +   is omitted.
  15.532 +
  15.533 +   A state may also return if there is not enough output space available to
  15.534 +   complete that state.  Those states are copying stored data, writing a
  15.535 +   literal byte, and copying a matching string.
  15.536 +
  15.537 +   When returning, a "goto inf_leave" is used to update the total counters,
  15.538 +   update the check value, and determine whether any progress has been made
  15.539 +   during that inflate() call in order to return the proper return code.
  15.540 +   Progress is defined as a change in either strm->avail_in or strm->avail_out.
  15.541 +   When there is a window, goto inf_leave will update the window with the last
  15.542 +   output written.  If a goto inf_leave occurs in the middle of decompression
  15.543 +   and there is no window currently, goto inf_leave will create one and copy
  15.544 +   output to the window for the next call of inflate().
  15.545 +
  15.546 +   In this implementation, the flush parameter of inflate() only affects the
  15.547 +   return code (per zlib.h).  inflate() always writes as much as possible to
  15.548 +   strm->next_out, given the space available and the provided input--the effect
  15.549 +   documented in zlib.h of Z_SYNC_FLUSH.  Furthermore, inflate() always defers
  15.550 +   the allocation of and copying into a sliding window until necessary, which
  15.551 +   provides the effect documented in zlib.h for Z_FINISH when the entire input
  15.552 +   stream available.  So the only thing the flush parameter actually does is:
  15.553 +   when flush is set to Z_FINISH, inflate() cannot return Z_OK.  Instead it
  15.554 +   will return Z_BUF_ERROR if it has not reached the end of the stream.
  15.555 + */
  15.556 +
  15.557 +int ZEXPORT inflate(strm, flush)
  15.558 +z_streamp strm;
  15.559 +int flush;
  15.560 +{
  15.561 +    struct inflate_state FAR *state;
  15.562 +    unsigned char FAR *next;    /* next input */
  15.563 +    unsigned char FAR *put;     /* next output */
  15.564 +    unsigned have, left;        /* available input and output */
  15.565 +    unsigned long hold;         /* bit buffer */
  15.566 +    unsigned bits;              /* bits in bit buffer */
  15.567 +    unsigned in, out;           /* save starting available input and output */
  15.568 +    unsigned copy;              /* number of stored or match bytes to copy */
  15.569 +    unsigned char FAR *from;    /* where to copy match bytes from */
  15.570 +    code this;                  /* current decoding table entry */
  15.571 +    code last;                  /* parent table entry */
  15.572 +    unsigned len;               /* length to copy for repeats, bits to drop */
  15.573 +    int ret;                    /* return code */
  15.574 +#ifdef GUNZIP
  15.575 +    unsigned char hbuf[4];      /* buffer for gzip header crc calculation */
  15.576 +#endif
  15.577 +    static const unsigned short order[19] = /* permutation of code lengths */
  15.578 +        {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  15.579 +
  15.580 +    if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  15.581 +        (strm->next_in == Z_NULL && strm->avail_in != 0))
  15.582 +        return Z_STREAM_ERROR;
  15.583 +
  15.584 +    state = (struct inflate_state FAR *)strm->state;
  15.585 +    if (state->mode == TYPE) state->mode = TYPEDO;      /* skip check */
  15.586 +    LOAD();
  15.587 +    in = have;
  15.588 +    out = left;
  15.589 +    ret = Z_OK;
  15.590 +    for (;;)
  15.591 +        switch (state->mode) {
  15.592 +        case HEAD:
  15.593 +            if (state->wrap == 0) {
  15.594 +                state->mode = TYPEDO;
  15.595 +                break;
  15.596 +            }
  15.597 +            NEEDBITS(16);
  15.598 +#ifdef GUNZIP
  15.599 +            if ((state->wrap & 2) && hold == 0x8b1f) {  /* gzip header */
  15.600 +                state->check = crc32(0L, Z_NULL, 0);
  15.601 +                CRC2(state->check, hold);
  15.602 +                INITBITS();
  15.603 +                state->mode = FLAGS;
  15.604 +                break;
  15.605 +            }
  15.606 +            state->flags = 0;           /* expect zlib header */
  15.607 +            if (state->head != Z_NULL)
  15.608 +                state->head->done = -1;
  15.609 +            if (!(state->wrap & 1) ||   /* check if zlib header allowed */
  15.610 +#else
  15.611 +            if (
  15.612 +#endif
  15.613 +                ((BITS(8) << 8) + (hold >> 8)) % 31) {
  15.614 +                strm->msg = (char *)"incorrect header check";
  15.615 +                state->mode = BAD;
  15.616 +                break;
  15.617 +            }
  15.618 +            if (BITS(4) != Z_DEFLATED) {
  15.619 +                strm->msg = (char *)"unknown compression method";
  15.620 +                state->mode = BAD;
  15.621 +                break;
  15.622 +            }
  15.623 +            DROPBITS(4);
  15.624 +            len = BITS(4) + 8;
  15.625 +            if (len > state->wbits) {
  15.626 +                strm->msg = (char *)"invalid window size";
  15.627 +                state->mode = BAD;
  15.628 +                break;
  15.629 +            }
  15.630 +            state->dmax = 1U << len;
  15.631 +            Tracev((stderr, "inflate:   zlib header ok\n"));
  15.632 +            strm->adler = state->check = adler32(0L, Z_NULL, 0);
  15.633 +            state->mode = hold & 0x200 ? DICTID : TYPE;
  15.634 +            INITBITS();
  15.635 +            break;
  15.636 +#ifdef GUNZIP
  15.637 +        case FLAGS:
  15.638 +            NEEDBITS(16);
  15.639 +            state->flags = (int)(hold);
  15.640 +            if ((state->flags & 0xff) != Z_DEFLATED) {
  15.641 +                strm->msg = (char *)"unknown compression method";
  15.642 +                state->mode = BAD;
  15.643 +                break;
  15.644 +            }
  15.645 +            if (state->flags & 0xe000) {
  15.646 +                strm->msg = (char *)"unknown header flags set";
  15.647 +                state->mode = BAD;
  15.648 +                break;
  15.649 +            }
  15.650 +            if (state->head != Z_NULL)
  15.651 +                state->head->text = (int)((hold >> 8) & 1);
  15.652 +            if (state->flags & 0x0200) CRC2(state->check, hold);
  15.653 +            INITBITS();
  15.654 +            state->mode = TIME;
  15.655 +        case TIME:
  15.656 +            NEEDBITS(32);
  15.657 +            if (state->head != Z_NULL)
  15.658 +                state->head->time = hold;
  15.659 +            if (state->flags & 0x0200) CRC4(state->check, hold);
  15.660 +            INITBITS();
  15.661 +            state->mode = OS;
  15.662 +        case OS:
  15.663 +            NEEDBITS(16);
  15.664 +            if (state->head != Z_NULL) {
  15.665 +                state->head->xflags = (int)(hold & 0xff);
  15.666 +                state->head->os = (int)(hold >> 8);
  15.667 +            }
  15.668 +            if (state->flags & 0x0200) CRC2(state->check, hold);
  15.669 +            INITBITS();
  15.670 +            state->mode = EXLEN;
  15.671 +        case EXLEN:
  15.672 +            if (state->flags & 0x0400) {
  15.673 +                NEEDBITS(16);
  15.674 +                state->length = (unsigned)(hold);
  15.675 +                if (state->head != Z_NULL)
  15.676 +                    state->head->extra_len = (unsigned)hold;
  15.677 +                if (state->flags & 0x0200) CRC2(state->check, hold);
  15.678 +                INITBITS();
  15.679 +            }
  15.680 +            else if (state->head != Z_NULL)
  15.681 +                state->head->extra = Z_NULL;
  15.682 +            state->mode = EXTRA;
  15.683 +        case EXTRA:
  15.684 +            if (state->flags & 0x0400) {
  15.685 +                copy = state->length;
  15.686 +                if (copy > have) copy = have;
  15.687 +                if (copy) {
  15.688 +                    if (state->head != Z_NULL &&
  15.689 +                        state->head->extra != Z_NULL) {
  15.690 +                        len = state->head->extra_len - state->length;
  15.691 +                        zmemcpy(state->head->extra + len, next,
  15.692 +                                len + copy > state->head->extra_max ?
  15.693 +                                state->head->extra_max - len : copy);
  15.694 +                    }
  15.695 +                    if (state->flags & 0x0200)
  15.696 +                        state->check = crc32(state->check, next, copy);
  15.697 +                    have -= copy;
  15.698 +                    next += copy;
  15.699 +                    state->length -= copy;
  15.700 +                }
  15.701 +                if (state->length) goto inf_leave;
  15.702 +            }
  15.703 +            state->length = 0;
  15.704 +            state->mode = NAME;
  15.705 +        case NAME:
  15.706 +            if (state->flags & 0x0800) {
  15.707 +                if (have == 0) goto inf_leave;
  15.708 +                copy = 0;
  15.709 +                do {
  15.710 +                    len = (unsigned)(next[copy++]);
  15.711 +                    if (state->head != Z_NULL &&
  15.712 +                            state->head->name != Z_NULL &&
  15.713 +                            state->length < state->head->name_max)
  15.714 +                        state->head->name[state->length++] = len;
  15.715 +                } while (len && copy < have);
  15.716 +                if (state->flags & 0x0200)
  15.717 +                    state->check = crc32(state->check, next, copy);
  15.718 +                have -= copy;
  15.719 +                next += copy;
  15.720 +                if (len) goto inf_leave;
  15.721 +            }
  15.722 +            else if (state->head != Z_NULL)
  15.723 +                state->head->name = Z_NULL;
  15.724 +            state->length = 0;
  15.725 +            state->mode = COMMENT;
  15.726 +        case COMMENT:
  15.727 +            if (state->flags & 0x1000) {
  15.728 +                if (have == 0) goto inf_leave;
  15.729 +                copy = 0;
  15.730 +                do {
  15.731 +                    len = (unsigned)(next[copy++]);
  15.732 +                    if (state->head != Z_NULL &&
  15.733 +                            state->head->comment != Z_NULL &&
  15.734 +                            state->length < state->head->comm_max)
  15.735 +                        state->head->comment[state->length++] = len;
  15.736 +                } while (len && copy < have);
  15.737 +                if (state->flags & 0x0200)
  15.738 +                    state->check = crc32(state->check, next, copy);
  15.739 +                have -= copy;
  15.740 +                next += copy;
  15.741 +                if (len) goto inf_leave;
  15.742 +            }
  15.743 +            else if (state->head != Z_NULL)
  15.744 +                state->head->comment = Z_NULL;
  15.745 +            state->mode = HCRC;
  15.746 +        case HCRC:
  15.747 +            if (state->flags & 0x0200) {
  15.748 +                NEEDBITS(16);
  15.749 +                if (hold != (state->check & 0xffff)) {
  15.750 +                    strm->msg = (char *)"header crc mismatch";
  15.751 +                    state->mode = BAD;
  15.752 +                    break;
  15.753 +                }
  15.754 +                INITBITS();
  15.755 +            }
  15.756 +            if (state->head != Z_NULL) {
  15.757 +                state->head->hcrc = (int)((state->flags >> 9) & 1);
  15.758 +                state->head->done = 1;
  15.759 +            }
  15.760 +            strm->adler = state->check = crc32(0L, Z_NULL, 0);
  15.761 +            state->mode = TYPE;
  15.762 +            break;
  15.763 +#endif
  15.764 +        case DICTID:
  15.765 +            NEEDBITS(32);
  15.766 +            strm->adler = state->check = REVERSE(hold);
  15.767 +            INITBITS();
  15.768 +            state->mode = DICT;
  15.769 +        case DICT:
  15.770 +            if (state->havedict == 0) {
  15.771 +                RESTORE();
  15.772 +                return Z_NEED_DICT;
  15.773 +            }
  15.774 +            strm->adler = state->check = adler32(0L, Z_NULL, 0);
  15.775 +            state->mode = TYPE;
  15.776 +        case TYPE:
  15.777 +            if (flush == Z_BLOCK) goto inf_leave;
  15.778 +        case TYPEDO:
  15.779 +            if (state->last) {
  15.780 +                BYTEBITS();
  15.781 +                state->mode = CHECK;
  15.782 +                break;
  15.783 +            }
  15.784 +            NEEDBITS(3);
  15.785 +            state->last = BITS(1);
  15.786 +            DROPBITS(1);
  15.787 +            switch (BITS(2)) {
  15.788 +            case 0:                             /* stored block */
  15.789 +                Tracev((stderr, "inflate:     stored block%s\n",
  15.790 +                        state->last ? " (last)" : ""));
  15.791 +                state->mode = STORED;
  15.792 +                break;
  15.793 +            case 1:                             /* fixed block */
  15.794 +                fixedtables(state);
  15.795 +                Tracev((stderr, "inflate:     fixed codes block%s\n",
  15.796 +                        state->last ? " (last)" : ""));
  15.797 +                state->mode = LEN;              /* decode codes */
  15.798 +                break;
  15.799 +            case 2:                             /* dynamic block */
  15.800 +                Tracev((stderr, "inflate:     dynamic codes block%s\n",
  15.801 +                        state->last ? " (last)" : ""));
  15.802 +                state->mode = TABLE;
  15.803 +                break;
  15.804 +            case 3:
  15.805 +                strm->msg = (char *)"invalid block type";
  15.806 +                state->mode = BAD;
  15.807 +            }
  15.808 +            DROPBITS(2);
  15.809 +            break;
  15.810 +        case STORED:
  15.811 +            BYTEBITS();                         /* go to byte boundary */
  15.812 +            NEEDBITS(32);
  15.813 +            if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  15.814 +                strm->msg = (char *)"invalid stored block lengths";
  15.815 +                state->mode = BAD;
  15.816 +                break;
  15.817 +            }
  15.818 +            state->length = (unsigned)hold & 0xffff;
  15.819 +            Tracev((stderr, "inflate:       stored length %u\n",
  15.820 +                    state->length));
  15.821 +            INITBITS();
  15.822 +            state->mode = COPY;
  15.823 +        case COPY:
  15.824 +            copy = state->length;
  15.825 +            if (copy) {
  15.826 +                if (copy > have) copy = have;
  15.827 +                if (copy > left) copy = left;
  15.828 +                if (copy == 0) goto inf_leave;
  15.829 +                zmemcpy(put, next, copy);
  15.830 +                have -= copy;
  15.831 +                next += copy;
  15.832 +                left -= copy;
  15.833 +                put += copy;
  15.834 +                state->length -= copy;
  15.835 +                break;
  15.836 +            }
  15.837 +            Tracev((stderr, "inflate:       stored end\n"));
  15.838 +            state->mode = TYPE;
  15.839 +            break;
  15.840 +        case TABLE:
  15.841 +            NEEDBITS(14);
  15.842 +            state->nlen = BITS(5) + 257;
  15.843 +            DROPBITS(5);
  15.844 +            state->ndist = BITS(5) + 1;
  15.845 +            DROPBITS(5);
  15.846 +            state->ncode = BITS(4) + 4;
  15.847 +            DROPBITS(4);
  15.848 +#ifndef PKZIP_BUG_WORKAROUND
  15.849 +            if (state->nlen > 286 || state->ndist > 30) {
  15.850 +                strm->msg = (char *)"too many length or distance symbols";
  15.851 +                state->mode = BAD;
  15.852 +                break;
  15.853 +            }
  15.854 +#endif
  15.855 +            Tracev((stderr, "inflate:       table sizes ok\n"));
  15.856 +            state->have = 0;
  15.857 +            state->mode = LENLENS;
  15.858 +        case LENLENS:
  15.859 +            while (state->have < state->ncode) {
  15.860 +                NEEDBITS(3);
  15.861 +                state->lens[order[state->have++]] = (unsigned short)BITS(3);
  15.862 +                DROPBITS(3);
  15.863 +            }
  15.864 +            while (state->have < 19)
  15.865 +                state->lens[order[state->have++]] = 0;
  15.866 +            state->next = state->codes;
  15.867 +            state->lencode = (code const FAR *)(state->next);
  15.868 +            state->lenbits = 7;
  15.869 +            ret = inflate_table(CODES, state->lens, 19, &(state->next),
  15.870 +                                &(state->lenbits), state->work);
  15.871 +            if (ret) {
  15.872 +                strm->msg = (char *)"invalid code lengths set";
  15.873 +                state->mode = BAD;
  15.874 +                break;
  15.875 +            }
  15.876 +            Tracev((stderr, "inflate:       code lengths ok\n"));
  15.877 +            state->have = 0;
  15.878 +            state->mode = CODELENS;
  15.879 +        case CODELENS:
  15.880 +            while (state->have < state->nlen + state->ndist) {
  15.881 +                for (;;) {
  15.882 +                    this = state->lencode[BITS(state->lenbits)];
  15.883 +                    if ((unsigned)(this.bits) <= bits) break;
  15.884 +                    PULLBYTE();
  15.885 +                }
  15.886 +                if (this.val < 16) {
  15.887 +                    NEEDBITS(this.bits);
  15.888 +                    DROPBITS(this.bits);
  15.889 +                    state->lens[state->have++] = this.val;
  15.890 +                }
  15.891 +                else {
  15.892 +                    if (this.val == 16) {
  15.893 +                        NEEDBITS(this.bits + 2);
  15.894 +                        DROPBITS(this.bits);
  15.895 +                        if (state->have == 0) {
  15.896 +                            strm->msg = (char *)"invalid bit length repeat";
  15.897 +                            state->mode = BAD;
  15.898 +                            break;
  15.899 +                        }
  15.900 +                        len = state->lens[state->have - 1];
  15.901 +                        copy = 3 + BITS(2);
  15.902 +                        DROPBITS(2);
  15.903 +                    }
  15.904 +                    else if (this.val == 17) {
  15.905 +                        NEEDBITS(this.bits + 3);
  15.906 +                        DROPBITS(this.bits);
  15.907 +                        len = 0;
  15.908 +                        copy = 3 + BITS(3);
  15.909 +                        DROPBITS(3);
  15.910 +                    }
  15.911 +                    else {
  15.912 +                        NEEDBITS(this.bits + 7);
  15.913 +                        DROPBITS(this.bits);
  15.914 +                        len = 0;
  15.915 +                        copy = 11 + BITS(7);
  15.916 +                        DROPBITS(7);
  15.917 +                    }
  15.918 +                    if (state->have + copy > state->nlen + state->ndist) {
  15.919 +                        strm->msg = (char *)"invalid bit length repeat";
  15.920 +                        state->mode = BAD;
  15.921 +                        break;
  15.922 +                    }
  15.923 +                    while (copy--)
  15.924 +                        state->lens[state->have++] = (unsigned short)len;
  15.925 +                }
  15.926 +            }
  15.927 +
  15.928 +            /* handle error breaks in while */
  15.929 +            if (state->mode == BAD) break;
  15.930 +
  15.931 +            /* build code tables */
  15.932 +            state->next = state->codes;
  15.933 +            state->lencode = (code const FAR *)(state->next);
  15.934 +            state->lenbits = 9;
  15.935 +            ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  15.936 +                                &(state->lenbits), state->work);
  15.937 +            if (ret) {
  15.938 +                strm->msg = (char *)"invalid literal/lengths set";
  15.939 +                state->mode = BAD;
  15.940 +                break;
  15.941 +            }
  15.942 +            state->distcode = (code const FAR *)(state->next);
  15.943 +            state->distbits = 6;
  15.944 +            ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  15.945 +                            &(state->next), &(state->distbits), state->work);
  15.946 +            if (ret) {
  15.947 +                strm->msg = (char *)"invalid distances set";
  15.948 +                state->mode = BAD;
  15.949 +                break;
  15.950 +            }
  15.951 +            Tracev((stderr, "inflate:       codes ok\n"));
  15.952 +            state->mode = LEN;
  15.953 +        case LEN:
  15.954 +            if (have >= 6 && left >= 258) {
  15.955 +                RESTORE();
  15.956 +                inflate_fast(strm, out);
  15.957 +                LOAD();
  15.958 +                break;
  15.959 +            }
  15.960 +            for (;;) {
  15.961 +                this = state->lencode[BITS(state->lenbits)];
  15.962 +                if ((unsigned)(this.bits) <= bits) break;
  15.963 +                PULLBYTE();
  15.964 +            }
  15.965 +            if (this.op && (this.op & 0xf0) == 0) {
  15.966 +                last = this;
  15.967 +                for (;;) {
  15.968 +                    this = state->lencode[last.val +
  15.969 +                            (BITS(last.bits + last.op) >> last.bits)];
  15.970 +                    if ((unsigned)(last.bits + this.bits) <= bits) break;
  15.971 +                    PULLBYTE();
  15.972 +                }
  15.973 +                DROPBITS(last.bits);
  15.974 +            }
  15.975 +            DROPBITS(this.bits);
  15.976 +            state->length = (unsigned)this.val;
  15.977 +            if ((int)(this.op) == 0) {
  15.978 +                Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
  15.979 +                        "inflate:         literal '%c'\n" :
  15.980 +                        "inflate:         literal 0x%02x\n", this.val));
  15.981 +                state->mode = LIT;
  15.982 +                break;
  15.983 +            }
  15.984 +            if (this.op & 32) {
  15.985 +                Tracevv((stderr, "inflate:         end of block\n"));
  15.986 +                state->mode = TYPE;
  15.987 +                break;
  15.988 +            }
  15.989 +            if (this.op & 64) {
  15.990 +                strm->msg = (char *)"invalid literal/length code";
  15.991 +                state->mode = BAD;
  15.992 +                break;
  15.993 +            }
  15.994 +            state->extra = (unsigned)(this.op) & 15;
  15.995 +            state->mode = LENEXT;
  15.996 +        case LENEXT:
  15.997 +            if (state->extra) {
  15.998 +                NEEDBITS(state->extra);
  15.999 +                state->length += BITS(state->extra);
 15.1000 +                DROPBITS(state->extra);
 15.1001 +            }
 15.1002 +            Tracevv((stderr, "inflate:         length %u\n", state->length));
 15.1003 +            state->mode = DIST;
 15.1004 +        case DIST:
 15.1005 +            for (;;) {
 15.1006 +                this = state->distcode[BITS(state->distbits)];
 15.1007 +                if ((unsigned)(this.bits) <= bits) break;
 15.1008 +                PULLBYTE();
 15.1009 +            }
 15.1010 +            if ((this.op & 0xf0) == 0) {
 15.1011 +                last = this;
 15.1012 +                for (;;) {
 15.1013 +                    this = state->distcode[last.val +
 15.1014 +                            (BITS(last.bits + last.op) >> last.bits)];
 15.1015 +                    if ((unsigned)(last.bits + this.bits) <= bits) break;
 15.1016 +                    PULLBYTE();
 15.1017 +                }
 15.1018 +                DROPBITS(last.bits);
 15.1019 +            }
 15.1020 +            DROPBITS(this.bits);
 15.1021 +            if (this.op & 64) {
 15.1022 +                strm->msg = (char *)"invalid distance code";
 15.1023 +                state->mode = BAD;
 15.1024 +                break;
 15.1025 +            }
 15.1026 +            state->offset = (unsigned)this.val;
 15.1027 +            state->extra = (unsigned)(this.op) & 15;
 15.1028 +            state->mode = DISTEXT;
 15.1029 +        case DISTEXT:
 15.1030 +            if (state->extra) {
 15.1031 +                NEEDBITS(state->extra);
 15.1032 +                state->offset += BITS(state->extra);
 15.1033 +                DROPBITS(state->extra);
 15.1034 +            }
 15.1035 +#ifdef INFLATE_STRICT
 15.1036 +            if (state->offset > state->dmax) {
 15.1037 +                strm->msg = (char *)"invalid distance too far back";
 15.1038 +                state->mode = BAD;
 15.1039 +                break;
 15.1040 +            }
 15.1041 +#endif
 15.1042 +            if (state->offset > state->whave + out - left) {
 15.1043 +                strm->msg = (char *)"invalid distance too far back";
 15.1044 +                state->mode = BAD;
 15.1045 +                break;
 15.1046 +            }
 15.1047 +            Tracevv((stderr, "inflate:         distance %u\n", state->offset));
 15.1048 +            state->mode = MATCH;
 15.1049 +        case MATCH:
 15.1050 +            if (left == 0) goto inf_leave;
 15.1051 +            copy = out - left;
 15.1052 +            if (state->offset > copy) {         /* copy from window */
 15.1053 +                copy = state->offset - copy;
 15.1054 +                if (copy > state->write) {
 15.1055 +                    copy -= state->write;
 15.1056 +                    from = state->window + (state->wsize - copy);
 15.1057 +                }
 15.1058 +                else
 15.1059 +                    from = state->window + (state->write - copy);
 15.1060 +                if (copy > state->length) copy = state->length;
 15.1061 +            }
 15.1062 +            else {                              /* copy from output */
 15.1063 +                from = put - state->offset;
 15.1064 +                copy = state->length;
 15.1065 +            }
 15.1066 +            if (copy > left) copy = left;
 15.1067 +            left -= copy;
 15.1068 +            state->length -= copy;
 15.1069 +            do {
 15.1070 +                *put++ = *from++;
 15.1071 +            } while (--copy);
 15.1072 +            if (state->length == 0) state->mode = LEN;
 15.1073 +            break;
 15.1074 +        case LIT:
 15.1075 +            if (left == 0) goto inf_leave;
 15.1076 +            *put++ = (unsigned char)(state->length);
 15.1077 +            left--;
 15.1078 +            state->mode = LEN;
 15.1079 +            break;
 15.1080 +        case CHECK:
 15.1081 +            if (state->wrap) {
 15.1082 +                NEEDBITS(32);
 15.1083 +                out -= left;
 15.1084 +                strm->total_out += out;
 15.1085 +                state->total += out;
 15.1086 +                if (out)
 15.1087 +                    strm->adler = state->check =
 15.1088 +                        UPDATE(state->check, put - out, out);
 15.1089 +                out = left;
 15.1090 +                if ((
 15.1091 +#ifdef GUNZIP
 15.1092 +                     state->flags ? hold :
 15.1093 +#endif
 15.1094 +                     REVERSE(hold)) != state->check) {
 15.1095 +                    strm->msg = (char *)"incorrect data check";
 15.1096 +                    state->mode = BAD;
 15.1097 +                    break;
 15.1098 +                }
 15.1099 +                INITBITS();
 15.1100 +                Tracev((stderr, "inflate:   check matches trailer\n"));
 15.1101 +            }
 15.1102 +#ifdef GUNZIP
 15.1103 +            state->mode = LENGTH;
 15.1104 +        case LENGTH:
 15.1105 +            if (state->wrap && state->flags) {
 15.1106 +                NEEDBITS(32);
 15.1107 +                if (hold != (state->total & 0xffffffffUL)) {
 15.1108 +                    strm->msg = (char *)"incorrect length check";
 15.1109 +                    state->mode = BAD;
 15.1110 +                    break;
 15.1111 +                }
 15.1112 +                INITBITS();
 15.1113 +                Tracev((stderr, "inflate:   length matches trailer\n"));
 15.1114 +            }
 15.1115 +#endif
 15.1116 +            state->mode = DONE;
 15.1117 +        case DONE:
 15.1118 +            ret = Z_STREAM_END;
 15.1119 +            goto inf_leave;
 15.1120 +        case BAD:
 15.1121 +            ret = Z_DATA_ERROR;
 15.1122 +            goto inf_leave;
 15.1123 +        case MEM:
 15.1124 +            return Z_MEM_ERROR;
 15.1125 +        case SYNC:
 15.1126 +        default:
 15.1127 +            return Z_STREAM_ERROR;
 15.1128 +        }
 15.1129 +
 15.1130 +    /*
 15.1131 +       Return from inflate(), updating the total counts and the check value.
 15.1132 +       If there was no progress during the inflate() call, return a buffer
 15.1133 +       error.  Call updatewindow() to create and/or update the window state.
 15.1134 +       Note: a memory error from inflate() is non-recoverable.
 15.1135 +     */
 15.1136 +  inf_leave:
 15.1137 +    RESTORE();
 15.1138 +    if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
 15.1139 +        if (updatewindow(strm, out)) {
 15.1140 +            state->mode = MEM;
 15.1141 +            return Z_MEM_ERROR;
 15.1142 +        }
 15.1143 +    in -= strm->avail_in;
 15.1144 +    out -= strm->avail_out;
 15.1145 +    strm->total_in += in;
 15.1146 +    strm->total_out += out;
 15.1147 +    state->total += out;
 15.1148 +    if (state->wrap && out)
 15.1149 +        strm->adler = state->check =
 15.1150 +            UPDATE(state->check, strm->next_out - out, out);
 15.1151 +    strm->data_type = state->bits + (state->last ? 64 : 0) +
 15.1152 +                      (state->mode == TYPE ? 128 : 0);
 15.1153 +    if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
 15.1154 +        ret = Z_BUF_ERROR;
 15.1155 +    return ret;
 15.1156 +}
 15.1157 +
 15.1158 +int ZEXPORT inflateEnd(strm)
 15.1159 +z_streamp strm;
 15.1160 +{
 15.1161 +    struct inflate_state FAR *state;
 15.1162 +    if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
 15.1163 +        return Z_STREAM_ERROR;
 15.1164 +    state = (struct inflate_state FAR *)strm->state;
 15.1165 +    if (state->window != Z_NULL) ZFREE(strm, state->window);
 15.1166 +    ZFREE(strm, strm->state);
 15.1167 +    strm->state = Z_NULL;
 15.1168 +    Tracev((stderr, "inflate: end\n"));
 15.1169 +    return Z_OK;
 15.1170 +}
 15.1171 +
 15.1172 +int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
 15.1173 +z_streamp strm;
 15.1174 +const Bytef *dictionary;
 15.1175 +uInt dictLength;
 15.1176 +{
 15.1177 +    struct inflate_state FAR *state;
 15.1178 +    unsigned long id;
 15.1179 +
 15.1180 +    /* check state */
 15.1181 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
 15.1182 +    state = (struct inflate_state FAR *)strm->state;
 15.1183 +    if (state->wrap != 0 && state->mode != DICT)
 15.1184 +        return Z_STREAM_ERROR;
 15.1185 +
 15.1186 +    /* check for correct dictionary id */
 15.1187 +    if (state->mode == DICT) {
 15.1188 +        id = adler32(0L, Z_NULL, 0);
 15.1189 +        id = adler32(id, dictionary, dictLength);
 15.1190 +        if (id != state->check)
 15.1191 +            return Z_DATA_ERROR;
 15.1192 +    }
 15.1193 +
 15.1194 +    /* copy dictionary to window */
 15.1195 +    if (updatewindow(strm, strm->avail_out)) {
 15.1196 +        state->mode = MEM;
 15.1197 +        return Z_MEM_ERROR;
 15.1198 +    }
 15.1199 +    if (dictLength > state->wsize) {
 15.1200 +        zmemcpy(state->window, dictionary + dictLength - state->wsize,
 15.1201 +                state->wsize);
 15.1202 +        state->whave = state->wsize;
 15.1203 +    }
 15.1204 +    else {
 15.1205 +        zmemcpy(state->window + state->wsize - dictLength, dictionary,
 15.1206 +                dictLength);
 15.1207 +        state->whave = dictLength;
 15.1208 +    }
 15.1209 +    state->havedict = 1;
 15.1210 +    Tracev((stderr, "inflate:   dictionary set\n"));
 15.1211 +    return Z_OK;
 15.1212 +}
 15.1213 +
 15.1214 +int ZEXPORT inflateGetHeader(strm, head)
 15.1215 +z_streamp strm;
 15.1216 +gz_headerp head;
 15.1217 +{
 15.1218 +    struct inflate_state FAR *state;
 15.1219 +
 15.1220 +    /* check state */
 15.1221 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
 15.1222 +    state = (struct inflate_state FAR *)strm->state;
 15.1223 +    if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
 15.1224 +
 15.1225 +    /* save header structure */
 15.1226 +    state->head = head;
 15.1227 +    head->done = 0;
 15.1228 +    return Z_OK;
 15.1229 +}
 15.1230 +
 15.1231 +/*
 15.1232 +   Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
 15.1233 +   or when out of input.  When called, *have is the number of pattern bytes
 15.1234 +   found in order so far, in 0..3.  On return *have is updated to the new
 15.1235 +   state.  If on return *have equals four, then the pattern was found and the
 15.1236 +   return value is how many bytes were read including the last byte of the
 15.1237 +   pattern.  If *have is less than four, then the pattern has not been found
 15.1238 +   yet and the return value is len.  In the latter case, syncsearch() can be
 15.1239 +   called again with more data and the *have state.  *have is initialized to
 15.1240 +   zero for the first call.
 15.1241 + */
 15.1242 +local unsigned syncsearch(have, buf, len)
 15.1243 +unsigned FAR *have;
 15.1244 +unsigned char FAR *buf;
 15.1245 +unsigned len;
 15.1246 +{
 15.1247 +    unsigned got;
 15.1248 +    unsigned next;
 15.1249 +
 15.1250 +    got = *have;
 15.1251 +    next = 0;
 15.1252 +    while (next < len && got < 4) {
 15.1253 +        if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
 15.1254 +            got++;
 15.1255 +        else if (buf[next])
 15.1256 +            got = 0;
 15.1257 +        else
 15.1258 +            got = 4 - got;
 15.1259 +        next++;
 15.1260 +    }
 15.1261 +    *have = got;
 15.1262 +    return next;
 15.1263 +}
 15.1264 +
 15.1265 +int ZEXPORT inflateSync(strm)
 15.1266 +z_streamp strm;
 15.1267 +{
 15.1268 +    unsigned len;               /* number of bytes to look at or looked at */
 15.1269 +    unsigned long in, out;      /* temporary to save total_in and total_out */
 15.1270 +    unsigned char buf[4];       /* to restore bit buffer to byte string */
 15.1271 +    struct inflate_state FAR *state;
 15.1272 +
 15.1273 +    /* check parameters */
 15.1274 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
 15.1275 +    state = (struct inflate_state FAR *)strm->state;
 15.1276 +    if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
 15.1277 +
 15.1278 +    /* if first time, start search in bit buffer */
 15.1279 +    if (state->mode != SYNC) {
 15.1280 +        state->mode = SYNC;
 15.1281 +        state->hold <<= state->bits & 7;
 15.1282 +        state->bits -= state->bits & 7;
 15.1283 +        len = 0;
 15.1284 +        while (state->bits >= 8) {
 15.1285 +            buf[len++] = (unsigned char)(state->hold);
 15.1286 +            state->hold >>= 8;
 15.1287 +            state->bits -= 8;
 15.1288 +        }
 15.1289 +        state->have = 0;
 15.1290 +        syncsearch(&(state->have), buf, len);
 15.1291 +    }
 15.1292 +
 15.1293 +    /* search available input */
 15.1294 +    len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
 15.1295 +    strm->avail_in -= len;
 15.1296 +    strm->next_in += len;
 15.1297 +    strm->total_in += len;
 15.1298 +
 15.1299 +    /* return no joy or set up to restart inflate() on a new block */
 15.1300 +    if (state->have != 4) return Z_DATA_ERROR;
 15.1301 +    in = strm->total_in;  out = strm->total_out;
 15.1302 +    inflateReset(strm);
 15.1303 +    strm->total_in = in;  strm->total_out = out;
 15.1304 +    state->mode = TYPE;
 15.1305 +    return Z_OK;
 15.1306 +}
 15.1307 +
 15.1308 +/*
 15.1309 +   Returns true if inflate is currently at the end of a block generated by
 15.1310 +   Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
 15.1311 +   implementation to provide an additional safety check. PPP uses
 15.1312 +   Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
 15.1313 +   block. When decompressing, PPP checks that at the end of input packet,
 15.1314 +   inflate is waiting for these length bytes.
 15.1315 + */
 15.1316 +int ZEXPORT inflateSyncPoint(strm)
 15.1317 +z_streamp strm;
 15.1318 +{
 15.1319 +    struct inflate_state FAR *state;
 15.1320 +
 15.1321 +    if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
 15.1322 +    state = (struct inflate_state FAR *)strm->state;
 15.1323 +    return state->mode == STORED && state->bits == 0;
 15.1324 +}
 15.1325 +
 15.1326 +int ZEXPORT inflateCopy(dest, source)
 15.1327 +z_streamp dest;
 15.1328 +z_streamp source;
 15.1329 +{
 15.1330 +    struct inflate_state FAR *state;
 15.1331 +    struct inflate_state FAR *copy;
 15.1332 +    unsigned char FAR *window;
 15.1333 +    unsigned wsize;
 15.1334 +
 15.1335 +    /* check input */
 15.1336 +    if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
 15.1337 +        source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
 15.1338 +        return Z_STREAM_ERROR;
 15.1339 +    state = (struct inflate_state FAR *)source->state;
 15.1340 +
 15.1341 +    /* allocate space */
 15.1342 +    copy = (struct inflate_state FAR *)
 15.1343 +           ZALLOC(source, 1, sizeof(struct inflate_state));
 15.1344 +    if (copy == Z_NULL) return Z_MEM_ERROR;
 15.1345 +    window = Z_NULL;
 15.1346 +    if (state->window != Z_NULL) {
 15.1347 +        window = (unsigned char FAR *)
 15.1348 +                 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
 15.1349 +        if (window == Z_NULL) {
 15.1350 +            ZFREE(source, copy);
 15.1351 +            return Z_MEM_ERROR;
 15.1352 +        }
 15.1353 +    }
 15.1354 +
 15.1355 +    /* copy state */
 15.1356 +    zmemcpy(dest, source, sizeof(z_stream));
 15.1357 +    zmemcpy(copy, state, sizeof(struct inflate_state));
 15.1358 +    if (state->lencode >= state->codes &&
 15.1359 +        state->lencode <= state->codes + ENOUGH - 1) {
 15.1360 +        copy->lencode = copy->codes + (state->lencode - state->codes);
 15.1361 +        copy->distcode = copy->codes + (state->distcode - state->codes);
 15.1362 +    }
 15.1363 +    copy->next = copy->codes + (state->next - state->codes);
 15.1364 +    if (window != Z_NULL) {
 15.1365 +        wsize = 1U << state->wbits;
 15.1366 +        zmemcpy(window, state->window, wsize);
 15.1367 +    }
 15.1368 +    copy->window = window;
 15.1369 +    dest->state = (struct internal_state FAR *)copy;
 15.1370 +    return Z_OK;
 15.1371 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/compiler-init/zlib/inflate.h	Sat Jul 15 04:51:28 2006 +0000
    16.3 @@ -0,0 +1,115 @@
    16.4 +/* inflate.h -- internal inflate state definition
    16.5 + * Copyright (C) 1995-2004 Mark Adler
    16.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    16.7 + */
    16.8 +
    16.9 +/* WARNING: this file should *not* be used by applications. It is
   16.10 +   part of the implementation of the compression library and is
   16.11 +   subject to change. Applications should only use zlib.h.
   16.12 + */
   16.13 +
   16.14 +/* define NO_GZIP when compiling if you want to disable gzip header and
   16.15 +   trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
   16.16 +   the crc code when it is not needed.  For shared libraries, gzip decoding
   16.17 +   should be left enabled. */
   16.18 +#ifndef NO_GZIP
   16.19 +#  define GUNZIP
   16.20 +#endif
   16.21 +
   16.22 +/* Possible inflate modes between inflate() calls */
   16.23 +typedef enum {
   16.24 +    HEAD,       /* i: waiting for magic header */
   16.25 +    FLAGS,      /* i: waiting for method and flags (gzip) */
   16.26 +    TIME,       /* i: waiting for modification time (gzip) */
   16.27 +    OS,         /* i: waiting for extra flags and operating system (gzip) */
   16.28 +    EXLEN,      /* i: waiting for extra length (gzip) */
   16.29 +    EXTRA,      /* i: waiting for extra bytes (gzip) */
   16.30 +    NAME,       /* i: waiting for end of file name (gzip) */
   16.31 +    COMMENT,    /* i: waiting for end of comment (gzip) */
   16.32 +    HCRC,       /* i: waiting for header crc (gzip) */
   16.33 +    DICTID,     /* i: waiting for dictionary check value */
   16.34 +    DICT,       /* waiting for inflateSetDictionary() call */
   16.35 +        TYPE,       /* i: waiting for type bits, including last-flag bit */
   16.36 +        TYPEDO,     /* i: same, but skip check to exit inflate on new block */
   16.37 +        STORED,     /* i: waiting for stored size (length and complement) */
   16.38 +        COPY,       /* i/o: waiting for input or output to copy stored block */
   16.39 +        TABLE,      /* i: waiting for dynamic block table lengths */
   16.40 +        LENLENS,    /* i: waiting for code length code lengths */
   16.41 +        CODELENS,   /* i: waiting for length/lit and distance code lengths */
   16.42 +            LEN,        /* i: waiting for length/lit code */
   16.43 +            LENEXT,     /* i: waiting for length extra bits */
   16.44 +            DIST,       /* i: waiting for distance code */
   16.45 +            DISTEXT,    /* i: waiting for distance extra bits */
   16.46 +            MATCH,      /* o: waiting for output space to copy string */
   16.47 +            LIT,        /* o: waiting for output space to write literal */
   16.48 +    CHECK,      /* i: waiting for 32-bit check value */
   16.49 +    LENGTH,     /* i: waiting for 32-bit length (gzip) */
   16.50 +    DONE,       /* finished check, done -- remain here until reset */
   16.51 +    BAD,        /* got a data error -- remain here until reset */
   16.52 +    MEM,        /* got an inflate() memory error -- remain here until reset */
   16.53 +    SYNC        /* looking for synchronization bytes to restart inflate() */
   16.54 +} inflate_mode;
   16.55 +
   16.56 +/*
   16.57 +    State transitions between above modes -
   16.58 +
   16.59 +    (most modes can go to the BAD or MEM mode -- not shown for clarity)
   16.60 +
   16.61 +    Process header:
   16.62 +        HEAD -> (gzip) or (zlib)
   16.63 +        (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
   16.64 +        NAME -> COMMENT -> HCRC -> TYPE
   16.65 +        (zlib) -> DICTID or TYPE
   16.66 +        DICTID -> DICT -> TYPE
   16.67 +    Read deflate blocks:
   16.68 +            TYPE -> STORED or TABLE or LEN or CHECK
   16.69 +            STORED -> COPY -> TYPE
   16.70 +            TABLE -> LENLENS -> CODELENS -> LEN
   16.71 +    Read deflate codes:
   16.72 +                LEN -> LENEXT or LIT or TYPE
   16.73 +                LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
   16.74 +                LIT -> LEN
   16.75 +    Process trailer:
   16.76 +        CHECK -> LENGTH -> DONE
   16.77 + */
   16.78 +
   16.79 +/* state maintained between inflate() calls.  Approximately 7K bytes. */
   16.80 +struct inflate_state {
   16.81 +    inflate_mode mode;          /* current inflate mode */
   16.82 +    int last;                   /* true if processing last block */
   16.83 +    int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
   16.84 +    int havedict;               /* true if dictionary provided */
   16.85 +    int flags;                  /* gzip header method and flags (0 if zlib) */
   16.86 +    unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */
   16.87 +    unsigned long check;        /* protected copy of check value */
   16.88 +    unsigned long total;        /* protected copy of output count */
   16.89 +    gz_headerp head;            /* where to save gzip header information */
   16.90 +        /* sliding window */
   16.91 +    unsigned wbits;             /* log base 2 of requested window size */
   16.92 +    unsigned wsize;             /* window size or zero if not using window */
   16.93 +    unsigned whave;             /* valid bytes in the window */
   16.94 +    unsigned write;             /* window write index */
   16.95 +    unsigned char FAR *window;  /* allocated sliding window, if needed */
   16.96 +        /* bit accumulator */
   16.97 +    unsigned long hold;         /* input bit accumulator */
   16.98 +    unsigned bits;              /* number of bits in "in" */
   16.99 +        /* for string and stored block copying */
  16.100 +    unsigned length;            /* literal or length of data to copy */
  16.101 +    unsigned offset;            /* distance back to copy string from */
  16.102 +        /* for table and code decoding */
  16.103 +    unsigned extra;             /* extra bits needed */
  16.104 +        /* fixed and dynamic code tables */
  16.105 +    code const FAR *lencode;    /* starting table for length/literal codes */
  16.106 +    code const FAR *distcode;   /* starting table for distance codes */
  16.107 +    unsigned lenbits;           /* index bits for lencode */
  16.108 +    unsigned distbits;          /* index bits for distcode */
  16.109 +        /* dynamic table building */
  16.110 +    unsigned ncode;             /* number of code length code lengths */
  16.111 +    unsigned nlen;              /* number of length code lengths */
  16.112 +    unsigned ndist;             /* number of distance code lengths */
  16.113 +    unsigned have;              /* number of code lengths in lens[] */
  16.114 +    code FAR *next;             /* next available space in codes[] */
  16.115 +    unsigned short lens[320];   /* temporary storage for code lengths */
  16.116 +    unsigned short work[288];   /* work area for code table building */
  16.117 +    code codes[ENOUGH];         /* space for code tables */
  16.118 +};
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/compiler-init/zlib/inftrees.c	Sat Jul 15 04:51:28 2006 +0000
    17.3 @@ -0,0 +1,329 @@
    17.4 +/* inftrees.c -- generate Huffman trees for efficient decoding
    17.5 + * Copyright (C) 1995-2005 Mark Adler
    17.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    17.7 + */
    17.8 +
    17.9 +#include "zutil.h"
   17.10 +#include "inftrees.h"
   17.11 +
   17.12 +#define MAXBITS 15
   17.13 +
   17.14 +const char inflate_copyright[] =
   17.15 +   " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
   17.16 +/*
   17.17 +  If you use the zlib library in a product, an acknowledgment is welcome
   17.18 +  in the documentation of your product. If for some reason you cannot
   17.19 +  include such an acknowledgment, I would appreciate that you keep this
   17.20 +  copyright string in the executable of your product.
   17.21 + */
   17.22 +
   17.23 +/*
   17.24 +   Build a set of tables to decode the provided canonical Huffman code.
   17.25 +   The code lengths are lens[0..codes-1].  The result starts at *table,
   17.26 +   whose indices are 0..2^bits-1.  work is a writable array of at least
   17.27 +   lens shorts, which is used as a work area.  type is the type of code
   17.28 +   to be generated, CODES, LENS, or DISTS.  On return, zero is success,
   17.29 +   -1 is an invalid code, and +1 means that ENOUGH isn't enough.  table
   17.30 +   on return points to the next available entry's address.  bits is the
   17.31 +   requested root table index bits, and on return it is the actual root
   17.32 +   table index bits.  It will differ if the request is greater than the
   17.33 +   longest code or if it is less than the shortest code.
   17.34 + */
   17.35 +int inflate_table(type, lens, codes, table, bits, work)
   17.36 +codetype type;
   17.37 +unsigned short FAR *lens;
   17.38 +unsigned codes;
   17.39 +code FAR * FAR *table;
   17.40 +unsigned FAR *bits;
   17.41 +unsigned short FAR *work;
   17.42 +{
   17.43 +    unsigned len;               /* a code's length in bits */
   17.44 +    unsigned sym;               /* index of code symbols */
   17.45 +    unsigned min, max;          /* minimum and maximum code lengths */
   17.46 +    unsigned root;              /* number of index bits for root table */
   17.47 +    unsigned curr;              /* number of index bits for current table */
   17.48 +    unsigned drop;              /* code bits to drop for sub-table */
   17.49 +    int left;                   /* number of prefix codes available */
   17.50 +    unsigned used;              /* code entries in table used */
   17.51 +    unsigned huff;              /* Huffman code */
   17.52 +    unsigned incr;              /* for incrementing code, index */
   17.53 +    unsigned fill;              /* index for replicating entries */
   17.54 +    unsigned low;               /* low bits for current root entry */
   17.55 +    unsigned mask;              /* mask for low root bits */
   17.56 +    code this;                  /* table entry for duplication */
   17.57 +    code FAR *next;             /* next available space in table */
   17.58 +    const unsigned short FAR *base;     /* base value table to use */
   17.59 +    const unsigned short FAR *extra;    /* extra bits table to use */
   17.60 +    int end;                    /* use base and extra for symbol > end */
   17.61 +    unsigned short count[MAXBITS+1];    /* number of codes of each length */
   17.62 +    unsigned short offs[MAXBITS+1];     /* offsets in table for each length */
   17.63 +    static const unsigned short lbase[31] = { /* Length codes 257..285 base */
   17.64 +        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
   17.65 +        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
   17.66 +    static const unsigned short lext[31] = { /* Length codes 257..285 extra */
   17.67 +        16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
   17.68 +        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
   17.69 +    static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
   17.70 +        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
   17.71 +        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
   17.72 +        8193, 12289, 16385, 24577, 0, 0};
   17.73 +    static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
   17.74 +        16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
   17.75 +        23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
   17.76 +        28, 28, 29, 29, 64, 64};
   17.77 +
   17.78 +    /*
   17.79 +       Process a set of code lengths to create a canonical Huffman code.  The
   17.80 +       code lengths are lens[0..codes-1].  Each length corresponds to the
   17.81 +       symbols 0..codes-1.  The Huffman code is generated by first sorting the
   17.82 +       symbols by length from short to long, and retaining the symbol order
   17.83 +       for codes with equal lengths.  Then the code starts with all zero bits
   17.84 +       for the first code of the shortest length, and the codes are integer
   17.85 +       increments for the same length, and zeros are appended as the length
   17.86 +       increases.  For the deflate format, these bits are stored backwards
   17.87 +       from their more natural integer increment ordering, and so when the
   17.88 +       decoding tables are built in the large loop below, the integer codes
   17.89 +       are incremented backwards.
   17.90 +
   17.91 +       This routine assumes, but does not check, that all of the entries in
   17.92 +       lens[] are in the range 0..MAXBITS.  The caller must assure this.
   17.93 +       1..MAXBITS is interpreted as that code length.  zero means that that
   17.94 +       symbol does not occur in this code.
   17.95 +
   17.96 +       The codes are sorted by computing a count of codes for each length,
   17.97 +       creating from that a table of starting indices for each length in the
   17.98 +       sorted table, and then entering the symbols in order in the sorted
   17.99 +       table.  The sorted table is work[], with that space being provided by
  17.100 +       the caller.
  17.101 +
  17.102 +       The length counts are used for other purposes as well, i.e. finding
  17.103 +       the minimum and maximum length codes, determining if there are any
  17.104 +       codes at all, checking for a valid set of lengths, and looking ahead
  17.105 +       at length counts to determine sub-table sizes when building the
  17.106 +       decoding tables.
  17.107 +     */
  17.108 +
  17.109 +    /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  17.110 +    for (len = 0; len <= MAXBITS; len++)
  17.111 +        count[len] = 0;
  17.112 +    for (sym = 0; sym < codes; sym++)
  17.113 +        count[lens[sym]]++;
  17.114 +
  17.115 +    /* bound code lengths, force root to be within code lengths */
  17.116 +    root = *bits;
  17.117 +    for (max = MAXBITS; max >= 1; max--)
  17.118 +        if (count[max] != 0) break;
  17.119 +    if (root > max) root = max;
  17.120 +    if (max == 0) {                     /* no symbols to code at all */
  17.121 +        this.op = (unsigned char)64;    /* invalid code marker */
  17.122 +        this.bits = (unsigned char)1;
  17.123 +        this.val = (unsigned short)0;
  17.124 +        *(*table)++ = this;             /* make a table to force an error */
  17.125 +        *(*table)++ = this;
  17.126 +        *bits = 1;
  17.127 +        return 0;     /* no symbols, but wait for decoding to report error */
  17.128 +    }
  17.129 +    for (min = 1; min <= MAXBITS; min++)
  17.130 +        if (count[min] != 0) break;
  17.131 +    if (root < min) root = min;
  17.132 +
  17.133 +    /* check for an over-subscribed or incomplete set of lengths */
  17.134 +    left = 1;
  17.135 +    for (len = 1; len <= MAXBITS; len++) {
  17.136 +        left <<= 1;
  17.137 +        left -= count[len];
  17.138 +        if (left < 0) return -1;        /* over-subscribed */
  17.139 +    }
  17.140 +    if (left > 0 && (type == CODES || max != 1))
  17.141 +        return -1;                      /* incomplete set */
  17.142 +
  17.143 +    /* generate offsets into symbol table for each length for sorting */
  17.144 +    offs[1] = 0;
  17.145 +    for (len = 1; len < MAXBITS; len++)
  17.146 +        offs[len + 1] = offs[len] + count[len];
  17.147 +
  17.148 +    /* sort symbols by length, by symbol order within each length */
  17.149 +    for (sym = 0; sym < codes; sym++)
  17.150 +        if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  17.151 +
  17.152 +    /*
  17.153 +       Create and fill in decoding tables.  In this loop, the table being
  17.154 +       filled is at next and has curr index bits.  The code being used is huff
  17.155 +       with length len.  That code is converted to an index by dropping drop
  17.156 +       bits off of the bottom.  For codes where len is less than drop + curr,
  17.157 +       those top drop + curr - len bits are incremented through all values to
  17.158 +       fill the table with replicated entries.
  17.159 +
  17.160 +       root is the number of index bits for the root table.  When len exceeds
  17.161 +       root, sub-tables are created pointed to by the root entry with an index
  17.162 +       of the low root bits of huff.  This is saved in low to check for when a
  17.163 +       new sub-table should be started.  drop is zero when the root table is
  17.164 +       being filled, and drop is root when sub-tables are being filled.
  17.165 +
  17.166 +       When a new sub-table is needed, it is necessary to look ahead in the
  17.167 +       code lengths to determine what size sub-table is needed.  The length
  17.168 +       counts are used for this, and so count[] is decremented as codes are
  17.169 +       entered in the tables.
  17.170 +
  17.171 +       used keeps track of how many table entries have been allocated from the
  17.172 +       provided *table space.  It is checked when a LENS table is being made
  17.173 +       against the space in *table, ENOUGH, minus the maximum space needed by
  17.174 +       the worst case distance code, MAXD.  This should never happen, but the
  17.175 +       sufficiency of ENOUGH has not been proven exhaustively, hence the check.
  17.176 +       This assumes that when type == LENS, bits == 9.
  17.177 +
  17.178 +       sym increments through all symbols, and the loop terminates when
  17.179 +       all codes of length max, i.e. all codes, have been processed.  This
  17.180 +       routine permits incomplete codes, so another loop after this one fills
  17.181 +       in the rest of the decoding tables with invalid code markers.
  17.182 +     */
  17.183 +
  17.184 +    /* set up for code type */
  17.185 +    switch (type) {
  17.186 +    case CODES:
  17.187 +        base = extra = work;    /* dummy value--not used */
  17.188 +        end = 19;
  17.189 +        break;
  17.190 +    case LENS:
  17.191 +        base = lbase;
  17.192 +        base -= 257;
  17.193 +        extra = lext;
  17.194 +        extra -= 257;
  17.195 +        end = 256;
  17.196 +        break;
  17.197 +    default:            /* DISTS */
  17.198 +        base = dbase;
  17.199 +        extra = dext;
  17.200 +        end = -1;
  17.201 +    }
  17.202 +
  17.203 +    /* initialize state for loop */
  17.204 +    huff = 0;                   /* starting code */
  17.205 +    sym = 0;                    /* starting code symbol */
  17.206 +    len = min;                  /* starting code length */
  17.207 +    next = *table;              /* current table to fill in */
  17.208 +    curr = root;                /* current table index bits */
  17.209 +    drop = 0;                   /* current bits to drop from code for index */
  17.210 +    low = (unsigned)(-1);       /* trigger new sub-table when len > root */
  17.211 +    used = 1U << root;          /* use root table entries */
  17.212 +    mask = used - 1;            /* mask for comparing low */
  17.213 +
  17.214 +    /* check available table space */
  17.215 +    if (type == LENS && used >= ENOUGH - MAXD)
  17.216 +        return 1;
  17.217 +
  17.218 +    /* process all codes and make table entries */
  17.219 +    for (;;) {
  17.220 +        /* create table entry */
  17.221 +        this.bits = (unsigned char)(len - drop);
  17.222 +        if ((int)(work[sym]) < end) {
  17.223 +            this.op = (unsigned char)0;
  17.224 +            this.val = work[sym];
  17.225 +        }
  17.226 +        else if ((int)(work[sym]) > end) {
  17.227 +            this.op = (unsigned char)(extra[work[sym]]);
  17.228 +            this.val = base[work[sym]];
  17.229 +        }
  17.230 +        else {
  17.231 +            this.op = (unsigned char)(32 + 64);         /* end of block */
  17.232 +            this.val = 0;
  17.233 +        }
  17.234 +
  17.235 +        /* replicate for those indices with low len bits equal to huff */
  17.236 +        incr = 1U << (len - drop);
  17.237 +        fill = 1U << curr;
  17.238 +        min = fill;                 /* save offset to next table */
  17.239 +        do {
  17.240 +            fill -= incr;
  17.241 +            next[(huff >> drop) + fill] = this;
  17.242 +        } while (fill != 0);
  17.243 +
  17.244 +        /* backwards increment the len-bit code huff */
  17.245 +        incr = 1U << (len - 1);
  17.246 +        while (huff & incr)
  17.247 +            incr >>= 1;
  17.248 +        if (incr != 0) {
  17.249 +            huff &= incr - 1;
  17.250 +            huff += incr;
  17.251 +        }
  17.252 +        else
  17.253 +            huff = 0;
  17.254 +
  17.255 +        /* go to next symbol, update count, len */
  17.256 +        sym++;
  17.257 +        if (--(count[len]) == 0) {
  17.258 +            if (len == max) break;
  17.259 +            len = lens[work[sym]];
  17.260 +        }
  17.261 +
  17.262 +        /* create new sub-table if needed */
  17.263 +        if (len > root && (huff & mask) != low) {
  17.264 +            /* if first time, transition to sub-tables */
  17.265 +            if (drop == 0)
  17.266 +                drop = root;
  17.267 +
  17.268 +            /* increment past last table */
  17.269 +            next += min;            /* here min is 1 << curr */
  17.270 +
  17.271 +            /* determine length of next table */
  17.272 +            curr = len - drop;
  17.273 +            left = (int)(1 << curr);
  17.274 +            while (curr + drop < max) {
  17.275 +                left -= count[curr + drop];
  17.276 +                if (left <= 0) break;
  17.277 +                curr++;
  17.278 +                left <<= 1;
  17.279 +            }
  17.280 +
  17.281 +            /* check for enough space */
  17.282 +            used += 1U << curr;
  17.283 +            if (type == LENS && used >= ENOUGH - MAXD)
  17.284 +                return 1;
  17.285 +
  17.286 +            /* point entry in root table to sub-table */
  17.287 +            low = huff & mask;
  17.288 +            (*table)[low].op = (unsigned char)curr;
  17.289 +            (*table)[low].bits = (unsigned char)root;
  17.290 +            (*table)[low].val = (unsigned short)(next - *table);
  17.291 +        }
  17.292 +    }
  17.293 +
  17.294 +    /*
  17.295 +       Fill in rest of table for incomplete codes.  This loop is similar to the
  17.296 +       loop above in incrementing huff for table indices.  It is assumed that
  17.297 +       len is equal to curr + drop, so there is no loop needed to increment
  17.298 +       through high index bits.  When the current sub-table is filled, the loop
  17.299 +       drops back to the root table to fill in any remaining entries there.
  17.300 +     */
  17.301 +    this.op = (unsigned char)64;                /* invalid code marker */
  17.302 +    this.bits = (unsigned char)(len - drop);
  17.303 +    this.val = (unsigned short)0;
  17.304 +    while (huff != 0) {
  17.305 +        /* when done with sub-table, drop back to root table */
  17.306 +        if (drop != 0 && (huff & mask) != low) {
  17.307 +            drop = 0;
  17.308 +            len = root;
  17.309 +            next = *table;
  17.310 +            this.bits = (unsigned char)len;
  17.311 +        }
  17.312 +
  17.313 +        /* put invalid code marker in table */
  17.314 +        next[huff >> drop] = this;
  17.315 +
  17.316 +        /* backwards increment the len-bit code huff */
  17.317 +        incr = 1U << (len - 1);
  17.318 +        while (huff & incr)
  17.319 +            incr >>= 1;
  17.320 +        if (incr != 0) {
  17.321 +            huff &= incr - 1;
  17.322 +            huff += incr;
  17.323 +        }
  17.324 +        else
  17.325 +            huff = 0;
  17.326 +    }
  17.327 +
  17.328 +    /* set return parameters */
  17.329 +    *table += used;
  17.330 +    *bits = root;
  17.331 +    return 0;
  17.332 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/compiler-init/zlib/inftrees.h	Sat Jul 15 04:51:28 2006 +0000
    18.3 @@ -0,0 +1,55 @@
    18.4 +/* inftrees.h -- header to use inftrees.c
    18.5 + * Copyright (C) 1995-2005 Mark Adler
    18.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    18.7 + */
    18.8 +
    18.9 +/* WARNING: this file should *not* be used by applications. It is
   18.10 +   part of the implementation of the compression library and is
   18.11 +   subject to change. Applications should only use zlib.h.
   18.12 + */
   18.13 +
   18.14 +/* Structure for decoding tables.  Each entry provides either the
   18.15 +   information needed to do the operation requested by the code that
   18.16 +   indexed that table entry, or it provides a pointer to another
   18.17 +   table that indexes more bits of the code.  op indicates whether
   18.18 +   the entry is a pointer to another table, a literal, a length or
   18.19 +   distance, an end-of-block, or an invalid code.  For a table
   18.20 +   pointer, the low four bits of op is the number of index bits of
   18.21 +   that table.  For a length or distance, the low four bits of op
   18.22 +   is the number of extra bits to get after the code.  bits is
   18.23 +   the number of bits in this code or part of the code to drop off
   18.24 +   of the bit buffer.  val is the actual byte to output in the case
   18.25 +   of a literal, the base length or distance, or the offset from
   18.26 +   the current table to the next table.  Each entry is four bytes. */
   18.27 +typedef struct {
   18.28 +    unsigned char op;           /* operation, extra bits, table bits */
   18.29 +    unsigned char bits;         /* bits in this part of the code */
   18.30 +    unsigned short val;         /* offset in table or code value */
   18.31 +} code;
   18.32 +
   18.33 +/* op values as set by inflate_table():
   18.34 +    00000000 - literal
   18.35 +    0000tttt - table link, tttt != 0 is the number of table index bits
   18.36 +    0001eeee - length or distance, eeee is the number of extra bits
   18.37 +    01100000 - end of block
   18.38 +    01000000 - invalid code
   18.39 + */
   18.40 +
   18.41 +/* Maximum size of dynamic tree.  The maximum found in a long but non-
   18.42 +   exhaustive search was 1444 code structures (852 for length/literals
   18.43 +   and 592 for distances, the latter actually the result of an
   18.44 +   exhaustive search).  The true maximum is not known, but the value
   18.45 +   below is more than safe. */
   18.46 +#define ENOUGH 2048
   18.47 +#define MAXD 592
   18.48 +
   18.49 +/* Type of code to build for inftable() */
   18.50 +typedef enum {
   18.51 +    CODES,
   18.52 +    LENS,
   18.53 +    DISTS
   18.54 +} codetype;
   18.55 +
   18.56 +extern int inflate_table OF((codetype type, unsigned short FAR *lens,
   18.57 +                             unsigned codes, code FAR * FAR *table,
   18.58 +                             unsigned FAR *bits, unsigned short FAR *work));
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/compiler-init/zlib/trees.c	Sat Jul 15 04:51:28 2006 +0000
    19.3 @@ -0,0 +1,1219 @@
    19.4 +/* trees.c -- output deflated data using Huffman coding
    19.5 + * Copyright (C) 1995-2005 Jean-loup Gailly
    19.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    19.7 + */
    19.8 +
    19.9 +/*
   19.10 + *  ALGORITHM
   19.11 + *
   19.12 + *      The "deflation" process uses several Huffman trees. The more
   19.13 + *      common source values are represented by shorter bit sequences.
   19.14 + *
   19.15 + *      Each code tree is stored in a compressed form which is itself
   19.16 + * a Huffman encoding of the lengths of all the code strings (in
   19.17 + * ascending order by source values).  The actual code strings are
   19.18 + * reconstructed from the lengths in the inflate process, as described
   19.19 + * in the deflate specification.
   19.20 + *
   19.21 + *  REFERENCES
   19.22 + *
   19.23 + *      Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
   19.24 + *      Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
   19.25 + *
   19.26 + *      Storer, James A.
   19.27 + *          Data Compression:  Methods and Theory, pp. 49-50.
   19.28 + *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
   19.29 + *
   19.30 + *      Sedgewick, R.
   19.31 + *          Algorithms, p290.
   19.32 + *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
   19.33 + */
   19.34 +
   19.35 +/* @(#) $Id$ */
   19.36 +
   19.37 +/* #define GEN_TREES_H */
   19.38 +
   19.39 +#include "deflate.h"
   19.40 +
   19.41 +#ifdef DEBUG
   19.42 +#  include <ctype.h>
   19.43 +#endif
   19.44 +
   19.45 +/* ===========================================================================
   19.46 + * Constants
   19.47 + */
   19.48 +
   19.49 +#define MAX_BL_BITS 7
   19.50 +/* Bit length codes must not exceed MAX_BL_BITS bits */
   19.51 +
   19.52 +#define END_BLOCK 256
   19.53 +/* end of block literal code */
   19.54 +
   19.55 +#define REP_3_6      16
   19.56 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */
   19.57 +
   19.58 +#define REPZ_3_10    17
   19.59 +/* repeat a zero length 3-10 times  (3 bits of repeat count) */
   19.60 +
   19.61 +#define REPZ_11_138  18
   19.62 +/* repeat a zero length 11-138 times  (7 bits of repeat count) */
   19.63 +
   19.64 +local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
   19.65 +   = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
   19.66 +
   19.67 +local const int extra_dbits[D_CODES] /* extra bits for each distance code */
   19.68 +   = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
   19.69 +
   19.70 +local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
   19.71 +   = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
   19.72 +
   19.73 +local const uch bl_order[BL_CODES]
   19.74 +   = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
   19.75 +/* The lengths of the bit length codes are sent in order of decreasing
   19.76 + * probability, to avoid transmitting the lengths for unused bit length codes.
   19.77 + */
   19.78 +
   19.79 +#define Buf_size (8 * 2*sizeof(char))
   19.80 +/* Number of bits used within bi_buf. (bi_buf might be implemented on
   19.81 + * more than 16 bits on some systems.)
   19.82 + */
   19.83 +
   19.84 +/* ===========================================================================
   19.85 + * Local data. These are initialized only once.
   19.86 + */
   19.87 +
   19.88 +#define DIST_CODE_LEN  512 /* see definition of array dist_code below */
   19.89 +
   19.90 +#if defined(GEN_TREES_H) || !defined(STDC)
   19.91 +/* non ANSI compilers may not accept trees.h */
   19.92 +
   19.93 +local ct_data static_ltree[L_CODES+2];
   19.94 +/* The static literal tree. Since the bit lengths are imposed, there is no
   19.95 + * need for the L_CODES extra codes used during heap construction. However
   19.96 + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
   19.97 + * below).
   19.98 + */
   19.99 +
  19.100 +local ct_data static_dtree[D_CODES];
  19.101 +/* The static distance tree. (Actually a trivial tree since all codes use
  19.102 + * 5 bits.)
  19.103 + */
  19.104 +
  19.105 +uch _dist_code[DIST_CODE_LEN];
  19.106 +/* Distance codes. The first 256 values correspond to the distances
  19.107 + * 3 .. 258, the last 256 values correspond to the top 8 bits of
  19.108 + * the 15 bit distances.
  19.109 + */
  19.110 +
  19.111 +uch _length_code[MAX_MATCH-MIN_MATCH+1];
  19.112 +/* length code for each normalized match length (0 == MIN_MATCH) */
  19.113 +
  19.114 +local int base_length[LENGTH_CODES];
  19.115 +/* First normalized length for each code (0 = MIN_MATCH) */
  19.116 +
  19.117 +local int base_dist[D_CODES];
  19.118 +/* First normalized distance for each code (0 = distance of 1) */
  19.119 +
  19.120 +#else
  19.121 +#  include "trees.h"
  19.122 +#endif /* GEN_TREES_H */
  19.123 +
  19.124 +struct static_tree_desc_s {
  19.125 +    const ct_data *static_tree;  /* static tree or NULL */
  19.126 +    const intf *extra_bits;      /* extra bits for each code or NULL */
  19.127 +    int     extra_base;          /* base index for extra_bits */
  19.128 +    int     elems;               /* max number of elements in the tree */
  19.129 +    int     max_length;          /* max bit length for the codes */
  19.130 +};
  19.131 +
  19.132 +local static_tree_desc  static_l_desc =
  19.133 +{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  19.134 +
  19.135 +local static_tree_desc  static_d_desc =
  19.136 +{static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS};
  19.137 +
  19.138 +local static_tree_desc  static_bl_desc =
  19.139 +{(const ct_data *)0, extra_blbits, 0,   BL_CODES, MAX_BL_BITS};
  19.140 +
  19.141 +/* ===========================================================================
  19.142 + * Local (static) routines in this file.
  19.143 + */
  19.144 +
  19.145 +local void tr_static_init OF((void));
  19.146 +local void init_block     OF((deflate_state *s));
  19.147 +local void pqdownheap     OF((deflate_state *s, ct_data *tree, int k));
  19.148 +local void gen_bitlen     OF((deflate_state *s, tree_desc *desc));
  19.149 +local void gen_codes      OF((ct_data *tree, int max_code, ushf *bl_count));
  19.150 +local void build_tree     OF((deflate_state *s, tree_desc *desc));
  19.151 +local void scan_tree      OF((deflate_state *s, ct_data *tree, int max_code));
  19.152 +local void send_tree      OF((deflate_state *s, ct_data *tree, int max_code));
  19.153 +local int  build_bl_tree  OF((deflate_state *s));
  19.154 +local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  19.155 +                              int blcodes));
  19.156 +local void compress_block OF((deflate_state *s, ct_data *ltree,
  19.157 +                              ct_data *dtree));
  19.158 +local void set_data_type  OF((deflate_state *s));
  19.159 +local unsigned bi_reverse OF((unsigned value, int length));
  19.160 +local void bi_windup      OF((deflate_state *s));
  19.161 +local void bi_flush       OF((deflate_state *s));
  19.162 +local void copy_block     OF((deflate_state *s, charf *buf, unsigned len,
  19.163 +                              int header));
  19.164 +
  19.165 +#ifdef GEN_TREES_H
  19.166 +local void gen_trees_header OF((void));
  19.167 +#endif
  19.168 +
  19.169 +#ifndef DEBUG
  19.170 +#  define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  19.171 +   /* Send a code of the given tree. c and tree must not have side effects */
  19.172 +
  19.173 +#else /* DEBUG */
  19.174 +#  define send_code(s, c, tree) \
  19.175 +     { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  19.176 +       send_bits(s, tree[c].Code, tree[c].Len); }
  19.177 +#endif
  19.178 +
  19.179 +/* ===========================================================================
  19.180 + * Output a short LSB first on the stream.
  19.181 + * IN assertion: there is enough room in pendingBuf.
  19.182 + */
  19.183 +#define put_short(s, w) { \
  19.184 +    put_byte(s, (uch)((w) & 0xff)); \
  19.185 +    put_byte(s, (uch)((ush)(w) >> 8)); \
  19.186 +}
  19.187 +
  19.188 +/* ===========================================================================
  19.189 + * Send a value on a given number of bits.
  19.190 + * IN assertion: length <= 16 and value fits in length bits.
  19.191 + */
  19.192 +#ifdef DEBUG
  19.193 +local void send_bits      OF((deflate_state *s, int value, int length));
  19.194 +
  19.195 +local void send_bits(s, value, length)
  19.196 +    deflate_state *s;
  19.197 +    int value;  /* value to send */
  19.198 +    int length; /* number of bits */
  19.199 +{
  19.200 +    Tracevv((stderr," l %2d v %4x ", length, value));
  19.201 +    Assert(length > 0 && length <= 15, "invalid length");
  19.202 +    s->bits_sent += (ulg)length;
  19.203 +
  19.204 +    /* If not enough room in bi_buf, use (valid) bits from bi_buf and
  19.205 +     * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
  19.206 +     * unused bits in value.
  19.207 +     */
  19.208 +    if (s->bi_valid > (int)Buf_size - length) {
  19.209 +        s->bi_buf |= (value << s->bi_valid);
  19.210 +        put_short(s, s->bi_buf);
  19.211 +        s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  19.212 +        s->bi_valid += length - Buf_size;
  19.213 +    } else {
  19.214 +        s->bi_buf |= value << s->bi_valid;
  19.215 +        s->bi_valid += length;
  19.216 +    }
  19.217 +}
  19.218 +#else /* !DEBUG */
  19.219 +
  19.220 +#define send_bits(s, value, length) \
  19.221 +{ int len = length;\
  19.222 +  if (s->bi_valid > (int)Buf_size - len) {\
  19.223 +    int val = value;\
  19.224 +    s->bi_buf |= (val << s->bi_valid);\
  19.225 +    put_short(s, s->bi_buf);\
  19.226 +    s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  19.227 +    s->bi_valid += len - Buf_size;\
  19.228 +  } else {\
  19.229 +    s->bi_buf |= (value) << s->bi_valid;\
  19.230 +    s->bi_valid += len;\
  19.231 +  }\
  19.232 +}
  19.233 +#endif /* DEBUG */
  19.234 +
  19.235 +
  19.236 +/* the arguments must not have side effects */
  19.237 +
  19.238 +/* ===========================================================================
  19.239 + * Initialize the various 'constant' tables.
  19.240 + */
  19.241 +local void tr_static_init()
  19.242 +{
  19.243 +#if defined(GEN_TREES_H) || !defined(STDC)
  19.244 +    static int static_init_done = 0;
  19.245 +    int n;        /* iterates over tree elements */
  19.246 +    int bits;     /* bit counter */
  19.247 +    int length;   /* length value */
  19.248 +    int code;     /* code value */
  19.249 +    int dist;     /* distance index */
  19.250 +    ush bl_count[MAX_BITS+1];
  19.251 +    /* number of codes at each bit length for an optimal tree */
  19.252 +
  19.253 +    if (static_init_done) return;
  19.254 +
  19.255 +    /* For some embedded targets, global variables are not initialized: */
  19.256 +    static_l_desc.static_tree = static_ltree;
  19.257 +    static_l_desc.extra_bits = extra_lbits;
  19.258 +    static_d_desc.static_tree = static_dtree;
  19.259 +    static_d_desc.extra_bits = extra_dbits;
  19.260 +    static_bl_desc.extra_bits = extra_blbits;
  19.261 +
  19.262 +    /* Initialize the mapping length (0..255) -> length code (0..28) */
  19.263 +    length = 0;
  19.264 +    for (code = 0; code < LENGTH_CODES-1; code++) {
  19.265 +        base_length[code] = length;
  19.266 +        for (n = 0; n < (1<<extra_lbits[code]); n++) {
  19.267 +            _length_code[length++] = (uch)code;
  19.268 +        }
  19.269 +    }
  19.270 +    Assert (length == 256, "tr_static_init: length != 256");
  19.271 +    /* Note that the length 255 (match length 258) can be represented
  19.272 +     * in two different ways: code 284 + 5 bits or code 285, so we
  19.273 +     * overwrite length_code[255] to use the best encoding:
  19.274 +     */
  19.275 +    _length_code[length-1] = (uch)code;
  19.276 +
  19.277 +    /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  19.278 +    dist = 0;
  19.279 +    for (code = 0 ; code < 16; code++) {
  19.280 +        base_dist[code] = dist;
  19.281 +        for (n = 0; n < (1<<extra_dbits[code]); n++) {
  19.282 +            _dist_code[dist++] = (uch)code;
  19.283 +        }
  19.284 +    }
  19.285 +    Assert (dist == 256, "tr_static_init: dist != 256");
  19.286 +    dist >>= 7; /* from now on, all distances are divided by 128 */
  19.287 +    for ( ; code < D_CODES; code++) {
  19.288 +        base_dist[code] = dist << 7;
  19.289 +        for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  19.290 +            _dist_code[256 + dist++] = (uch)code;
  19.291 +        }
  19.292 +    }
  19.293 +    Assert (dist == 256, "tr_static_init: 256+dist != 512");
  19.294 +
  19.295 +    /* Construct the codes of the static literal tree */
  19.296 +    for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  19.297 +    n = 0;
  19.298 +    while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  19.299 +    while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  19.300 +    while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  19.301 +    while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  19.302 +    /* Codes 286 and 287 do not exist, but we must include them in the
  19.303 +     * tree construction to get a canonical Huffman tree (longest code
  19.304 +     * all ones)
  19.305 +     */
  19.306 +    gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  19.307 +
  19.308 +    /* The static distance tree is trivial: */
  19.309 +    for (n = 0; n < D_CODES; n++) {
  19.310 +        static_dtree[n].Len = 5;
  19.311 +        static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  19.312 +    }
  19.313 +    static_init_done = 1;
  19.314 +
  19.315 +#  ifdef GEN_TREES_H
  19.316 +    gen_trees_header();
  19.317 +#  endif
  19.318 +#endif /* defined(GEN_TREES_H) || !defined(STDC) */
  19.319 +}
  19.320 +
  19.321 +/* ===========================================================================
  19.322 + * Genererate the file trees.h describing the static trees.
  19.323 + */
  19.324 +#ifdef GEN_TREES_H
  19.325 +#  ifndef DEBUG
  19.326 +#    include <stdio.h>
  19.327 +#  endif
  19.328 +
  19.329 +#  define SEPARATOR(i, last, width) \
  19.330 +      ((i) == (last)? "\n};\n\n" :    \
  19.331 +       ((i) % (width) == (width)-1 ? ",\n" : ", "))
  19.332 +
  19.333 +void gen_trees_header()
  19.334 +{
  19.335 +    FILE *header = fopen("trees.h", "w");
  19.336 +    int i;
  19.337 +
  19.338 +    Assert (header != NULL, "Can't open trees.h");
  19.339 +    fprintf(header,
  19.340 +            "/* header created automatically with -DGEN_TREES_H */\n\n");
  19.341 +
  19.342 +    fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  19.343 +    for (i = 0; i < L_CODES+2; i++) {
  19.344 +        fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  19.345 +                static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  19.346 +    }
  19.347 +
  19.348 +    fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  19.349 +    for (i = 0; i < D_CODES; i++) {
  19.350 +        fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  19.351 +                static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  19.352 +    }
  19.353 +
  19.354 +    fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  19.355 +    for (i = 0; i < DIST_CODE_LEN; i++) {
  19.356 +        fprintf(header, "%2u%s", _dist_code[i],
  19.357 +                SEPARATOR(i, DIST_CODE_LEN-1, 20));
  19.358 +    }
  19.359 +
  19.360 +    fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  19.361 +    for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  19.362 +        fprintf(header, "%2u%s", _length_code[i],
  19.363 +                SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  19.364 +    }
  19.365 +
  19.366 +    fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  19.367 +    for (i = 0; i < LENGTH_CODES; i++) {
  19.368 +        fprintf(header, "%1u%s", base_length[i],
  19.369 +                SEPARATOR(i, LENGTH_CODES-1, 20));
  19.370 +    }
  19.371 +
  19.372 +    fprintf(header, "local const int base_dist[D_CODES] = {\n");
  19.373 +    for (i = 0; i < D_CODES; i++) {
  19.374 +        fprintf(header, "%5u%s", base_dist[i],
  19.375 +                SEPARATOR(i, D_CODES-1, 10));
  19.376 +    }
  19.377 +
  19.378 +    fclose(header);
  19.379 +}
  19.380 +#endif /* GEN_TREES_H */
  19.381 +
  19.382 +/* ===========================================================================
  19.383 + * Initialize the tree data structures for a new zlib stream.
  19.384 + */
  19.385 +void _tr_init(s)
  19.386 +    deflate_state *s;
  19.387 +{
  19.388 +    tr_static_init();
  19.389 +
  19.390 +    s->l_desc.dyn_tree = s->dyn_ltree;
  19.391 +    s->l_desc.stat_desc = &static_l_desc;
  19.392 +
  19.393 +    s->d_desc.dyn_tree = s->dyn_dtree;
  19.394 +    s->d_desc.stat_desc = &static_d_desc;
  19.395 +
  19.396 +    s->bl_desc.dyn_tree = s->bl_tree;
  19.397 +    s->bl_desc.stat_desc = &static_bl_desc;
  19.398 +
  19.399 +    s->bi_buf = 0;
  19.400 +    s->bi_valid = 0;
  19.401 +    s->last_eob_len = 8; /* enough lookahead for inflate */
  19.402 +#ifdef DEBUG
  19.403 +    s->compressed_len = 0L;
  19.404 +    s->bits_sent = 0L;
  19.405 +#endif
  19.406 +
  19.407 +    /* Initialize the first block of the first file: */
  19.408 +    init_block(s);
  19.409 +}
  19.410 +
  19.411 +/* ===========================================================================
  19.412 + * Initialize a new block.
  19.413 + */
  19.414 +local void init_block(s)
  19.415 +    deflate_state *s;
  19.416 +{
  19.417 +    int n; /* iterates over tree elements */
  19.418 +
  19.419 +    /* Initialize the trees. */
  19.420 +    for (n = 0; n < L_CODES;  n++) s->dyn_ltree[n].Freq = 0;
  19.421 +    for (n = 0; n < D_CODES;  n++) s->dyn_dtree[n].Freq = 0;
  19.422 +    for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  19.423 +
  19.424 +    s->dyn_ltree[END_BLOCK].Freq = 1;
  19.425 +    s->opt_len = s->static_len = 0L;
  19.426 +    s->last_lit = s->matches = 0;
  19.427 +}
  19.428 +
  19.429 +#define SMALLEST 1
  19.430 +/* Index within the heap array of least frequent node in the Huffman tree */
  19.431 +
  19.432 +
  19.433 +/* ===========================================================================
  19.434 + * Remove the smallest element from the heap and recreate the heap with
  19.435 + * one less element. Updates heap and heap_len.
  19.436 + */
  19.437 +#define pqremove(s, tree, top) \
  19.438 +{\
  19.439 +    top = s->heap[SMALLEST]; \
  19.440 +    s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  19.441 +    pqdownheap(s, tree, SMALLEST); \
  19.442 +}
  19.443 +
  19.444 +/* ===========================================================================
  19.445 + * Compares to subtrees, using the tree depth as tie breaker when
  19.446 + * the subtrees have equal frequency. This minimizes the worst case length.
  19.447 + */
  19.448 +#define smaller(tree, n, m, depth) \
  19.449 +   (tree[n].Freq < tree[m].Freq || \
  19.450 +   (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  19.451 +
  19.452 +/* ===========================================================================
  19.453 + * Restore the heap property by moving down the tree starting at node k,
  19.454 + * exchanging a node with the smallest of its two sons if necessary, stopping
  19.455 + * when the heap property is re-established (each father smaller than its
  19.456 + * two sons).
  19.457 + */
  19.458 +local void pqdownheap(s, tree, k)
  19.459 +    deflate_state *s;
  19.460 +    ct_data *tree;  /* the tree to restore */
  19.461 +    int k;               /* node to move down */
  19.462 +{
  19.463 +    int v = s->heap[k];
  19.464 +    int j = k << 1;  /* left son of k */
  19.465 +    while (j <= s->heap_len) {
  19.466 +        /* Set j to the smallest of the two sons: */
  19.467 +        if (j < s->heap_len &&
  19.468 +            smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  19.469 +            j++;
  19.470 +        }
  19.471 +        /* Exit if v is smaller than both sons */
  19.472 +        if (smaller(tree, v, s->heap[j], s->depth)) break;
  19.473 +
  19.474 +        /* Exchange v with the smallest son */
  19.475 +        s->heap[k] = s->heap[j];  k = j;
  19.476 +
  19.477 +        /* And continue down the tree, setting j to the left son of k */
  19.478 +        j <<= 1;
  19.479 +    }
  19.480 +    s->heap[k] = v;
  19.481 +}
  19.482 +
  19.483 +/* ===========================================================================
  19.484 + * Compute the optimal bit lengths for a tree and update the total bit length
  19.485 + * for the current block.
  19.486 + * IN assertion: the fields freq and dad are set, heap[heap_max] and
  19.487 + *    above are the tree nodes sorted by increasing frequency.
  19.488 + * OUT assertions: the field len is set to the optimal bit length, the
  19.489 + *     array bl_count contains the frequencies for each bit length.
  19.490 + *     The length opt_len is updated; static_len is also updated if stree is
  19.491 + *     not null.
  19.492 + */
  19.493 +local void gen_bitlen(s, desc)
  19.494 +    deflate_state *s;
  19.495 +    tree_desc *desc;    /* the tree descriptor */
  19.496 +{
  19.497 +    ct_data *tree        = desc->dyn_tree;
  19.498 +    int max_code         = desc->max_code;
  19.499 +    const ct_data *stree = desc->stat_desc->static_tree;
  19.500 +    const intf *extra    = desc->stat_desc->extra_bits;
  19.501 +    int base             = desc->stat_desc->extra_base;
  19.502 +    int max_length       = desc->stat_desc->max_length;
  19.503 +    int h;              /* heap index */
  19.504 +    int n, m;           /* iterate over the tree elements */
  19.505 +    int bits;           /* bit length */
  19.506 +    int xbits;          /* extra bits */
  19.507 +    ush f;              /* frequency */
  19.508 +    int overflow = 0;   /* number of elements with bit length too large */
  19.509 +
  19.510 +    for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  19.511 +
  19.512 +    /* In a first pass, compute the optimal bit lengths (which may
  19.513 +     * overflow in the case of the bit length tree).
  19.514 +     */
  19.515 +    tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  19.516 +
  19.517 +    for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  19.518 +        n = s->heap[h];
  19.519 +        bits = tree[tree[n].Dad].Len + 1;
  19.520 +        if (bits > max_length) bits = max_length, overflow++;
  19.521 +        tree[n].Len = (ush)bits;
  19.522 +        /* We overwrite tree[n].Dad which is no longer needed */
  19.523 +
  19.524 +        if (n > max_code) continue; /* not a leaf node */
  19.525 +
  19.526 +        s->bl_count[bits]++;
  19.527 +        xbits = 0;
  19.528 +        if (n >= base) xbits = extra[n-base];
  19.529 +        f = tree[n].Freq;
  19.530 +        s->opt_len += (ulg)f * (bits + xbits);
  19.531 +        if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  19.532 +    }
  19.533 +    if (overflow == 0) return;
  19.534 +
  19.535 +    Trace((stderr,"\nbit length overflow\n"));
  19.536 +    /* This happens for example on obj2 and pic of the Calgary corpus */
  19.537 +
  19.538 +    /* Find the first bit length which could increase: */
  19.539 +    do {
  19.540 +        bits = max_length-1;
  19.541 +        while (s->bl_count[bits] == 0) bits--;
  19.542 +        s->bl_count[bits]--;      /* move one leaf down the tree */
  19.543 +        s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  19.544 +        s->bl_count[max_length]--;
  19.545 +        /* The brother of the overflow item also moves one step up,
  19.546 +         * but this does not affect bl_count[max_length]
  19.547 +         */
  19.548 +        overflow -= 2;
  19.549 +    } while (overflow > 0);
  19.550 +
  19.551 +    /* Now recompute all bit lengths, scanning in increasing frequency.
  19.552 +     * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  19.553 +     * lengths instead of fixing only the wrong ones. This idea is taken
  19.554 +     * from 'ar' written by Haruhiko Okumura.)
  19.555 +     */
  19.556 +    for (bits = max_length; bits != 0; bits--) {
  19.557 +        n = s->bl_count[bits];
  19.558 +        while (n != 0) {
  19.559 +            m = s->heap[--h];
  19.560 +            if (m > max_code) continue;
  19.561 +            if ((unsigned) tree[m].Len != (unsigned) bits) {
  19.562 +                Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  19.563 +                s->opt_len += ((long)bits - (long)tree[m].Len)
  19.564 +                              *(long)tree[m].Freq;
  19.565 +                tree[m].Len = (ush)bits;
  19.566 +            }
  19.567 +            n--;
  19.568 +        }
  19.569 +    }
  19.570 +}
  19.571 +
  19.572 +/* ===========================================================================
  19.573 + * Generate the codes for a given tree and bit counts (which need not be
  19.574 + * optimal).
  19.575 + * IN assertion: the array bl_count contains the bit length statistics for
  19.576 + * the given tree and the field len is set for all tree elements.
  19.577 + * OUT assertion: the field code is set for all tree elements of non
  19.578 + *     zero code length.
  19.579 + */
  19.580 +local void gen_codes (tree, max_code, bl_count)
  19.581 +    ct_data *tree;             /* the tree to decorate */
  19.582 +    int max_code;              /* largest code with non zero frequency */
  19.583 +    ushf *bl_count;            /* number of codes at each bit length */
  19.584 +{
  19.585 +    ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  19.586 +    ush code = 0;              /* running code value */
  19.587 +    int bits;                  /* bit index */
  19.588 +    int n;                     /* code index */
  19.589 +
  19.590 +    /* The distribution counts are first used to generate the code values
  19.591 +     * without bit reversal.
  19.592 +     */
  19.593 +    for (bits = 1; bits <= MAX_BITS; bits++) {
  19.594 +        next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  19.595 +    }
  19.596 +    /* Check that the bit counts in bl_count are consistent. The last code
  19.597 +     * must be all ones.
  19.598 +     */
  19.599 +    Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  19.600 +            "inconsistent bit counts");
  19.601 +    Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  19.602 +
  19.603 +    for (n = 0;  n <= max_code; n++) {
  19.604 +        int len = tree[n].Len;
  19.605 +        if (len == 0) continue;
  19.606 +        /* Now reverse the bits */
  19.607 +        tree[n].Code = bi_reverse(next_code[len]++, len);
  19.608 +
  19.609 +        Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  19.610 +             n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  19.611 +    }
  19.612 +}
  19.613 +
  19.614 +/* ===========================================================================
  19.615 + * Construct one Huffman tree and assigns the code bit strings and lengths.
  19.616 + * Update the total bit length for the current block.
  19.617 + * IN assertion: the field freq is set for all tree elements.
  19.618 + * OUT assertions: the fields len and code are set to the optimal bit length
  19.619 + *     and corresponding code. The length opt_len is updated; static_len is
  19.620 + *     also updated if stree is not null. The field max_code is set.
  19.621 + */
  19.622 +local void build_tree(s, desc)
  19.623 +    deflate_state *s;
  19.624 +    tree_desc *desc; /* the tree descriptor */
  19.625 +{
  19.626 +    ct_data *tree         = desc->dyn_tree;
  19.627 +    const ct_data *stree  = desc->stat_desc->static_tree;
  19.628 +    int elems             = desc->stat_desc->elems;
  19.629 +    int n, m;          /* iterate over heap elements */
  19.630 +    int max_code = -1; /* largest code with non zero frequency */
  19.631 +    int node;          /* new node being created */
  19.632 +
  19.633 +    /* Construct the initial heap, with least frequent element in
  19.634 +     * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  19.635 +     * heap[0] is not used.
  19.636 +     */
  19.637 +    s->heap_len = 0, s->heap_max = HEAP_SIZE;
  19.638 +
  19.639 +    for (n = 0; n < elems; n++) {
  19.640 +        if (tree[n].Freq != 0) {
  19.641 +            s->heap[++(s->heap_len)] = max_code = n;
  19.642 +            s->depth[n] = 0;
  19.643 +        } else {
  19.644 +            tree[n].Len = 0;
  19.645 +        }
  19.646 +    }
  19.647 +
  19.648 +    /* The pkzip format requires that at least one distance code exists,
  19.649 +     * and that at least one bit should be sent even if there is only one
  19.650 +     * possible code. So to avoid special checks later on we force at least
  19.651 +     * two codes of non zero frequency.
  19.652 +     */
  19.653 +    while (s->heap_len < 2) {
  19.654 +        node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  19.655 +        tree[node].Freq = 1;
  19.656 +        s->depth[node] = 0;
  19.657 +        s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  19.658 +        /* node is 0 or 1 so it does not have extra bits */
  19.659 +    }
  19.660 +    desc->max_code = max_code;
  19.661 +
  19.662 +    /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  19.663 +     * establish sub-heaps of increasing lengths:
  19.664 +     */
  19.665 +    for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  19.666 +
  19.667 +    /* Construct the Huffman tree by repeatedly combining the least two
  19.668 +     * frequent nodes.
  19.669 +     */
  19.670 +    node = elems;              /* next internal node of the tree */
  19.671 +    do {
  19.672 +        pqremove(s, tree, n);  /* n = node of least frequency */
  19.673 +        m = s->heap[SMALLEST]; /* m = node of next least frequency */
  19.674 +
  19.675 +        s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  19.676 +        s->heap[--(s->heap_max)] = m;
  19.677 +
  19.678 +        /* Create a new node father of n and m */
  19.679 +        tree[node].Freq = tree[n].Freq + tree[m].Freq;
  19.680 +        s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  19.681 +                                s->depth[n] : s->depth[m]) + 1);
  19.682 +        tree[n].Dad = tree[m].Dad = (ush)node;
  19.683 +#ifdef DUMP_BL_TREE
  19.684 +        if (tree == s->bl_tree) {
  19.685 +            fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  19.686 +                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  19.687 +        }
  19.688 +#endif
  19.689 +        /* and insert the new node in the heap */
  19.690 +        s->heap[SMALLEST] = node++;
  19.691 +        pqdownheap(s, tree, SMALLEST);
  19.692 +
  19.693 +    } while (s->heap_len >= 2);
  19.694 +
  19.695 +    s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  19.696 +
  19.697 +    /* At this point, the fields freq and dad are set. We can now
  19.698 +     * generate the bit lengths.
  19.699 +     */
  19.700 +    gen_bitlen(s, (tree_desc *)desc);
  19.701 +
  19.702 +    /* The field len is now set, we can generate the bit codes */
  19.703 +    gen_codes ((ct_data *)tree, max_code, s->bl_count);
  19.704 +}
  19.705 +
  19.706 +/* ===========================================================================
  19.707 + * Scan a literal or distance tree to determine the frequencies of the codes
  19.708 + * in the bit length tree.
  19.709 + */
  19.710 +local void scan_tree (s, tree, max_code)
  19.711 +    deflate_state *s;
  19.712 +    ct_data *tree;   /* the tree to be scanned */
  19.713 +    int max_code;    /* and its largest code of non zero frequency */
  19.714 +{
  19.715 +    int n;                     /* iterates over all tree elements */
  19.716 +    int prevlen = -1;          /* last emitted length */
  19.717 +    int curlen;                /* length of current code */
  19.718 +    int nextlen = tree[0].Len; /* length of next code */
  19.719 +    int count = 0;             /* repeat count of the current code */
  19.720 +    int max_count = 7;         /* max repeat count */
  19.721 +    int min_count = 4;         /* min repeat count */
  19.722 +
  19.723 +    if (nextlen == 0) max_count = 138, min_count = 3;
  19.724 +    tree[max_code+1].Len = (ush)0xffff; /* guard */
  19.725 +
  19.726 +    for (n = 0; n <= max_code; n++) {
  19.727 +        curlen = nextlen; nextlen = tree[n+1].Len;
  19.728 +        if (++count < max_count && curlen == nextlen) {
  19.729 +            continue;
  19.730 +        } else if (count < min_count) {
  19.731 +            s->bl_tree[curlen].Freq += count;
  19.732 +        } else if (curlen != 0) {
  19.733 +            if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  19.734 +            s->bl_tree[REP_3_6].Freq++;
  19.735 +        } else if (count <= 10) {
  19.736 +            s->bl_tree[REPZ_3_10].Freq++;
  19.737 +        } else {
  19.738 +            s->bl_tree[REPZ_11_138].Freq++;
  19.739 +        }
  19.740 +        count = 0; prevlen = curlen;
  19.741 +        if (nextlen == 0) {
  19.742 +            max_count = 138, min_count = 3;
  19.743 +        } else if (curlen == nextlen) {
  19.744 +            max_count = 6, min_count = 3;
  19.745 +        } else {
  19.746 +            max_count = 7, min_count = 4;
  19.747 +        }
  19.748 +    }
  19.749 +}
  19.750 +
  19.751 +/* ===========================================================================
  19.752 + * Send a literal or distance tree in compressed form, using the codes in
  19.753 + * bl_tree.
  19.754 + */
  19.755 +local void send_tree (s, tree, max_code)
  19.756 +    deflate_state *s;
  19.757 +    ct_data *tree; /* the tree to be scanned */
  19.758 +    int max_code;       /* and its largest code of non zero frequency */
  19.759 +{
  19.760 +    int n;                     /* iterates over all tree elements */
  19.761 +    int prevlen = -1;          /* last emitted length */
  19.762 +    int curlen;                /* length of current code */
  19.763 +    int nextlen = tree[0].Len; /* length of next code */
  19.764 +    int count = 0;             /* repeat count of the current code */
  19.765 +    int max_count = 7;         /* max repeat count */
  19.766 +    int min_count = 4;         /* min repeat count */
  19.767 +
  19.768 +    /* tree[max_code+1].Len = -1; */  /* guard already set */
  19.769 +    if (nextlen == 0) max_count = 138, min_count = 3;
  19.770 +
  19.771 +    for (n = 0; n <= max_code; n++) {
  19.772 +        curlen = nextlen; nextlen = tree[n+1].Len;
  19.773 +        if (++count < max_count && curlen == nextlen) {
  19.774 +            continue;
  19.775 +        } else if (count < min_count) {
  19.776 +            do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  19.777 +
  19.778 +        } else if (curlen != 0) {
  19.779 +            if (curlen != prevlen) {
  19.780 +                send_code(s, curlen, s->bl_tree); count--;
  19.781 +            }
  19.782 +            Assert(count >= 3 && count <= 6, " 3_6?");
  19.783 +            send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  19.784 +
  19.785 +        } else if (count <= 10) {
  19.786 +            send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  19.787 +
  19.788 +        } else {
  19.789 +            send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  19.790 +        }
  19.791 +        count = 0; prevlen = curlen;
  19.792 +        if (nextlen == 0) {
  19.793 +            max_count = 138, min_count = 3;
  19.794 +        } else if (curlen == nextlen) {
  19.795 +            max_count = 6, min_count = 3;
  19.796 +        } else {
  19.797 +            max_count = 7, min_count = 4;
  19.798 +        }
  19.799 +    }
  19.800 +}
  19.801 +
  19.802 +/* ===========================================================================
  19.803 + * Construct the Huffman tree for the bit lengths and return the index in
  19.804 + * bl_order of the last bit length code to send.
  19.805 + */
  19.806 +local int build_bl_tree(s)
  19.807 +    deflate_state *s;
  19.808 +{
  19.809 +    int max_blindex;  /* index of last bit length code of non zero freq */
  19.810 +
  19.811 +    /* Determine the bit length frequencies for literal and distance trees */
  19.812 +    scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  19.813 +    scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  19.814 +
  19.815 +    /* Build the bit length tree: */
  19.816 +    build_tree(s, (tree_desc *)(&(s->bl_desc)));
  19.817 +    /* opt_len now includes the length of the tree representations, except
  19.818 +     * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  19.819 +     */
  19.820 +
  19.821 +    /* Determine the number of bit length codes to send. The pkzip format
  19.822 +     * requires that at least 4 bit length codes be sent. (appnote.txt says
  19.823 +     * 3 but the actual value used is 4.)
  19.824 +     */
  19.825 +    for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  19.826 +        if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  19.827 +    }
  19.828 +    /* Update opt_len to include the bit length tree and counts */
  19.829 +    s->opt_len += 3*(max_blindex+1) + 5+5+4;
  19.830 +    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  19.831 +            s->opt_len, s->static_len));
  19.832 +
  19.833 +    return max_blindex;
  19.834 +}
  19.835 +
  19.836 +/* ===========================================================================
  19.837 + * Send the header for a block using dynamic Huffman trees: the counts, the
  19.838 + * lengths of the bit length codes, the literal tree and the distance tree.
  19.839 + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  19.840 + */
  19.841 +local void send_all_trees(s, lcodes, dcodes, blcodes)
  19.842 +    deflate_state *s;
  19.843 +    int lcodes, dcodes, blcodes; /* number of codes for each tree */
  19.844 +{
  19.845 +    int rank;                    /* index in bl_order */
  19.846 +
  19.847 +    Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  19.848 +    Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  19.849 +            "too many codes");
  19.850 +    Tracev((stderr, "\nbl counts: "));
  19.851 +    send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  19.852 +    send_bits(s, dcodes-1,   5);
  19.853 +    send_bits(s, blcodes-4,  4); /* not -3 as stated in appnote.txt */
  19.854 +    for (rank = 0; rank < blcodes; rank++) {
  19.855 +        Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  19.856 +        send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  19.857 +    }
  19.858 +    Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  19.859 +
  19.860 +    send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  19.861 +    Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  19.862 +
  19.863 +    send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  19.864 +    Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  19.865 +}
  19.866 +
  19.867 +/* ===========================================================================
  19.868 + * Send a stored block
  19.869 + */
  19.870 +void _tr_stored_block(s, buf, stored_len, eof)
  19.871 +    deflate_state *s;
  19.872 +    charf *buf;       /* input block */
  19.873 +    ulg stored_len;   /* length of input block */
  19.874 +    int eof;          /* true if this is the last block for a file */
  19.875 +{
  19.876 +    send_bits(s, (STORED_BLOCK<<1)+eof, 3);  /* send block type */
  19.877 +#ifdef DEBUG
  19.878 +    s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  19.879 +    s->compressed_len += (stored_len + 4) << 3;
  19.880 +#endif
  19.881 +    copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  19.882 +}
  19.883 +
  19.884 +/* ===========================================================================
  19.885 + * Send one empty static block to give enough lookahead for inflate.
  19.886 + * This takes 10 bits, of which 7 may remain in the bit buffer.
  19.887 + * The current inflate code requires 9 bits of lookahead. If the
  19.888 + * last two codes for the previous block (real code plus EOB) were coded
  19.889 + * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
  19.890 + * the last real code. In this case we send two empty static blocks instead
  19.891 + * of one. (There are no problems if the previous block is stored or fixed.)
  19.892 + * To simplify the code, we assume the worst case of last real code encoded
  19.893 + * on one bit only.
  19.894 + */
  19.895 +void _tr_align(s)
  19.896 +    deflate_state *s;
  19.897 +{
  19.898 +    send_bits(s, STATIC_TREES<<1, 3);
  19.899 +    send_code(s, END_BLOCK, static_ltree);
  19.900 +#ifdef DEBUG
  19.901 +    s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  19.902 +#endif
  19.903 +    bi_flush(s);
  19.904 +    /* Of the 10 bits for the empty block, we have already sent
  19.905 +     * (10 - bi_valid) bits. The lookahead for the last real code (before
  19.906 +     * the EOB of the previous block) was thus at least one plus the length
  19.907 +     * of the EOB plus what we have just sent of the empty static block.
  19.908 +     */
  19.909 +    if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  19.910 +        send_bits(s, STATIC_TREES<<1, 3);
  19.911 +        send_code(s, END_BLOCK, static_ltree);
  19.912 +#ifdef DEBUG
  19.913 +        s->compressed_len += 10L;
  19.914 +#endif
  19.915 +        bi_flush(s);
  19.916 +    }
  19.917 +    s->last_eob_len = 7;
  19.918 +}
  19.919 +
  19.920 +/* ===========================================================================
  19.921 + * Determine the best encoding for the current block: dynamic trees, static
  19.922 + * trees or store, and output the encoded block to the zip file.
  19.923 + */
  19.924 +void _tr_flush_block(s, buf, stored_len, eof)
  19.925 +    deflate_state *s;
  19.926 +    charf *buf;       /* input block, or NULL if too old */
  19.927 +    ulg stored_len;   /* length of input block */
  19.928 +    int eof;          /* true if this is the last block for a file */
  19.929 +{
  19.930 +    ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  19.931 +    int max_blindex = 0;  /* index of last bit length code of non zero freq */
  19.932 +
  19.933 +    /* Build the Huffman trees unless a stored block is forced */
  19.934 +    if (s->level > 0) {
  19.935 +
  19.936 +        /* Check if the file is binary or text */
  19.937 +        if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  19.938 +            set_data_type(s);
  19.939 +
  19.940 +        /* Construct the literal and distance trees */
  19.941 +        build_tree(s, (tree_desc *)(&(s->l_desc)));
  19.942 +        Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  19.943 +                s->static_len));
  19.944 +
  19.945 +        build_tree(s, (tree_desc *)(&(s->d_desc)));
  19.946 +        Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  19.947 +                s->static_len));
  19.948 +        /* At this point, opt_len and static_len are the total bit lengths of
  19.949 +         * the compressed block data, excluding the tree representations.
  19.950 +         */
  19.951 +
  19.952 +        /* Build the bit length tree for the above two trees, and get the index
  19.953 +         * in bl_order of the last bit length code to send.
  19.954 +         */
  19.955 +        max_blindex = build_bl_tree(s);
  19.956 +
  19.957 +        /* Determine the best encoding. Compute the block lengths in bytes. */
  19.958 +        opt_lenb = (s->opt_len+3+7)>>3;
  19.959 +        static_lenb = (s->static_len+3+7)>>3;
  19.960 +
  19.961 +        Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  19.962 +                opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  19.963 +                s->last_lit));
  19.964 +
  19.965 +        if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  19.966 +
  19.967 +    } else {
  19.968 +        Assert(buf != (char*)0, "lost buf");
  19.969 +        opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  19.970 +    }
  19.971 +
  19.972 +#ifdef FORCE_STORED
  19.973 +    if (buf != (char*)0) { /* force stored block */
  19.974 +#else
  19.975 +    if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  19.976 +                       /* 4: two words for the lengths */
  19.977 +#endif
  19.978 +        /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  19.979 +         * Otherwise we can't have processed more than WSIZE input bytes since
  19.980 +         * the last block flush, because compression would have been
  19.981 +         * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  19.982 +         * transform a block into a stored block.
  19.983 +         */
  19.984 +        _tr_stored_block(s, buf, stored_len, eof);
  19.985 +
  19.986 +#ifdef FORCE_STATIC
  19.987 +    } else if (static_lenb >= 0) { /* force static trees */
  19.988 +#else
  19.989 +    } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  19.990 +#endif
  19.991 +        send_bits(s, (STATIC_TREES<<1)+eof, 3);
  19.992 +        compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  19.993 +#ifdef DEBUG
  19.994 +        s->compressed_len += 3 + s->static_len;
  19.995 +#endif
  19.996 +    } else {
  19.997 +        send_bits(s, (DYN_TREES<<1)+eof, 3);
  19.998 +        send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  19.999 +                       max_blindex+1);
 19.1000 +        compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
 19.1001 +#ifdef DEBUG
 19.1002 +        s->compressed_len += 3 + s->opt_len;
 19.1003 +#endif
 19.1004 +    }
 19.1005 +    Assert (s->compressed_len == s->bits_sent, "bad compressed size");
 19.1006 +    /* The above check is made mod 2^32, for files larger than 512 MB
 19.1007 +     * and uLong implemented on 32 bits.
 19.1008 +     */
 19.1009 +    init_block(s);
 19.1010 +
 19.1011 +    if (eof) {
 19.1012 +        bi_windup(s);
 19.1013 +#ifdef DEBUG
 19.1014 +        s->compressed_len += 7;  /* align on byte boundary */
 19.1015 +#endif
 19.1016 +    }
 19.1017 +    Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
 19.1018 +           s->compressed_len-7*eof));
 19.1019 +}
 19.1020 +
 19.1021 +/* ===========================================================================
 19.1022 + * Save the match info and tally the frequency counts. Return true if
 19.1023 + * the current block must be flushed.
 19.1024 + */
 19.1025 +int _tr_tally (s, dist, lc)
 19.1026 +    deflate_state *s;
 19.1027 +    unsigned dist;  /* distance of matched string */
 19.1028 +    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
 19.1029 +{
 19.1030 +    s->d_buf[s->last_lit] = (ush)dist;
 19.1031 +    s->l_buf[s->last_lit++] = (uch)lc;
 19.1032 +    if (dist == 0) {
 19.1033 +        /* lc is the unmatched char */
 19.1034 +        s->dyn_ltree[lc].Freq++;
 19.1035 +    } else {
 19.1036 +        s->matches++;
 19.1037 +        /* Here, lc is the match length - MIN_MATCH */
 19.1038 +        dist--;             /* dist = match distance - 1 */
 19.1039 +        Assert((ush)dist < (ush)MAX_DIST(s) &&
 19.1040 +               (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
 19.1041 +               (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
 19.1042 +
 19.1043 +        s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
 19.1044 +        s->dyn_dtree[d_code(dist)].Freq++;
 19.1045 +    }
 19.1046 +
 19.1047 +#ifdef TRUNCATE_BLOCK
 19.1048 +    /* Try to guess if it is profitable to stop the current block here */
 19.1049 +    if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
 19.1050 +        /* Compute an upper bound for the compressed length */
 19.1051 +        ulg out_length = (ulg)s->last_lit*8L;
 19.1052 +        ulg in_length = (ulg)((long)s->strstart - s->block_start);
 19.1053 +        int dcode;
 19.1054 +        for (dcode = 0; dcode < D_CODES; dcode++) {
 19.1055 +            out_length += (ulg)s->dyn_dtree[dcode].Freq *
 19.1056 +                (5L+extra_dbits[dcode]);
 19.1057 +        }
 19.1058 +        out_length >>= 3;
 19.1059 +        Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
 19.1060 +               s->last_lit, in_length, out_length,
 19.1061 +               100L - out_length*100L/in_length));
 19.1062 +        if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
 19.1063 +    }
 19.1064 +#endif
 19.1065 +    return (s->last_lit == s->lit_bufsize-1);
 19.1066 +    /* We avoid equality with lit_bufsize because of wraparound at 64K
 19.1067 +     * on 16 bit machines and because stored blocks are restricted to
 19.1068 +     * 64K-1 bytes.
 19.1069 +     */
 19.1070 +}
 19.1071 +
 19.1072 +/* ===========================================================================
 19.1073 + * Send the block data compressed using the given Huffman trees
 19.1074 + */
 19.1075 +local void compress_block(s, ltree, dtree)
 19.1076 +    deflate_state *s;
 19.1077 +    ct_data *ltree; /* literal tree */
 19.1078 +    ct_data *dtree; /* distance tree */
 19.1079 +{
 19.1080 +    unsigned dist;      /* distance of matched string */
 19.1081 +    int lc;             /* match length or unmatched char (if dist == 0) */
 19.1082 +    unsigned lx = 0;    /* running index in l_buf */
 19.1083 +    unsigned code;      /* the code to send */
 19.1084 +    int extra;          /* number of extra bits to send */
 19.1085 +
 19.1086 +    if (s->last_lit != 0) do {
 19.1087 +        dist = s->d_buf[lx];
 19.1088 +        lc = s->l_buf[lx++];
 19.1089 +        if (dist == 0) {
 19.1090 +            send_code(s, lc, ltree); /* send a literal byte */
 19.1091 +            Tracecv(isgraph(lc), (stderr," '%c' ", lc));
 19.1092 +        } else {
 19.1093 +            /* Here, lc is the match length - MIN_MATCH */
 19.1094 +            code = _length_code[lc];
 19.1095 +            send_code(s, code+LITERALS+1, ltree); /* send the length code */
 19.1096 +            extra = extra_lbits[code];
 19.1097 +            if (extra != 0) {
 19.1098 +                lc -= base_length[code];
 19.1099 +                send_bits(s, lc, extra);       /* send the extra length bits */
 19.1100 +            }
 19.1101 +            dist--; /* dist is now the match distance - 1 */
 19.1102 +            code = d_code(dist);
 19.1103 +            Assert (code < D_CODES, "bad d_code");
 19.1104 +
 19.1105 +            send_code(s, code, dtree);       /* send the distance code */
 19.1106 +            extra = extra_dbits[code];
 19.1107 +            if (extra != 0) {
 19.1108 +                dist -= base_dist[code];
 19.1109 +                send_bits(s, dist, extra);   /* send the extra distance bits */
 19.1110 +            }
 19.1111 +        } /* literal or match pair ? */
 19.1112 +
 19.1113 +        /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
 19.1114 +        Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
 19.1115 +               "pendingBuf overflow");
 19.1116 +
 19.1117 +    } while (lx < s->last_lit);
 19.1118 +
 19.1119 +    send_code(s, END_BLOCK, ltree);
 19.1120 +    s->last_eob_len = ltree[END_BLOCK].Len;
 19.1121 +}
 19.1122 +
 19.1123 +/* ===========================================================================
 19.1124 + * Set the data type to BINARY or TEXT, using a crude approximation:
 19.1125 + * set it to Z_TEXT if all symbols are either printable characters (33 to 255)
 19.1126 + * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
 19.1127 + * IN assertion: the fields Freq of dyn_ltree are set.
 19.1128 + */
 19.1129 +local void set_data_type(s)
 19.1130 +    deflate_state *s;
 19.1131 +{
 19.1132 +    int n;
 19.1133 +
 19.1134 +    for (n = 0; n < 9; n++)
 19.1135 +        if (s->dyn_ltree[n].Freq != 0)
 19.1136 +            break;
 19.1137 +    if (n == 9)
 19.1138 +        for (n = 14; n < 32; n++)
 19.1139 +            if (s->dyn_ltree[n].Freq != 0)
 19.1140 +                break;
 19.1141 +    s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
 19.1142 +}
 19.1143 +
 19.1144 +/* ===========================================================================
 19.1145 + * Reverse the first len bits of a code, using straightforward code (a faster
 19.1146 + * method would use a table)
 19.1147 + * IN assertion: 1 <= len <= 15
 19.1148 + */
 19.1149 +local unsigned bi_reverse(code, len)
 19.1150 +    unsigned code; /* the value to invert */
 19.1151 +    int len;       /* its bit length */
 19.1152 +{
 19.1153 +    register unsigned res = 0;
 19.1154 +    do {
 19.1155 +        res |= code & 1;
 19.1156 +        code >>= 1, res <<= 1;
 19.1157 +    } while (--len > 0);
 19.1158 +    return res >> 1;
 19.1159 +}
 19.1160 +
 19.1161 +/* ===========================================================================
 19.1162 + * Flush the bit buffer, keeping at most 7 bits in it.
 19.1163 + */
 19.1164 +local void bi_flush(s)
 19.1165 +    deflate_state *s;
 19.1166 +{
 19.1167 +    if (s->bi_valid == 16) {
 19.1168 +        put_short(s, s->bi_buf);
 19.1169 +        s->bi_buf = 0;
 19.1170 +        s->bi_valid = 0;
 19.1171 +    } else if (s->bi_valid >= 8) {
 19.1172 +        put_byte(s, (Byte)s->bi_buf);
 19.1173 +        s->bi_buf >>= 8;
 19.1174 +        s->bi_valid -= 8;
 19.1175 +    }
 19.1176 +}
 19.1177 +
 19.1178 +/* ===========================================================================
 19.1179 + * Flush the bit buffer and align the output on a byte boundary
 19.1180 + */
 19.1181 +local void bi_windup(s)
 19.1182 +    deflate_state *s;
 19.1183 +{
 19.1184 +    if (s->bi_valid > 8) {
 19.1185 +        put_short(s, s->bi_buf);
 19.1186 +    } else if (s->bi_valid > 0) {
 19.1187 +        put_byte(s, (Byte)s->bi_buf);
 19.1188 +    }
 19.1189 +    s->bi_buf = 0;
 19.1190 +    s->bi_valid = 0;
 19.1191 +#ifdef DEBUG
 19.1192 +    s->bits_sent = (s->bits_sent+7) & ~7;
 19.1193 +#endif
 19.1194 +}
 19.1195 +
 19.1196 +/* ===========================================================================
 19.1197 + * Copy a stored block, storing first the length and its
 19.1198 + * one's complement if requested.
 19.1199 + */
 19.1200 +local void copy_block(s, buf, len, header)
 19.1201 +    deflate_state *s;
 19.1202 +    charf    *buf;    /* the input data */
 19.1203 +    unsigned len;     /* its length */
 19.1204 +    int      header;  /* true if block header must be written */
 19.1205 +{
 19.1206 +    bi_windup(s);        /* align on byte boundary */
 19.1207 +    s->last_eob_len = 8; /* enough lookahead for inflate */
 19.1208 +
 19.1209 +    if (header) {
 19.1210 +        put_short(s, (ush)len);
 19.1211 +        put_short(s, (ush)~len);
 19.1212 +#ifdef DEBUG
 19.1213 +        s->bits_sent += 2*16;
 19.1214 +#endif
 19.1215 +    }
 19.1216 +#ifdef DEBUG
 19.1217 +    s->bits_sent += (ulg)len<<3;
 19.1218 +#endif
 19.1219 +    while (len--) {
 19.1220 +        put_byte(s, *buf++);
 19.1221 +    }
 19.1222 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/compiler-init/zlib/trees.h	Sat Jul 15 04:51:28 2006 +0000
    20.3 @@ -0,0 +1,128 @@
    20.4 +/* header created automatically with -DGEN_TREES_H */
    20.5 +
    20.6 +local const ct_data static_ltree[L_CODES+2] = {
    20.7 +{{ 12},{  8}}, {{140},{  8}}, {{ 76},{  8}}, {{204},{  8}}, {{ 44},{  8}},
    20.8 +{{172},{  8}}, {{108},{  8}}, {{236},{  8}}, {{ 28},{  8}}, {{156},{  8}},
    20.9 +{{ 92},{  8}}, {{220},{  8}}, {{ 60},{  8}}, {{188},{  8}}, {{124},{  8}},
   20.10 +{{252},{  8}}, {{  2},{  8}}, {{130},{  8}}, {{ 66},{  8}}, {{194},{  8}},
   20.11 +{{ 34},{  8}}, {{162},{  8}}, {{ 98},{  8}}, {{226},{  8}}, {{ 18},{  8}},
   20.12 +{{146},{  8}}, {{ 82},{  8}}, {{210},{  8}}, {{ 50},{  8}}, {{178},{  8}},
   20.13 +{{114},{  8}}, {{242},{  8}}, {{ 10},{  8}}, {{138},{  8}}, {{ 74},{  8}},
   20.14 +{{202},{  8}}, {{ 42},{  8}}, {{170},{  8}}, {{106},{  8}}, {{234},{  8}},
   20.15 +{{ 26},{  8}}, {{154},{  8}}, {{ 90},{  8}}, {{218},{  8}}, {{ 58},{  8}},
   20.16 +{{186},{  8}}, {{122},{  8}}, {{250},{  8}}, {{  6},{  8}}, {{134},{  8}},
   20.17 +{{ 70},{  8}}, {{198},{  8}}, {{ 38},{  8}}, {{166},{  8}}, {{102},{  8}},
   20.18 +{{230},{  8}}, {{ 22},{  8}}, {{150},{  8}}, {{ 86},{  8}}, {{214},{  8}},
   20.19 +{{ 54},{  8}}, {{182},{  8}}, {{118},{  8}}, {{246},{  8}}, {{ 14},{  8}},
   20.20 +{{142},{  8}}, {{ 78},{  8}}, {{206},{  8}}, {{ 46},{  8}}, {{174},{  8}},
   20.21 +{{110},{  8}}, {{238},{  8}}, {{ 30},{  8}}, {{158},{  8}}, {{ 94},{  8}},
   20.22 +{{222},{  8}}, {{ 62},{  8}}, {{190},{  8}}, {{126},{  8}}, {{254},{  8}},
   20.23 +{{  1},{  8}}, {{129},{  8}}, {{ 65},{  8}}, {{193},{  8}}, {{ 33},{  8}},
   20.24 +{{161},{  8}}, {{ 97},{  8}}, {{225},{  8}}, {{ 17},{  8}}, {{145},{  8}},
   20.25 +{{ 81},{  8}}, {{209},{  8}}, {{ 49},{  8}}, {{177},{  8}}, {{113},{  8}},
   20.26 +{{241},{  8}}, {{  9},{  8}}, {{137},{  8}}, {{ 73},{  8}}, {{201},{  8}},
   20.27 +{{ 41},{  8}}, {{169},{  8}}, {{105},{  8}}, {{233},{  8}}, {{ 25},{  8}},
   20.28 +{{153},{  8}}, {{ 89},{  8}}, {{217},{  8}}, {{ 57},{  8}}, {{185},{  8}},
   20.29 +{{121},{  8}}, {{249},{  8}}, {{  5},{  8}}, {{133},{  8}}, {{ 69},{  8}},
   20.30 +{{197},{  8}}, {{ 37},{  8}}, {{165},{  8}}, {{101},{  8}}, {{229},{  8}},
   20.31 +{{ 21},{  8}}, {{149},{  8}}, {{ 85},{  8}}, {{213},{  8}}, {{ 53},{  8}},
   20.32 +{{181},{  8}}, {{117},{  8}}, {{245},{  8}}, {{ 13},{  8}}, {{141},{  8}},
   20.33 +{{ 77},{  8}}, {{205},{  8}}, {{ 45},{  8}}, {{173},{  8}}, {{109},{  8}},
   20.34 +{{237},{  8}}, {{ 29},{  8}}, {{157},{  8}}, {{ 93},{  8}}, {{221},{  8}},
   20.35 +{{ 61},{  8}}, {{189},{  8}}, {{125},{  8}}, {{253},{  8}}, {{ 19},{  9}},
   20.36 +{{275},{  9}}, {{147},{  9}}, {{403},{  9}}, {{ 83},{  9}}, {{339},{  9}},
   20.37 +{{211},{  9}}, {{467},{  9}}, {{ 51},{  9}}, {{307},{  9}}, {{179},{  9}},
   20.38 +{{435},{  9}}, {{115},{  9}}, {{371},{  9}}, {{243},{  9}}, {{499},{  9}},
   20.39 +{{ 11},{  9}}, {{267},{  9}}, {{139},{  9}}, {{395},{  9}}, {{ 75},{  9}},
   20.40 +{{331},{  9}}, {{203},{  9}}, {{459},{  9}}, {{ 43},{  9}}, {{299},{  9}},
   20.41 +{{171},{  9}}, {{427},{  9}}, {{107},{  9}}, {{363},{  9}}, {{235},{  9}},
   20.42 +{{491},{  9}}, {{ 27},{  9}}, {{283},{  9}}, {{155},{  9}}, {{411},{  9}},
   20.43 +{{ 91},{  9}}, {{347},{  9}}, {{219},{  9}}, {{475},{  9}}, {{ 59},{  9}},
   20.44 +{{315},{  9}}, {{187},{  9}}, {{443},{  9}}, {{123},{  9}}, {{379},{  9}},
   20.45 +{{251},{  9}}, {{507},{  9}}, {{  7},{  9}}, {{263},{  9}}, {{135},{  9}},
   20.46 +{{391},{  9}}, {{ 71},{  9}}, {{327},{  9}}, {{199},{  9}}, {{455},{  9}},
   20.47 +{{ 39},{  9}}, {{295},{  9}}, {{167},{  9}}, {{423},{  9}}, {{103},{  9}},
   20.48 +{{359},{  9}}, {{231},{  9}}, {{487},{  9}}, {{ 23},{  9}}, {{279},{  9}},
   20.49 +{{151},{  9}}, {{407},{  9}}, {{ 87},{  9}}, {{343},{  9}}, {{215},{  9}},
   20.50 +{{471},{  9}}, {{ 55},{  9}}, {{311},{  9}}, {{183},{  9}}, {{439},{  9}},
   20.51 +{{119},{  9}}, {{375},{  9}}, {{247},{  9}}, {{503},{  9}}, {{ 15},{  9}},
   20.52 +{{271},{  9}}, {{143},{  9}}, {{399},{  9}}, {{ 79},{  9}}, {{335},{  9}},
   20.53 +{{207},{  9}}, {{463},{  9}}, {{ 47},{  9}}, {{303},{  9}}, {{175},{  9}},
   20.54 +{{431},{  9}}, {{111},{  9}}, {{367},{  9}}, {{239},{  9}}, {{495},{  9}},
   20.55 +{{ 31},{  9}}, {{287},{  9}}, {{159},{  9}}, {{415},{  9}}, {{ 95},{  9}},
   20.56 +{{351},{  9}}, {{223},{  9}}, {{479},{  9}}, {{ 63},{  9}}, {{319},{  9}},
   20.57 +{{191},{  9}}, {{447},{  9}}, {{127},{  9}}, {{383},{  9}}, {{255},{  9}},
   20.58 +{{511},{  9}}, {{  0},{  7}}, {{ 64},{  7}}, {{ 32},{  7}}, {{ 96},{  7}},
   20.59 +{{ 16},{  7}}, {{ 80},{  7}}, {{ 48},{  7}}, {{112},{  7}}, {{  8},{  7}},
   20.60 +{{ 72},{  7}}, {{ 40},{  7}}, {{104},{  7}}, {{ 24},{  7}}, {{ 88},{  7}},
   20.61 +{{ 56},{  7}}, {{120},{  7}}, {{  4},{  7}}, {{ 68},{  7}}, {{ 36},{  7}},
   20.62 +{{100},{  7}}, {{ 20},{  7}}, {{ 84},{  7}}, {{ 52},{  7}}, {{116},{  7}},
   20.63 +{{  3},{  8}}, {{131},{  8}}, {{ 67},{  8}}, {{195},{  8}}, {{ 35},{  8}},
   20.64 +{{163},{  8}}, {{ 99},{  8}}, {{227},{  8}}
   20.65 +};
   20.66 +
   20.67 +local const ct_data static_dtree[D_CODES] = {
   20.68 +{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
   20.69 +{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
   20.70 +{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
   20.71 +{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
   20.72 +{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
   20.73 +{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
   20.74 +};
   20.75 +
   20.76 +const uch _dist_code[DIST_CODE_LEN] = {
   20.77 + 0,  1,  2,  3,  4,  4,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  8,
   20.78 + 8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10,
   20.79 +10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
   20.80 +11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
   20.81 +12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
   20.82 +13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
   20.83 +13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
   20.84 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
   20.85 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
   20.86 +14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
   20.87 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
   20.88 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
   20.89 +15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,  0,  0, 16, 17,
   20.90 +18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
   20.91 +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
   20.92 +24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
   20.93 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
   20.94 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
   20.95 +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
   20.96 +27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
   20.97 +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
   20.98 +28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
   20.99 +28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  20.100 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  20.101 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  20.102 +29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  20.103 +};
  20.104 +
  20.105 +const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  20.106 + 0,  1,  2,  3,  4,  5,  6,  7,  8,  8,  9,  9, 10, 10, 11, 11, 12, 12, 12, 12,
  20.107 +13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  20.108 +17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  20.109 +19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  20.110 +21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  20.111 +22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  20.112 +23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  20.113 +24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  20.114 +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  20.115 +25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  20.116 +26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  20.117 +26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  20.118 +27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  20.119 +};
  20.120 +
  20.121 +local const int base_length[LENGTH_CODES] = {
  20.122 +0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  20.123 +64, 80, 96, 112, 128, 160, 192, 224, 0
  20.124 +};
  20.125 +
  20.126 +local const int base_dist[D_CODES] = {
  20.127 +    0,     1,     2,     3,     4,     6,     8,    12,    16,    24,
  20.128 +   32,    48,    64,    96,   128,   192,   256,   384,   512,   768,
  20.129 + 1024,  1536,  2048,  3072,  4096,  6144,  8192, 12288, 16384, 24576
  20.130 +};
  20.131 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/compiler-init/zlib/uncompr.c	Sat Jul 15 04:51:28 2006 +0000
    21.3 @@ -0,0 +1,61 @@
    21.4 +/* uncompr.c -- decompress a memory buffer
    21.5 + * Copyright (C) 1995-2003 Jean-loup Gailly.
    21.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    21.7 + */
    21.8 +
    21.9 +/* @(#) $Id$ */
   21.10 +
   21.11 +#define ZLIB_INTERNAL
   21.12 +#include "zlib.h"
   21.13 +
   21.14 +/* ===========================================================================
   21.15 +     Decompresses the source buffer into the destination buffer.  sourceLen is
   21.16 +   the byte length of the source buffer. Upon entry, destLen is the total
   21.17 +   size of the destination buffer, which must be large enough to hold the
   21.18 +   entire uncompressed data. (The size of the uncompressed data must have
   21.19 +   been saved previously by the compressor and transmitted to the decompressor
   21.20 +   by some mechanism outside the scope of this compression library.)
   21.21 +   Upon exit, destLen is the actual size of the compressed buffer.
   21.22 +     This function can be used to decompress a whole file at once if the
   21.23 +   input file is mmap'ed.
   21.24 +
   21.25 +     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
   21.26 +   enough memory, Z_BUF_ERROR if there was not enough room in the output
   21.27 +   buffer, or Z_DATA_ERROR if the input data was corrupted.
   21.28 +*/
   21.29 +int ZEXPORT uncompress (dest, destLen, source, sourceLen)
   21.30 +    Bytef *dest;
   21.31 +    uLongf *destLen;
   21.32 +    const Bytef *source;
   21.33 +    uLong sourceLen;
   21.34 +{
   21.35 +    z_stream stream;
   21.36 +    int err;
   21.37 +
   21.38 +    stream.next_in = (Bytef*)source;
   21.39 +    stream.avail_in = (uInt)sourceLen;
   21.40 +    /* Check for source > 64K on 16-bit machine: */
   21.41 +    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
   21.42 +
   21.43 +    stream.next_out = dest;
   21.44 +    stream.avail_out = (uInt)*destLen;
   21.45 +    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
   21.46 +
   21.47 +    stream.zalloc = (alloc_func)0;
   21.48 +    stream.zfree = (free_func)0;
   21.49 +
   21.50 +    err = inflateInit(&stream);
   21.51 +    if (err != Z_OK) return err;
   21.52 +
   21.53 +    err = inflate(&stream, Z_FINISH);
   21.54 +    if (err != Z_STREAM_END) {
   21.55 +        inflateEnd(&stream);
   21.56 +        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
   21.57 +            return Z_DATA_ERROR;
   21.58 +        return err;
   21.59 +    }
   21.60 +    *destLen = stream.total_out;
   21.61 +
   21.62 +    err = inflateEnd(&stream);
   21.63 +    return err;
   21.64 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/compiler-init/zlib/zconf.h	Sat Jul 15 04:51:28 2006 +0000
    22.3 @@ -0,0 +1,281 @@
    22.4 +/* zconf.h -- configuration of the zlib compression library
    22.5 + * Copyright (C) 1995-2005 Jean-loup Gailly.
    22.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    22.7 + */
    22.8 +
    22.9 +/* @(#) $Id$ */
   22.10 +
   22.11 +#ifndef ZCONF_H
   22.12 +#define ZCONF_H
   22.13 +
   22.14 +#if defined(__MSDOS__) && !defined(MSDOS)
   22.15 +#  define MSDOS
   22.16 +#endif
   22.17 +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
   22.18 +#  define OS2
   22.19 +#endif
   22.20 +#if defined(_WINDOWS) && !defined(WINDOWS)
   22.21 +#  define WINDOWS
   22.22 +#endif
   22.23 +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
   22.24 +#  ifndef WIN32
   22.25 +#    define WIN32
   22.26 +#  endif
   22.27 +#endif
   22.28 +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
   22.29 +#  if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
   22.30 +#    ifndef SYS16BIT
   22.31 +#      define SYS16BIT
   22.32 +#    endif
   22.33 +#  endif
   22.34 +#endif
   22.35 +
   22.36 +/*
   22.37 + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
   22.38 + * than 64k bytes at a time (needed on systems with 16-bit int).
   22.39 + */
   22.40 +#ifdef SYS16BIT
   22.41 +#  define MAXSEG_64K
   22.42 +#endif
   22.43 +#ifdef MSDOS
   22.44 +#  define UNALIGNED_OK
   22.45 +#endif
   22.46 +
   22.47 +#ifdef __STDC_VERSION__
   22.48 +#  ifndef STDC
   22.49 +#    define STDC
   22.50 +#  endif
   22.51 +#  if __STDC_VERSION__ >= 199901L
   22.52 +#    ifndef STDC99
   22.53 +#      define STDC99
   22.54 +#    endif
   22.55 +#  endif
   22.56 +#endif
   22.57 +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
   22.58 +#  define STDC
   22.59 +#endif
   22.60 +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
   22.61 +#  define STDC
   22.62 +#endif
   22.63 +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
   22.64 +#  define STDC
   22.65 +#endif
   22.66 +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
   22.67 +#  define STDC
   22.68 +#endif
   22.69 +
   22.70 +#if defined(__OS400__) && !defined(STDC)    /* iSeries (formerly AS/400). */
   22.71 +#  define STDC
   22.72 +#endif
   22.73 +
   22.74 +#ifndef STDC
   22.75 +#  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
   22.76 +#    define const       /* note: need a more gentle solution here */
   22.77 +#  endif
   22.78 +#endif
   22.79 +
   22.80 +/* Some Mac compilers merge all .h files incorrectly: */
   22.81 +#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
   22.82 +#  define NO_DUMMY_DECL
   22.83 +#endif
   22.84 +
   22.85 +/* Maximum value for memLevel in deflateInit2 */
   22.86 +#ifndef MAX_MEM_LEVEL
   22.87 +#  ifdef MAXSEG_64K
   22.88 +#    define MAX_MEM_LEVEL 8
   22.89 +#  else
   22.90 +#    define MAX_MEM_LEVEL 9
   22.91 +#  endif
   22.92 +#endif
   22.93 +
   22.94 +/* Maximum value for windowBits in deflateInit2 and inflateInit2.
   22.95 + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
   22.96 + * created by gzip. (Files created by minigzip can still be extracted by
   22.97 + * gzip.)
   22.98 + */
   22.99 +#ifndef MAX_WBITS
  22.100 +#  define MAX_WBITS   15 /* 32K LZ77 window */
  22.101 +#endif
  22.102 +
  22.103 +/* The memory requirements for deflate are (in bytes):
  22.104 +            (1 << (windowBits+2)) +  (1 << (memLevel+9))
  22.105 + that is: 128K for windowBits=15  +  128K for memLevel = 8  (default values)
  22.106 + plus a few kilobytes for small objects. For example, if you want to reduce
  22.107 + the default memory requirements from 256K to 128K, compile with
  22.108 +     make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
  22.109 + Of course this will generally degrade compression (there's no free lunch).
  22.110 +
  22.111 +   The memory requirements for inflate are (in bytes) 1 << windowBits
  22.112 + that is, 32K for windowBits=15 (default value) plus a few kilobytes
  22.113 + for small objects.
  22.114 +*/
  22.115 +
  22.116 +                        /* Type declarations */
  22.117 +
  22.118 +#ifndef OF /* function prototypes */
  22.119 +#  ifdef STDC
  22.120 +#    define OF(args)  args
  22.121 +#  else
  22.122 +#    define OF(args)  ()
  22.123 +#  endif
  22.124 +#endif
  22.125 +
  22.126 +/* The following definitions for FAR are needed only for MSDOS mixed
  22.127 + * model programming (small or medium model with some far allocations).
  22.128 + * This was tested only with MSC; for other MSDOS compilers you may have
  22.129 + * to define NO_MEMCPY in zutil.h.  If you don't need the mixed model,
  22.130 + * just define FAR to be empty.
  22.131 + */
  22.132 +#ifdef SYS16BIT
  22.133 +#  if defined(M_I86SM) || defined(M_I86MM)
  22.134 +     /* MSC small or medium model */
  22.135 +#    define SMALL_MEDIUM
  22.136 +#    ifdef _MSC_VER
  22.137 +#      define FAR _far
  22.138 +#    else
  22.139 +#      define FAR far
  22.140 +#    endif
  22.141 +#  endif
  22.142 +#  if (defined(__SMALL__) || defined(__MEDIUM__))
  22.143 +     /* Turbo C small or medium model */
  22.144 +#    define SMALL_MEDIUM
  22.145 +#    ifdef __BORLANDC__
  22.146 +#      define FAR _far
  22.147 +#    else
  22.148 +#      define FAR far
  22.149 +#    endif
  22.150 +#  endif
  22.151 +#endif
  22.152 +
  22.153 +#if defined(WINDOWS) || defined(WIN32)
  22.154 +   /* If building or using zlib as a DLL, define ZLIB_DLL.
  22.155 +    * This is not mandatory, but it offers a little performance increase.
  22.156 +    */
  22.157 +#  ifdef ZLIB_DLL
  22.158 +#    if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  22.159 +#      ifdef ZLIB_INTERNAL
  22.160 +#        define ZEXTERN extern __declspec(dllexport)
  22.161 +#      else
  22.162 +#        define ZEXTERN extern __declspec(dllimport)
  22.163 +#      endif
  22.164 +#    endif
  22.165 +#  endif  /* ZLIB_DLL */
  22.166 +   /* If building or using zlib with the WINAPI/WINAPIV calling convention,
  22.167 +    * define ZLIB_WINAPI.
  22.168 +    * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
  22.169 +    */
  22.170 +#  ifdef ZLIB_WINAPI
  22.171 +#    ifdef FAR
  22.172 +#      undef FAR
  22.173 +#    endif
  22.174 +#    include <windows.h>
  22.175 +     /* No need for _export, use ZLIB.DEF instead. */
  22.176 +     /* For complete Windows compatibility, use WINAPI, not __stdcall. */
  22.177 +#    define ZEXPORT WINAPI
  22.178 +#    ifdef WIN32
  22.179 +#      define ZEXPORTVA WINAPIV
  22.180 +#    else
  22.181 +#      define ZEXPORTVA FAR CDECL
  22.182 +#    endif
  22.183 +#  endif
  22.184 +#endif
  22.185 +
  22.186 +#if defined (__BEOS__)
  22.187 +#  ifdef ZLIB_DLL
  22.188 +#    ifdef ZLIB_INTERNAL
  22.189 +#      define ZEXPORT   __declspec(dllexport)
  22.190 +#      define ZEXPORTVA __declspec(dllexport)
  22.191 +#    else
  22.192 +#      define ZEXPORT   __declspec(dllimport)
  22.193 +#      define ZEXPORTVA __declspec(dllimport)
  22.194 +#    endif
  22.195 +#  endif
  22.196 +#endif
  22.197 +
  22.198 +#ifndef ZEXTERN
  22.199 +#  define ZEXTERN extern
  22.200 +#endif
  22.201 +#ifndef ZEXPORT
  22.202 +#  define ZEXPORT
  22.203 +#endif
  22.204 +#ifndef ZEXPORTVA
  22.205 +#  define ZEXPORTVA
  22.206 +#endif
  22.207 +
  22.208 +#ifndef FAR
  22.209 +#  define FAR
  22.210 +#endif
  22.211 +
  22.212 +#if !defined(__MACTYPES__)
  22.213 +typedef unsigned char  Byte;  /* 8 bits */
  22.214 +#endif
  22.215 +typedef unsigned int   uInt;  /* 16 bits or more */
  22.216 +typedef unsigned long  uLong; /* 32 bits or more */
  22.217 +
  22.218 +#ifdef SMALL_MEDIUM
  22.219 +   /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
  22.220 +#  define Bytef Byte FAR
  22.221 +#else
  22.222 +   typedef Byte  FAR Bytef;
  22.223 +#endif
  22.224 +typedef char  FAR charf;
  22.225 +typedef int   FAR intf;
  22.226 +typedef uInt  FAR uIntf;
  22.227 +typedef uLong FAR uLongf;
  22.228 +
  22.229 +#ifdef STDC
  22.230 +   typedef void const *voidpc;
  22.231 +   typedef void FAR   *voidpf;
  22.232 +   typedef void       *voidp;
  22.233 +#else
  22.234 +   typedef Byte const *voidpc;
  22.235 +   typedef Byte FAR   *voidpf;
  22.236 +   typedef Byte       *voidp;
  22.237 +#endif
  22.238 +
  22.239 +#if 0           /* HAVE_UNISTD_H -- this line is updated by ./configure */
  22.240 +#  include <sys/types.h> /* for off_t */
  22.241 +#  include <unistd.h>    /* for SEEK_* and off_t */
  22.242 +#  ifdef VMS
  22.243 +#    include <unixio.h>   /* for off_t */
  22.244 +#  endif
  22.245 +#  define z_off_t off_t
  22.246 +#endif
  22.247 +#ifndef SEEK_SET
  22.248 +#  define SEEK_SET        0       /* Seek from beginning of file.  */
  22.249 +#  define SEEK_CUR        1       /* Seek from current position.  */
  22.250 +#  define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
  22.251 +#endif
  22.252 +#ifndef z_off_t
  22.253 +#  define z_off_t long
  22.254 +#endif
  22.255 +
  22.256 +#if defined(__OS400__)
  22.257 +#  define NO_vsnprintf
  22.258 +#endif
  22.259 +
  22.260 +#if defined(__MVS__)
  22.261 +#  define NO_vsnprintf
  22.262 +#  ifdef FAR
  22.263 +#    undef FAR
  22.264 +#  endif
  22.265 +#endif
  22.266 +
  22.267 +/* MVS linker does not support external names larger than 8 bytes */
  22.268 +#if defined(__MVS__)
  22.269 +#   pragma map(deflateInit_,"DEIN")
  22.270 +#   pragma map(deflateInit2_,"DEIN2")
  22.271 +#   pragma map(deflateEnd,"DEEND")
  22.272 +#   pragma map(deflateBound,"DEBND")
  22.273 +#   pragma map(inflateInit_,"ININ")
  22.274 +#   pragma map(inflateInit2_,"ININ2")
  22.275 +#   pragma map(inflateEnd,"INEND")
  22.276 +#   pragma map(inflateSync,"INSY")
  22.277 +#   pragma map(inflateSetDictionary,"INSEDI")
  22.278 +#   pragma map(compressBound,"CMBND")
  22.279 +#   pragma map(inflate_table,"INTABL")
  22.280 +#   pragma map(inflate_fast,"INFA")
  22.281 +#   pragma map(inflate_copyright,"INCOPY")
  22.282 +#endif
  22.283 +
  22.284 +#endif /* ZCONF_H */
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/compiler-init/zlib/zlib.h	Sat Jul 15 04:51:28 2006 +0000
    23.3 @@ -0,0 +1,1357 @@
    23.4 +/* zlib.h -- interface of the 'zlib' general purpose compression library
    23.5 +  version 1.2.3, July 18th, 2005
    23.6 +
    23.7 +  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
    23.8 +
    23.9 +  This software is provided 'as-is', without any express or implied
   23.10 +  warranty.  In no event will the authors be held liable for any damages
   23.11 +  arising from the use of this software.
   23.12 +
   23.13 +  Permission is granted to anyone to use this software for any purpose,
   23.14 +  including commercial applications, and to alter it and redistribute it
   23.15 +  freely, subject to the following restrictions:
   23.16 +
   23.17 +  1. The origin of this software must not be misrepresented; you must not
   23.18 +     claim that you wrote the original software. If you use this software
   23.19 +     in a product, an acknowledgment in the product documentation would be
   23.20 +     appreciated but is not required.
   23.21 +  2. Altered source versions must be plainly marked as such, and must not be
   23.22 +     misrepresented as being the original software.
   23.23 +  3. This notice may not be removed or altered from any source distribution.
   23.24 +
   23.25 +  Jean-loup Gailly        Mark Adler
   23.26 +  [email protected]          [email protected]
   23.27 +
   23.28 +
   23.29 +  The data format used by the zlib library is described by RFCs (Request for
   23.30 +  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
   23.31 +  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
   23.32 +*/
   23.33 +
   23.34 +#ifndef ZLIB_H
   23.35 +#define ZLIB_H
   23.36 +
   23.37 +#include "zconf.h"
   23.38 +
   23.39 +#ifdef __cplusplus
   23.40 +extern "C" {
   23.41 +#endif
   23.42 +
   23.43 +#define ZLIB_VERSION "1.2.3"
   23.44 +#define ZLIB_VERNUM 0x1230
   23.45 +
   23.46 +/*
   23.47 +     The 'zlib' compression library provides in-memory compression and
   23.48 +  decompression functions, including integrity checks of the uncompressed
   23.49 +  data.  This version of the library supports only one compression method
   23.50 +  (deflation) but other algorithms will be added later and will have the same
   23.51 +  stream interface.
   23.52 +
   23.53 +     Compression can be done in a single step if the buffers are large
   23.54 +  enough (for example if an input file is mmap'ed), or can be done by
   23.55 +  repeated calls of the compression function.  In the latter case, the
   23.56 +  application must provide more input and/or consume the output
   23.57 +  (providing more output space) before each call.
   23.58 +
   23.59 +     The compressed data format used by default by the in-memory functions is
   23.60 +  the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
   23.61 +  around a deflate stream, which is itself documented in RFC 1951.
   23.62 +
   23.63 +     The library also supports reading and writing files in gzip (.gz) format
   23.64 +  with an interface similar to that of stdio using the functions that start
   23.65 +  with "gz".  The gzip format is different from the zlib format.  gzip is a
   23.66 +  gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
   23.67 +
   23.68 +     This library can optionally read and write gzip streams in memory as well.
   23.69 +
   23.70 +     The zlib format was designed to be compact and fast for use in memory
   23.71 +  and on communications channels.  The gzip format was designed for single-
   23.72 +  file compression on file systems, has a larger header than zlib to maintain
   23.73 +  directory information, and uses a different, slower check method than zlib.
   23.74 +
   23.75 +     The library does not install any signal handler. The decoder checks
   23.76 +  the consistency of the compressed data, so the library should never
   23.77 +  crash even in case of corrupted input.
   23.78 +*/
   23.79 +
   23.80 +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
   23.81 +typedef void   (*free_func)  OF((voidpf opaque, voidpf address));
   23.82 +
   23.83 +struct internal_state;
   23.84 +
   23.85 +typedef struct z_stream_s {
   23.86 +    Bytef    *next_in;  /* next input byte */
   23.87 +    uInt     avail_in;  /* number of bytes available at next_in */
   23.88 +    uLong    total_in;  /* total nb of input bytes read so far */
   23.89 +
   23.90 +    Bytef    *next_out; /* next output byte should be put there */
   23.91 +    uInt     avail_out; /* remaining free space at next_out */
   23.92 +    uLong    total_out; /* total nb of bytes output so far */
   23.93 +
   23.94 +    char     *msg;      /* last error message, NULL if no error */
   23.95 +    struct internal_state FAR *state; /* not visible by applications */
   23.96 +
   23.97 +    alloc_func zalloc;  /* used to allocate the internal state */
   23.98 +    free_func  zfree;   /* used to free the internal state */
   23.99 +    voidpf     opaque;  /* private data object passed to zalloc and zfree */
  23.100 +
  23.101 +    int     data_type;  /* best guess about the data type: binary or text */
  23.102 +    uLong   adler;      /* adler32 value of the uncompressed data */
  23.103 +    uLong   reserved;   /* reserved for future use */
  23.104 +} z_stream;
  23.105 +
  23.106 +typedef z_stream FAR *z_streamp;
  23.107 +
  23.108 +/*
  23.109 +     gzip header information passed to and from zlib routines.  See RFC 1952
  23.110 +  for more details on the meanings of these fields.
  23.111 +*/
  23.112 +typedef struct gz_header_s {
  23.113 +    int     text;       /* true if compressed data believed to be text */
  23.114 +    uLong   time;       /* modification time */
  23.115 +    int     xflags;     /* extra flags (not used when writing a gzip file) */
  23.116 +    int     os;         /* operating system */
  23.117 +    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
  23.118 +    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
  23.119 +    uInt    extra_max;  /* space at extra (only when reading header) */
  23.120 +    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
  23.121 +    uInt    name_max;   /* space at name (only when reading header) */
  23.122 +    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
  23.123 +    uInt    comm_max;   /* space at comment (only when reading header) */
  23.124 +    int     hcrc;       /* true if there was or will be a header crc */
  23.125 +    int     done;       /* true when done reading gzip header (not used
  23.126 +                           when writing a gzip file) */
  23.127 +} gz_header;
  23.128 +
  23.129 +typedef gz_header FAR *gz_headerp;
  23.130 +
  23.131 +/*
  23.132 +   The application must update next_in and avail_in when avail_in has
  23.133 +   dropped to zero. It must update next_out and avail_out when avail_out
  23.134 +   has dropped to zero. The application must initialize zalloc, zfree and
  23.135 +   opaque before calling the init function. All other fields are set by the
  23.136 +   compression library and must not be updated by the application.
  23.137 +
  23.138 +   The opaque value provided by the application will be passed as the first
  23.139 +   parameter for calls of zalloc and zfree. This can be useful for custom
  23.140 +   memory management. The compression library attaches no meaning to the
  23.141 +   opaque value.
  23.142 +
  23.143 +   zalloc must return Z_NULL if there is not enough memory for the object.
  23.144 +   If zlib is used in a multi-threaded application, zalloc and zfree must be
  23.145 +   thread safe.
  23.146 +
  23.147 +   On 16-bit systems, the functions zalloc and zfree must be able to allocate
  23.148 +   exactly 65536 bytes, but will not be required to allocate more than this
  23.149 +   if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
  23.150 +   pointers returned by zalloc for objects of exactly 65536 bytes *must*
  23.151 +   have their offset normalized to zero. The default allocation function
  23.152 +   provided by this library ensures this (see zutil.c). To reduce memory
  23.153 +   requirements and avoid any allocation of 64K objects, at the expense of
  23.154 +   compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
  23.155 +
  23.156 +   The fields total_in and total_out can be used for statistics or
  23.157 +   progress reports. After compression, total_in holds the total size of
  23.158 +   the uncompressed data and may be saved for use in the decompressor
  23.159 +   (particularly if the decompressor wants to decompress everything in
  23.160 +   a single step).
  23.161 +*/
  23.162 +
  23.163 +                        /* constants */
  23.164 +
  23.165 +#define Z_NO_FLUSH      0
  23.166 +#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  23.167 +#define Z_SYNC_FLUSH    2
  23.168 +#define Z_FULL_FLUSH    3
  23.169 +#define Z_FINISH        4
  23.170 +#define Z_BLOCK         5
  23.171 +/* Allowed flush values; see deflate() and inflate() below for details */
  23.172 +
  23.173 +#define Z_OK            0
  23.174 +#define Z_STREAM_END    1
  23.175 +#define Z_NEED_DICT     2
  23.176 +#define Z_ERRNO        (-1)
  23.177 +#define Z_STREAM_ERROR (-2)
  23.178 +#define Z_DATA_ERROR   (-3)
  23.179 +#define Z_MEM_ERROR    (-4)
  23.180 +#define Z_BUF_ERROR    (-5)
  23.181 +#define Z_VERSION_ERROR (-6)
  23.182 +/* Return codes for the compression/decompression functions. Negative
  23.183 + * values are errors, positive values are used for special but normal events.
  23.184 + */
  23.185 +
  23.186 +#define Z_NO_COMPRESSION         0
  23.187 +#define Z_BEST_SPEED             1
  23.188 +#define Z_BEST_COMPRESSION       9
  23.189 +#define Z_DEFAULT_COMPRESSION  (-1)
  23.190 +/* compression levels */
  23.191 +
  23.192 +#define Z_FILTERED            1
  23.193 +#define Z_HUFFMAN_ONLY        2
  23.194 +#define Z_RLE                 3
  23.195 +#define Z_FIXED               4
  23.196 +#define Z_DEFAULT_STRATEGY    0
  23.197 +/* compression strategy; see deflateInit2() below for details */
  23.198 +
  23.199 +#define Z_BINARY   0
  23.200 +#define Z_TEXT     1
  23.201 +#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
  23.202 +#define Z_UNKNOWN  2
  23.203 +/* Possible values of the data_type field (though see inflate()) */
  23.204 +
  23.205 +#define Z_DEFLATED   8
  23.206 +/* The deflate compression method (the only one supported in this version) */
  23.207 +
  23.208 +#define Z_NULL  0  /* for initializing zalloc, zfree, opaque */
  23.209 +
  23.210 +#define zlib_version zlibVersion()
  23.211 +/* for compatibility with versions < 1.0.2 */
  23.212 +
  23.213 +                        /* basic functions */
  23.214 +
  23.215 +ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  23.216 +/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
  23.217 +   If the first character differs, the library code actually used is
  23.218 +   not compatible with the zlib.h header file used by the application.
  23.219 +   This check is automatically made by deflateInit and inflateInit.
  23.220 + */
  23.221 +
  23.222 +/*
  23.223 +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
  23.224 +
  23.225 +     Initializes the internal stream state for compression. The fields
  23.226 +   zalloc, zfree and opaque must be initialized before by the caller.
  23.227 +   If zalloc and zfree are set to Z_NULL, deflateInit updates them to
  23.228 +   use default allocation functions.
  23.229 +
  23.230 +     The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
  23.231 +   1 gives best speed, 9 gives best compression, 0 gives no compression at
  23.232 +   all (the input data is simply copied a block at a time).
  23.233 +   Z_DEFAULT_COMPRESSION requests a default compromise between speed and
  23.234 +   compression (currently equivalent to level 6).
  23.235 +
  23.236 +     deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
  23.237 +   enough memory, Z_STREAM_ERROR if level is not a valid compression level,
  23.238 +   Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
  23.239 +   with the version assumed by the caller (ZLIB_VERSION).
  23.240 +   msg is set to null if there is no error message.  deflateInit does not
  23.241 +   perform any compression: this will be done by deflate().
  23.242 +*/
  23.243 +
  23.244 +
  23.245 +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  23.246 +/*
  23.247 +    deflate compresses as much data as possible, and stops when the input
  23.248 +  buffer becomes empty or the output buffer becomes full. It may introduce some
  23.249 +  output latency (reading input without producing any output) except when
  23.250 +  forced to flush.
  23.251 +
  23.252 +    The detailed semantics are as follows. deflate performs one or both of the
  23.253 +  following actions:
  23.254 +
  23.255 +  - Compress more input starting at next_in and update next_in and avail_in
  23.256 +    accordingly. If not all input can be processed (because there is not
  23.257 +    enough room in the output buffer), next_in and avail_in are updated and
  23.258 +    processing will resume at this point for the next call of deflate().
  23.259 +
  23.260 +  - Provide more output starting at next_out and update next_out and avail_out
  23.261 +    accordingly. This action is forced if the parameter flush is non zero.
  23.262 +    Forcing flush frequently degrades the compression ratio, so this parameter
  23.263 +    should be set only when necessary (in interactive applications).
  23.264 +    Some output may be provided even if flush is not set.
  23.265 +
  23.266 +  Before the call of deflate(), the application should ensure that at least
  23.267 +  one of the actions is possible, by providing more input and/or consuming
  23.268 +  more output, and updating avail_in or avail_out accordingly; avail_out
  23.269 +  should never be zero before the call. The application can consume the
  23.270 +  compressed output when it wants, for example when the output buffer is full
  23.271 +  (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
  23.272 +  and with zero avail_out, it must be called again after making room in the
  23.273 +  output buffer because there might be more output pending.
  23.274 +
  23.275 +    Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
  23.276 +  decide how much data to accumualte before producing output, in order to
  23.277 +  maximize compression.
  23.278 +
  23.279 +    If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
  23.280 +  flushed to the output buffer and the output is aligned on a byte boundary, so
  23.281 +  that the decompressor can get all input data available so far. (In particular
  23.282 +  avail_in is zero after the call if enough output space has been provided
  23.283 +  before the call.)  Flushing may degrade compression for some compression
  23.284 +  algorithms and so it should be used only when necessary.
  23.285 +
  23.286 +    If flush is set to Z_FULL_FLUSH, all output is flushed as with
  23.287 +  Z_SYNC_FLUSH, and the compression state is reset so that decompression can
  23.288 +  restart from this point if previous compressed data has been damaged or if
  23.289 +  random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
  23.290 +  compression.
  23.291 +
  23.292 +    If deflate returns with avail_out == 0, this function must be called again
  23.293 +  with the same value of the flush parameter and more output space (updated
  23.294 +  avail_out), until the flush is complete (deflate returns with non-zero
  23.295 +  avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
  23.296 +  avail_out is greater than six to avoid repeated flush markers due to
  23.297 +  avail_out == 0 on return.
  23.298 +
  23.299 +    If the parameter flush is set to Z_FINISH, pending input is processed,
  23.300 +  pending output is flushed and deflate returns with Z_STREAM_END if there
  23.301 +  was enough output space; if deflate returns with Z_OK, this function must be
  23.302 +  called again with Z_FINISH and more output space (updated avail_out) but no
  23.303 +  more input data, until it returns with Z_STREAM_END or an error. After
  23.304 +  deflate has returned Z_STREAM_END, the only possible operations on the
  23.305 +  stream are deflateReset or deflateEnd.
  23.306 +
  23.307 +    Z_FINISH can be used immediately after deflateInit if all the compression
  23.308 +  is to be done in a single step. In this case, avail_out must be at least
  23.309 +  the value returned by deflateBound (see below). If deflate does not return
  23.310 +  Z_STREAM_END, then it must be called again as described above.
  23.311 +
  23.312 +    deflate() sets strm->adler to the adler32 checksum of all input read
  23.313 +  so far (that is, total_in bytes).
  23.314 +
  23.315 +    deflate() may update strm->data_type if it can make a good guess about
  23.316 +  the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
  23.317 +  binary. This field is only for information purposes and does not affect
  23.318 +  the compression algorithm in any manner.
  23.319 +
  23.320 +    deflate() returns Z_OK if some progress has been made (more input
  23.321 +  processed or more output produced), Z_STREAM_END if all input has been
  23.322 +  consumed and all output has been produced (only when flush is set to
  23.323 +  Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
  23.324 +  if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
  23.325 +  (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
  23.326 +  fatal, and deflate() can be called again with more input and more output
  23.327 +  space to continue compressing.
  23.328 +*/
  23.329 +
  23.330 +
  23.331 +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  23.332 +/*
  23.333 +     All dynamically allocated data structures for this stream are freed.
  23.334 +   This function discards any unprocessed input and does not flush any
  23.335 +   pending output.
  23.336 +
  23.337 +     deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
  23.338 +   stream state was inconsistent, Z_DATA_ERROR if the stream was freed
  23.339 +   prematurely (some input or output was discarded). In the error case,
  23.340 +   msg may be set but then points to a static string (which must not be
  23.341 +   deallocated).
  23.342 +*/
  23.343 +
  23.344 +
  23.345 +/*
  23.346 +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
  23.347 +
  23.348 +     Initializes the internal stream state for decompression. The fields
  23.349 +   next_in, avail_in, zalloc, zfree and opaque must be initialized before by
  23.350 +   the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
  23.351 +   value depends on the compression method), inflateInit determines the
  23.352 +   compression method from the zlib header and allocates all data structures
  23.353 +   accordingly; otherwise the allocation will be deferred to the first call of
  23.354 +   inflate.  If zalloc and zfree are set to Z_NULL, inflateInit updates them to
  23.355 +   use default allocation functions.
  23.356 +
  23.357 +     inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
  23.358 +   memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
  23.359 +   version assumed by the caller.  msg is set to null if there is no error
  23.360 +   message. inflateInit does not perform any decompression apart from reading
  23.361 +   the zlib header if present: this will be done by inflate().  (So next_in and
  23.362 +   avail_in may be modified, but next_out and avail_out are unchanged.)
  23.363 +*/
  23.364 +
  23.365 +
  23.366 +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  23.367 +/*
  23.368 +    inflate decompresses as much data as possible, and stops when the input
  23.369 +  buffer becomes empty or the output buffer becomes full. It may introduce
  23.370 +  some output latency (reading input without producing any output) except when
  23.371 +  forced to flush.
  23.372 +
  23.373 +  The detailed semantics are as follows. inflate performs one or both of the
  23.374 +  following actions:
  23.375 +
  23.376 +  - Decompress more input starting at next_in and update next_in and avail_in
  23.377 +    accordingly. If not all input can be processed (because there is not
  23.378 +    enough room in the output buffer), next_in is updated and processing
  23.379 +    will resume at this point for the next call of inflate().
  23.380 +
  23.381 +  - Provide more output starting at next_out and update next_out and avail_out
  23.382 +    accordingly.  inflate() provides as much output as possible, until there
  23.383 +    is no more input data or no more space in the output buffer (see below
  23.384 +    about the flush parameter).
  23.385 +
  23.386 +  Before the call of inflate(), the application should ensure that at least
  23.387 +  one of the actions is possible, by providing more input and/or consuming
  23.388 +  more output, and updating the next_* and avail_* values accordingly.
  23.389 +  The application can consume the uncompressed output when it wants, for
  23.390 +  example when the output buffer is full (avail_out == 0), or after each
  23.391 +  call of inflate(). If inflate returns Z_OK and with zero avail_out, it
  23.392 +  must be called again after making room in the output buffer because there
  23.393 +  might be more output pending.
  23.394 +
  23.395 +    The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
  23.396 +  Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
  23.397 +  output as possible to the output buffer. Z_BLOCK requests that inflate() stop
  23.398 +  if and when it gets to the next deflate block boundary. When decoding the
  23.399 +  zlib or gzip format, this will cause inflate() to return immediately after
  23.400 +  the header and before the first block. When doing a raw inflate, inflate()
  23.401 +  will go ahead and process the first block, and will return when it gets to
  23.402 +  the end of that block, or when it runs out of data.
  23.403 +
  23.404 +    The Z_BLOCK option assists in appending to or combining deflate streams.
  23.405 +  Also to assist in this, on return inflate() will set strm->data_type to the
  23.406 +  number of unused bits in the last byte taken from strm->next_in, plus 64
  23.407 +  if inflate() is currently decoding the last block in the deflate stream,
  23.408 +  plus 128 if inflate() returned immediately after decoding an end-of-block
  23.409 +  code or decoding the complete header up to just before the first byte of the
  23.410 +  deflate stream. The end-of-block will not be indicated until all of the
  23.411 +  uncompressed data from that block has been written to strm->next_out.  The
  23.412 +  number of unused bits may in general be greater than seven, except when
  23.413 +  bit 7 of data_type is set, in which case the number of unused bits will be
  23.414 +  less than eight.
  23.415 +
  23.416 +    inflate() should normally be called until it returns Z_STREAM_END or an
  23.417 +  error. However if all decompression is to be performed in a single step
  23.418 +  (a single call of inflate), the parameter flush should be set to
  23.419 +  Z_FINISH. In this case all pending input is processed and all pending
  23.420 +  output is flushed; avail_out must be large enough to hold all the
  23.421 +  uncompressed data. (The size of the uncompressed data may have been saved
  23.422 +  by the compressor for this purpose.) The next operation on this stream must
  23.423 +  be inflateEnd to deallocate the decompression state. The use of Z_FINISH
  23.424 +  is never required, but can be used to inform inflate that a faster approach
  23.425 +  may be used for the single inflate() call.
  23.426 +
  23.427 +     In this implementation, inflate() always flushes as much output as
  23.428 +  possible to the output buffer, and always uses the faster approach on the
  23.429 +  first call. So the only effect of the flush parameter in this implementation
  23.430 +  is on the return value of inflate(), as noted below, or when it returns early
  23.431 +  because Z_BLOCK is used.
  23.432 +
  23.433 +     If a preset dictionary is needed after this call (see inflateSetDictionary
  23.434 +  below), inflate sets strm->adler to the adler32 checksum of the dictionary
  23.435 +  chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
  23.436 +  strm->adler to the adler32 checksum of all output produced so far (that is,
  23.437 +  total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
  23.438 +  below. At the end of the stream, inflate() checks that its computed adler32
  23.439 +  checksum is equal to that saved by the compressor and returns Z_STREAM_END
  23.440 +  only if the checksum is correct.
  23.441 +
  23.442 +    inflate() will decompress and check either zlib-wrapped or gzip-wrapped
  23.443 +  deflate data.  The header type is detected automatically.  Any information
  23.444 +  contained in the gzip header is not retained, so applications that need that
  23.445 +  information should instead use raw inflate, see inflateInit2() below, or
  23.446 +  inflateBack() and perform their own processing of the gzip header and
  23.447 +  trailer.
  23.448 +
  23.449 +    inflate() returns Z_OK if some progress has been made (more input processed
  23.450 +  or more output produced), Z_STREAM_END if the end of the compressed data has
  23.451 +  been reached and all uncompressed output has been produced, Z_NEED_DICT if a
  23.452 +  preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
  23.453 +  corrupted (input stream not conforming to the zlib format or incorrect check
  23.454 +  value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
  23.455 +  if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
  23.456 +  Z_BUF_ERROR if no progress is possible or if there was not enough room in the
  23.457 +  output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
  23.458 +  inflate() can be called again with more input and more output space to
  23.459 +  continue decompressing. If Z_DATA_ERROR is returned, the application may then
  23.460 +  call inflateSync() to look for a good compression block if a partial recovery
  23.461 +  of the data is desired.
  23.462 +*/
  23.463 +
  23.464 +
  23.465 +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  23.466 +/*
  23.467 +     All dynamically allocated data structures for this stream are freed.
  23.468 +   This function discards any unprocessed input and does not flush any
  23.469 +   pending output.
  23.470 +
  23.471 +     inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
  23.472 +   was inconsistent. In the error case, msg may be set but then points to a
  23.473 +   static string (which must not be deallocated).
  23.474 +*/
  23.475 +
  23.476 +                        /* Advanced functions */
  23.477 +
  23.478 +/*
  23.479 +    The following functions are needed only in some special applications.
  23.480 +*/
  23.481 +
  23.482 +/*
  23.483 +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
  23.484 +                                     int  level,
  23.485 +                                     int  method,
  23.486 +                                     int  windowBits,
  23.487 +                                     int  memLevel,
  23.488 +                                     int  strategy));
  23.489 +
  23.490 +     This is another version of deflateInit with more compression options. The
  23.491 +   fields next_in, zalloc, zfree and opaque must be initialized before by
  23.492 +   the caller.
  23.493 +
  23.494 +     The method parameter is the compression method. It must be Z_DEFLATED in
  23.495 +   this version of the library.
  23.496 +
  23.497 +     The windowBits parameter is the base two logarithm of the window size
  23.498 +   (the size of the history buffer). It should be in the range 8..15 for this
  23.499 +   version of the library. Larger values of this parameter result in better
  23.500 +   compression at the expense of memory usage. The default value is 15 if
  23.501 +   deflateInit is used instead.
  23.502 +
  23.503 +     windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
  23.504 +   determines the window size. deflate() will then generate raw deflate data
  23.505 +   with no zlib header or trailer, and will not compute an adler32 check value.
  23.506 +
  23.507 +     windowBits can also be greater than 15 for optional gzip encoding. Add
  23.508 +   16 to windowBits to write a simple gzip header and trailer around the
  23.509 +   compressed data instead of a zlib wrapper. The gzip header will have no
  23.510 +   file name, no extra data, no comment, no modification time (set to zero),
  23.511 +   no header crc, and the operating system will be set to 255 (unknown).  If a
  23.512 +   gzip stream is being written, strm->adler is a crc32 instead of an adler32.
  23.513 +
  23.514 +     The memLevel parameter specifies how much memory should be allocated
  23.515 +   for the internal compression state. memLevel=1 uses minimum memory but
  23.516 +   is slow and reduces compression ratio; memLevel=9 uses maximum memory
  23.517 +   for optimal speed. The default value is 8. See zconf.h for total memory
  23.518 +   usage as a function of windowBits and memLevel.
  23.519 +
  23.520 +     The strategy parameter is used to tune the compression algorithm. Use the
  23.521 +   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
  23.522 +   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
  23.523 +   string match), or Z_RLE to limit match distances to one (run-length
  23.524 +   encoding). Filtered data consists mostly of small values with a somewhat
  23.525 +   random distribution. In this case, the compression algorithm is tuned to
  23.526 +   compress them better. The effect of Z_FILTERED is to force more Huffman
  23.527 +   coding and less string matching; it is somewhat intermediate between
  23.528 +   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
  23.529 +   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
  23.530 +   parameter only affects the compression ratio but not the correctness of the
  23.531 +   compressed output even if it is not set appropriately.  Z_FIXED prevents the
  23.532 +   use of dynamic Huffman codes, allowing for a simpler decoder for special
  23.533 +   applications.
  23.534 +
  23.535 +      deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
  23.536 +   memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
  23.537 +   method). msg is set to null if there is no error message.  deflateInit2 does
  23.538 +   not perform any compression: this will be done by deflate().
  23.539 +*/
  23.540 +
  23.541 +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  23.542 +                                             const Bytef *dictionary,
  23.543 +                                             uInt  dictLength));
  23.544 +/*
  23.545 +     Initializes the compression dictionary from the given byte sequence
  23.546 +   without producing any compressed output. This function must be called
  23.547 +   immediately after deflateInit, deflateInit2 or deflateReset, before any
  23.548 +   call of deflate. The compressor and decompressor must use exactly the same
  23.549 +   dictionary (see inflateSetDictionary).
  23.550 +
  23.551 +     The dictionary should consist of strings (byte sequences) that are likely
  23.552 +   to be encountered later in the data to be compressed, with the most commonly
  23.553 +   used strings preferably put towards the end of the dictionary. Using a
  23.554 +   dictionary is most useful when the data to be compressed is short and can be
  23.555 +   predicted with good accuracy; the data can then be compressed better than
  23.556 +   with the default empty dictionary.
  23.557 +
  23.558 +     Depending on the size of the compression data structures selected by
  23.559 +   deflateInit or deflateInit2, a part of the dictionary may in effect be
  23.560 +   discarded, for example if the dictionary is larger than the window size in
  23.561 +   deflate or deflate2. Thus the strings most likely to be useful should be
  23.562 +   put at the end of the dictionary, not at the front. In addition, the
  23.563 +   current implementation of deflate will use at most the window size minus
  23.564 +   262 bytes of the provided dictionary.
  23.565 +
  23.566 +     Upon return of this function, strm->adler is set to the adler32 value
  23.567 +   of the dictionary; the decompressor may later use this value to determine
  23.568 +   which dictionary has been used by the compressor. (The adler32 value
  23.569 +   applies to the whole dictionary even if only a subset of the dictionary is
  23.570 +   actually used by the compressor.) If a raw deflate was requested, then the
  23.571 +   adler32 value is not computed and strm->adler is not set.
  23.572 +
  23.573 +     deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
  23.574 +   parameter is invalid (such as NULL dictionary) or the stream state is
  23.575 +   inconsistent (for example if deflate has already been called for this stream
  23.576 +   or if the compression method is bsort). deflateSetDictionary does not
  23.577 +   perform any compression: this will be done by deflate().
  23.578 +*/
  23.579 +
  23.580 +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  23.581 +                                    z_streamp source));
  23.582 +/*
  23.583 +     Sets the destination stream as a complete copy of the source stream.
  23.584 +
  23.585 +     This function can be useful when several compression strategies will be
  23.586 +   tried, for example when there are several ways of pre-processing the input
  23.587 +   data with a filter. The streams that will be discarded should then be freed
  23.588 +   by calling deflateEnd.  Note that deflateCopy duplicates the internal
  23.589 +   compression state which can be quite large, so this strategy is slow and
  23.590 +   can consume lots of memory.
  23.591 +
  23.592 +     deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
  23.593 +   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
  23.594 +   (such as zalloc being NULL). msg is left unchanged in both source and
  23.595 +   destination.
  23.596 +*/
  23.597 +
  23.598 +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  23.599 +/*
  23.600 +     This function is equivalent to deflateEnd followed by deflateInit,
  23.601 +   but does not free and reallocate all the internal compression state.
  23.602 +   The stream will keep the same compression level and any other attributes
  23.603 +   that may have been set by deflateInit2.
  23.604 +
  23.605 +      deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.606 +   stream state was inconsistent (such as zalloc or state being NULL).
  23.607 +*/
  23.608 +
  23.609 +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  23.610 +                                      int level,
  23.611 +                                      int strategy));
  23.612 +/*
  23.613 +     Dynamically update the compression level and compression strategy.  The
  23.614 +   interpretation of level and strategy is as in deflateInit2.  This can be
  23.615 +   used to switch between compression and straight copy of the input data, or
  23.616 +   to switch to a different kind of input data requiring a different
  23.617 +   strategy. If the compression level is changed, the input available so far
  23.618 +   is compressed with the old level (and may be flushed); the new level will
  23.619 +   take effect only at the next call of deflate().
  23.620 +
  23.621 +     Before the call of deflateParams, the stream state must be set as for
  23.622 +   a call of deflate(), since the currently available input may have to
  23.623 +   be compressed and flushed. In particular, strm->avail_out must be non-zero.
  23.624 +
  23.625 +     deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
  23.626 +   stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
  23.627 +   if strm->avail_out was zero.
  23.628 +*/
  23.629 +
  23.630 +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  23.631 +                                    int good_length,
  23.632 +                                    int max_lazy,
  23.633 +                                    int nice_length,
  23.634 +                                    int max_chain));
  23.635 +/*
  23.636 +     Fine tune deflate's internal compression parameters.  This should only be
  23.637 +   used by someone who understands the algorithm used by zlib's deflate for
  23.638 +   searching for the best matching string, and even then only by the most
  23.639 +   fanatic optimizer trying to squeeze out the last compressed bit for their
  23.640 +   specific input data.  Read the deflate.c source code for the meaning of the
  23.641 +   max_lazy, good_length, nice_length, and max_chain parameters.
  23.642 +
  23.643 +     deflateTune() can be called after deflateInit() or deflateInit2(), and
  23.644 +   returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
  23.645 + */
  23.646 +
  23.647 +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  23.648 +                                       uLong sourceLen));
  23.649 +/*
  23.650 +     deflateBound() returns an upper bound on the compressed size after
  23.651 +   deflation of sourceLen bytes.  It must be called after deflateInit()
  23.652 +   or deflateInit2().  This would be used to allocate an output buffer
  23.653 +   for deflation in a single pass, and so would be called before deflate().
  23.654 +*/
  23.655 +
  23.656 +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  23.657 +                                     int bits,
  23.658 +                                     int value));
  23.659 +/*
  23.660 +     deflatePrime() inserts bits in the deflate output stream.  The intent
  23.661 +  is that this function is used to start off the deflate output with the
  23.662 +  bits leftover from a previous deflate stream when appending to it.  As such,
  23.663 +  this function can only be used for raw deflate, and must be used before the
  23.664 +  first deflate() call after a deflateInit2() or deflateReset().  bits must be
  23.665 +  less than or equal to 16, and that many of the least significant bits of
  23.666 +  value will be inserted in the output.
  23.667 +
  23.668 +      deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.669 +   stream state was inconsistent.
  23.670 +*/
  23.671 +
  23.672 +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  23.673 +                                         gz_headerp head));
  23.674 +/*
  23.675 +      deflateSetHeader() provides gzip header information for when a gzip
  23.676 +   stream is requested by deflateInit2().  deflateSetHeader() may be called
  23.677 +   after deflateInit2() or deflateReset() and before the first call of
  23.678 +   deflate().  The text, time, os, extra field, name, and comment information
  23.679 +   in the provided gz_header structure are written to the gzip header (xflag is
  23.680 +   ignored -- the extra flags are set according to the compression level).  The
  23.681 +   caller must assure that, if not Z_NULL, name and comment are terminated with
  23.682 +   a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
  23.683 +   available there.  If hcrc is true, a gzip header crc is included.  Note that
  23.684 +   the current versions of the command-line version of gzip (up through version
  23.685 +   1.3.x) do not support header crc's, and will report that it is a "multi-part
  23.686 +   gzip file" and give up.
  23.687 +
  23.688 +      If deflateSetHeader is not used, the default gzip header has text false,
  23.689 +   the time set to zero, and os set to 255, with no extra, name, or comment
  23.690 +   fields.  The gzip header is returned to the default state by deflateReset().
  23.691 +
  23.692 +      deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.693 +   stream state was inconsistent.
  23.694 +*/
  23.695 +
  23.696 +/*
  23.697 +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
  23.698 +                                     int  windowBits));
  23.699 +
  23.700 +     This is another version of inflateInit with an extra parameter. The
  23.701 +   fields next_in, avail_in, zalloc, zfree and opaque must be initialized
  23.702 +   before by the caller.
  23.703 +
  23.704 +     The windowBits parameter is the base two logarithm of the maximum window
  23.705 +   size (the size of the history buffer).  It should be in the range 8..15 for
  23.706 +   this version of the library. The default value is 15 if inflateInit is used
  23.707 +   instead. windowBits must be greater than or equal to the windowBits value
  23.708 +   provided to deflateInit2() while compressing, or it must be equal to 15 if
  23.709 +   deflateInit2() was not used. If a compressed stream with a larger window
  23.710 +   size is given as input, inflate() will return with the error code
  23.711 +   Z_DATA_ERROR instead of trying to allocate a larger window.
  23.712 +
  23.713 +     windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
  23.714 +   determines the window size. inflate() will then process raw deflate data,
  23.715 +   not looking for a zlib or gzip header, not generating a check value, and not
  23.716 +   looking for any check values for comparison at the end of the stream. This
  23.717 +   is for use with other formats that use the deflate compressed data format
  23.718 +   such as zip.  Those formats provide their own check values. If a custom
  23.719 +   format is developed using the raw deflate format for compressed data, it is
  23.720 +   recommended that a check value such as an adler32 or a crc32 be applied to
  23.721 +   the uncompressed data as is done in the zlib, gzip, and zip formats.  For
  23.722 +   most applications, the zlib format should be used as is. Note that comments
  23.723 +   above on the use in deflateInit2() applies to the magnitude of windowBits.
  23.724 +
  23.725 +     windowBits can also be greater than 15 for optional gzip decoding. Add
  23.726 +   32 to windowBits to enable zlib and gzip decoding with automatic header
  23.727 +   detection, or add 16 to decode only the gzip format (the zlib format will
  23.728 +   return a Z_DATA_ERROR).  If a gzip stream is being decoded, strm->adler is
  23.729 +   a crc32 instead of an adler32.
  23.730 +
  23.731 +     inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
  23.732 +   memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
  23.733 +   is set to null if there is no error message.  inflateInit2 does not perform
  23.734 +   any decompression apart from reading the zlib header if present: this will
  23.735 +   be done by inflate(). (So next_in and avail_in may be modified, but next_out
  23.736 +   and avail_out are unchanged.)
  23.737 +*/
  23.738 +
  23.739 +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  23.740 +                                             const Bytef *dictionary,
  23.741 +                                             uInt  dictLength));
  23.742 +/*
  23.743 +     Initializes the decompression dictionary from the given uncompressed byte
  23.744 +   sequence. This function must be called immediately after a call of inflate,
  23.745 +   if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
  23.746 +   can be determined from the adler32 value returned by that call of inflate.
  23.747 +   The compressor and decompressor must use exactly the same dictionary (see
  23.748 +   deflateSetDictionary).  For raw inflate, this function can be called
  23.749 +   immediately after inflateInit2() or inflateReset() and before any call of
  23.750 +   inflate() to set the dictionary.  The application must insure that the
  23.751 +   dictionary that was used for compression is provided.
  23.752 +
  23.753 +     inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
  23.754 +   parameter is invalid (such as NULL dictionary) or the stream state is
  23.755 +   inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
  23.756 +   expected one (incorrect adler32 value). inflateSetDictionary does not
  23.757 +   perform any decompression: this will be done by subsequent calls of
  23.758 +   inflate().
  23.759 +*/
  23.760 +
  23.761 +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  23.762 +/*
  23.763 +    Skips invalid compressed data until a full flush point (see above the
  23.764 +  description of deflate with Z_FULL_FLUSH) can be found, or until all
  23.765 +  available input is skipped. No output is provided.
  23.766 +
  23.767 +    inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
  23.768 +  if no more input was provided, Z_DATA_ERROR if no flush point has been found,
  23.769 +  or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
  23.770 +  case, the application may save the current current value of total_in which
  23.771 +  indicates where valid compressed data was found. In the error case, the
  23.772 +  application may repeatedly call inflateSync, providing more input each time,
  23.773 +  until success or end of the input data.
  23.774 +*/
  23.775 +
  23.776 +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  23.777 +                                    z_streamp source));
  23.778 +/*
  23.779 +     Sets the destination stream as a complete copy of the source stream.
  23.780 +
  23.781 +     This function can be useful when randomly accessing a large stream.  The
  23.782 +   first pass through the stream can periodically record the inflate state,
  23.783 +   allowing restarting inflate at those points when randomly accessing the
  23.784 +   stream.
  23.785 +
  23.786 +     inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
  23.787 +   enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
  23.788 +   (such as zalloc being NULL). msg is left unchanged in both source and
  23.789 +   destination.
  23.790 +*/
  23.791 +
  23.792 +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  23.793 +/*
  23.794 +     This function is equivalent to inflateEnd followed by inflateInit,
  23.795 +   but does not free and reallocate all the internal decompression state.
  23.796 +   The stream will keep attributes that may have been set by inflateInit2.
  23.797 +
  23.798 +      inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.799 +   stream state was inconsistent (such as zalloc or state being NULL).
  23.800 +*/
  23.801 +
  23.802 +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  23.803 +                                     int bits,
  23.804 +                                     int value));
  23.805 +/*
  23.806 +     This function inserts bits in the inflate input stream.  The intent is
  23.807 +  that this function is used to start inflating at a bit position in the
  23.808 +  middle of a byte.  The provided bits will be used before any bytes are used
  23.809 +  from next_in.  This function should only be used with raw inflate, and
  23.810 +  should be used before the first inflate() call after inflateInit2() or
  23.811 +  inflateReset().  bits must be less than or equal to 16, and that many of the
  23.812 +  least significant bits of value will be inserted in the input.
  23.813 +
  23.814 +      inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.815 +   stream state was inconsistent.
  23.816 +*/
  23.817 +
  23.818 +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  23.819 +                                         gz_headerp head));
  23.820 +/*
  23.821 +      inflateGetHeader() requests that gzip header information be stored in the
  23.822 +   provided gz_header structure.  inflateGetHeader() may be called after
  23.823 +   inflateInit2() or inflateReset(), and before the first call of inflate().
  23.824 +   As inflate() processes the gzip stream, head->done is zero until the header
  23.825 +   is completed, at which time head->done is set to one.  If a zlib stream is
  23.826 +   being decoded, then head->done is set to -1 to indicate that there will be
  23.827 +   no gzip header information forthcoming.  Note that Z_BLOCK can be used to
  23.828 +   force inflate() to return immediately after header processing is complete
  23.829 +   and before any actual data is decompressed.
  23.830 +
  23.831 +      The text, time, xflags, and os fields are filled in with the gzip header
  23.832 +   contents.  hcrc is set to true if there is a header CRC.  (The header CRC
  23.833 +   was valid if done is set to one.)  If extra is not Z_NULL, then extra_max
  23.834 +   contains the maximum number of bytes to write to extra.  Once done is true,
  23.835 +   extra_len contains the actual extra field length, and extra contains the
  23.836 +   extra field, or that field truncated if extra_max is less than extra_len.
  23.837 +   If name is not Z_NULL, then up to name_max characters are written there,
  23.838 +   terminated with a zero unless the length is greater than name_max.  If
  23.839 +   comment is not Z_NULL, then up to comm_max characters are written there,
  23.840 +   terminated with a zero unless the length is greater than comm_max.  When
  23.841 +   any of extra, name, or comment are not Z_NULL and the respective field is
  23.842 +   not present in the header, then that field is set to Z_NULL to signal its
  23.843 +   absence.  This allows the use of deflateSetHeader() with the returned
  23.844 +   structure to duplicate the header.  However if those fields are set to
  23.845 +   allocated memory, then the application will need to save those pointers
  23.846 +   elsewhere so that they can be eventually freed.
  23.847 +
  23.848 +      If inflateGetHeader is not used, then the header information is simply
  23.849 +   discarded.  The header is always checked for validity, including the header
  23.850 +   CRC if present.  inflateReset() will reset the process to discard the header
  23.851 +   information.  The application would need to call inflateGetHeader() again to
  23.852 +   retrieve the header from the next gzip stream.
  23.853 +
  23.854 +      inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
  23.855 +   stream state was inconsistent.
  23.856 +*/
  23.857 +
  23.858 +/*
  23.859 +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
  23.860 +                                        unsigned char FAR *window));
  23.861 +
  23.862 +     Initialize the internal stream state for decompression using inflateBack()
  23.863 +   calls.  The fields zalloc, zfree and opaque in strm must be initialized
  23.864 +   before the call.  If zalloc and zfree are Z_NULL, then the default library-
  23.865 +   derived memory allocation routines are used.  windowBits is the base two
  23.866 +   logarithm of the window size, in the range 8..15.  window is a caller
  23.867 +   supplied buffer of that size.  Except for special applications where it is
  23.868 +   assured that deflate was used with small window sizes, windowBits must be 15
  23.869 +   and a 32K byte window must be supplied to be able to decompress general
  23.870 +   deflate streams.
  23.871 +
  23.872 +     See inflateBack() for the usage of these routines.
  23.873 +
  23.874 +     inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
  23.875 +   the paramaters are invalid, Z_MEM_ERROR if the internal state could not
  23.876 +   be allocated, or Z_VERSION_ERROR if the version of the library does not
  23.877 +   match the version of the header file.
  23.878 +*/
  23.879 +
  23.880 +typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  23.881 +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  23.882 +
  23.883 +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  23.884 +                                    in_func in, void FAR *in_desc,
  23.885 +                                    out_func out, void FAR *out_desc));
  23.886 +/*
  23.887 +     inflateBack() does a raw inflate with a single call using a call-back
  23.888 +   interface for input and output.  This is more efficient than inflate() for
  23.889 +   file i/o applications in that it avoids copying between the output and the
  23.890 +   sliding window by simply making the window itself the output buffer.  This
  23.891 +   function trusts the application to not change the output buffer passed by
  23.892 +   the output function, at least until inflateBack() returns.
  23.893 +
  23.894 +     inflateBackInit() must be called first to allocate the internal state
  23.895 +   and to initialize the state with the user-provided window buffer.
  23.896 +   inflateBack() may then be used multiple times to inflate a complete, raw
  23.897 +   deflate stream with each call.  inflateBackEnd() is then called to free
  23.898 +   the allocated state.
  23.899 +
  23.900 +     A raw deflate stream is one with no zlib or gzip header or trailer.
  23.901 +   This routine would normally be used in a utility that reads zip or gzip
  23.902 +   files and writes out uncompressed files.  The utility would decode the
  23.903 +   header and process the trailer on its own, hence this routine expects
  23.904 +   only the raw deflate stream to decompress.  This is different from the
  23.905 +   normal behavior of inflate(), which expects either a zlib or gzip header and
  23.906 +   trailer around the deflate stream.
  23.907 +
  23.908 +     inflateBack() uses two subroutines supplied by the caller that are then
  23.909 +   called by inflateBack() for input and output.  inflateBack() calls those
  23.910 +   routines until it reads a complete deflate stream and writes out all of the
  23.911 +   uncompressed data, or until it encounters an error.  The function's
  23.912 +   parameters and return types are defined above in the in_func and out_func
  23.913 +   typedefs.  inflateBack() will call in(in_desc, &buf) which should return the
  23.914 +   number of bytes of provided input, and a pointer to that input in buf.  If
  23.915 +   there is no input available, in() must return zero--buf is ignored in that
  23.916 +   case--and inflateBack() will return a buffer error.  inflateBack() will call
  23.917 +   out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].  out()
  23.918 +   should return zero on success, or non-zero on failure.  If out() returns
  23.919 +   non-zero, inflateBack() will return with an error.  Neither in() nor out()
  23.920 +   are permitted to change the contents of the window provided to
  23.921 +   inflateBackInit(), which is also the buffer that out() uses to write from.
  23.922 +   The length written by out() will be at most the window size.  Any non-zero
  23.923 +   amount of input may be provided by in().
  23.924 +
  23.925 +     For convenience, inflateBack() can be provided input on the first call by
  23.926 +   setting strm->next_in and strm->avail_in.  If that input is exhausted, then
  23.927 +   in() will be called.  Therefore strm->next_in must be initialized before
  23.928 +   calling inflateBack().  If strm->next_in is Z_NULL, then in() will be called
  23.929 +   immediately for input.  If strm->next_in is not Z_NULL, then strm->avail_in
  23.930 +   must also be initialized, and then if strm->avail_in is not zero, input will
  23.931 +   initially be taken from strm->next_in[0 .. strm->avail_in - 1].
  23.932 +
  23.933 +     The in_desc and out_desc parameters of inflateBack() is passed as the
  23.934 +   first parameter of in() and out() respectively when they are called.  These
  23.935 +   descriptors can be optionally used to pass any information that the caller-
  23.936 +   supplied in() and out() functions need to do their job.
  23.937 +
  23.938 +     On return, inflateBack() will set strm->next_in and strm->avail_in to
  23.939 +   pass back any unused input that was provided by the last in() call.  The
  23.940 +   return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
  23.941 +   if in() or out() returned an error, Z_DATA_ERROR if there was a format
  23.942 +   error in the deflate stream (in which case strm->msg is set to indicate the
  23.943 +   nature of the error), or Z_STREAM_ERROR if the stream was not properly
  23.944 +   initialized.  In the case of Z_BUF_ERROR, an input or output error can be
  23.945 +   distinguished using strm->next_in which will be Z_NULL only if in() returned
  23.946 +   an error.  If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
  23.947 +   out() returning non-zero.  (in() will always be called before out(), so
  23.948 +   strm->next_in is assured to be defined if out() returns non-zero.)  Note
  23.949 +   that inflateBack() cannot return Z_OK.
  23.950 +*/
  23.951 +
  23.952 +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  23.953 +/*
  23.954 +     All memory allocated by inflateBackInit() is freed.
  23.955 +
  23.956 +     inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
  23.957 +   state was inconsistent.
  23.958 +*/
  23.959 +
  23.960 +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  23.961 +/* Return flags indicating compile-time options.
  23.962 +
  23.963 +    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
  23.964 +     1.0: size of uInt
  23.965 +     3.2: size of uLong
  23.966 +     5.4: size of voidpf (pointer)
  23.967 +     7.6: size of z_off_t
  23.968 +
  23.969 +    Compiler, assembler, and debug options:
  23.970 +     8: DEBUG
  23.971 +     9: ASMV or ASMINF -- use ASM code
  23.972 +     10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
  23.973 +     11: 0 (reserved)
  23.974 +
  23.975 +    One-time table building (smaller code, but not thread-safe if true):
  23.976 +     12: BUILDFIXED -- build static block decoding tables when needed
  23.977 +     13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
  23.978 +     14,15: 0 (reserved)
  23.979 +
  23.980 +    Library content (indicates missing functionality):
  23.981 +     16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
  23.982 +                          deflate code when not needed)
  23.983 +     17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
  23.984 +                    and decode gzip streams (to avoid linking crc code)
  23.985 +     18-19: 0 (reserved)
  23.986 +
  23.987 +    Operation variations (changes in library functionality):
  23.988 +     20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
  23.989 +     21: FASTEST -- deflate algorithm with only one, lowest compression level
  23.990 +     22,23: 0 (reserved)
  23.991 +
  23.992 +    The sprintf variant used by gzprintf (zero is best):
  23.993 +     24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
  23.994 +     25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
  23.995 +     26: 0 = returns value, 1 = void -- 1 means inferred string length returned
  23.996 +
  23.997 +    Remainder:
  23.998 +     27-31: 0 (reserved)
  23.999 + */
 23.1000 +
 23.1001 +
 23.1002 +                        /* utility functions */
 23.1003 +
 23.1004 +/*
 23.1005 +     The following utility functions are implemented on top of the
 23.1006 +   basic stream-oriented functions. To simplify the interface, some
 23.1007 +   default options are assumed (compression level and memory usage,
 23.1008 +   standard memory allocation functions). The source code of these
 23.1009 +   utility functions can easily be modified if you need special options.
 23.1010 +*/
 23.1011 +
 23.1012 +ZEXTERN int ZEXPORT compress OF((Bytef *dest,   uLongf *destLen,
 23.1013 +                                 const Bytef *source, uLong sourceLen));
 23.1014 +/*
 23.1015 +     Compresses the source buffer into the destination buffer.  sourceLen is
 23.1016 +   the byte length of the source buffer. Upon entry, destLen is the total
 23.1017 +   size of the destination buffer, which must be at least the value returned
 23.1018 +   by compressBound(sourceLen). Upon exit, destLen is the actual size of the
 23.1019 +   compressed buffer.
 23.1020 +     This function can be used to compress a whole file at once if the
 23.1021 +   input file is mmap'ed.
 23.1022 +     compress returns Z_OK if success, Z_MEM_ERROR if there was not
 23.1023 +   enough memory, Z_BUF_ERROR if there was not enough room in the output
 23.1024 +   buffer.
 23.1025 +*/
 23.1026 +
 23.1027 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,
 23.1028 +                                  const Bytef *source, uLong sourceLen,
 23.1029 +                                  int level));
 23.1030 +/*
 23.1031 +     Compresses the source buffer into the destination buffer. The level
 23.1032 +   parameter has the same meaning as in deflateInit.  sourceLen is the byte
 23.1033 +   length of the source buffer. Upon entry, destLen is the total size of the
 23.1034 +   destination buffer, which must be at least the value returned by
 23.1035 +   compressBound(sourceLen). Upon exit, destLen is the actual size of the
 23.1036 +   compressed buffer.
 23.1037 +
 23.1038 +     compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
 23.1039 +   memory, Z_BUF_ERROR if there was not enough room in the output buffer,
 23.1040 +   Z_STREAM_ERROR if the level parameter is invalid.
 23.1041 +*/
 23.1042 +
 23.1043 +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
 23.1044 +/*
 23.1045 +     compressBound() returns an upper bound on the compressed size after
 23.1046 +   compress() or compress2() on sourceLen bytes.  It would be used before
 23.1047 +   a compress() or compress2() call to allocate the destination buffer.
 23.1048 +*/
 23.1049 +
 23.1050 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,
 23.1051 +                                   const Bytef *source, uLong sourceLen));
 23.1052 +/*
 23.1053 +     Decompresses the source buffer into the destination buffer.  sourceLen is
 23.1054 +   the byte length of the source buffer. Upon entry, destLen is the total
 23.1055 +   size of the destination buffer, which must be large enough to hold the
 23.1056 +   entire uncompressed data. (The size of the uncompressed data must have
 23.1057 +   been saved previously by the compressor and transmitted to the decompressor
 23.1058 +   by some mechanism outside the scope of this compression library.)
 23.1059 +   Upon exit, destLen is the actual size of the compressed buffer.
 23.1060 +     This function can be used to decompress a whole file at once if the
 23.1061 +   input file is mmap'ed.
 23.1062 +
 23.1063 +     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
 23.1064 +   enough memory, Z_BUF_ERROR if there was not enough room in the output
 23.1065 +   buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
 23.1066 +*/
 23.1067 +
 23.1068 +
 23.1069 +typedef voidp gzFile;
 23.1070 +
 23.1071 +ZEXTERN gzFile ZEXPORT gzopen  OF((const char *path, const char *mode));
 23.1072 +/*
 23.1073 +     Opens a gzip (.gz) file for reading or writing. The mode parameter
 23.1074 +   is as in fopen ("rb" or "wb") but can also include a compression level
 23.1075 +   ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
 23.1076 +   Huffman only compression as in "wb1h", or 'R' for run-length encoding
 23.1077 +   as in "wb1R". (See the description of deflateInit2 for more information
 23.1078 +   about the strategy parameter.)
 23.1079 +
 23.1080 +     gzopen can be used to read a file which is not in gzip format; in this
 23.1081 +   case gzread will directly read from the file without decompression.
 23.1082 +
 23.1083 +     gzopen returns NULL if the file could not be opened or if there was
 23.1084 +   insufficient memory to allocate the (de)compression state; errno
 23.1085 +   can be checked to distinguish the two cases (if errno is zero, the
 23.1086 +   zlib error is Z_MEM_ERROR).  */
 23.1087 +
 23.1088 +ZEXTERN gzFile ZEXPORT gzdopen  OF((int fd, const char *mode));
 23.1089 +/*
 23.1090 +     gzdopen() associates a gzFile with the file descriptor fd.  File
 23.1091 +   descriptors are obtained from calls like open, dup, creat, pipe or
 23.1092 +   fileno (in the file has been previously opened with fopen).
 23.1093 +   The mode parameter is as in gzopen.
 23.1094 +     The next call of gzclose on the returned gzFile will also close the
 23.1095 +   file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
 23.1096 +   descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
 23.1097 +     gzdopen returns NULL if there was insufficient memory to allocate
 23.1098 +   the (de)compression state.
 23.1099 +*/
 23.1100 +
 23.1101 +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
 23.1102 +/*
 23.1103 +     Dynamically update the compression level or strategy. See the description
 23.1104 +   of deflateInit2 for the meaning of these parameters.
 23.1105 +     gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
 23.1106 +   opened for writing.
 23.1107 +*/
 23.1108 +
 23.1109 +ZEXTERN int ZEXPORT    gzread  OF((gzFile file, voidp buf, unsigned len));
 23.1110 +/*
 23.1111 +     Reads the given number of uncompressed bytes from the compressed file.
 23.1112 +   If the input file was not in gzip format, gzread copies the given number
 23.1113 +   of bytes into the buffer.
 23.1114 +     gzread returns the number of uncompressed bytes actually read (0 for
 23.1115 +   end of file, -1 for error). */
 23.1116 +
 23.1117 +ZEXTERN int ZEXPORT    gzwrite OF((gzFile file,
 23.1118 +                                   voidpc buf, unsigned len));
 23.1119 +/*
 23.1120 +     Writes the given number of uncompressed bytes into the compressed file.
 23.1121 +   gzwrite returns the number of uncompressed bytes actually written
 23.1122 +   (0 in case of error).
 23.1123 +*/
 23.1124 +
 23.1125 +ZEXTERN int ZEXPORTVA   gzprintf OF((gzFile file, const char *format, ...));
 23.1126 +/*
 23.1127 +     Converts, formats, and writes the args to the compressed file under
 23.1128 +   control of the format string, as in fprintf. gzprintf returns the number of
 23.1129 +   uncompressed bytes actually written (0 in case of error).  The number of
 23.1130 +   uncompressed bytes written is limited to 4095. The caller should assure that
 23.1131 +   this limit is not exceeded. If it is exceeded, then gzprintf() will return
 23.1132 +   return an error (0) with nothing written. In this case, there may also be a
 23.1133 +   buffer overflow with unpredictable consequences, which is possible only if
 23.1134 +   zlib was compiled with the insecure functions sprintf() or vsprintf()
 23.1135 +   because the secure snprintf() or vsnprintf() functions were not available.
 23.1136 +*/
 23.1137 +
 23.1138 +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
 23.1139 +/*
 23.1140 +      Writes the given null-terminated string to the compressed file, excluding
 23.1141 +   the terminating null character.
 23.1142 +      gzputs returns the number of characters written, or -1 in case of error.
 23.1143 +*/
 23.1144 +
 23.1145 +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
 23.1146 +/*
 23.1147 +      Reads bytes from the compressed file until len-1 characters are read, or
 23.1148 +   a newline character is read and transferred to buf, or an end-of-file
 23.1149 +   condition is encountered.  The string is then terminated with a null
 23.1150 +   character.
 23.1151 +      gzgets returns buf, or Z_NULL in case of error.
 23.1152 +*/
 23.1153 +
 23.1154 +ZEXTERN int ZEXPORT    gzputc OF((gzFile file, int c));
 23.1155 +/*
 23.1156 +      Writes c, converted to an unsigned char, into the compressed file.
 23.1157 +   gzputc returns the value that was written, or -1 in case of error.
 23.1158 +*/
 23.1159 +
 23.1160 +ZEXTERN int ZEXPORT    gzgetc OF((gzFile file));
 23.1161 +/*
 23.1162 +      Reads one byte from the compressed file. gzgetc returns this byte
 23.1163 +   or -1 in case of end of file or error.
 23.1164 +*/
 23.1165 +
 23.1166 +ZEXTERN int ZEXPORT    gzungetc OF((int c, gzFile file));
 23.1167 +/*
 23.1168 +      Push one character back onto the stream to be read again later.
 23.1169 +   Only one character of push-back is allowed.  gzungetc() returns the
 23.1170 +   character pushed, or -1 on failure.  gzungetc() will fail if a
 23.1171 +   character has been pushed but not read yet, or if c is -1. The pushed
 23.1172 +   character will be discarded if the stream is repositioned with gzseek()
 23.1173 +   or gzrewind().
 23.1174 +*/
 23.1175 +
 23.1176 +ZEXTERN int ZEXPORT    gzflush OF((gzFile file, int flush));
 23.1177 +/*
 23.1178 +     Flushes all pending output into the compressed file. The parameter
 23.1179 +   flush is as in the deflate() function. The return value is the zlib
 23.1180 +   error number (see function gzerror below). gzflush returns Z_OK if
 23.1181 +   the flush parameter is Z_FINISH and all output could be flushed.
 23.1182 +     gzflush should be called only when strictly necessary because it can
 23.1183 +   degrade compression.
 23.1184 +*/
 23.1185 +
 23.1186 +ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
 23.1187 +                                      z_off_t offset, int whence));
 23.1188 +/*
 23.1189 +      Sets the starting position for the next gzread or gzwrite on the
 23.1190 +   given compressed file. The offset represents a number of bytes in the
 23.1191 +   uncompressed data stream. The whence parameter is defined as in lseek(2);
 23.1192 +   the value SEEK_END is not supported.
 23.1193 +     If the file is opened for reading, this function is emulated but can be
 23.1194 +   extremely slow. If the file is opened for writing, only forward seeks are
 23.1195 +   supported; gzseek then compresses a sequence of zeroes up to the new
 23.1196 +   starting position.
 23.1197 +
 23.1198 +      gzseek returns the resulting offset location as measured in bytes from
 23.1199 +   the beginning of the uncompressed stream, or -1 in case of error, in
 23.1200 +   particular if the file is opened for writing and the new starting position
 23.1201 +   would be before the current position.
 23.1202 +*/
 23.1203 +
 23.1204 +ZEXTERN int ZEXPORT    gzrewind OF((gzFile file));
 23.1205 +/*
 23.1206 +     Rewinds the given file. This function is supported only for reading.
 23.1207 +
 23.1208 +   gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 23.1209 +*/
 23.1210 +
 23.1211 +ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
 23.1212 +/*
 23.1213 +     Returns the starting position for the next gzread or gzwrite on the
 23.1214 +   given compressed file. This position represents a number of bytes in the
 23.1215 +   uncompressed data stream.
 23.1216 +
 23.1217 +   gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 23.1218 +*/
 23.1219 +
 23.1220 +ZEXTERN int ZEXPORT gzeof OF((gzFile file));
 23.1221 +/*
 23.1222 +     Returns 1 when EOF has previously been detected reading the given
 23.1223 +   input stream, otherwise zero.
 23.1224 +*/
 23.1225 +
 23.1226 +ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
 23.1227 +/*
 23.1228 +     Returns 1 if file is being read directly without decompression, otherwise
 23.1229 +   zero.
 23.1230 +*/
 23.1231 +
 23.1232 +ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
 23.1233 +/*
 23.1234 +     Flushes all pending output if necessary, closes the compressed file
 23.1235 +   and deallocates all the (de)compression state. The return value is the zlib
 23.1236 +   error number (see function gzerror below).
 23.1237 +*/
 23.1238 +
 23.1239 +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
 23.1240 +/*
 23.1241 +     Returns the error message for the last error which occurred on the
 23.1242 +   given compressed file. errnum is set to zlib error number. If an
 23.1243 +   error occurred in the file system and not in the compression library,
 23.1244 +   errnum is set to Z_ERRNO and the application may consult errno
 23.1245 +   to get the exact error code.
 23.1246 +*/
 23.1247 +
 23.1248 +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
 23.1249 +/*
 23.1250 +     Clears the error and end-of-file flags for file. This is analogous to the
 23.1251 +   clearerr() function in stdio. This is useful for continuing to read a gzip
 23.1252 +   file that is being written concurrently.
 23.1253 +*/
 23.1254 +
 23.1255 +                        /* checksum functions */
 23.1256 +
 23.1257 +/*
 23.1258 +     These functions are not related to compression but are exported
 23.1259 +   anyway because they might be useful in applications using the
 23.1260 +   compression library.
 23.1261 +*/
 23.1262 +
 23.1263 +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
 23.1264 +/*
 23.1265 +     Update a running Adler-32 checksum with the bytes buf[0..len-1] and
 23.1266 +   return the updated checksum. If buf is NULL, this function returns
 23.1267 +   the required initial value for the checksum.
 23.1268 +   An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
 23.1269 +   much faster. Usage example:
 23.1270 +
 23.1271 +     uLong adler = adler32(0L, Z_NULL, 0);
 23.1272 +
 23.1273 +     while (read_buffer(buffer, length) != EOF) {
 23.1274 +       adler = adler32(adler, buffer, length);
 23.1275 +     }
 23.1276 +     if (adler != original_adler) error();
 23.1277 +*/
 23.1278 +
 23.1279 +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
 23.1280 +                                          z_off_t len2));
 23.1281 +/*
 23.1282 +     Combine two Adler-32 checksums into one.  For two sequences of bytes, seq1
 23.1283 +   and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
 23.1284 +   each, adler1 and adler2.  adler32_combine() returns the Adler-32 checksum of
 23.1285 +   seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
 23.1286 +*/
 23.1287 +
 23.1288 +ZEXTERN uLong ZEXPORT crc32   OF((uLong crc, const Bytef *buf, uInt len));
 23.1289 +/*
 23.1290 +     Update a running CRC-32 with the bytes buf[0..len-1] and return the
 23.1291 +   updated CRC-32. If buf is NULL, this function returns the required initial
 23.1292 +   value for the for the crc. Pre- and post-conditioning (one's complement) is
 23.1293 +   performed within this function so it shouldn't be done by the application.
 23.1294 +   Usage example:
 23.1295 +
 23.1296 +     uLong crc = crc32(0L, Z_NULL, 0);
 23.1297 +
 23.1298 +     while (read_buffer(buffer, length) != EOF) {
 23.1299 +       crc = crc32(crc, buffer, length);
 23.1300 +     }
 23.1301 +     if (crc != original_crc) error();
 23.1302 +*/
 23.1303 +
 23.1304 +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
 23.1305 +
 23.1306 +/*
 23.1307 +     Combine two CRC-32 check values into one.  For two sequences of bytes,
 23.1308 +   seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 23.1309 +   calculated for each, crc1 and crc2.  crc32_combine() returns the CRC-32
 23.1310 +   check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
 23.1311 +   len2.
 23.1312 +*/
 23.1313 +
 23.1314 +
 23.1315 +                        /* various hacks, don't look :) */
 23.1316 +
 23.1317 +/* deflateInit and inflateInit are macros to allow checking the zlib version
 23.1318 + * and the compiler's view of z_stream:
 23.1319 + */
 23.1320 +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
 23.1321 +                                     const char *version, int stream_size));
 23.1322 +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
 23.1323 +                                     const char *version, int stream_size));
 23.1324 +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int  level, int  method,
 23.1325 +                                      int windowBits, int memLevel,
 23.1326 +                                      int strategy, const char *version,
 23.1327 +                                      int stream_size));
 23.1328 +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
 23.1329 +                                      const char *version, int stream_size));
 23.1330 +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
 23.1331 +                                         unsigned char FAR *window,
 23.1332 +                                         const char *version,
 23.1333 +                                         int stream_size));
 23.1334 +#define deflateInit(strm, level) \
 23.1335 +        deflateInit_((strm), (level),       ZLIB_VERSION, sizeof(z_stream))
 23.1336 +#define inflateInit(strm) \
 23.1337 +        inflateInit_((strm),                ZLIB_VERSION, sizeof(z_stream))
 23.1338 +#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
 23.1339 +        deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
 23.1340 +                      (strategy),           ZLIB_VERSION, sizeof(z_stream))
 23.1341 +#define inflateInit2(strm, windowBits) \
 23.1342 +        inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
 23.1343 +#define inflateBackInit(strm, windowBits, window) \
 23.1344 +        inflateBackInit_((strm), (windowBits), (window), \
 23.1345 +        ZLIB_VERSION, sizeof(z_stream))
 23.1346 +
 23.1347 +
 23.1348 +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
 23.1349 +    struct internal_state {int dummy;}; /* hack for buggy compilers */
 23.1350 +#endif
 23.1351 +
 23.1352 +ZEXTERN const char   * ZEXPORT zError           OF((int));
 23.1353 +ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
 23.1354 +ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
 23.1355 +
 23.1356 +#ifdef __cplusplus
 23.1357 +}
 23.1358 +#endif
 23.1359 +
 23.1360 +#endif /* ZLIB_H */
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/compiler-init/zlib/zutil.c	Sat Jul 15 04:51:28 2006 +0000
    24.3 @@ -0,0 +1,318 @@
    24.4 +/* zutil.c -- target dependent utility functions for the compression library
    24.5 + * Copyright (C) 1995-2005 Jean-loup Gailly.
    24.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    24.7 + */
    24.8 +
    24.9 +/* @(#) $Id$ */
   24.10 +
   24.11 +#include "zutil.h"
   24.12 +
   24.13 +#ifndef NO_DUMMY_DECL
   24.14 +struct internal_state      {int dummy;}; /* for buggy compilers */
   24.15 +#endif
   24.16 +
   24.17 +const char * const z_errmsg[10] = {
   24.18 +"need dictionary",     /* Z_NEED_DICT       2  */
   24.19 +"stream end",          /* Z_STREAM_END      1  */
   24.20 +"",                    /* Z_OK              0  */
   24.21 +"file error",          /* Z_ERRNO         (-1) */
   24.22 +"stream error",        /* Z_STREAM_ERROR  (-2) */
   24.23 +"data error",          /* Z_DATA_ERROR    (-3) */
   24.24 +"insufficient memory", /* Z_MEM_ERROR     (-4) */
   24.25 +"buffer error",        /* Z_BUF_ERROR     (-5) */
   24.26 +"incompatible version",/* Z_VERSION_ERROR (-6) */
   24.27 +""};
   24.28 +
   24.29 +
   24.30 +const char * ZEXPORT zlibVersion()
   24.31 +{
   24.32 +    return ZLIB_VERSION;
   24.33 +}
   24.34 +
   24.35 +uLong ZEXPORT zlibCompileFlags()
   24.36 +{
   24.37 +    uLong flags;
   24.38 +
   24.39 +    flags = 0;
   24.40 +    switch (sizeof(uInt)) {
   24.41 +    case 2:     break;
   24.42 +    case 4:     flags += 1;     break;
   24.43 +    case 8:     flags += 2;     break;
   24.44 +    default:    flags += 3;
   24.45 +    }
   24.46 +    switch (sizeof(uLong)) {
   24.47 +    case 2:     break;
   24.48 +    case 4:     flags += 1 << 2;        break;
   24.49 +    case 8:     flags += 2 << 2;        break;
   24.50 +    default:    flags += 3 << 2;
   24.51 +    }
   24.52 +    switch (sizeof(voidpf)) {
   24.53 +    case 2:     break;
   24.54 +    case 4:     flags += 1 << 4;        break;
   24.55 +    case 8:     flags += 2 << 4;        break;
   24.56 +    default:    flags += 3 << 4;
   24.57 +    }
   24.58 +    switch (sizeof(z_off_t)) {
   24.59 +    case 2:     break;
   24.60 +    case 4:     flags += 1 << 6;        break;
   24.61 +    case 8:     flags += 2 << 6;        break;
   24.62 +    default:    flags += 3 << 6;
   24.63 +    }
   24.64 +#ifdef DEBUG
   24.65 +    flags += 1 << 8;
   24.66 +#endif
   24.67 +#if defined(ASMV) || defined(ASMINF)
   24.68 +    flags += 1 << 9;
   24.69 +#endif
   24.70 +#ifdef ZLIB_WINAPI
   24.71 +    flags += 1 << 10;
   24.72 +#endif
   24.73 +#ifdef BUILDFIXED
   24.74 +    flags += 1 << 12;
   24.75 +#endif
   24.76 +#ifdef DYNAMIC_CRC_TABLE
   24.77 +    flags += 1 << 13;
   24.78 +#endif
   24.79 +#ifdef NO_GZCOMPRESS
   24.80 +    flags += 1L << 16;
   24.81 +#endif
   24.82 +#ifdef NO_GZIP
   24.83 +    flags += 1L << 17;
   24.84 +#endif
   24.85 +#ifdef PKZIP_BUG_WORKAROUND
   24.86 +    flags += 1L << 20;
   24.87 +#endif
   24.88 +#ifdef FASTEST
   24.89 +    flags += 1L << 21;
   24.90 +#endif
   24.91 +#ifdef STDC
   24.92 +#  ifdef NO_vsnprintf
   24.93 +        flags += 1L << 25;
   24.94 +#    ifdef HAS_vsprintf_void
   24.95 +        flags += 1L << 26;
   24.96 +#    endif
   24.97 +#  else
   24.98 +#    ifdef HAS_vsnprintf_void
   24.99 +        flags += 1L << 26;
  24.100 +#    endif
  24.101 +#  endif
  24.102 +#else
  24.103 +        flags += 1L << 24;
  24.104 +#  ifdef NO_snprintf
  24.105 +        flags += 1L << 25;
  24.106 +#    ifdef HAS_sprintf_void
  24.107 +        flags += 1L << 26;
  24.108 +#    endif
  24.109 +#  else
  24.110 +#    ifdef HAS_snprintf_void
  24.111 +        flags += 1L << 26;
  24.112 +#    endif
  24.113 +#  endif
  24.114 +#endif
  24.115 +    return flags;
  24.116 +}
  24.117 +
  24.118 +#ifdef DEBUG
  24.119 +
  24.120 +#  ifndef verbose
  24.121 +#    define verbose 0
  24.122 +#  endif
  24.123 +int z_verbose = verbose;
  24.124 +
  24.125 +void z_error (m)
  24.126 +    char *m;
  24.127 +{
  24.128 +    fprintf(stderr, "%s\n", m);
  24.129 +    exit(1);
  24.130 +}
  24.131 +#endif
  24.132 +
  24.133 +/* exported to allow conversion of error code to string for compress() and
  24.134 + * uncompress()
  24.135 + */
  24.136 +const char * ZEXPORT zError(err)
  24.137 +    int err;
  24.138 +{
  24.139 +    return ERR_MSG(err);
  24.140 +}
  24.141 +
  24.142 +#if defined(_WIN32_WCE)
  24.143 +    /* The Microsoft C Run-Time Library for Windows CE doesn't have
  24.144 +     * errno.  We define it as a global variable to simplify porting.
  24.145 +     * Its value is always 0 and should not be used.
  24.146 +     */
  24.147 +    int errno = 0;
  24.148 +#endif
  24.149 +
  24.150 +#ifndef HAVE_MEMCPY
  24.151 +
  24.152 +void zmemcpy(dest, source, len)
  24.153 +    Bytef* dest;
  24.154 +    const Bytef* source;
  24.155 +    uInt  len;
  24.156 +{
  24.157 +    if (len == 0) return;
  24.158 +    do {
  24.159 +        *dest++ = *source++; /* ??? to be unrolled */
  24.160 +    } while (--len != 0);
  24.161 +}
  24.162 +
  24.163 +int zmemcmp(s1, s2, len)
  24.164 +    const Bytef* s1;
  24.165 +    const Bytef* s2;
  24.166 +    uInt  len;
  24.167 +{
  24.168 +    uInt j;
  24.169 +
  24.170 +    for (j = 0; j < len; j++) {
  24.171 +        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  24.172 +    }
  24.173 +    return 0;
  24.174 +}
  24.175 +
  24.176 +void zmemzero(dest, len)
  24.177 +    Bytef* dest;
  24.178 +    uInt  len;
  24.179 +{
  24.180 +    if (len == 0) return;
  24.181 +    do {
  24.182 +        *dest++ = 0;  /* ??? to be unrolled */
  24.183 +    } while (--len != 0);
  24.184 +}
  24.185 +#endif
  24.186 +
  24.187 +
  24.188 +#ifdef SYS16BIT
  24.189 +
  24.190 +#ifdef __TURBOC__
  24.191 +/* Turbo C in 16-bit mode */
  24.192 +
  24.193 +#  define MY_ZCALLOC
  24.194 +
  24.195 +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
  24.196 + * and farmalloc(64K) returns a pointer with an offset of 8, so we
  24.197 + * must fix the pointer. Warning: the pointer must be put back to its
  24.198 + * original form in order to free it, use zcfree().
  24.199 + */
  24.200 +
  24.201 +#define MAX_PTR 10
  24.202 +/* 10*64K = 640K */
  24.203 +
  24.204 +local int next_ptr = 0;
  24.205 +
  24.206 +typedef struct ptr_table_s {
  24.207 +    voidpf org_ptr;
  24.208 +    voidpf new_ptr;
  24.209 +} ptr_table;
  24.210 +
  24.211 +local ptr_table table[MAX_PTR];
  24.212 +/* This table is used to remember the original form of pointers
  24.213 + * to large buffers (64K). Such pointers are normalized with a zero offset.
  24.214 + * Since MSDOS is not a preemptive multitasking OS, this table is not
  24.215 + * protected from concurrent access. This hack doesn't work anyway on
  24.216 + * a protected system like OS/2. Use Microsoft C instead.
  24.217 + */
  24.218 +
  24.219 +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  24.220 +{
  24.221 +    voidpf buf = opaque; /* just to make some compilers happy */
  24.222 +    ulg bsize = (ulg)items*size;
  24.223 +
  24.224 +    /* If we allocate less than 65520 bytes, we assume that farmalloc
  24.225 +     * will return a usable pointer which doesn't have to be normalized.
  24.226 +     */
  24.227 +    if (bsize < 65520L) {
  24.228 +        buf = farmalloc(bsize);
  24.229 +        if (*(ush*)&buf != 0) return buf;
  24.230 +    } else {
  24.231 +        buf = farmalloc(bsize + 16L);
  24.232 +    }
  24.233 +    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  24.234 +    table[next_ptr].org_ptr = buf;
  24.235 +
  24.236 +    /* Normalize the pointer to seg:0 */
  24.237 +    *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  24.238 +    *(ush*)&buf = 0;
  24.239 +    table[next_ptr++].new_ptr = buf;
  24.240 +    return buf;
  24.241 +}
  24.242 +
  24.243 +void  zcfree (voidpf opaque, voidpf ptr)
  24.244 +{
  24.245 +    int n;
  24.246 +    if (*(ush*)&ptr != 0) { /* object < 64K */
  24.247 +        farfree(ptr);
  24.248 +        return;
  24.249 +    }
  24.250 +    /* Find the original pointer */
  24.251 +    for (n = 0; n < next_ptr; n++) {
  24.252 +        if (ptr != table[n].new_ptr) continue;
  24.253 +
  24.254 +        farfree(table[n].org_ptr);
  24.255 +        while (++n < next_ptr) {
  24.256 +            table[n-1] = table[n];
  24.257 +        }
  24.258 +        next_ptr--;
  24.259 +        return;
  24.260 +    }
  24.261 +    ptr = opaque; /* just to make some compilers happy */
  24.262 +    Assert(0, "zcfree: ptr not found");
  24.263 +}
  24.264 +
  24.265 +#endif /* __TURBOC__ */
  24.266 +
  24.267 +
  24.268 +#ifdef M_I86
  24.269 +/* Microsoft C in 16-bit mode */
  24.270 +
  24.271 +#  define MY_ZCALLOC
  24.272 +
  24.273 +#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  24.274 +#  define _halloc  halloc
  24.275 +#  define _hfree   hfree
  24.276 +#endif
  24.277 +
  24.278 +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  24.279 +{
  24.280 +    if (opaque) opaque = 0; /* to make compiler happy */
  24.281 +    return _halloc((long)items, size);
  24.282 +}
  24.283 +
  24.284 +void  zcfree (voidpf opaque, voidpf ptr)
  24.285 +{
  24.286 +    if (opaque) opaque = 0; /* to make compiler happy */
  24.287 +    _hfree(ptr);
  24.288 +}
  24.289 +
  24.290 +#endif /* M_I86 */
  24.291 +
  24.292 +#endif /* SYS16BIT */
  24.293 +
  24.294 +
  24.295 +#ifndef MY_ZCALLOC /* Any system without a special alloc function */
  24.296 +
  24.297 +#ifndef STDC
  24.298 +extern voidp  malloc OF((uInt size));
  24.299 +extern voidp  calloc OF((uInt items, uInt size));
  24.300 +extern void   free   OF((voidpf ptr));
  24.301 +#endif
  24.302 +
  24.303 +voidpf zcalloc (opaque, items, size)
  24.304 +    voidpf opaque;
  24.305 +    unsigned items;
  24.306 +    unsigned size;
  24.307 +{
  24.308 +    if (opaque) items += size - size; /* make compiler happy */
  24.309 +    return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  24.310 +                              (voidpf)calloc(items, size);
  24.311 +}
  24.312 +
  24.313 +void  zcfree (opaque, ptr)
  24.314 +    voidpf opaque;
  24.315 +    voidpf ptr;
  24.316 +{
  24.317 +    free(ptr);
  24.318 +    if (opaque) return; /* make compiler happy */
  24.319 +}
  24.320 +
  24.321 +#endif /* MY_ZCALLOC */
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/compiler-init/zlib/zutil.h	Sat Jul 15 04:51:28 2006 +0000
    25.3 @@ -0,0 +1,269 @@
    25.4 +/* zutil.h -- internal interface and configuration of the compression library
    25.5 + * Copyright (C) 1995-2005 Jean-loup Gailly.
    25.6 + * For conditions of distribution and use, see copyright notice in zlib.h
    25.7 + */
    25.8 +
    25.9 +/* WARNING: this file should *not* be used by applications. It is
   25.10 +   part of the implementation of the compression library and is
   25.11 +   subject to change. Applications should only use zlib.h.
   25.12 + */
   25.13 +
   25.14 +/* @(#) $Id$ */
   25.15 +
   25.16 +#ifndef ZUTIL_H
   25.17 +#define ZUTIL_H
   25.18 +
   25.19 +#define ZLIB_INTERNAL
   25.20 +#include "zlib.h"
   25.21 +
   25.22 +#ifdef STDC
   25.23 +#  ifndef _WIN32_WCE
   25.24 +#    include <stddef.h>
   25.25 +#  endif
   25.26 +#  include <string.h>
   25.27 +#  include <stdlib.h>
   25.28 +#endif
   25.29 +#ifdef NO_ERRNO_H
   25.30 +#   ifdef _WIN32_WCE
   25.31 +      /* The Microsoft C Run-Time Library for Windows CE doesn't have
   25.32 +       * errno.  We define it as a global variable to simplify porting.
   25.33 +       * Its value is always 0 and should not be used.  We rename it to
   25.34 +       * avoid conflict with other libraries that use the same workaround.
   25.35 +       */
   25.36 +#     define errno z_errno
   25.37 +#   endif
   25.38 +    extern int errno;
   25.39 +#else
   25.40 +#  ifndef _WIN32_WCE
   25.41 +#    include <errno.h>
   25.42 +#  endif
   25.43 +#endif
   25.44 +
   25.45 +#ifndef local
   25.46 +#  define local static
   25.47 +#endif
   25.48 +/* compile with -Dlocal if your debugger can't find static symbols */
   25.49 +
   25.50 +typedef unsigned char  uch;
   25.51 +typedef uch FAR uchf;
   25.52 +typedef unsigned short ush;
   25.53 +typedef ush FAR ushf;
   25.54 +typedef unsigned long  ulg;
   25.55 +
   25.56 +extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
   25.57 +/* (size given to avoid silly warnings with Visual C++) */
   25.58 +
   25.59 +#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
   25.60 +
   25.61 +#define ERR_RETURN(strm,err) \
   25.62 +  return (strm->msg = (char*)ERR_MSG(err), (err))
   25.63 +/* To be used only when the state is known to be valid */
   25.64 +
   25.65 +        /* common constants */
   25.66 +
   25.67 +#ifndef DEF_WBITS
   25.68 +#  define DEF_WBITS MAX_WBITS
   25.69 +#endif
   25.70 +/* default windowBits for decompression. MAX_WBITS is for compression only */
   25.71 +
   25.72 +#if MAX_MEM_LEVEL >= 8
   25.73 +#  define DEF_MEM_LEVEL 8
   25.74 +#else
   25.75 +#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
   25.76 +#endif
   25.77 +/* default memLevel */
   25.78 +
   25.79 +#define STORED_BLOCK 0
   25.80 +#define STATIC_TREES 1
   25.81 +#define DYN_TREES    2
   25.82 +/* The three kinds of block type */
   25.83 +
   25.84 +#define MIN_MATCH  3
   25.85 +#define MAX_MATCH  258
   25.86 +/* The minimum and maximum match lengths */
   25.87 +
   25.88 +#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
   25.89 +
   25.90 +        /* target dependencies */
   25.91 +
   25.92 +#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
   25.93 +#  define OS_CODE  0x00
   25.94 +#  if defined(__TURBOC__) || defined(__BORLANDC__)
   25.95 +#    if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
   25.96 +       /* Allow compilation with ANSI keywords only enabled */
   25.97 +       void _Cdecl farfree( void *block );
   25.98 +       void *_Cdecl farmalloc( unsigned long nbytes );
   25.99 +#    else
  25.100 +#      include <alloc.h>
  25.101 +#    endif
  25.102 +#  else /* MSC or DJGPP */
  25.103 +#    include <malloc.h>
  25.104 +#  endif
  25.105 +#endif
  25.106 +
  25.107 +#ifdef AMIGA
  25.108 +#  define OS_CODE  0x01
  25.109 +#endif
  25.110 +
  25.111 +#if defined(VAXC) || defined(VMS)
  25.112 +#  define OS_CODE  0x02
  25.113 +#  define F_OPEN(name, mode) \
  25.114 +     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  25.115 +#endif
  25.116 +
  25.117 +#if defined(ATARI) || defined(atarist)
  25.118 +#  define OS_CODE  0x05
  25.119 +#endif
  25.120 +
  25.121 +#ifdef OS2
  25.122 +#  define OS_CODE  0x06
  25.123 +#  ifdef M_I86
  25.124 +     #include <malloc.h>
  25.125 +#  endif
  25.126 +#endif
  25.127 +
  25.128 +#if defined(MACOS) || defined(TARGET_OS_MAC)
  25.129 +#  define OS_CODE  0x07
  25.130 +#  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  25.131 +#    include <unix.h> /* for fdopen */
  25.132 +#  else
  25.133 +#    ifndef fdopen
  25.134 +#      define fdopen(fd,mode) NULL /* No fdopen() */
  25.135 +#    endif
  25.136 +#  endif
  25.137 +#endif
  25.138 +
  25.139 +#ifdef TOPS20
  25.140 +#  define OS_CODE  0x0a
  25.141 +#endif
  25.142 +
  25.143 +#ifdef WIN32
  25.144 +#  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
  25.145 +#    define OS_CODE  0x0b
  25.146 +#  endif
  25.147 +#endif
  25.148 +
  25.149 +#ifdef __50SERIES /* Prime/PRIMOS */
  25.150 +#  define OS_CODE  0x0f
  25.151 +#endif
  25.152 +
  25.153 +#if defined(_BEOS_) || defined(RISCOS)
  25.154 +#  define fdopen(fd,mode) NULL /* No fdopen() */
  25.155 +#endif
  25.156 +
  25.157 +#if (defined(_MSC_VER) && (_MSC_VER > 600))
  25.158 +#  if defined(_WIN32_WCE)
  25.159 +#    define fdopen(fd,mode) NULL /* No fdopen() */
  25.160 +#    ifndef _PTRDIFF_T_DEFINED
  25.161 +       typedef int ptrdiff_t;
  25.162 +#      define _PTRDIFF_T_DEFINED
  25.163 +#    endif
  25.164 +#  else
  25.165 +#    define fdopen(fd,type)  _fdopen(fd,type)
  25.166 +#  endif
  25.167 +#endif
  25.168 +
  25.169 +        /* common defaults */
  25.170 +
  25.171 +#ifndef OS_CODE
  25.172 +#  define OS_CODE  0x03  /* assume Unix */
  25.173 +#endif
  25.174 +
  25.175 +#ifndef F_OPEN
  25.176 +#  define F_OPEN(name, mode) fopen((name), (mode))
  25.177 +#endif
  25.178 +
  25.179 +         /* functions */
  25.180 +
  25.181 +#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  25.182 +#  ifndef HAVE_VSNPRINTF
  25.183 +#    define HAVE_VSNPRINTF
  25.184 +#  endif
  25.185 +#endif
  25.186 +#if defined(__CYGWIN__)
  25.187 +#  ifndef HAVE_VSNPRINTF
  25.188 +#    define HAVE_VSNPRINTF
  25.189 +#  endif
  25.190 +#endif
  25.191 +#ifndef HAVE_VSNPRINTF
  25.192 +#  ifdef MSDOS
  25.193 +     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
  25.194 +        but for now we just assume it doesn't. */
  25.195 +#    define NO_vsnprintf
  25.196 +#  endif
  25.197 +#  ifdef __TURBOC__
  25.198 +#    define NO_vsnprintf
  25.199 +#  endif
  25.200 +#  ifdef WIN32
  25.201 +     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
  25.202 +#    if !defined(vsnprintf) && !defined(NO_vsnprintf)
  25.203 +#      define vsnprintf _vsnprintf
  25.204 +#    endif
  25.205 +#  endif
  25.206 +#  ifdef __SASC
  25.207 +#    define NO_vsnprintf
  25.208 +#  endif
  25.209 +#endif
  25.210 +#ifdef VMS
  25.211 +#  define NO_vsnprintf
  25.212 +#endif
  25.213 +
  25.214 +#if defined(pyr)
  25.215 +#  define NO_MEMCPY
  25.216 +#endif
  25.217 +#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  25.218 + /* Use our own functions for small and medium model with MSC <= 5.0.
  25.219 +  * You may have to use the same strategy for Borland C (untested).
  25.220 +  * The __SC__ check is for Symantec.
  25.221 +  */
  25.222 +#  define NO_MEMCPY
  25.223 +#endif
  25.224 +#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  25.225 +#  define HAVE_MEMCPY
  25.226 +#endif
  25.227 +#ifdef HAVE_MEMCPY
  25.228 +#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  25.229 +#    define zmemcpy _fmemcpy
  25.230 +#    define zmemcmp _fmemcmp
  25.231 +#    define zmemzero(dest, len) _fmemset(dest, 0, len)
  25.232 +#  else
  25.233 +#    define zmemcpy memcpy
  25.234 +#    define zmemcmp memcmp
  25.235 +#    define zmemzero(dest, len) memset(dest, 0, len)
  25.236 +#  endif
  25.237 +#else
  25.238 +   extern void zmemcpy  OF((Bytef* dest, const Bytef* source, uInt len));
  25.239 +   extern int  zmemcmp  OF((const Bytef* s1, const Bytef* s2, uInt len));
  25.240 +   extern void zmemzero OF((Bytef* dest, uInt len));
  25.241 +#endif
  25.242 +
  25.243 +/* Diagnostic functions */
  25.244 +#ifdef DEBUG
  25.245 +#  include <stdio.h>
  25.246 +   extern int z_verbose;
  25.247 +   extern void z_error    OF((char *m));
  25.248 +#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  25.249 +#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
  25.250 +#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
  25.251 +#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  25.252 +#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  25.253 +#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  25.254 +#else
  25.255 +#  define Assert(cond,msg)
  25.256 +#  define Trace(x)
  25.257 +#  define Tracev(x)
  25.258 +#  define Tracevv(x)
  25.259 +#  define Tracec(c,x)
  25.260 +#  define Tracecv(c,x)
  25.261 +#endif
  25.262 +
  25.263 +
  25.264 +voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  25.265 +void   zcfree  OF((voidpf opaque, voidpf ptr));
  25.266 +
  25.267 +#define ZALLOC(strm, items, size) \
  25.268 +           (*((strm)->zalloc))((strm)->opaque, (items), (size))
  25.269 +#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  25.270 +#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  25.271 +
  25.272 +#endif /* ZUTIL_H */