aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/zlib
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/zlib')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/adler32.c358
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/compress.c160
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.c850
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.h882
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.c3930
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.h692
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/infback.c1280
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.c680
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.h22
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inffixed.h188
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.c2992
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.h244
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.c612
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.h124
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.c2448
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.h256
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/uncompr.c118
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/zconf.h1012
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/zlib.h3488
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.c648
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.h504
21 files changed, 10744 insertions, 10744 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/adler32.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/adler32.c
index 003d373..a868f07 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/adler32.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/adler32.c
@@ -1,179 +1,179 @@
1/* adler32.c -- compute the Adler-32 checksum of a data stream 1/* adler32.c -- compute the Adler-32 checksum of a data stream
2 * Copyright (C) 1995-2011 Mark Adler 2 * Copyright (C) 1995-2011 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#include "zutil.h" 8#include "zutil.h"
9 9
10#define local static 10#define local static
11 11
12local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 12local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
13 13
14#define BASE 65521 /* largest prime smaller than 65536 */ 14#define BASE 65521 /* largest prime smaller than 65536 */
15#define NMAX 5552 15#define NMAX 5552
16/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 16/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
17 17
18#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 18#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
19#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 19#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
20#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 20#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
21#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 21#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
22#define DO16(buf) DO8(buf,0); DO8(buf,8); 22#define DO16(buf) DO8(buf,0); DO8(buf,8);
23 23
24/* use NO_DIVIDE if your processor does not do division in hardware -- 24/* use NO_DIVIDE if your processor does not do division in hardware --
25 try it both ways to see which is faster */ 25 try it both ways to see which is faster */
26#ifdef NO_DIVIDE 26#ifdef NO_DIVIDE
27/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 27/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
28 (thank you to John Reiser for pointing this out) */ 28 (thank you to John Reiser for pointing this out) */
29# define CHOP(a) \ 29# define CHOP(a) \
30 do { \ 30 do { \
31 unsigned long tmp = a >> 16; \ 31 unsigned long tmp = a >> 16; \
32 a &= 0xffffUL; \ 32 a &= 0xffffUL; \
33 a += (tmp << 4) - tmp; \ 33 a += (tmp << 4) - tmp; \
34 } while (0) 34 } while (0)
35# define MOD28(a) \ 35# define MOD28(a) \
36 do { \ 36 do { \
37 CHOP(a); \ 37 CHOP(a); \
38 if (a >= BASE) a -= BASE; \ 38 if (a >= BASE) a -= BASE; \
39 } while (0) 39 } while (0)
40# define MOD(a) \ 40# define MOD(a) \
41 do { \ 41 do { \
42 CHOP(a); \ 42 CHOP(a); \
43 MOD28(a); \ 43 MOD28(a); \
44 } while (0) 44 } while (0)
45# define MOD63(a) \ 45# define MOD63(a) \
46 do { /* this assumes a is not negative */ \ 46 do { /* this assumes a is not negative */ \
47 z_off64_t tmp = a >> 32; \ 47 z_off64_t tmp = a >> 32; \
48 a &= 0xffffffffL; \ 48 a &= 0xffffffffL; \
49 a += (tmp << 8) - (tmp << 5) + tmp; \ 49 a += (tmp << 8) - (tmp << 5) + tmp; \
50 tmp = a >> 16; \ 50 tmp = a >> 16; \
51 a &= 0xffffL; \ 51 a &= 0xffffL; \
52 a += (tmp << 4) - tmp; \ 52 a += (tmp << 4) - tmp; \
53 tmp = a >> 16; \ 53 tmp = a >> 16; \
54 a &= 0xffffL; \ 54 a &= 0xffffL; \
55 a += (tmp << 4) - tmp; \ 55 a += (tmp << 4) - tmp; \
56 if (a >= BASE) a -= BASE; \ 56 if (a >= BASE) a -= BASE; \
57 } while (0) 57 } while (0)
58#else 58#else
59# define MOD(a) a %= BASE 59# define MOD(a) a %= BASE
60# define MOD28(a) a %= BASE 60# define MOD28(a) a %= BASE
61# define MOD63(a) a %= BASE 61# define MOD63(a) a %= BASE
62#endif 62#endif
63 63
64/* ========================================================================= */ 64/* ========================================================================= */
65uLong ZEXPORT adler32(adler, buf, len) 65uLong ZEXPORT adler32(adler, buf, len)
66 uLong adler; 66 uLong adler;
67 const Bytef *buf; 67 const Bytef *buf;
68 uInt len; 68 uInt len;
69{ 69{
70 unsigned long sum2; 70 unsigned long sum2;
71 unsigned n; 71 unsigned n;
72 72
73 /* split Adler-32 into component sums */ 73 /* split Adler-32 into component sums */
74 sum2 = (adler >> 16) & 0xffff; 74 sum2 = (adler >> 16) & 0xffff;
75 adler &= 0xffff; 75 adler &= 0xffff;
76 76
77 /* in case user likes doing a byte at a time, keep it fast */ 77 /* in case user likes doing a byte at a time, keep it fast */
78 if (len == 1) { 78 if (len == 1) {
79 adler += buf[0]; 79 adler += buf[0];
80 if (adler >= BASE) 80 if (adler >= BASE)
81 adler -= BASE; 81 adler -= BASE;
82 sum2 += adler; 82 sum2 += adler;
83 if (sum2 >= BASE) 83 if (sum2 >= BASE)
84 sum2 -= BASE; 84 sum2 -= BASE;
85 return adler | (sum2 << 16); 85 return adler | (sum2 << 16);
86 } 86 }
87 87
88 /* initial Adler-32 value (deferred check for len == 1 speed) */ 88 /* initial Adler-32 value (deferred check for len == 1 speed) */
89 if (buf == Z_NULL) 89 if (buf == Z_NULL)
90 return 1L; 90 return 1L;
91 91
92 /* in case short lengths are provided, keep it somewhat fast */ 92 /* in case short lengths are provided, keep it somewhat fast */
93 if (len < 16) { 93 if (len < 16) {
94 while (len--) { 94 while (len--) {
95 adler += *buf++; 95 adler += *buf++;
96 sum2 += adler; 96 sum2 += adler;
97 } 97 }
98 if (adler >= BASE) 98 if (adler >= BASE)
99 adler -= BASE; 99 adler -= BASE;
100 MOD28(sum2); /* only added so many BASE's */ 100 MOD28(sum2); /* only added so many BASE's */
101 return adler | (sum2 << 16); 101 return adler | (sum2 << 16);
102 } 102 }
103 103
104 /* do length NMAX blocks -- requires just one modulo operation */ 104 /* do length NMAX blocks -- requires just one modulo operation */
105 while (len >= NMAX) { 105 while (len >= NMAX) {
106 len -= NMAX; 106 len -= NMAX;
107 n = NMAX / 16; /* NMAX is divisible by 16 */ 107 n = NMAX / 16; /* NMAX is divisible by 16 */
108 do { 108 do {
109 DO16(buf); /* 16 sums unrolled */ 109 DO16(buf); /* 16 sums unrolled */
110 buf += 16; 110 buf += 16;
111 } while (--n); 111 } while (--n);
112 MOD(adler); 112 MOD(adler);
113 MOD(sum2); 113 MOD(sum2);
114 } 114 }
115 115
116 /* do remaining bytes (less than NMAX, still just one modulo) */ 116 /* do remaining bytes (less than NMAX, still just one modulo) */
117 if (len) { /* avoid modulos if none remaining */ 117 if (len) { /* avoid modulos if none remaining */
118 while (len >= 16) { 118 while (len >= 16) {
119 len -= 16; 119 len -= 16;
120 DO16(buf); 120 DO16(buf);
121 buf += 16; 121 buf += 16;
122 } 122 }
123 while (len--) { 123 while (len--) {
124 adler += *buf++; 124 adler += *buf++;
125 sum2 += adler; 125 sum2 += adler;
126 } 126 }
127 MOD(adler); 127 MOD(adler);
128 MOD(sum2); 128 MOD(sum2);
129 } 129 }
130 130
131 /* return recombined sums */ 131 /* return recombined sums */
132 return adler | (sum2 << 16); 132 return adler | (sum2 << 16);
133} 133}
134 134
135/* ========================================================================= */ 135/* ========================================================================= */
136local uLong adler32_combine_(adler1, adler2, len2) 136local uLong adler32_combine_(adler1, adler2, len2)
137 uLong adler1; 137 uLong adler1;
138 uLong adler2; 138 uLong adler2;
139 z_off64_t len2; 139 z_off64_t len2;
140{ 140{
141 unsigned long sum1; 141 unsigned long sum1;
142 unsigned long sum2; 142 unsigned long sum2;
143 unsigned rem; 143 unsigned rem;
144 144
145 /* for negative len, return invalid adler32 as a clue for debugging */ 145 /* for negative len, return invalid adler32 as a clue for debugging */
146 if (len2 < 0) 146 if (len2 < 0)
147 return 0xffffffffUL; 147 return 0xffffffffUL;
148 148
149 /* the derivation of this formula is left as an exercise for the reader */ 149 /* the derivation of this formula is left as an exercise for the reader */
150 MOD63(len2); /* assumes len2 >= 0 */ 150 MOD63(len2); /* assumes len2 >= 0 */
151 rem = (unsigned)len2; 151 rem = (unsigned)len2;
152 sum1 = adler1 & 0xffff; 152 sum1 = adler1 & 0xffff;
153 sum2 = rem * sum1; 153 sum2 = rem * sum1;
154 MOD(sum2); 154 MOD(sum2);
155 sum1 += (adler2 & 0xffff) + BASE - 1; 155 sum1 += (adler2 & 0xffff) + BASE - 1;
156 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 156 sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
157 if (sum1 >= BASE) sum1 -= BASE; 157 if (sum1 >= BASE) sum1 -= BASE;
158 if (sum1 >= BASE) sum1 -= BASE; 158 if (sum1 >= BASE) sum1 -= BASE;
159 if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 159 if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
160 if (sum2 >= BASE) sum2 -= BASE; 160 if (sum2 >= BASE) sum2 -= BASE;
161 return sum1 | (sum2 << 16); 161 return sum1 | (sum2 << 16);
162} 162}
163 163
164/* ========================================================================= */ 164/* ========================================================================= */
165uLong ZEXPORT adler32_combine(adler1, adler2, len2) 165uLong ZEXPORT adler32_combine(adler1, adler2, len2)
166 uLong adler1; 166 uLong adler1;
167 uLong adler2; 167 uLong adler2;
168 z_off_t len2; 168 z_off_t len2;
169{ 169{
170 return adler32_combine_(adler1, adler2, len2); 170 return adler32_combine_(adler1, adler2, len2);
171} 171}
172 172
173uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 173uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
174 uLong adler1; 174 uLong adler1;
175 uLong adler2; 175 uLong adler2;
176 z_off64_t len2; 176 z_off64_t len2;
177{ 177{
178 return adler32_combine_(adler1, adler2, len2); 178 return adler32_combine_(adler1, adler2, len2);
179} 179}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/compress.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/compress.c
index c46727a..ea4dfbe 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/compress.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/compress.c
@@ -1,80 +1,80 @@
1/* compress.c -- compress a memory buffer 1/* compress.c -- compress a memory buffer
2 * Copyright (C) 1995-2005 Jean-loup Gailly. 2 * Copyright (C) 1995-2005 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#define ZLIB_INTERNAL 8#define ZLIB_INTERNAL
9#include "zlib.h" 9#include "zlib.h"
10 10
11/* =========================================================================== 11/* ===========================================================================
12 Compresses the source buffer into the destination buffer. The level 12 Compresses the source buffer into the destination buffer. The level
13 parameter has the same meaning as in deflateInit. sourceLen is the byte 13 parameter has the same meaning as in deflateInit. sourceLen is the byte
14 length of the source buffer. Upon entry, destLen is the total size of the 14 length of the source buffer. Upon entry, destLen is the total size of the
15 destination buffer, which must be at least 0.1% larger than sourceLen plus 15 destination buffer, which must be at least 0.1% larger than sourceLen plus
16 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 16 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
17 17
18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 18 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 memory, Z_BUF_ERROR if there was not enough room in the output buffer, 19 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 Z_STREAM_ERROR if the level parameter is invalid. 20 Z_STREAM_ERROR if the level parameter is invalid.
21*/ 21*/
22int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 22int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
23 Bytef *dest; 23 Bytef *dest;
24 uLongf *destLen; 24 uLongf *destLen;
25 const Bytef *source; 25 const Bytef *source;
26 uLong sourceLen; 26 uLong sourceLen;
27 int level; 27 int level;
28{ 28{
29 z_stream stream; 29 z_stream stream;
30 int err; 30 int err;
31 31
32 stream.next_in = (Bytef*)source; 32 stream.next_in = (Bytef*)source;
33 stream.avail_in = (uInt)sourceLen; 33 stream.avail_in = (uInt)sourceLen;
34#ifdef MAXSEG_64K 34#ifdef MAXSEG_64K
35 /* Check for source > 64K on 16-bit machine: */ 35 /* Check for source > 64K on 16-bit machine: */
36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37#endif 37#endif
38 stream.next_out = dest; 38 stream.next_out = dest;
39 stream.avail_out = (uInt)*destLen; 39 stream.avail_out = (uInt)*destLen;
40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
41 41
42 stream.zalloc = (alloc_func)0; 42 stream.zalloc = (alloc_func)0;
43 stream.zfree = (free_func)0; 43 stream.zfree = (free_func)0;
44 stream.opaque = (voidpf)0; 44 stream.opaque = (voidpf)0;
45 45
46 err = deflateInit(&stream, level); 46 err = deflateInit(&stream, level);
47 if (err != Z_OK) return err; 47 if (err != Z_OK) return err;
48 48
49 err = deflate(&stream, Z_FINISH); 49 err = deflate(&stream, Z_FINISH);
50 if (err != Z_STREAM_END) { 50 if (err != Z_STREAM_END) {
51 deflateEnd(&stream); 51 deflateEnd(&stream);
52 return err == Z_OK ? Z_BUF_ERROR : err; 52 return err == Z_OK ? Z_BUF_ERROR : err;
53 } 53 }
54 *destLen = stream.total_out; 54 *destLen = stream.total_out;
55 55
56 err = deflateEnd(&stream); 56 err = deflateEnd(&stream);
57 return err; 57 return err;
58} 58}
59 59
60/* =========================================================================== 60/* ===========================================================================
61 */ 61 */
62int ZEXPORT compress (dest, destLen, source, sourceLen) 62int ZEXPORT compress (dest, destLen, source, sourceLen)
63 Bytef *dest; 63 Bytef *dest;
64 uLongf *destLen; 64 uLongf *destLen;
65 const Bytef *source; 65 const Bytef *source;
66 uLong sourceLen; 66 uLong sourceLen;
67{ 67{
68 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 68 return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
69} 69}
70 70
71/* =========================================================================== 71/* ===========================================================================
72 If the default memLevel or windowBits for deflateInit() is changed, then 72 If the default memLevel or windowBits for deflateInit() is changed, then
73 this function needs to be updated. 73 this function needs to be updated.
74 */ 74 */
75uLong ZEXPORT compressBound (sourceLen) 75uLong ZEXPORT compressBound (sourceLen)
76 uLong sourceLen; 76 uLong sourceLen;
77{ 77{
78 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 78 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
79 (sourceLen >> 25) + 13; 79 (sourceLen >> 25) + 13;
80} 80}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.c
index 95a30f1..979a719 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.c
@@ -1,425 +1,425 @@
1/* crc32.c -- compute the CRC-32 of a data stream 1/* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler 2 * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 * 4 *
5 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster 5 * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
6 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 6 * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
7 * tables for updating the shift register in one step with three exclusive-ors 7 * tables for updating the shift register in one step with three exclusive-ors
8 * instead of four steps with four exclusive-ors. This results in about a 8 * instead of four steps with four exclusive-ors. This results in about a
9 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 9 * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
10 */ 10 */
11 11
12/* @(#) $Id$ */ 12/* @(#) $Id$ */
13 13
14/* 14/*
15 Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 15 Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
16 protection on the static variables used to control the first-use generation 16 protection on the static variables used to control the first-use generation
17 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 17 of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
18 first call get_crc_table() to initialize the tables before allowing more than 18 first call get_crc_table() to initialize the tables before allowing more than
19 one thread to use crc32(). 19 one thread to use crc32().
20 20
21 DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. 21 DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
22 */ 22 */
23 23
24#ifdef MAKECRCH 24#ifdef MAKECRCH
25# include <stdio.h> 25# include <stdio.h>
26# ifndef DYNAMIC_CRC_TABLE 26# ifndef DYNAMIC_CRC_TABLE
27# define DYNAMIC_CRC_TABLE 27# define DYNAMIC_CRC_TABLE
28# endif /* !DYNAMIC_CRC_TABLE */ 28# endif /* !DYNAMIC_CRC_TABLE */
29#endif /* MAKECRCH */ 29#endif /* MAKECRCH */
30 30
31#include "zutil.h" /* for STDC and FAR definitions */ 31#include "zutil.h" /* for STDC and FAR definitions */
32 32
33#define local static 33#define local static
34 34
35/* Definitions for doing the crc four data bytes at a time. */ 35/* Definitions for doing the crc four data bytes at a time. */
36#if !defined(NOBYFOUR) && defined(Z_U4) 36#if !defined(NOBYFOUR) && defined(Z_U4)
37# define BYFOUR 37# define BYFOUR
38#endif 38#endif
39#ifdef BYFOUR 39#ifdef BYFOUR
40 local unsigned long crc32_little OF((unsigned long, 40 local unsigned long crc32_little OF((unsigned long,
41 const unsigned char FAR *, unsigned)); 41 const unsigned char FAR *, unsigned));
42 local unsigned long crc32_big OF((unsigned long, 42 local unsigned long crc32_big OF((unsigned long,
43 const unsigned char FAR *, unsigned)); 43 const unsigned char FAR *, unsigned));
44# define TBLS 8 44# define TBLS 8
45#else 45#else
46# define TBLS 1 46# define TBLS 1
47#endif /* BYFOUR */ 47#endif /* BYFOUR */
48 48
49/* Local functions for crc concatenation */ 49/* Local functions for crc concatenation */
50local unsigned long gf2_matrix_times OF((unsigned long *mat, 50local unsigned long gf2_matrix_times OF((unsigned long *mat,
51 unsigned long vec)); 51 unsigned long vec));
52local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 52local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
53local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); 53local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
54 54
55 55
56#ifdef DYNAMIC_CRC_TABLE 56#ifdef DYNAMIC_CRC_TABLE
57 57
58local volatile int crc_table_empty = 1; 58local volatile int crc_table_empty = 1;
59local z_crc_t FAR crc_table[TBLS][256]; 59local z_crc_t FAR crc_table[TBLS][256];
60local void make_crc_table OF((void)); 60local void make_crc_table OF((void));
61#ifdef MAKECRCH 61#ifdef MAKECRCH
62 local void write_table OF((FILE *, const z_crc_t FAR *)); 62 local void write_table OF((FILE *, const z_crc_t FAR *));
63#endif /* MAKECRCH */ 63#endif /* MAKECRCH */
64/* 64/*
65 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 65 Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
66 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. 66 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.
67 67
68 Polynomials over GF(2) are represented in binary, one bit per coefficient, 68 Polynomials over GF(2) are represented in binary, one bit per coefficient,
69 with the lowest powers in the most significant bit. Then adding polynomials 69 with the lowest powers in the most significant bit. Then adding polynomials
70 is just exclusive-or, and multiplying a polynomial by x is a right shift by 70 is just exclusive-or, and multiplying a polynomial by x is a right shift by
71 one. If we call the above polynomial p, and represent a byte as the 71 one. If we call the above polynomial p, and represent a byte as the
72 polynomial q, also with the lowest power in the most significant bit (so the 72 polynomial q, also with the lowest power in the most significant bit (so the
73 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 73 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
74 where a mod b means the remainder after dividing a by b. 74 where a mod b means the remainder after dividing a by b.
75 75
76 This calculation is done using the shift-register method of multiplying and 76 This calculation is done using the shift-register method of multiplying and
77 taking the remainder. The register is initialized to zero, and for each 77 taking the remainder. The register is initialized to zero, and for each
78 incoming bit, x^32 is added mod p to the register if the bit is a one (where 78 incoming bit, x^32 is added mod p to the register if the bit is a one (where
79 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 79 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
80 x (which is shifting right by one and adding x^32 mod p if the bit shifted 80 x (which is shifting right by one and adding x^32 mod p if the bit shifted
81 out is a one). We start with the highest power (least significant bit) of 81 out is a one). We start with the highest power (least significant bit) of
82 q and repeat for all eight bits of q. 82 q and repeat for all eight bits of q.
83 83
84 The first table is simply the CRC of all possible eight bit values. This is 84 The first table is simply the CRC of all possible eight bit values. This is
85 all the information needed to generate CRCs on data a byte at a time for all 85 all the information needed to generate CRCs on data a byte at a time for all
86 combinations of CRC register values and incoming bytes. The remaining tables 86 combinations of CRC register values and incoming bytes. The remaining tables
87 allow for word-at-a-time CRC calculation for both big-endian and little- 87 allow for word-at-a-time CRC calculation for both big-endian and little-
88 endian machines, where a word is four bytes. 88 endian machines, where a word is four bytes.
89*/ 89*/
90local void make_crc_table() 90local void make_crc_table()
91{ 91{
92 z_crc_t c; 92 z_crc_t c;
93 int n, k; 93 int n, k;
94 z_crc_t poly; /* polynomial exclusive-or pattern */ 94 z_crc_t poly; /* polynomial exclusive-or pattern */
95 /* terms of polynomial defining this crc (except x^32): */ 95 /* terms of polynomial defining this crc (except x^32): */
96 static volatile int first = 1; /* flag to limit concurrent making */ 96 static volatile int first = 1; /* flag to limit concurrent making */
97 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 97 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
98 98
99 /* See if another task is already doing this (not thread-safe, but better 99 /* See if another task is already doing this (not thread-safe, but better
100 than nothing -- significantly reduces duration of vulnerability in 100 than nothing -- significantly reduces duration of vulnerability in
101 case the advice about DYNAMIC_CRC_TABLE is ignored) */ 101 case the advice about DYNAMIC_CRC_TABLE is ignored) */
102 if (first) { 102 if (first) {
103 first = 0; 103 first = 0;
104 104
105 /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 105 /* make exclusive-or pattern from polynomial (0xedb88320UL) */
106 poly = 0; 106 poly = 0;
107 for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) 107 for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
108 poly |= (z_crc_t)1 << (31 - p[n]); 108 poly |= (z_crc_t)1 << (31 - p[n]);
109 109
110 /* generate a crc for every 8-bit value */ 110 /* generate a crc for every 8-bit value */
111 for (n = 0; n < 256; n++) { 111 for (n = 0; n < 256; n++) {
112 c = (z_crc_t)n; 112 c = (z_crc_t)n;
113 for (k = 0; k < 8; k++) 113 for (k = 0; k < 8; k++)
114 c = c & 1 ? poly ^ (c >> 1) : c >> 1; 114 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
115 crc_table[0][n] = c; 115 crc_table[0][n] = c;
116 } 116 }
117 117
118#ifdef BYFOUR 118#ifdef BYFOUR
119 /* generate crc for each value followed by one, two, and three zeros, 119 /* generate crc for each value followed by one, two, and three zeros,
120 and then the byte reversal of those as well as the first table */ 120 and then the byte reversal of those as well as the first table */
121 for (n = 0; n < 256; n++) { 121 for (n = 0; n < 256; n++) {
122 c = crc_table[0][n]; 122 c = crc_table[0][n];
123 crc_table[4][n] = ZSWAP32(c); 123 crc_table[4][n] = ZSWAP32(c);
124 for (k = 1; k < 4; k++) { 124 for (k = 1; k < 4; k++) {
125 c = crc_table[0][c & 0xff] ^ (c >> 8); 125 c = crc_table[0][c & 0xff] ^ (c >> 8);
126 crc_table[k][n] = c; 126 crc_table[k][n] = c;
127 crc_table[k + 4][n] = ZSWAP32(c); 127 crc_table[k + 4][n] = ZSWAP32(c);
128 } 128 }
129 } 129 }
130#endif /* BYFOUR */ 130#endif /* BYFOUR */
131 131
132 crc_table_empty = 0; 132 crc_table_empty = 0;
133 } 133 }
134 else { /* not first */ 134 else { /* not first */
135 /* wait for the other guy to finish (not efficient, but rare) */ 135 /* wait for the other guy to finish (not efficient, but rare) */
136 while (crc_table_empty) 136 while (crc_table_empty)
137 ; 137 ;
138 } 138 }
139 139
140#ifdef MAKECRCH 140#ifdef MAKECRCH
141 /* write out CRC tables to crc32.h */ 141 /* write out CRC tables to crc32.h */
142 { 142 {
143 FILE *out; 143 FILE *out;
144 144
145 out = fopen("crc32.h", "w"); 145 out = fopen("crc32.h", "w");
146 if (out == NULL) return; 146 if (out == NULL) return;
147 fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 147 fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
148 fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 148 fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
149 fprintf(out, "local const z_crc_t FAR "); 149 fprintf(out, "local const z_crc_t FAR ");
150 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 150 fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
151 write_table(out, crc_table[0]); 151 write_table(out, crc_table[0]);
152# ifdef BYFOUR 152# ifdef BYFOUR
153 fprintf(out, "#ifdef BYFOUR\n"); 153 fprintf(out, "#ifdef BYFOUR\n");
154 for (k = 1; k < 8; k++) { 154 for (k = 1; k < 8; k++) {
155 fprintf(out, " },\n {\n"); 155 fprintf(out, " },\n {\n");
156 write_table(out, crc_table[k]); 156 write_table(out, crc_table[k]);
157 } 157 }
158 fprintf(out, "#endif\n"); 158 fprintf(out, "#endif\n");
159# endif /* BYFOUR */ 159# endif /* BYFOUR */
160 fprintf(out, " }\n};\n"); 160 fprintf(out, " }\n};\n");
161 fclose(out); 161 fclose(out);
162 } 162 }
163#endif /* MAKECRCH */ 163#endif /* MAKECRCH */
164} 164}
165 165
166#ifdef MAKECRCH 166#ifdef MAKECRCH
167local void write_table(out, table) 167local void write_table(out, table)
168 FILE *out; 168 FILE *out;
169 const z_crc_t FAR *table; 169 const z_crc_t FAR *table;
170{ 170{
171 int n; 171 int n;
172 172
173 for (n = 0; n < 256; n++) 173 for (n = 0; n < 256; n++)
174 fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", 174 fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
175 (unsigned long)(table[n]), 175 (unsigned long)(table[n]),
176 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 176 n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
177} 177}
178#endif /* MAKECRCH */ 178#endif /* MAKECRCH */
179 179
180#else /* !DYNAMIC_CRC_TABLE */ 180#else /* !DYNAMIC_CRC_TABLE */
181/* ======================================================================== 181/* ========================================================================
182 * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 182 * Tables of CRC-32s of all single-byte values, made by make_crc_table().
183 */ 183 */
184#include "crc32.h" 184#include "crc32.h"
185#endif /* DYNAMIC_CRC_TABLE */ 185#endif /* DYNAMIC_CRC_TABLE */
186 186
187/* ========================================================================= 187/* =========================================================================
188 * This function can be used by asm versions of crc32() 188 * This function can be used by asm versions of crc32()
189 */ 189 */
190const z_crc_t FAR * ZEXPORT get_crc_table() 190const z_crc_t FAR * ZEXPORT get_crc_table()
191{ 191{
192#ifdef DYNAMIC_CRC_TABLE 192#ifdef DYNAMIC_CRC_TABLE
193 if (crc_table_empty) 193 if (crc_table_empty)
194 make_crc_table(); 194 make_crc_table();
195#endif /* DYNAMIC_CRC_TABLE */ 195#endif /* DYNAMIC_CRC_TABLE */
196 return (const z_crc_t FAR *)crc_table; 196 return (const z_crc_t FAR *)crc_table;
197} 197}
198 198
199/* ========================================================================= */ 199/* ========================================================================= */
200#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 200#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
201#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 201#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
202 202
203/* ========================================================================= */ 203/* ========================================================================= */
204unsigned long ZEXPORT crc32(crc, buf, len) 204unsigned long ZEXPORT crc32(crc, buf, len)
205 unsigned long crc; 205 unsigned long crc;
206 const unsigned char FAR *buf; 206 const unsigned char FAR *buf;
207 uInt len; 207 uInt len;
208{ 208{
209 if (buf == Z_NULL) return 0UL; 209 if (buf == Z_NULL) return 0UL;
210 210
211#ifdef DYNAMIC_CRC_TABLE 211#ifdef DYNAMIC_CRC_TABLE
212 if (crc_table_empty) 212 if (crc_table_empty)
213 make_crc_table(); 213 make_crc_table();
214#endif /* DYNAMIC_CRC_TABLE */ 214#endif /* DYNAMIC_CRC_TABLE */
215 215
216#ifdef BYFOUR 216#ifdef BYFOUR
217 if (sizeof(void *) == sizeof(ptrdiff_t)) { 217 if (sizeof(void *) == sizeof(ptrdiff_t)) {
218 z_crc_t endian; 218 z_crc_t endian;
219 219
220 endian = 1; 220 endian = 1;
221 if (*((unsigned char *)(&endian))) 221 if (*((unsigned char *)(&endian)))
222 return crc32_little(crc, buf, len); 222 return crc32_little(crc, buf, len);
223 else 223 else
224 return crc32_big(crc, buf, len); 224 return crc32_big(crc, buf, len);
225 } 225 }
226#endif /* BYFOUR */ 226#endif /* BYFOUR */
227 crc = crc ^ 0xffffffffUL; 227 crc = crc ^ 0xffffffffUL;
228 while (len >= 8) { 228 while (len >= 8) {
229 DO8; 229 DO8;
230 len -= 8; 230 len -= 8;
231 } 231 }
232 if (len) do { 232 if (len) do {
233 DO1; 233 DO1;
234 } while (--len); 234 } while (--len);
235 return crc ^ 0xffffffffUL; 235 return crc ^ 0xffffffffUL;
236} 236}
237 237
238#ifdef BYFOUR 238#ifdef BYFOUR
239 239
240/* ========================================================================= */ 240/* ========================================================================= */
241#define DOLIT4 c ^= *buf4++; \ 241#define DOLIT4 c ^= *buf4++; \
242 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 242 c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
243 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 243 crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
244#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 244#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
245 245
246/* ========================================================================= */ 246/* ========================================================================= */
247local unsigned long crc32_little(crc, buf, len) 247local unsigned long crc32_little(crc, buf, len)
248 unsigned long crc; 248 unsigned long crc;
249 const unsigned char FAR *buf; 249 const unsigned char FAR *buf;
250 unsigned len; 250 unsigned len;
251{ 251{
252 register z_crc_t c; 252 register z_crc_t c;
253 register const z_crc_t FAR *buf4; 253 register const z_crc_t FAR *buf4;
254 254
255 c = (z_crc_t)crc; 255 c = (z_crc_t)crc;
256 c = ~c; 256 c = ~c;
257 while (len && ((ptrdiff_t)buf & 3)) { 257 while (len && ((ptrdiff_t)buf & 3)) {
258 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 258 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
259 len--; 259 len--;
260 } 260 }
261 261
262 buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 262 buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
263 while (len >= 32) { 263 while (len >= 32) {
264 DOLIT32; 264 DOLIT32;
265 len -= 32; 265 len -= 32;
266 } 266 }
267 while (len >= 4) { 267 while (len >= 4) {
268 DOLIT4; 268 DOLIT4;
269 len -= 4; 269 len -= 4;
270 } 270 }
271 buf = (const unsigned char FAR *)buf4; 271 buf = (const unsigned char FAR *)buf4;
272 272
273 if (len) do { 273 if (len) do {
274 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 274 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
275 } while (--len); 275 } while (--len);
276 c = ~c; 276 c = ~c;
277 return (unsigned long)c; 277 return (unsigned long)c;
278} 278}
279 279
280/* ========================================================================= */ 280/* ========================================================================= */
281#define DOBIG4 c ^= *++buf4; \ 281#define DOBIG4 c ^= *++buf4; \
282 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 282 c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
283 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 283 crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
284#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 284#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
285 285
286/* ========================================================================= */ 286/* ========================================================================= */
287local unsigned long crc32_big(crc, buf, len) 287local unsigned long crc32_big(crc, buf, len)
288 unsigned long crc; 288 unsigned long crc;
289 const unsigned char FAR *buf; 289 const unsigned char FAR *buf;
290 unsigned len; 290 unsigned len;
291{ 291{
292 register z_crc_t c; 292 register z_crc_t c;
293 register const z_crc_t FAR *buf4; 293 register const z_crc_t FAR *buf4;
294 294
295 c = ZSWAP32((z_crc_t)crc); 295 c = ZSWAP32((z_crc_t)crc);
296 c = ~c; 296 c = ~c;
297 while (len && ((ptrdiff_t)buf & 3)) { 297 while (len && ((ptrdiff_t)buf & 3)) {
298 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 298 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
299 len--; 299 len--;
300 } 300 }
301 301
302 buf4 = (const z_crc_t FAR *)(const void FAR *)buf; 302 buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
303 buf4--; 303 buf4--;
304 while (len >= 32) { 304 while (len >= 32) {
305 DOBIG32; 305 DOBIG32;
306 len -= 32; 306 len -= 32;
307 } 307 }
308 while (len >= 4) { 308 while (len >= 4) {
309 DOBIG4; 309 DOBIG4;
310 len -= 4; 310 len -= 4;
311 } 311 }
312 buf4++; 312 buf4++;
313 buf = (const unsigned char FAR *)buf4; 313 buf = (const unsigned char FAR *)buf4;
314 314
315 if (len) do { 315 if (len) do {
316 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 316 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
317 } while (--len); 317 } while (--len);
318 c = ~c; 318 c = ~c;
319 return (unsigned long)(ZSWAP32(c)); 319 return (unsigned long)(ZSWAP32(c));
320} 320}
321 321
322#endif /* BYFOUR */ 322#endif /* BYFOUR */
323 323
324#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 324#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
325 325
326/* ========================================================================= */ 326/* ========================================================================= */
327local unsigned long gf2_matrix_times(mat, vec) 327local unsigned long gf2_matrix_times(mat, vec)
328 unsigned long *mat; 328 unsigned long *mat;
329 unsigned long vec; 329 unsigned long vec;
330{ 330{
331 unsigned long sum; 331 unsigned long sum;
332 332
333 sum = 0; 333 sum = 0;
334 while (vec) { 334 while (vec) {
335 if (vec & 1) 335 if (vec & 1)
336 sum ^= *mat; 336 sum ^= *mat;
337 vec >>= 1; 337 vec >>= 1;
338 mat++; 338 mat++;
339 } 339 }
340 return sum; 340 return sum;
341} 341}
342 342
343/* ========================================================================= */ 343/* ========================================================================= */
344local void gf2_matrix_square(square, mat) 344local void gf2_matrix_square(square, mat)
345 unsigned long *square; 345 unsigned long *square;
346 unsigned long *mat; 346 unsigned long *mat;
347{ 347{
348 int n; 348 int n;
349 349
350 for (n = 0; n < GF2_DIM; n++) 350 for (n = 0; n < GF2_DIM; n++)
351 square[n] = gf2_matrix_times(mat, mat[n]); 351 square[n] = gf2_matrix_times(mat, mat[n]);
352} 352}
353 353
354/* ========================================================================= */ 354/* ========================================================================= */
355local uLong crc32_combine_(crc1, crc2, len2) 355local uLong crc32_combine_(crc1, crc2, len2)
356 uLong crc1; 356 uLong crc1;
357 uLong crc2; 357 uLong crc2;
358 z_off64_t len2; 358 z_off64_t len2;
359{ 359{
360 int n; 360 int n;
361 unsigned long row; 361 unsigned long row;
362 unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ 362 unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
363 unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ 363 unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
364 364
365 /* degenerate case (also disallow negative lengths) */ 365 /* degenerate case (also disallow negative lengths) */
366 if (len2 <= 0) 366 if (len2 <= 0)
367 return crc1; 367 return crc1;
368 368
369 /* put operator for one zero bit in odd */ 369 /* put operator for one zero bit in odd */
370 odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ 370 odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
371 row = 1; 371 row = 1;
372 for (n = 1; n < GF2_DIM; n++) { 372 for (n = 1; n < GF2_DIM; n++) {
373 odd[n] = row; 373 odd[n] = row;
374 row <<= 1; 374 row <<= 1;
375 } 375 }
376 376
377 /* put operator for two zero bits in even */ 377 /* put operator for two zero bits in even */
378 gf2_matrix_square(even, odd); 378 gf2_matrix_square(even, odd);
379 379
380 /* put operator for four zero bits in odd */ 380 /* put operator for four zero bits in odd */
381 gf2_matrix_square(odd, even); 381 gf2_matrix_square(odd, even);
382 382
383 /* apply len2 zeros to crc1 (first square will put the operator for one 383 /* apply len2 zeros to crc1 (first square will put the operator for one
384 zero byte, eight zero bits, in even) */ 384 zero byte, eight zero bits, in even) */
385 do { 385 do {
386 /* apply zeros operator for this bit of len2 */ 386 /* apply zeros operator for this bit of len2 */
387 gf2_matrix_square(even, odd); 387 gf2_matrix_square(even, odd);
388 if (len2 & 1) 388 if (len2 & 1)
389 crc1 = gf2_matrix_times(even, crc1); 389 crc1 = gf2_matrix_times(even, crc1);
390 len2 >>= 1; 390 len2 >>= 1;
391 391
392 /* if no more bits set, then done */ 392 /* if no more bits set, then done */
393 if (len2 == 0) 393 if (len2 == 0)
394 break; 394 break;
395 395
396 /* another iteration of the loop with odd and even swapped */ 396 /* another iteration of the loop with odd and even swapped */
397 gf2_matrix_square(odd, even); 397 gf2_matrix_square(odd, even);
398 if (len2 & 1) 398 if (len2 & 1)
399 crc1 = gf2_matrix_times(odd, crc1); 399 crc1 = gf2_matrix_times(odd, crc1);
400 len2 >>= 1; 400 len2 >>= 1;
401 401
402 /* if no more bits set, then done */ 402 /* if no more bits set, then done */
403 } while (len2 != 0); 403 } while (len2 != 0);
404 404
405 /* return combined crc */ 405 /* return combined crc */
406 crc1 ^= crc2; 406 crc1 ^= crc2;
407 return crc1; 407 return crc1;
408} 408}
409 409
410/* ========================================================================= */ 410/* ========================================================================= */
411uLong ZEXPORT crc32_combine(crc1, crc2, len2) 411uLong ZEXPORT crc32_combine(crc1, crc2, len2)
412 uLong crc1; 412 uLong crc1;
413 uLong crc2; 413 uLong crc2;
414 z_off_t len2; 414 z_off_t len2;
415{ 415{
416 return crc32_combine_(crc1, crc2, len2); 416 return crc32_combine_(crc1, crc2, len2);
417} 417}
418 418
419uLong ZEXPORT crc32_combine64(crc1, crc2, len2) 419uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
420 uLong crc1; 420 uLong crc1;
421 uLong crc2; 421 uLong crc2;
422 z_off64_t len2; 422 z_off64_t len2;
423{ 423{
424 return crc32_combine_(crc1, crc2, len2); 424 return crc32_combine_(crc1, crc2, len2);
425} 425}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.h
index b7e25cf..9e0c778 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/crc32.h
@@ -1,441 +1,441 @@
1/* crc32.h -- tables for rapid CRC calculation 1/* crc32.h -- tables for rapid CRC calculation
2 * Generated automatically by crc32.c 2 * Generated automatically by crc32.c
3 */ 3 */
4 4
5local const z_crc_t FAR crc_table[TBLS][256] = 5local const z_crc_t FAR crc_table[TBLS][256] =
6{ 6{
7 { 7 {
8 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, 8 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
9 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, 9 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
10 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, 10 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
11 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, 11 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
12 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, 12 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
13 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, 13 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
14 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, 14 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
15 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, 15 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
16 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, 16 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
17 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, 17 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
18 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, 18 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
19 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, 19 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
20 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, 20 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
21 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, 21 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
22 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, 22 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
23 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, 23 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
24 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, 24 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
25 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, 25 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
26 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, 26 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
27 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, 27 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
28 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, 28 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
29 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, 29 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
30 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, 30 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
31 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, 31 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
32 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, 32 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
33 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, 33 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
34 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, 34 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
35 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, 35 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
36 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, 36 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
37 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, 37 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
38 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, 38 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
39 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, 39 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
40 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, 40 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
41 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, 41 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
42 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, 42 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
43 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, 43 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
44 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, 44 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
45 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, 45 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
46 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, 46 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
47 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, 47 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
48 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, 48 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
49 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, 49 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
50 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, 50 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
51 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, 51 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
52 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, 52 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
53 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, 53 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
54 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, 54 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
55 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, 55 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
56 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, 56 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
57 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 57 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
58 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 58 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
59 0x2d02ef8dUL 59 0x2d02ef8dUL
60#ifdef BYFOUR 60#ifdef BYFOUR
61 }, 61 },
62 { 62 {
63 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, 63 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
64 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, 64 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
65 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, 65 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
66 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, 66 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
67 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, 67 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
68 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, 68 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
69 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, 69 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
70 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, 70 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
71 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, 71 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
72 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, 72 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
73 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, 73 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
74 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, 74 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
75 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, 75 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
76 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, 76 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
77 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, 77 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
78 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, 78 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
79 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, 79 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
80 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, 80 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
81 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, 81 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
82 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, 82 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
83 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, 83 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
84 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, 84 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
85 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, 85 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
86 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, 86 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
87 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, 87 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
88 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, 88 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
89 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, 89 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
90 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, 90 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
91 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, 91 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
92 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, 92 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
93 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, 93 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
94 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, 94 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
95 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, 95 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
96 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, 96 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
97 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, 97 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
98 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, 98 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
99 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, 99 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
100 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, 100 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
101 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, 101 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
102 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, 102 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
103 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, 103 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
104 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, 104 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
105 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, 105 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
106 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, 106 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
107 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, 107 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
108 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, 108 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
109 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, 109 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
110 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, 110 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
111 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, 111 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
112 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, 112 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
113 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, 113 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
114 0x9324fd72UL 114 0x9324fd72UL
115 }, 115 },
116 { 116 {
117 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, 117 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
118 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, 118 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
119 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, 119 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
120 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, 120 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
121 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, 121 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
122 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, 122 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
123 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, 123 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
124 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, 124 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
125 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, 125 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
126 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, 126 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
127 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, 127 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
128 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, 128 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
129 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, 129 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
130 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, 130 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
131 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, 131 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
132 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, 132 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
133 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, 133 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
134 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, 134 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
135 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, 135 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
136 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, 136 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
137 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, 137 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
138 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, 138 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
139 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, 139 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
140 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, 140 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
141 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, 141 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
142 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, 142 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
143 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, 143 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
144 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, 144 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
145 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, 145 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
146 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, 146 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
147 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, 147 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
148 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, 148 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
149 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, 149 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
150 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, 150 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
151 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, 151 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
152 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, 152 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
153 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, 153 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
154 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, 154 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
155 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, 155 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
156 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, 156 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
157 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, 157 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
158 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, 158 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
159 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, 159 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
160 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, 160 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
161 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, 161 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
162 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, 162 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
163 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, 163 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
164 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, 164 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
165 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, 165 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
166 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, 166 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
167 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, 167 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
168 0xbe9834edUL 168 0xbe9834edUL
169 }, 169 },
170 { 170 {
171 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, 171 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
172 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, 172 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
173 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, 173 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
174 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, 174 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
175 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, 175 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
176 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, 176 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
177 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, 177 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
178 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, 178 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
179 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, 179 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
180 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, 180 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
181 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, 181 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
182 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, 182 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
183 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, 183 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
184 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, 184 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
185 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, 185 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
186 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, 186 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
187 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, 187 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
188 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, 188 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
189 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, 189 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
190 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, 190 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
191 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, 191 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
192 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, 192 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
193 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, 193 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
194 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, 194 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
195 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, 195 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
196 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, 196 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
197 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, 197 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
198 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, 198 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
199 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, 199 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
200 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, 200 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
201 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, 201 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
202 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, 202 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
203 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, 203 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
204 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, 204 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
205 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, 205 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
206 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, 206 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
207 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, 207 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
208 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, 208 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
209 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, 209 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
210 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, 210 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
211 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, 211 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
212 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, 212 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
213 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, 213 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
214 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, 214 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
215 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, 215 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
216 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, 216 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
217 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, 217 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
218 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, 218 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
219 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, 219 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
220 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, 220 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
221 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, 221 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
222 0xde0506f1UL 222 0xde0506f1UL
223 }, 223 },
224 { 224 {
225 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, 225 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
226 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, 226 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
227 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, 227 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
228 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, 228 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
229 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, 229 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
230 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, 230 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
231 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, 231 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
232 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, 232 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
233 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, 233 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
234 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, 234 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
235 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, 235 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
236 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, 236 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
237 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, 237 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
238 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, 238 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
239 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, 239 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
240 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, 240 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
241 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, 241 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
242 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, 242 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
243 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, 243 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
244 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, 244 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
245 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, 245 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
246 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, 246 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
247 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, 247 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
248 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, 248 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
249 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, 249 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
250 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, 250 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
251 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, 251 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
252 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, 252 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
253 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, 253 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
254 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, 254 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
255 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, 255 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
256 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, 256 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
257 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, 257 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
258 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, 258 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
259 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, 259 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
260 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, 260 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
261 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, 261 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
262 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, 262 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
263 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, 263 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
264 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, 264 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
265 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, 265 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
266 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, 266 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
267 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, 267 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
268 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, 268 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
269 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, 269 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
270 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, 270 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
271 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, 271 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
272 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, 272 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
273 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, 273 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
274 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, 274 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
275 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, 275 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
276 0x8def022dUL 276 0x8def022dUL
277 }, 277 },
278 { 278 {
279 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, 279 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
280 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, 280 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
281 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, 281 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
282 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, 282 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
283 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, 283 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
284 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, 284 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
285 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, 285 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
286 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, 286 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
287 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, 287 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
288 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, 288 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
289 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, 289 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
290 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, 290 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
291 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, 291 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
292 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, 292 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
293 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, 293 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
294 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, 294 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
295 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, 295 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
296 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, 296 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
297 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, 297 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
298 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, 298 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
299 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, 299 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
300 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, 300 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
301 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, 301 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
302 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, 302 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
303 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, 303 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
304 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, 304 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
305 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, 305 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
306 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, 306 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
307 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, 307 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
308 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, 308 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
309 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, 309 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
310 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, 310 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
311 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, 311 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
312 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, 312 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
313 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, 313 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
314 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, 314 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
315 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, 315 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
316 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, 316 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
317 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, 317 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
318 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, 318 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
319 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, 319 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
320 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, 320 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
321 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, 321 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
322 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, 322 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
323 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, 323 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
324 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, 324 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
325 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, 325 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
326 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, 326 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
327 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, 327 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
328 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, 328 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
329 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, 329 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
330 0x72fd2493UL 330 0x72fd2493UL
331 }, 331 },
332 { 332 {
333 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, 333 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
334 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, 334 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
335 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, 335 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
336 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, 336 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
337 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, 337 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
338 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, 338 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
339 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, 339 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
340 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, 340 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
341 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, 341 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
342 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, 342 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
343 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, 343 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
344 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, 344 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
345 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, 345 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
346 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, 346 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
347 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, 347 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
348 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, 348 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
349 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, 349 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
350 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, 350 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
351 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, 351 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
352 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, 352 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
353 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, 353 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
354 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, 354 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
355 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, 355 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
356 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, 356 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
357 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, 357 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
358 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, 358 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
359 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, 359 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
360 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, 360 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
361 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, 361 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
362 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, 362 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
363 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, 363 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
364 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, 364 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
365 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, 365 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
366 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, 366 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
367 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, 367 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
368 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, 368 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
369 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, 369 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
370 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, 370 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
371 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, 371 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
372 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, 372 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
373 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, 373 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
374 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, 374 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
375 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, 375 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
376 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, 376 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
377 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, 377 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
378 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, 378 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
379 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, 379 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
380 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, 380 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
381 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, 381 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
382 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, 382 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
383 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, 383 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
384 0xed3498beUL 384 0xed3498beUL
385 }, 385 },
386 { 386 {
387 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, 387 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
388 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, 388 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
389 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, 389 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
390 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, 390 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
391 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, 391 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
392 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, 392 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
393 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, 393 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
394 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, 394 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
395 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, 395 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
396 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, 396 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
397 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, 397 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
398 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, 398 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
399 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, 399 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
400 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, 400 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
401 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, 401 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
402 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, 402 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
403 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, 403 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
404 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, 404 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
405 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, 405 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
406 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, 406 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
407 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, 407 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
408 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, 408 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
409 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, 409 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
410 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, 410 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
411 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, 411 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
412 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, 412 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
413 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, 413 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
414 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, 414 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
415 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, 415 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
416 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, 416 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
417 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, 417 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
418 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, 418 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
419 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, 419 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
420 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, 420 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
421 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, 421 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
422 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, 422 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
423 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, 423 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
424 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, 424 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
425 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, 425 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
426 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, 426 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
427 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, 427 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
428 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, 428 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
429 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, 429 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
430 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, 430 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
431 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, 431 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
432 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, 432 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
433 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, 433 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
434 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, 434 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
435 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, 435 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
436 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, 436 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
437 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, 437 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
438 0xf10605deUL 438 0xf10605deUL
439#endif 439#endif
440 } 440 }
441}; 441};
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.c
index e22f566..89778e5 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.c
@@ -1,1965 +1,1965 @@
1/* deflate.c -- compress data using the deflation algorithm 1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler 2 * Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* 6/*
7 * ALGORITHM 7 * ALGORITHM
8 * 8 *
9 * The "deflation" process depends on being able to identify portions 9 * The "deflation" process depends on being able to identify portions
10 * of the input text which are identical to earlier input (within a 10 * of the input text which are identical to earlier input (within a
11 * sliding window trailing behind the input currently being processed). 11 * sliding window trailing behind the input currently being processed).
12 * 12 *
13 * The most straightforward technique turns out to be the fastest for 13 * The most straightforward technique turns out to be the fastest for
14 * most input files: try all possible matches and select the longest. 14 * most input files: try all possible matches and select the longest.
15 * The key feature of this algorithm is that insertions into the string 15 * The key feature of this algorithm is that insertions into the string
16 * dictionary are very simple and thus fast, and deletions are avoided 16 * dictionary are very simple and thus fast, and deletions are avoided
17 * completely. Insertions are performed at each input character, whereas 17 * completely. Insertions are performed at each input character, whereas
18 * string matches are performed only when the previous match ends. So it 18 * string matches are performed only when the previous match ends. So it
19 * is preferable to spend more time in matches to allow very fast string 19 * is preferable to spend more time in matches to allow very fast string
20 * insertions and avoid deletions. The matching algorithm for small 20 * insertions and avoid deletions. The matching algorithm for small
21 * strings is inspired from that of Rabin & Karp. A brute force approach 21 * strings is inspired from that of Rabin & Karp. A brute force approach
22 * is used to find longer strings when a small match has been found. 22 * is used to find longer strings when a small match has been found.
23 * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze 23 * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
24 * (by Leonid Broukhis). 24 * (by Leonid Broukhis).
25 * A previous version of this file used a more sophisticated algorithm 25 * A previous version of this file used a more sophisticated algorithm
26 * (by Fiala and Greene) which is guaranteed to run in linear amortized 26 * (by Fiala and Greene) which is guaranteed to run in linear amortized
27 * time, but has a larger average cost, uses more memory and is patented. 27 * time, but has a larger average cost, uses more memory and is patented.
28 * However the F&G algorithm may be faster for some highly redundant 28 * However the F&G algorithm may be faster for some highly redundant
29 * files if the parameter max_chain_length (described below) is too large. 29 * files if the parameter max_chain_length (described below) is too large.
30 * 30 *
31 * ACKNOWLEDGEMENTS 31 * ACKNOWLEDGEMENTS
32 * 32 *
33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and 33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
34 * I found it in 'freeze' written by Leonid Broukhis. 34 * I found it in 'freeze' written by Leonid Broukhis.
35 * Thanks to many people for bug reports and testing. 35 * Thanks to many people for bug reports and testing.
36 * 36 *
37 * REFERENCES 37 * REFERENCES
38 * 38 *
39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". 39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
40 * Available in http://tools.ietf.org/html/rfc1951 40 * Available in http://tools.ietf.org/html/rfc1951
41 * 41 *
42 * A description of the Rabin and Karp algorithm is given in the book 42 * A description of the Rabin and Karp algorithm is given in the book
43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
44 * 44 *
45 * Fiala,E.R., and Greene,D.H. 45 * Fiala,E.R., and Greene,D.H.
46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
47 * 47 *
48 */ 48 */
49 49
50/* @(#) $Id$ */ 50/* @(#) $Id$ */
51 51
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler "; 55 " deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler ";
56/* 56/*
57 If you use the zlib library in a product, an acknowledgment is welcome 57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot 58 in the documentation of your product. If for some reason you cannot
59 include such an acknowledgment, I would appreciate that you keep this 59 include such an acknowledgment, I would appreciate that you keep this
60 copyright string in the executable of your product. 60 copyright string in the executable of your product.
61 */ 61 */
62 62
63/* =========================================================================== 63/* ===========================================================================
64 * Function prototypes. 64 * Function prototypes.
65 */ 65 */
66typedef enum { 66typedef enum {
67 need_more, /* block not completed, need more input or more output */ 67 need_more, /* block not completed, need more input or more output */
68 block_done, /* block flush performed */ 68 block_done, /* block flush performed */
69 finish_started, /* finish started, need only more output at next deflate */ 69 finish_started, /* finish started, need only more output at next deflate */
70 finish_done /* finish done, accept no more input or output */ 70 finish_done /* finish done, accept no more input or output */
71} block_state; 71} block_state;
72 72
73typedef block_state (*compress_func) OF((deflate_state *s, int flush)); 73typedef block_state (*compress_func) OF((deflate_state *s, int flush));
74/* Compression function. Returns the block state after the call. */ 74/* Compression function. Returns the block state after the call. */
75 75
76local void fill_window OF((deflate_state *s)); 76local void fill_window OF((deflate_state *s));
77local block_state deflate_stored OF((deflate_state *s, int flush)); 77local block_state deflate_stored OF((deflate_state *s, int flush));
78local block_state deflate_fast OF((deflate_state *s, int flush)); 78local block_state deflate_fast OF((deflate_state *s, int flush));
79#ifndef FASTEST 79#ifndef FASTEST
80local block_state deflate_slow OF((deflate_state *s, int flush)); 80local block_state deflate_slow OF((deflate_state *s, int flush));
81#endif 81#endif
82local block_state deflate_rle OF((deflate_state *s, int flush)); 82local block_state deflate_rle OF((deflate_state *s, int flush));
83local block_state deflate_huff OF((deflate_state *s, int flush)); 83local block_state deflate_huff OF((deflate_state *s, int flush));
84local void lm_init OF((deflate_state *s)); 84local void lm_init OF((deflate_state *s));
85local void putShortMSB OF((deflate_state *s, uInt b)); 85local void putShortMSB OF((deflate_state *s, uInt b));
86local void flush_pending OF((z_streamp strm)); 86local void flush_pending OF((z_streamp strm));
87local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); 87local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
88#ifdef ASMV 88#ifdef ASMV
89 void match_init OF((void)); /* asm code initialization */ 89 void match_init OF((void)); /* asm code initialization */
90 uInt longest_match OF((deflate_state *s, IPos cur_match)); 90 uInt longest_match OF((deflate_state *s, IPos cur_match));
91#else 91#else
92local uInt longest_match OF((deflate_state *s, IPos cur_match)); 92local uInt longest_match OF((deflate_state *s, IPos cur_match));
93#endif 93#endif
94 94
95#ifdef DEBUG 95#ifdef DEBUG
96local void check_match OF((deflate_state *s, IPos start, IPos match, 96local void check_match OF((deflate_state *s, IPos start, IPos match,
97 int length)); 97 int length));
98#endif 98#endif
99 99
100/* =========================================================================== 100/* ===========================================================================
101 * Local data 101 * Local data
102 */ 102 */
103 103
104#define NIL 0 104#define NIL 0
105/* Tail of hash chains */ 105/* Tail of hash chains */
106 106
107#ifndef TOO_FAR 107#ifndef TOO_FAR
108# define TOO_FAR 4096 108# define TOO_FAR 4096
109#endif 109#endif
110/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ 110/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
111 111
112/* Values for max_lazy_match, good_match and max_chain_length, depending on 112/* Values for max_lazy_match, good_match and max_chain_length, depending on
113 * the desired pack level (0..9). The values given below have been tuned to 113 * the desired pack level (0..9). The values given below have been tuned to
114 * exclude worst case performance for pathological files. Better values may be 114 * exclude worst case performance for pathological files. Better values may be
115 * found for specific files. 115 * found for specific files.
116 */ 116 */
117typedef struct config_s { 117typedef struct config_s {
118 ush good_length; /* reduce lazy search above this match length */ 118 ush good_length; /* reduce lazy search above this match length */
119 ush max_lazy; /* do not perform lazy search above this match length */ 119 ush max_lazy; /* do not perform lazy search above this match length */
120 ush nice_length; /* quit search above this match length */ 120 ush nice_length; /* quit search above this match length */
121 ush max_chain; 121 ush max_chain;
122 compress_func func; 122 compress_func func;
123} config; 123} config;
124 124
125#ifdef FASTEST 125#ifdef FASTEST
126local const config configuration_table[2] = { 126local const config configuration_table[2] = {
127/* good lazy nice chain */ 127/* good lazy nice chain */
128/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 128/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
129/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ 129/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
130#else 130#else
131local const config configuration_table[10] = { 131local const config configuration_table[10] = {
132/* good lazy nice chain */ 132/* good lazy nice chain */
133/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 133/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
134/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ 134/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
135/* 2 */ {4, 5, 16, 8, deflate_fast}, 135/* 2 */ {4, 5, 16, 8, deflate_fast},
136/* 3 */ {4, 6, 32, 32, deflate_fast}, 136/* 3 */ {4, 6, 32, 32, deflate_fast},
137 137
138/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ 138/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
139/* 5 */ {8, 16, 32, 32, deflate_slow}, 139/* 5 */ {8, 16, 32, 32, deflate_slow},
140/* 6 */ {8, 16, 128, 128, deflate_slow}, 140/* 6 */ {8, 16, 128, 128, deflate_slow},
141/* 7 */ {8, 32, 128, 256, deflate_slow}, 141/* 7 */ {8, 32, 128, 256, deflate_slow},
142/* 8 */ {32, 128, 258, 1024, deflate_slow}, 142/* 8 */ {32, 128, 258, 1024, deflate_slow},
143/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ 143/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
144#endif 144#endif
145 145
146/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 146/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
147 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different 147 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
148 * meaning. 148 * meaning.
149 */ 149 */
150 150
151#define EQUAL 0 151#define EQUAL 0
152/* result of memcmp for equal strings */ 152/* result of memcmp for equal strings */
153 153
154#ifndef NO_DUMMY_DECL 154#ifndef NO_DUMMY_DECL
155struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ 155struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
156#endif 156#endif
157 157
158/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ 158/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
159#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) 159#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
160 160
161/* =========================================================================== 161/* ===========================================================================
162 * Update a hash value with the given input byte 162 * Update a hash value with the given input byte
163 * IN assertion: all calls to to UPDATE_HASH are made with consecutive 163 * IN assertion: all calls to to UPDATE_HASH are made with consecutive
164 * input characters, so that a running hash key can be computed from the 164 * input characters, so that a running hash key can be computed from the
165 * previous key instead of complete recalculation each time. 165 * previous key instead of complete recalculation each time.
166 */ 166 */
167#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 167#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
168 168
169 169
170/* =========================================================================== 170/* ===========================================================================
171 * Insert string str in the dictionary and set match_head to the previous head 171 * Insert string str in the dictionary and set match_head to the previous head
172 * of the hash chain (the most recent string with same hash key). Return 172 * of the hash chain (the most recent string with same hash key). Return
173 * the previous length of the hash chain. 173 * the previous length of the hash chain.
174 * If this file is compiled with -DFASTEST, the compression level is forced 174 * If this file is compiled with -DFASTEST, the compression level is forced
175 * to 1, and no hash chains are maintained. 175 * to 1, and no hash chains are maintained.
176 * IN assertion: all calls to to INSERT_STRING are made with consecutive 176 * IN assertion: all calls to to INSERT_STRING are made with consecutive
177 * input characters and the first MIN_MATCH bytes of str are valid 177 * input characters and the first MIN_MATCH bytes of str are valid
178 * (except for the last MIN_MATCH-1 bytes of the input file). 178 * (except for the last MIN_MATCH-1 bytes of the input file).
179 */ 179 */
180#ifdef FASTEST 180#ifdef FASTEST
181#define INSERT_STRING(s, str, match_head) \ 181#define INSERT_STRING(s, str, match_head) \
182 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ 182 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
183 match_head = s->head[s->ins_h], \ 183 match_head = s->head[s->ins_h], \
184 s->head[s->ins_h] = (Pos)(str)) 184 s->head[s->ins_h] = (Pos)(str))
185#else 185#else
186#define INSERT_STRING(s, str, match_head) \ 186#define INSERT_STRING(s, str, match_head) \
187 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ 187 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
188 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ 188 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
189 s->head[s->ins_h] = (Pos)(str)) 189 s->head[s->ins_h] = (Pos)(str))
190#endif 190#endif
191 191
192/* =========================================================================== 192/* ===========================================================================
193 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 193 * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
194 * prev[] will be initialized on the fly. 194 * prev[] will be initialized on the fly.
195 */ 195 */
196#define CLEAR_HASH(s) \ 196#define CLEAR_HASH(s) \
197 s->head[s->hash_size-1] = NIL; \ 197 s->head[s->hash_size-1] = NIL; \
198 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); 198 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
199 199
200/* ========================================================================= */ 200/* ========================================================================= */
201int ZEXPORT deflateInit_(strm, level, version, stream_size) 201int ZEXPORT deflateInit_(strm, level, version, stream_size)
202 z_streamp strm; 202 z_streamp strm;
203 int level; 203 int level;
204 const char *version; 204 const char *version;
205 int stream_size; 205 int stream_size;
206{ 206{
207 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 207 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
208 Z_DEFAULT_STRATEGY, version, stream_size); 208 Z_DEFAULT_STRATEGY, version, stream_size);
209 /* To do: ignore strm->next_in if we use it as window */ 209 /* To do: ignore strm->next_in if we use it as window */
210} 210}
211 211
212/* ========================================================================= */ 212/* ========================================================================= */
213int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, 213int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
214 version, stream_size) 214 version, stream_size)
215 z_streamp strm; 215 z_streamp strm;
216 int level; 216 int level;
217 int method; 217 int method;
218 int windowBits; 218 int windowBits;
219 int memLevel; 219 int memLevel;
220 int strategy; 220 int strategy;
221 const char *version; 221 const char *version;
222 int stream_size; 222 int stream_size;
223{ 223{
224 deflate_state *s; 224 deflate_state *s;
225 int wrap = 1; 225 int wrap = 1;
226 static const char my_version[] = ZLIB_VERSION; 226 static const char my_version[] = ZLIB_VERSION;
227 227
228 ushf *overlay; 228 ushf *overlay;
229 /* We overlay pending_buf and d_buf+l_buf. This works since the average 229 /* We overlay pending_buf and d_buf+l_buf. This works since the average
230 * output size for (length,distance) codes is <= 24 bits. 230 * output size for (length,distance) codes is <= 24 bits.
231 */ 231 */
232 232
233 if (version == Z_NULL || version[0] != my_version[0] || 233 if (version == Z_NULL || version[0] != my_version[0] ||
234 stream_size != sizeof(z_stream)) { 234 stream_size != sizeof(z_stream)) {
235 return Z_VERSION_ERROR; 235 return Z_VERSION_ERROR;
236 } 236 }
237 if (strm == Z_NULL) return Z_STREAM_ERROR; 237 if (strm == Z_NULL) return Z_STREAM_ERROR;
238 238
239 strm->msg = Z_NULL; 239 strm->msg = Z_NULL;
240 if (strm->zalloc == (alloc_func)0) { 240 if (strm->zalloc == (alloc_func)0) {
241#ifdef Z_SOLO 241#ifdef Z_SOLO
242 return Z_STREAM_ERROR; 242 return Z_STREAM_ERROR;
243#else 243#else
244 strm->zalloc = zcalloc; 244 strm->zalloc = zcalloc;
245 strm->opaque = (voidpf)0; 245 strm->opaque = (voidpf)0;
246#endif 246#endif
247 } 247 }
248 if (strm->zfree == (free_func)0) 248 if (strm->zfree == (free_func)0)
249#ifdef Z_SOLO 249#ifdef Z_SOLO
250 return Z_STREAM_ERROR; 250 return Z_STREAM_ERROR;
251#else 251#else
252 strm->zfree = zcfree; 252 strm->zfree = zcfree;
253#endif 253#endif
254 254
255#ifdef FASTEST 255#ifdef FASTEST
256 if (level != 0) level = 1; 256 if (level != 0) level = 1;
257#else 257#else
258 if (level == Z_DEFAULT_COMPRESSION) level = 6; 258 if (level == Z_DEFAULT_COMPRESSION) level = 6;
259#endif 259#endif
260 260
261 if (windowBits < 0) { /* suppress zlib wrapper */ 261 if (windowBits < 0) { /* suppress zlib wrapper */
262 wrap = 0; 262 wrap = 0;
263 windowBits = -windowBits; 263 windowBits = -windowBits;
264 } 264 }
265#ifdef GZIP 265#ifdef GZIP
266 else if (windowBits > 15) { 266 else if (windowBits > 15) {
267 wrap = 2; /* write gzip wrapper instead */ 267 wrap = 2; /* write gzip wrapper instead */
268 windowBits -= 16; 268 windowBits -= 16;
269 } 269 }
270#endif 270#endif
271 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 271 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
272 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || 272 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
273 strategy < 0 || strategy > Z_FIXED) { 273 strategy < 0 || strategy > Z_FIXED) {
274 return Z_STREAM_ERROR; 274 return Z_STREAM_ERROR;
275 } 275 }
276 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ 276 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
277 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); 277 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
278 if (s == Z_NULL) return Z_MEM_ERROR; 278 if (s == Z_NULL) return Z_MEM_ERROR;
279 strm->state = (struct internal_state FAR *)s; 279 strm->state = (struct internal_state FAR *)s;
280 s->strm = strm; 280 s->strm = strm;
281 281
282 s->wrap = wrap; 282 s->wrap = wrap;
283 s->gzhead = Z_NULL; 283 s->gzhead = Z_NULL;
284 s->w_bits = windowBits; 284 s->w_bits = windowBits;
285 s->w_size = 1 << s->w_bits; 285 s->w_size = 1 << s->w_bits;
286 s->w_mask = s->w_size - 1; 286 s->w_mask = s->w_size - 1;
287 287
288 s->hash_bits = memLevel + 7; 288 s->hash_bits = memLevel + 7;
289 s->hash_size = 1 << s->hash_bits; 289 s->hash_size = 1 << s->hash_bits;
290 s->hash_mask = s->hash_size - 1; 290 s->hash_mask = s->hash_size - 1;
291 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); 291 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
292 292
293 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 293 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
294 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 294 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
295 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 295 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
296 296
297 s->high_water = 0; /* nothing written to s->window yet */ 297 s->high_water = 0; /* nothing written to s->window yet */
298 298
299 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 299 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
300 300
301 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); 301 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
302 s->pending_buf = (uchf *) overlay; 302 s->pending_buf = (uchf *) overlay;
303 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); 303 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
304 304
305 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 305 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
306 s->pending_buf == Z_NULL) { 306 s->pending_buf == Z_NULL) {
307 s->status = FINISH_STATE; 307 s->status = FINISH_STATE;
308 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 308 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
309 deflateEnd (strm); 309 deflateEnd (strm);
310 return Z_MEM_ERROR; 310 return Z_MEM_ERROR;
311 } 311 }
312 s->d_buf = overlay + s->lit_bufsize/sizeof(ush); 312 s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
313 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; 313 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
314 314
315 s->level = level; 315 s->level = level;
316 s->strategy = strategy; 316 s->strategy = strategy;
317 s->method = (Byte)method; 317 s->method = (Byte)method;
318 318
319 return deflateReset(strm); 319 return deflateReset(strm);
320} 320}
321 321
322/* ========================================================================= */ 322/* ========================================================================= */
323int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) 323int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
324 z_streamp strm; 324 z_streamp strm;
325 const Bytef *dictionary; 325 const Bytef *dictionary;
326 uInt dictLength; 326 uInt dictLength;
327{ 327{
328 deflate_state *s; 328 deflate_state *s;
329 uInt str, n; 329 uInt str, n;
330 int wrap; 330 int wrap;
331 unsigned avail; 331 unsigned avail;
332 unsigned char *next; 332 unsigned char *next;
333 333
334 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) 334 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
335 return Z_STREAM_ERROR; 335 return Z_STREAM_ERROR;
336 s = strm->state; 336 s = strm->state;
337 wrap = s->wrap; 337 wrap = s->wrap;
338 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) 338 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
339 return Z_STREAM_ERROR; 339 return Z_STREAM_ERROR;
340 340
341 /* when using zlib wrappers, compute Adler-32 for provided dictionary */ 341 /* when using zlib wrappers, compute Adler-32 for provided dictionary */
342 if (wrap == 1) 342 if (wrap == 1)
343 strm->adler = adler32(strm->adler, dictionary, dictLength); 343 strm->adler = adler32(strm->adler, dictionary, dictLength);
344 s->wrap = 0; /* avoid computing Adler-32 in read_buf */ 344 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
345 345
346 /* if dictionary would fill window, just replace the history */ 346 /* if dictionary would fill window, just replace the history */
347 if (dictLength >= s->w_size) { 347 if (dictLength >= s->w_size) {
348 if (wrap == 0) { /* already empty otherwise */ 348 if (wrap == 0) { /* already empty otherwise */
349 CLEAR_HASH(s); 349 CLEAR_HASH(s);
350 s->strstart = 0; 350 s->strstart = 0;
351 s->block_start = 0L; 351 s->block_start = 0L;
352 s->insert = 0; 352 s->insert = 0;
353 } 353 }
354 dictionary += dictLength - s->w_size; /* use the tail */ 354 dictionary += dictLength - s->w_size; /* use the tail */
355 dictLength = s->w_size; 355 dictLength = s->w_size;
356 } 356 }
357 357
358 /* insert dictionary into window and hash */ 358 /* insert dictionary into window and hash */
359 avail = strm->avail_in; 359 avail = strm->avail_in;
360 next = strm->next_in; 360 next = strm->next_in;
361 strm->avail_in = dictLength; 361 strm->avail_in = dictLength;
362 strm->next_in = (Bytef *)dictionary; 362 strm->next_in = (Bytef *)dictionary;
363 fill_window(s); 363 fill_window(s);
364 while (s->lookahead >= MIN_MATCH) { 364 while (s->lookahead >= MIN_MATCH) {
365 str = s->strstart; 365 str = s->strstart;
366 n = s->lookahead - (MIN_MATCH-1); 366 n = s->lookahead - (MIN_MATCH-1);
367 do { 367 do {
368 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); 368 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
369#ifndef FASTEST 369#ifndef FASTEST
370 s->prev[str & s->w_mask] = s->head[s->ins_h]; 370 s->prev[str & s->w_mask] = s->head[s->ins_h];
371#endif 371#endif
372 s->head[s->ins_h] = (Pos)str; 372 s->head[s->ins_h] = (Pos)str;
373 str++; 373 str++;
374 } while (--n); 374 } while (--n);
375 s->strstart = str; 375 s->strstart = str;
376 s->lookahead = MIN_MATCH-1; 376 s->lookahead = MIN_MATCH-1;
377 fill_window(s); 377 fill_window(s);
378 } 378 }
379 s->strstart += s->lookahead; 379 s->strstart += s->lookahead;
380 s->block_start = (long)s->strstart; 380 s->block_start = (long)s->strstart;
381 s->insert = s->lookahead; 381 s->insert = s->lookahead;
382 s->lookahead = 0; 382 s->lookahead = 0;
383 s->match_length = s->prev_length = MIN_MATCH-1; 383 s->match_length = s->prev_length = MIN_MATCH-1;
384 s->match_available = 0; 384 s->match_available = 0;
385 strm->next_in = next; 385 strm->next_in = next;
386 strm->avail_in = avail; 386 strm->avail_in = avail;
387 s->wrap = wrap; 387 s->wrap = wrap;
388 return Z_OK; 388 return Z_OK;
389} 389}
390 390
391/* ========================================================================= */ 391/* ========================================================================= */
392int ZEXPORT deflateResetKeep (strm) 392int ZEXPORT deflateResetKeep (strm)
393 z_streamp strm; 393 z_streamp strm;
394{ 394{
395 deflate_state *s; 395 deflate_state *s;
396 396
397 if (strm == Z_NULL || strm->state == Z_NULL || 397 if (strm == Z_NULL || strm->state == Z_NULL ||
398 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { 398 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
399 return Z_STREAM_ERROR; 399 return Z_STREAM_ERROR;
400 } 400 }
401 401
402 strm->total_in = strm->total_out = 0; 402 strm->total_in = strm->total_out = 0;
403 strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ 403 strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
404 strm->data_type = Z_UNKNOWN; 404 strm->data_type = Z_UNKNOWN;
405 405
406 s = (deflate_state *)strm->state; 406 s = (deflate_state *)strm->state;
407 s->pending = 0; 407 s->pending = 0;
408 s->pending_out = s->pending_buf; 408 s->pending_out = s->pending_buf;
409 409
410 if (s->wrap < 0) { 410 if (s->wrap < 0) {
411 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ 411 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
412 } 412 }
413 s->status = s->wrap ? INIT_STATE : BUSY_STATE; 413 s->status = s->wrap ? INIT_STATE : BUSY_STATE;
414 strm->adler = 414 strm->adler =
415#ifdef GZIP 415#ifdef GZIP
416 s->wrap == 2 ? crc32(0L, Z_NULL, 0) : 416 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
417#endif 417#endif
418 adler32(0L, Z_NULL, 0); 418 adler32(0L, Z_NULL, 0);
419 s->last_flush = Z_NO_FLUSH; 419 s->last_flush = Z_NO_FLUSH;
420 420
421 _tr_init(s); 421 _tr_init(s);
422 422
423 return Z_OK; 423 return Z_OK;
424} 424}
425 425
426/* ========================================================================= */ 426/* ========================================================================= */
427int ZEXPORT deflateReset (strm) 427int ZEXPORT deflateReset (strm)
428 z_streamp strm; 428 z_streamp strm;
429{ 429{
430 int ret; 430 int ret;
431 431
432 ret = deflateResetKeep(strm); 432 ret = deflateResetKeep(strm);
433 if (ret == Z_OK) 433 if (ret == Z_OK)
434 lm_init(strm->state); 434 lm_init(strm->state);
435 return ret; 435 return ret;
436} 436}
437 437
438/* ========================================================================= */ 438/* ========================================================================= */
439int ZEXPORT deflateSetHeader (strm, head) 439int ZEXPORT deflateSetHeader (strm, head)
440 z_streamp strm; 440 z_streamp strm;
441 gz_headerp head; 441 gz_headerp head;
442{ 442{
443 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 443 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
444 if (strm->state->wrap != 2) return Z_STREAM_ERROR; 444 if (strm->state->wrap != 2) return Z_STREAM_ERROR;
445 strm->state->gzhead = head; 445 strm->state->gzhead = head;
446 return Z_OK; 446 return Z_OK;
447} 447}
448 448
449/* ========================================================================= */ 449/* ========================================================================= */
450int ZEXPORT deflatePending (strm, pending, bits) 450int ZEXPORT deflatePending (strm, pending, bits)
451 unsigned *pending; 451 unsigned *pending;
452 int *bits; 452 int *bits;
453 z_streamp strm; 453 z_streamp strm;
454{ 454{
455 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 455 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
456 if (pending != Z_NULL) 456 if (pending != Z_NULL)
457 *pending = strm->state->pending; 457 *pending = strm->state->pending;
458 if (bits != Z_NULL) 458 if (bits != Z_NULL)
459 *bits = strm->state->bi_valid; 459 *bits = strm->state->bi_valid;
460 return Z_OK; 460 return Z_OK;
461} 461}
462 462
463/* ========================================================================= */ 463/* ========================================================================= */
464int ZEXPORT deflatePrime (strm, bits, value) 464int ZEXPORT deflatePrime (strm, bits, value)
465 z_streamp strm; 465 z_streamp strm;
466 int bits; 466 int bits;
467 int value; 467 int value;
468{ 468{
469 deflate_state *s; 469 deflate_state *s;
470 int put; 470 int put;
471 471
472 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 472 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
473 s = strm->state; 473 s = strm->state;
474 if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) 474 if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
475 return Z_BUF_ERROR; 475 return Z_BUF_ERROR;
476 do { 476 do {
477 put = Buf_size - s->bi_valid; 477 put = Buf_size - s->bi_valid;
478 if (put > bits) 478 if (put > bits)
479 put = bits; 479 put = bits;
480 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); 480 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
481 s->bi_valid += put; 481 s->bi_valid += put;
482 _tr_flush_bits(s); 482 _tr_flush_bits(s);
483 value >>= put; 483 value >>= put;
484 bits -= put; 484 bits -= put;
485 } while (bits); 485 } while (bits);
486 return Z_OK; 486 return Z_OK;
487} 487}
488 488
489/* ========================================================================= */ 489/* ========================================================================= */
490int ZEXPORT deflateParams(strm, level, strategy) 490int ZEXPORT deflateParams(strm, level, strategy)
491 z_streamp strm; 491 z_streamp strm;
492 int level; 492 int level;
493 int strategy; 493 int strategy;
494{ 494{
495 deflate_state *s; 495 deflate_state *s;
496 compress_func func; 496 compress_func func;
497 int err = Z_OK; 497 int err = Z_OK;
498 498
499 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 499 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
500 s = strm->state; 500 s = strm->state;
501 501
502#ifdef FASTEST 502#ifdef FASTEST
503 if (level != 0) level = 1; 503 if (level != 0) level = 1;
504#else 504#else
505 if (level == Z_DEFAULT_COMPRESSION) level = 6; 505 if (level == Z_DEFAULT_COMPRESSION) level = 6;
506#endif 506#endif
507 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { 507 if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
508 return Z_STREAM_ERROR; 508 return Z_STREAM_ERROR;
509 } 509 }
510 func = configuration_table[s->level].func; 510 func = configuration_table[s->level].func;
511 511
512 if ((strategy != s->strategy || func != configuration_table[level].func) && 512 if ((strategy != s->strategy || func != configuration_table[level].func) &&
513 strm->total_in != 0) { 513 strm->total_in != 0) {
514 /* Flush the last buffer: */ 514 /* Flush the last buffer: */
515 err = deflate(strm, Z_BLOCK); 515 err = deflate(strm, Z_BLOCK);
516 } 516 }
517 if (s->level != level) { 517 if (s->level != level) {
518 s->level = level; 518 s->level = level;
519 s->max_lazy_match = configuration_table[level].max_lazy; 519 s->max_lazy_match = configuration_table[level].max_lazy;
520 s->good_match = configuration_table[level].good_length; 520 s->good_match = configuration_table[level].good_length;
521 s->nice_match = configuration_table[level].nice_length; 521 s->nice_match = configuration_table[level].nice_length;
522 s->max_chain_length = configuration_table[level].max_chain; 522 s->max_chain_length = configuration_table[level].max_chain;
523 } 523 }
524 s->strategy = strategy; 524 s->strategy = strategy;
525 return err; 525 return err;
526} 526}
527 527
528/* ========================================================================= */ 528/* ========================================================================= */
529int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) 529int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
530 z_streamp strm; 530 z_streamp strm;
531 int good_length; 531 int good_length;
532 int max_lazy; 532 int max_lazy;
533 int nice_length; 533 int nice_length;
534 int max_chain; 534 int max_chain;
535{ 535{
536 deflate_state *s; 536 deflate_state *s;
537 537
538 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 538 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
539 s = strm->state; 539 s = strm->state;
540 s->good_match = good_length; 540 s->good_match = good_length;
541 s->max_lazy_match = max_lazy; 541 s->max_lazy_match = max_lazy;
542 s->nice_match = nice_length; 542 s->nice_match = nice_length;
543 s->max_chain_length = max_chain; 543 s->max_chain_length = max_chain;
544 return Z_OK; 544 return Z_OK;
545} 545}
546 546
547/* ========================================================================= 547/* =========================================================================
548 * For the default windowBits of 15 and memLevel of 8, this function returns 548 * For the default windowBits of 15 and memLevel of 8, this function returns
549 * a close to exact, as well as small, upper bound on the compressed size. 549 * a close to exact, as well as small, upper bound on the compressed size.
550 * They are coded as constants here for a reason--if the #define's are 550 * They are coded as constants here for a reason--if the #define's are
551 * changed, then this function needs to be changed as well. The return 551 * changed, then this function needs to be changed as well. The return
552 * value for 15 and 8 only works for those exact settings. 552 * value for 15 and 8 only works for those exact settings.
553 * 553 *
554 * For any setting other than those defaults for windowBits and memLevel, 554 * For any setting other than those defaults for windowBits and memLevel,
555 * the value returned is a conservative worst case for the maximum expansion 555 * the value returned is a conservative worst case for the maximum expansion
556 * resulting from using fixed blocks instead of stored blocks, which deflate 556 * resulting from using fixed blocks instead of stored blocks, which deflate
557 * can emit on compressed data for some combinations of the parameters. 557 * can emit on compressed data for some combinations of the parameters.
558 * 558 *
559 * This function could be more sophisticated to provide closer upper bounds for 559 * This function could be more sophisticated to provide closer upper bounds for
560 * every combination of windowBits and memLevel. But even the conservative 560 * every combination of windowBits and memLevel. But even the conservative
561 * upper bound of about 14% expansion does not seem onerous for output buffer 561 * upper bound of about 14% expansion does not seem onerous for output buffer
562 * allocation. 562 * allocation.
563 */ 563 */
564uLong ZEXPORT deflateBound(strm, sourceLen) 564uLong ZEXPORT deflateBound(strm, sourceLen)
565 z_streamp strm; 565 z_streamp strm;
566 uLong sourceLen; 566 uLong sourceLen;
567{ 567{
568 deflate_state *s; 568 deflate_state *s;
569 uLong complen, wraplen; 569 uLong complen, wraplen;
570 Bytef *str; 570 Bytef *str;
571 571
572 /* conservative upper bound for compressed data */ 572 /* conservative upper bound for compressed data */
573 complen = sourceLen + 573 complen = sourceLen +
574 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; 574 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
575 575
576 /* if can't get parameters, return conservative bound plus zlib wrapper */ 576 /* if can't get parameters, return conservative bound plus zlib wrapper */
577 if (strm == Z_NULL || strm->state == Z_NULL) 577 if (strm == Z_NULL || strm->state == Z_NULL)
578 return complen + 6; 578 return complen + 6;
579 579
580 /* compute wrapper length */ 580 /* compute wrapper length */
581 s = strm->state; 581 s = strm->state;
582 switch (s->wrap) { 582 switch (s->wrap) {
583 case 0: /* raw deflate */ 583 case 0: /* raw deflate */
584 wraplen = 0; 584 wraplen = 0;
585 break; 585 break;
586 case 1: /* zlib wrapper */ 586 case 1: /* zlib wrapper */
587 wraplen = 6 + (s->strstart ? 4 : 0); 587 wraplen = 6 + (s->strstart ? 4 : 0);
588 break; 588 break;
589 case 2: /* gzip wrapper */ 589 case 2: /* gzip wrapper */
590 wraplen = 18; 590 wraplen = 18;
591 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ 591 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
592 if (s->gzhead->extra != Z_NULL) 592 if (s->gzhead->extra != Z_NULL)
593 wraplen += 2 + s->gzhead->extra_len; 593 wraplen += 2 + s->gzhead->extra_len;
594 str = s->gzhead->name; 594 str = s->gzhead->name;
595 if (str != Z_NULL) 595 if (str != Z_NULL)
596 do { 596 do {
597 wraplen++; 597 wraplen++;
598 } while (*str++); 598 } while (*str++);
599 str = s->gzhead->comment; 599 str = s->gzhead->comment;
600 if (str != Z_NULL) 600 if (str != Z_NULL)
601 do { 601 do {
602 wraplen++; 602 wraplen++;
603 } while (*str++); 603 } while (*str++);
604 if (s->gzhead->hcrc) 604 if (s->gzhead->hcrc)
605 wraplen += 2; 605 wraplen += 2;
606 } 606 }
607 break; 607 break;
608 default: /* for compiler happiness */ 608 default: /* for compiler happiness */
609 wraplen = 6; 609 wraplen = 6;
610 } 610 }
611 611
612 /* if not default parameters, return conservative bound */ 612 /* if not default parameters, return conservative bound */
613 if (s->w_bits != 15 || s->hash_bits != 8 + 7) 613 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
614 return complen + wraplen; 614 return complen + wraplen;
615 615
616 /* default settings: return tight bound for that case */ 616 /* default settings: return tight bound for that case */
617 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 617 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
618 (sourceLen >> 25) + 13 - 6 + wraplen; 618 (sourceLen >> 25) + 13 - 6 + wraplen;
619} 619}
620 620
621/* ========================================================================= 621/* =========================================================================
622 * Put a short in the pending buffer. The 16-bit value is put in MSB order. 622 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
623 * IN assertion: the stream state is correct and there is enough room in 623 * IN assertion: the stream state is correct and there is enough room in
624 * pending_buf. 624 * pending_buf.
625 */ 625 */
626local void putShortMSB (s, b) 626local void putShortMSB (s, b)
627 deflate_state *s; 627 deflate_state *s;
628 uInt b; 628 uInt b;
629{ 629{
630 put_byte(s, (Byte)(b >> 8)); 630 put_byte(s, (Byte)(b >> 8));
631 put_byte(s, (Byte)(b & 0xff)); 631 put_byte(s, (Byte)(b & 0xff));
632} 632}
633 633
634/* ========================================================================= 634/* =========================================================================
635 * Flush as much pending output as possible. All deflate() output goes 635 * Flush as much pending output as possible. All deflate() output goes
636 * through this function so some applications may wish to modify it 636 * through this function so some applications may wish to modify it
637 * to avoid allocating a large strm->next_out buffer and copying into it. 637 * to avoid allocating a large strm->next_out buffer and copying into it.
638 * (See also read_buf()). 638 * (See also read_buf()).
639 */ 639 */
640local void flush_pending(strm) 640local void flush_pending(strm)
641 z_streamp strm; 641 z_streamp strm;
642{ 642{
643 unsigned len; 643 unsigned len;
644 deflate_state *s = strm->state; 644 deflate_state *s = strm->state;
645 645
646 _tr_flush_bits(s); 646 _tr_flush_bits(s);
647 len = s->pending; 647 len = s->pending;
648 if (len > strm->avail_out) len = strm->avail_out; 648 if (len > strm->avail_out) len = strm->avail_out;
649 if (len == 0) return; 649 if (len == 0) return;
650 650
651 zmemcpy(strm->next_out, s->pending_out, len); 651 zmemcpy(strm->next_out, s->pending_out, len);
652 strm->next_out += len; 652 strm->next_out += len;
653 s->pending_out += len; 653 s->pending_out += len;
654 strm->total_out += len; 654 strm->total_out += len;
655 strm->avail_out -= len; 655 strm->avail_out -= len;
656 s->pending -= len; 656 s->pending -= len;
657 if (s->pending == 0) { 657 if (s->pending == 0) {
658 s->pending_out = s->pending_buf; 658 s->pending_out = s->pending_buf;
659 } 659 }
660} 660}
661 661
662/* ========================================================================= */ 662/* ========================================================================= */
663int ZEXPORT deflate (strm, flush) 663int ZEXPORT deflate (strm, flush)
664 z_streamp strm; 664 z_streamp strm;
665 int flush; 665 int flush;
666{ 666{
667 int old_flush; /* value of flush param for previous deflate call */ 667 int old_flush; /* value of flush param for previous deflate call */
668 deflate_state *s; 668 deflate_state *s;
669 669
670 if (strm == Z_NULL || strm->state == Z_NULL || 670 if (strm == Z_NULL || strm->state == Z_NULL ||
671 flush > Z_BLOCK || flush < 0) { 671 flush > Z_BLOCK || flush < 0) {
672 return Z_STREAM_ERROR; 672 return Z_STREAM_ERROR;
673 } 673 }
674 s = strm->state; 674 s = strm->state;
675 675
676 if (strm->next_out == Z_NULL || 676 if (strm->next_out == Z_NULL ||
677 (strm->next_in == Z_NULL && strm->avail_in != 0) || 677 (strm->next_in == Z_NULL && strm->avail_in != 0) ||
678 (s->status == FINISH_STATE && flush != Z_FINISH)) { 678 (s->status == FINISH_STATE && flush != Z_FINISH)) {
679 ERR_RETURN(strm, Z_STREAM_ERROR); 679 ERR_RETURN(strm, Z_STREAM_ERROR);
680 } 680 }
681 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); 681 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
682 682
683 s->strm = strm; /* just in case */ 683 s->strm = strm; /* just in case */
684 old_flush = s->last_flush; 684 old_flush = s->last_flush;
685 s->last_flush = flush; 685 s->last_flush = flush;
686 686
687 /* Write the header */ 687 /* Write the header */
688 if (s->status == INIT_STATE) { 688 if (s->status == INIT_STATE) {
689#ifdef GZIP 689#ifdef GZIP
690 if (s->wrap == 2) { 690 if (s->wrap == 2) {
691 strm->adler = crc32(0L, Z_NULL, 0); 691 strm->adler = crc32(0L, Z_NULL, 0);
692 put_byte(s, 31); 692 put_byte(s, 31);
693 put_byte(s, 139); 693 put_byte(s, 139);
694 put_byte(s, 8); 694 put_byte(s, 8);
695 if (s->gzhead == Z_NULL) { 695 if (s->gzhead == Z_NULL) {
696 put_byte(s, 0); 696 put_byte(s, 0);
697 put_byte(s, 0); 697 put_byte(s, 0);
698 put_byte(s, 0); 698 put_byte(s, 0);
699 put_byte(s, 0); 699 put_byte(s, 0);
700 put_byte(s, 0); 700 put_byte(s, 0);
701 put_byte(s, s->level == 9 ? 2 : 701 put_byte(s, s->level == 9 ? 2 :
702 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 702 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
703 4 : 0)); 703 4 : 0));
704 put_byte(s, OS_CODE); 704 put_byte(s, OS_CODE);
705 s->status = BUSY_STATE; 705 s->status = BUSY_STATE;
706 } 706 }
707 else { 707 else {
708 put_byte(s, (s->gzhead->text ? 1 : 0) + 708 put_byte(s, (s->gzhead->text ? 1 : 0) +
709 (s->gzhead->hcrc ? 2 : 0) + 709 (s->gzhead->hcrc ? 2 : 0) +
710 (s->gzhead->extra == Z_NULL ? 0 : 4) + 710 (s->gzhead->extra == Z_NULL ? 0 : 4) +
711 (s->gzhead->name == Z_NULL ? 0 : 8) + 711 (s->gzhead->name == Z_NULL ? 0 : 8) +
712 (s->gzhead->comment == Z_NULL ? 0 : 16) 712 (s->gzhead->comment == Z_NULL ? 0 : 16)
713 ); 713 );
714 put_byte(s, (Byte)(s->gzhead->time & 0xff)); 714 put_byte(s, (Byte)(s->gzhead->time & 0xff));
715 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); 715 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
716 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); 716 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
717 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); 717 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
718 put_byte(s, s->level == 9 ? 2 : 718 put_byte(s, s->level == 9 ? 2 :
719 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 719 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
720 4 : 0)); 720 4 : 0));
721 put_byte(s, s->gzhead->os & 0xff); 721 put_byte(s, s->gzhead->os & 0xff);
722 if (s->gzhead->extra != Z_NULL) { 722 if (s->gzhead->extra != Z_NULL) {
723 put_byte(s, s->gzhead->extra_len & 0xff); 723 put_byte(s, s->gzhead->extra_len & 0xff);
724 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); 724 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
725 } 725 }
726 if (s->gzhead->hcrc) 726 if (s->gzhead->hcrc)
727 strm->adler = crc32(strm->adler, s->pending_buf, 727 strm->adler = crc32(strm->adler, s->pending_buf,
728 s->pending); 728 s->pending);
729 s->gzindex = 0; 729 s->gzindex = 0;
730 s->status = EXTRA_STATE; 730 s->status = EXTRA_STATE;
731 } 731 }
732 } 732 }
733 else 733 else
734#endif 734#endif
735 { 735 {
736 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; 736 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
737 uInt level_flags; 737 uInt level_flags;
738 738
739 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) 739 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
740 level_flags = 0; 740 level_flags = 0;
741 else if (s->level < 6) 741 else if (s->level < 6)
742 level_flags = 1; 742 level_flags = 1;
743 else if (s->level == 6) 743 else if (s->level == 6)
744 level_flags = 2; 744 level_flags = 2;
745 else 745 else
746 level_flags = 3; 746 level_flags = 3;
747 header |= (level_flags << 6); 747 header |= (level_flags << 6);
748 if (s->strstart != 0) header |= PRESET_DICT; 748 if (s->strstart != 0) header |= PRESET_DICT;
749 header += 31 - (header % 31); 749 header += 31 - (header % 31);
750 750
751 s->status = BUSY_STATE; 751 s->status = BUSY_STATE;
752 putShortMSB(s, header); 752 putShortMSB(s, header);
753 753
754 /* Save the adler32 of the preset dictionary: */ 754 /* Save the adler32 of the preset dictionary: */
755 if (s->strstart != 0) { 755 if (s->strstart != 0) {
756 putShortMSB(s, (uInt)(strm->adler >> 16)); 756 putShortMSB(s, (uInt)(strm->adler >> 16));
757 putShortMSB(s, (uInt)(strm->adler & 0xffff)); 757 putShortMSB(s, (uInt)(strm->adler & 0xffff));
758 } 758 }
759 strm->adler = adler32(0L, Z_NULL, 0); 759 strm->adler = adler32(0L, Z_NULL, 0);
760 } 760 }
761 } 761 }
762#ifdef GZIP 762#ifdef GZIP
763 if (s->status == EXTRA_STATE) { 763 if (s->status == EXTRA_STATE) {
764 if (s->gzhead->extra != Z_NULL) { 764 if (s->gzhead->extra != Z_NULL) {
765 uInt beg = s->pending; /* start of bytes to update crc */ 765 uInt beg = s->pending; /* start of bytes to update crc */
766 766
767 while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { 767 while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
768 if (s->pending == s->pending_buf_size) { 768 if (s->pending == s->pending_buf_size) {
769 if (s->gzhead->hcrc && s->pending > beg) 769 if (s->gzhead->hcrc && s->pending > beg)
770 strm->adler = crc32(strm->adler, s->pending_buf + beg, 770 strm->adler = crc32(strm->adler, s->pending_buf + beg,
771 s->pending - beg); 771 s->pending - beg);
772 flush_pending(strm); 772 flush_pending(strm);
773 beg = s->pending; 773 beg = s->pending;
774 if (s->pending == s->pending_buf_size) 774 if (s->pending == s->pending_buf_size)
775 break; 775 break;
776 } 776 }
777 put_byte(s, s->gzhead->extra[s->gzindex]); 777 put_byte(s, s->gzhead->extra[s->gzindex]);
778 s->gzindex++; 778 s->gzindex++;
779 } 779 }
780 if (s->gzhead->hcrc && s->pending > beg) 780 if (s->gzhead->hcrc && s->pending > beg)
781 strm->adler = crc32(strm->adler, s->pending_buf + beg, 781 strm->adler = crc32(strm->adler, s->pending_buf + beg,
782 s->pending - beg); 782 s->pending - beg);
783 if (s->gzindex == s->gzhead->extra_len) { 783 if (s->gzindex == s->gzhead->extra_len) {
784 s->gzindex = 0; 784 s->gzindex = 0;
785 s->status = NAME_STATE; 785 s->status = NAME_STATE;
786 } 786 }
787 } 787 }
788 else 788 else
789 s->status = NAME_STATE; 789 s->status = NAME_STATE;
790 } 790 }
791 if (s->status == NAME_STATE) { 791 if (s->status == NAME_STATE) {
792 if (s->gzhead->name != Z_NULL) { 792 if (s->gzhead->name != Z_NULL) {
793 uInt beg = s->pending; /* start of bytes to update crc */ 793 uInt beg = s->pending; /* start of bytes to update crc */
794 int val; 794 int val;
795 795
796 do { 796 do {
797 if (s->pending == s->pending_buf_size) { 797 if (s->pending == s->pending_buf_size) {
798 if (s->gzhead->hcrc && s->pending > beg) 798 if (s->gzhead->hcrc && s->pending > beg)
799 strm->adler = crc32(strm->adler, s->pending_buf + beg, 799 strm->adler = crc32(strm->adler, s->pending_buf + beg,
800 s->pending - beg); 800 s->pending - beg);
801 flush_pending(strm); 801 flush_pending(strm);
802 beg = s->pending; 802 beg = s->pending;
803 if (s->pending == s->pending_buf_size) { 803 if (s->pending == s->pending_buf_size) {
804 val = 1; 804 val = 1;
805 break; 805 break;
806 } 806 }
807 } 807 }
808 val = s->gzhead->name[s->gzindex++]; 808 val = s->gzhead->name[s->gzindex++];
809 put_byte(s, val); 809 put_byte(s, val);
810 } while (val != 0); 810 } while (val != 0);
811 if (s->gzhead->hcrc && s->pending > beg) 811 if (s->gzhead->hcrc && s->pending > beg)
812 strm->adler = crc32(strm->adler, s->pending_buf + beg, 812 strm->adler = crc32(strm->adler, s->pending_buf + beg,
813 s->pending - beg); 813 s->pending - beg);
814 if (val == 0) { 814 if (val == 0) {
815 s->gzindex = 0; 815 s->gzindex = 0;
816 s->status = COMMENT_STATE; 816 s->status = COMMENT_STATE;
817 } 817 }
818 } 818 }
819 else 819 else
820 s->status = COMMENT_STATE; 820 s->status = COMMENT_STATE;
821 } 821 }
822 if (s->status == COMMENT_STATE) { 822 if (s->status == COMMENT_STATE) {
823 if (s->gzhead->comment != Z_NULL) { 823 if (s->gzhead->comment != Z_NULL) {
824 uInt beg = s->pending; /* start of bytes to update crc */ 824 uInt beg = s->pending; /* start of bytes to update crc */
825 int val; 825 int val;
826 826
827 do { 827 do {
828 if (s->pending == s->pending_buf_size) { 828 if (s->pending == s->pending_buf_size) {
829 if (s->gzhead->hcrc && s->pending > beg) 829 if (s->gzhead->hcrc && s->pending > beg)
830 strm->adler = crc32(strm->adler, s->pending_buf + beg, 830 strm->adler = crc32(strm->adler, s->pending_buf + beg,
831 s->pending - beg); 831 s->pending - beg);
832 flush_pending(strm); 832 flush_pending(strm);
833 beg = s->pending; 833 beg = s->pending;
834 if (s->pending == s->pending_buf_size) { 834 if (s->pending == s->pending_buf_size) {
835 val = 1; 835 val = 1;
836 break; 836 break;
837 } 837 }
838 } 838 }
839 val = s->gzhead->comment[s->gzindex++]; 839 val = s->gzhead->comment[s->gzindex++];
840 put_byte(s, val); 840 put_byte(s, val);
841 } while (val != 0); 841 } while (val != 0);
842 if (s->gzhead->hcrc && s->pending > beg) 842 if (s->gzhead->hcrc && s->pending > beg)
843 strm->adler = crc32(strm->adler, s->pending_buf + beg, 843 strm->adler = crc32(strm->adler, s->pending_buf + beg,
844 s->pending - beg); 844 s->pending - beg);
845 if (val == 0) 845 if (val == 0)
846 s->status = HCRC_STATE; 846 s->status = HCRC_STATE;
847 } 847 }
848 else 848 else
849 s->status = HCRC_STATE; 849 s->status = HCRC_STATE;
850 } 850 }
851 if (s->status == HCRC_STATE) { 851 if (s->status == HCRC_STATE) {
852 if (s->gzhead->hcrc) { 852 if (s->gzhead->hcrc) {
853 if (s->pending + 2 > s->pending_buf_size) 853 if (s->pending + 2 > s->pending_buf_size)
854 flush_pending(strm); 854 flush_pending(strm);
855 if (s->pending + 2 <= s->pending_buf_size) { 855 if (s->pending + 2 <= s->pending_buf_size) {
856 put_byte(s, (Byte)(strm->adler & 0xff)); 856 put_byte(s, (Byte)(strm->adler & 0xff));
857 put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); 857 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
858 strm->adler = crc32(0L, Z_NULL, 0); 858 strm->adler = crc32(0L, Z_NULL, 0);
859 s->status = BUSY_STATE; 859 s->status = BUSY_STATE;
860 } 860 }
861 } 861 }
862 else 862 else
863 s->status = BUSY_STATE; 863 s->status = BUSY_STATE;
864 } 864 }
865#endif 865#endif
866 866
867 /* Flush as much pending output as possible */ 867 /* Flush as much pending output as possible */
868 if (s->pending != 0) { 868 if (s->pending != 0) {
869 flush_pending(strm); 869 flush_pending(strm);
870 if (strm->avail_out == 0) { 870 if (strm->avail_out == 0) {
871 /* Since avail_out is 0, deflate will be called again with 871 /* Since avail_out is 0, deflate will be called again with
872 * more output space, but possibly with both pending and 872 * more output space, but possibly with both pending and
873 * avail_in equal to zero. There won't be anything to do, 873 * avail_in equal to zero. There won't be anything to do,
874 * but this is not an error situation so make sure we 874 * but this is not an error situation so make sure we
875 * return OK instead of BUF_ERROR at next call of deflate: 875 * return OK instead of BUF_ERROR at next call of deflate:
876 */ 876 */
877 s->last_flush = -1; 877 s->last_flush = -1;
878 return Z_OK; 878 return Z_OK;
879 } 879 }
880 880
881 /* Make sure there is something to do and avoid duplicate consecutive 881 /* Make sure there is something to do and avoid duplicate consecutive
882 * flushes. For repeated and useless calls with Z_FINISH, we keep 882 * flushes. For repeated and useless calls with Z_FINISH, we keep
883 * returning Z_STREAM_END instead of Z_BUF_ERROR. 883 * returning Z_STREAM_END instead of Z_BUF_ERROR.
884 */ 884 */
885 } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && 885 } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
886 flush != Z_FINISH) { 886 flush != Z_FINISH) {
887 ERR_RETURN(strm, Z_BUF_ERROR); 887 ERR_RETURN(strm, Z_BUF_ERROR);
888 } 888 }
889 889
890 /* User must not provide more input after the first FINISH: */ 890 /* User must not provide more input after the first FINISH: */
891 if (s->status == FINISH_STATE && strm->avail_in != 0) { 891 if (s->status == FINISH_STATE && strm->avail_in != 0) {
892 ERR_RETURN(strm, Z_BUF_ERROR); 892 ERR_RETURN(strm, Z_BUF_ERROR);
893 } 893 }
894 894
895 /* Start a new block or continue the current one. 895 /* Start a new block or continue the current one.
896 */ 896 */
897 if (strm->avail_in != 0 || s->lookahead != 0 || 897 if (strm->avail_in != 0 || s->lookahead != 0 ||
898 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { 898 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
899 block_state bstate; 899 block_state bstate;
900 900
901 bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : 901 bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
902 (s->strategy == Z_RLE ? deflate_rle(s, flush) : 902 (s->strategy == Z_RLE ? deflate_rle(s, flush) :
903 (*(configuration_table[s->level].func))(s, flush)); 903 (*(configuration_table[s->level].func))(s, flush));
904 904
905 if (bstate == finish_started || bstate == finish_done) { 905 if (bstate == finish_started || bstate == finish_done) {
906 s->status = FINISH_STATE; 906 s->status = FINISH_STATE;
907 } 907 }
908 if (bstate == need_more || bstate == finish_started) { 908 if (bstate == need_more || bstate == finish_started) {
909 if (strm->avail_out == 0) { 909 if (strm->avail_out == 0) {
910 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ 910 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
911 } 911 }
912 return Z_OK; 912 return Z_OK;
913 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call 913 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
914 * of deflate should use the same flush parameter to make sure 914 * of deflate should use the same flush parameter to make sure
915 * that the flush is complete. So we don't have to output an 915 * that the flush is complete. So we don't have to output an
916 * empty block here, this will be done at next call. This also 916 * empty block here, this will be done at next call. This also
917 * ensures that for a very small output buffer, we emit at most 917 * ensures that for a very small output buffer, we emit at most
918 * one empty block. 918 * one empty block.
919 */ 919 */
920 } 920 }
921 if (bstate == block_done) { 921 if (bstate == block_done) {
922 if (flush == Z_PARTIAL_FLUSH) { 922 if (flush == Z_PARTIAL_FLUSH) {
923 _tr_align(s); 923 _tr_align(s);
924 } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ 924 } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
925 _tr_stored_block(s, (char*)0, 0L, 0); 925 _tr_stored_block(s, (char*)0, 0L, 0);
926 /* For a full flush, this empty block will be recognized 926 /* For a full flush, this empty block will be recognized
927 * as a special marker by inflate_sync(). 927 * as a special marker by inflate_sync().
928 */ 928 */
929 if (flush == Z_FULL_FLUSH) { 929 if (flush == Z_FULL_FLUSH) {
930 CLEAR_HASH(s); /* forget history */ 930 CLEAR_HASH(s); /* forget history */
931 if (s->lookahead == 0) { 931 if (s->lookahead == 0) {
932 s->strstart = 0; 932 s->strstart = 0;
933 s->block_start = 0L; 933 s->block_start = 0L;
934 s->insert = 0; 934 s->insert = 0;
935 } 935 }
936 } 936 }
937 } 937 }
938 flush_pending(strm); 938 flush_pending(strm);
939 if (strm->avail_out == 0) { 939 if (strm->avail_out == 0) {
940 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ 940 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
941 return Z_OK; 941 return Z_OK;
942 } 942 }
943 } 943 }
944 } 944 }
945 Assert(strm->avail_out > 0, "bug2"); 945 Assert(strm->avail_out > 0, "bug2");
946 946
947 if (flush != Z_FINISH) return Z_OK; 947 if (flush != Z_FINISH) return Z_OK;
948 if (s->wrap <= 0) return Z_STREAM_END; 948 if (s->wrap <= 0) return Z_STREAM_END;
949 949
950 /* Write the trailer */ 950 /* Write the trailer */
951#ifdef GZIP 951#ifdef GZIP
952 if (s->wrap == 2) { 952 if (s->wrap == 2) {
953 put_byte(s, (Byte)(strm->adler & 0xff)); 953 put_byte(s, (Byte)(strm->adler & 0xff));
954 put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); 954 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
955 put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); 955 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
956 put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); 956 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
957 put_byte(s, (Byte)(strm->total_in & 0xff)); 957 put_byte(s, (Byte)(strm->total_in & 0xff));
958 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); 958 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
959 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); 959 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
960 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); 960 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
961 } 961 }
962 else 962 else
963#endif 963#endif
964 { 964 {
965 putShortMSB(s, (uInt)(strm->adler >> 16)); 965 putShortMSB(s, (uInt)(strm->adler >> 16));
966 putShortMSB(s, (uInt)(strm->adler & 0xffff)); 966 putShortMSB(s, (uInt)(strm->adler & 0xffff));
967 } 967 }
968 flush_pending(strm); 968 flush_pending(strm);
969 /* If avail_out is zero, the application will call deflate again 969 /* If avail_out is zero, the application will call deflate again
970 * to flush the rest. 970 * to flush the rest.
971 */ 971 */
972 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ 972 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
973 return s->pending != 0 ? Z_OK : Z_STREAM_END; 973 return s->pending != 0 ? Z_OK : Z_STREAM_END;
974} 974}
975 975
976/* ========================================================================= */ 976/* ========================================================================= */
977int ZEXPORT deflateEnd (strm) 977int ZEXPORT deflateEnd (strm)
978 z_streamp strm; 978 z_streamp strm;
979{ 979{
980 int status; 980 int status;
981 981
982 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 982 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
983 983
984 status = strm->state->status; 984 status = strm->state->status;
985 if (status != INIT_STATE && 985 if (status != INIT_STATE &&
986 status != EXTRA_STATE && 986 status != EXTRA_STATE &&
987 status != NAME_STATE && 987 status != NAME_STATE &&
988 status != COMMENT_STATE && 988 status != COMMENT_STATE &&
989 status != HCRC_STATE && 989 status != HCRC_STATE &&
990 status != BUSY_STATE && 990 status != BUSY_STATE &&
991 status != FINISH_STATE) { 991 status != FINISH_STATE) {
992 return Z_STREAM_ERROR; 992 return Z_STREAM_ERROR;
993 } 993 }
994 994
995 /* Deallocate in reverse order of allocations: */ 995 /* Deallocate in reverse order of allocations: */
996 TRY_FREE(strm, strm->state->pending_buf); 996 TRY_FREE(strm, strm->state->pending_buf);
997 TRY_FREE(strm, strm->state->head); 997 TRY_FREE(strm, strm->state->head);
998 TRY_FREE(strm, strm->state->prev); 998 TRY_FREE(strm, strm->state->prev);
999 TRY_FREE(strm, strm->state->window); 999 TRY_FREE(strm, strm->state->window);
1000 1000
1001 ZFREE(strm, strm->state); 1001 ZFREE(strm, strm->state);
1002 strm->state = Z_NULL; 1002 strm->state = Z_NULL;
1003 1003
1004 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; 1004 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
1005} 1005}
1006 1006
1007/* ========================================================================= 1007/* =========================================================================
1008 * Copy the source state to the destination state. 1008 * Copy the source state to the destination state.
1009 * To simplify the source, this is not supported for 16-bit MSDOS (which 1009 * To simplify the source, this is not supported for 16-bit MSDOS (which
1010 * doesn't have enough memory anyway to duplicate compression states). 1010 * doesn't have enough memory anyway to duplicate compression states).
1011 */ 1011 */
1012int ZEXPORT deflateCopy (dest, source) 1012int ZEXPORT deflateCopy (dest, source)
1013 z_streamp dest; 1013 z_streamp dest;
1014 z_streamp source; 1014 z_streamp source;
1015{ 1015{
1016#ifdef MAXSEG_64K 1016#ifdef MAXSEG_64K
1017 return Z_STREAM_ERROR; 1017 return Z_STREAM_ERROR;
1018#else 1018#else
1019 deflate_state *ds; 1019 deflate_state *ds;
1020 deflate_state *ss; 1020 deflate_state *ss;
1021 ushf *overlay; 1021 ushf *overlay;
1022 1022
1023 1023
1024 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { 1024 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
1025 return Z_STREAM_ERROR; 1025 return Z_STREAM_ERROR;
1026 } 1026 }
1027 1027
1028 ss = source->state; 1028 ss = source->state;
1029 1029
1030 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); 1030 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1031 1031
1032 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); 1032 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
1033 if (ds == Z_NULL) return Z_MEM_ERROR; 1033 if (ds == Z_NULL) return Z_MEM_ERROR;
1034 dest->state = (struct internal_state FAR *) ds; 1034 dest->state = (struct internal_state FAR *) ds;
1035 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); 1035 zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
1036 ds->strm = dest; 1036 ds->strm = dest;
1037 1037
1038 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); 1038 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
1039 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); 1039 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
1040 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); 1040 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
1041 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); 1041 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
1042 ds->pending_buf = (uchf *) overlay; 1042 ds->pending_buf = (uchf *) overlay;
1043 1043
1044 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || 1044 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
1045 ds->pending_buf == Z_NULL) { 1045 ds->pending_buf == Z_NULL) {
1046 deflateEnd (dest); 1046 deflateEnd (dest);
1047 return Z_MEM_ERROR; 1047 return Z_MEM_ERROR;
1048 } 1048 }
1049 /* following zmemcpy do not work for 16-bit MSDOS */ 1049 /* following zmemcpy do not work for 16-bit MSDOS */
1050 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); 1050 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
1051 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); 1051 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
1052 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); 1052 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
1053 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); 1053 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1054 1054
1055 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); 1055 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1056 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); 1056 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
1057 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; 1057 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
1058 1058
1059 ds->l_desc.dyn_tree = ds->dyn_ltree; 1059 ds->l_desc.dyn_tree = ds->dyn_ltree;
1060 ds->d_desc.dyn_tree = ds->dyn_dtree; 1060 ds->d_desc.dyn_tree = ds->dyn_dtree;
1061 ds->bl_desc.dyn_tree = ds->bl_tree; 1061 ds->bl_desc.dyn_tree = ds->bl_tree;
1062 1062
1063 return Z_OK; 1063 return Z_OK;
1064#endif /* MAXSEG_64K */ 1064#endif /* MAXSEG_64K */
1065} 1065}
1066 1066
1067/* =========================================================================== 1067/* ===========================================================================
1068 * Read a new buffer from the current input stream, update the adler32 1068 * Read a new buffer from the current input stream, update the adler32
1069 * and total number of bytes read. All deflate() input goes through 1069 * and total number of bytes read. All deflate() input goes through
1070 * this function so some applications may wish to modify it to avoid 1070 * this function so some applications may wish to modify it to avoid
1071 * allocating a large strm->next_in buffer and copying from it. 1071 * allocating a large strm->next_in buffer and copying from it.
1072 * (See also flush_pending()). 1072 * (See also flush_pending()).
1073 */ 1073 */
1074local int read_buf(strm, buf, size) 1074local int read_buf(strm, buf, size)
1075 z_streamp strm; 1075 z_streamp strm;
1076 Bytef *buf; 1076 Bytef *buf;
1077 unsigned size; 1077 unsigned size;
1078{ 1078{
1079 unsigned len = strm->avail_in; 1079 unsigned len = strm->avail_in;
1080 1080
1081 if (len > size) len = size; 1081 if (len > size) len = size;
1082 if (len == 0) return 0; 1082 if (len == 0) return 0;
1083 1083
1084 strm->avail_in -= len; 1084 strm->avail_in -= len;
1085 1085
1086 zmemcpy(buf, strm->next_in, len); 1086 zmemcpy(buf, strm->next_in, len);
1087 if (strm->state->wrap == 1) { 1087 if (strm->state->wrap == 1) {
1088 strm->adler = adler32(strm->adler, buf, len); 1088 strm->adler = adler32(strm->adler, buf, len);
1089 } 1089 }
1090#ifdef GZIP 1090#ifdef GZIP
1091 else if (strm->state->wrap == 2) { 1091 else if (strm->state->wrap == 2) {
1092 strm->adler = crc32(strm->adler, buf, len); 1092 strm->adler = crc32(strm->adler, buf, len);
1093 } 1093 }
1094#endif 1094#endif
1095 strm->next_in += len; 1095 strm->next_in += len;
1096 strm->total_in += len; 1096 strm->total_in += len;
1097 1097
1098 return (int)len; 1098 return (int)len;
1099} 1099}
1100 1100
1101/* =========================================================================== 1101/* ===========================================================================
1102 * Initialize the "longest match" routines for a new zlib stream 1102 * Initialize the "longest match" routines for a new zlib stream
1103 */ 1103 */
1104local void lm_init (s) 1104local void lm_init (s)
1105 deflate_state *s; 1105 deflate_state *s;
1106{ 1106{
1107 s->window_size = (ulg)2L*s->w_size; 1107 s->window_size = (ulg)2L*s->w_size;
1108 1108
1109 CLEAR_HASH(s); 1109 CLEAR_HASH(s);
1110 1110
1111 /* Set the default configuration parameters: 1111 /* Set the default configuration parameters:
1112 */ 1112 */
1113 s->max_lazy_match = configuration_table[s->level].max_lazy; 1113 s->max_lazy_match = configuration_table[s->level].max_lazy;
1114 s->good_match = configuration_table[s->level].good_length; 1114 s->good_match = configuration_table[s->level].good_length;
1115 s->nice_match = configuration_table[s->level].nice_length; 1115 s->nice_match = configuration_table[s->level].nice_length;
1116 s->max_chain_length = configuration_table[s->level].max_chain; 1116 s->max_chain_length = configuration_table[s->level].max_chain;
1117 1117
1118 s->strstart = 0; 1118 s->strstart = 0;
1119 s->block_start = 0L; 1119 s->block_start = 0L;
1120 s->lookahead = 0; 1120 s->lookahead = 0;
1121 s->insert = 0; 1121 s->insert = 0;
1122 s->match_length = s->prev_length = MIN_MATCH-1; 1122 s->match_length = s->prev_length = MIN_MATCH-1;
1123 s->match_available = 0; 1123 s->match_available = 0;
1124 s->ins_h = 0; 1124 s->ins_h = 0;
1125#ifndef FASTEST 1125#ifndef FASTEST
1126#ifdef ASMV 1126#ifdef ASMV
1127 match_init(); /* initialize the asm code */ 1127 match_init(); /* initialize the asm code */
1128#endif 1128#endif
1129#endif 1129#endif
1130} 1130}
1131 1131
1132#ifndef FASTEST 1132#ifndef FASTEST
1133/* =========================================================================== 1133/* ===========================================================================
1134 * Set match_start to the longest match starting at the given string and 1134 * Set match_start to the longest match starting at the given string and
1135 * return its length. Matches shorter or equal to prev_length are discarded, 1135 * return its length. Matches shorter or equal to prev_length are discarded,
1136 * in which case the result is equal to prev_length and match_start is 1136 * in which case the result is equal to prev_length and match_start is
1137 * garbage. 1137 * garbage.
1138 * IN assertions: cur_match is the head of the hash chain for the current 1138 * IN assertions: cur_match is the head of the hash chain for the current
1139 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 1139 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
1140 * OUT assertion: the match length is not greater than s->lookahead. 1140 * OUT assertion: the match length is not greater than s->lookahead.
1141 */ 1141 */
1142#ifndef ASMV 1142#ifndef ASMV
1143/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 1143/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
1144 * match.S. The code will be functionally equivalent. 1144 * match.S. The code will be functionally equivalent.
1145 */ 1145 */
1146local uInt longest_match(s, cur_match) 1146local uInt longest_match(s, cur_match)
1147 deflate_state *s; 1147 deflate_state *s;
1148 IPos cur_match; /* current match */ 1148 IPos cur_match; /* current match */
1149{ 1149{
1150 unsigned chain_length = s->max_chain_length;/* max hash chain length */ 1150 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1151 register Bytef *scan = s->window + s->strstart; /* current string */ 1151 register Bytef *scan = s->window + s->strstart; /* current string */
1152 register Bytef *match; /* matched string */ 1152 register Bytef *match; /* matched string */
1153 register int len; /* length of current match */ 1153 register int len; /* length of current match */
1154 int best_len = s->prev_length; /* best match length so far */ 1154 int best_len = s->prev_length; /* best match length so far */
1155 int nice_match = s->nice_match; /* stop if match long enough */ 1155 int nice_match = s->nice_match; /* stop if match long enough */
1156 IPos limit = s->strstart > (IPos)MAX_DIST(s) ? 1156 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1157 s->strstart - (IPos)MAX_DIST(s) : NIL; 1157 s->strstart - (IPos)MAX_DIST(s) : NIL;
1158 /* Stop when cur_match becomes <= limit. To simplify the code, 1158 /* Stop when cur_match becomes <= limit. To simplify the code,
1159 * we prevent matches with the string of window index 0. 1159 * we prevent matches with the string of window index 0.
1160 */ 1160 */
1161 Posf *prev = s->prev; 1161 Posf *prev = s->prev;
1162 uInt wmask = s->w_mask; 1162 uInt wmask = s->w_mask;
1163 1163
1164#ifdef UNALIGNED_OK 1164#ifdef UNALIGNED_OK
1165 /* Compare two bytes at a time. Note: this is not always beneficial. 1165 /* Compare two bytes at a time. Note: this is not always beneficial.
1166 * Try with and without -DUNALIGNED_OK to check. 1166 * Try with and without -DUNALIGNED_OK to check.
1167 */ 1167 */
1168 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; 1168 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1169 register ush scan_start = *(ushf*)scan; 1169 register ush scan_start = *(ushf*)scan;
1170 register ush scan_end = *(ushf*)(scan+best_len-1); 1170 register ush scan_end = *(ushf*)(scan+best_len-1);
1171#else 1171#else
1172 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 1172 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1173 register Byte scan_end1 = scan[best_len-1]; 1173 register Byte scan_end1 = scan[best_len-1];
1174 register Byte scan_end = scan[best_len]; 1174 register Byte scan_end = scan[best_len];
1175#endif 1175#endif
1176 1176
1177 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 1177 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1178 * It is easy to get rid of this optimization if necessary. 1178 * It is easy to get rid of this optimization if necessary.
1179 */ 1179 */
1180 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 1180 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1181 1181
1182 /* Do not waste too much time if we already have a good match: */ 1182 /* Do not waste too much time if we already have a good match: */
1183 if (s->prev_length >= s->good_match) { 1183 if (s->prev_length >= s->good_match) {
1184 chain_length >>= 2; 1184 chain_length >>= 2;
1185 } 1185 }
1186 /* Do not look for matches beyond the end of the input. This is necessary 1186 /* Do not look for matches beyond the end of the input. This is necessary
1187 * to make deflate deterministic. 1187 * to make deflate deterministic.
1188 */ 1188 */
1189 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; 1189 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
1190 1190
1191 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 1191 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1192 1192
1193 do { 1193 do {
1194 Assert(cur_match < s->strstart, "no future"); 1194 Assert(cur_match < s->strstart, "no future");
1195 match = s->window + cur_match; 1195 match = s->window + cur_match;
1196 1196
1197 /* Skip to next match if the match length cannot increase 1197 /* Skip to next match if the match length cannot increase
1198 * or if the match length is less than 2. Note that the checks below 1198 * or if the match length is less than 2. Note that the checks below
1199 * for insufficient lookahead only occur occasionally for performance 1199 * for insufficient lookahead only occur occasionally for performance
1200 * reasons. Therefore uninitialized memory will be accessed, and 1200 * reasons. Therefore uninitialized memory will be accessed, and
1201 * conditional jumps will be made that depend on those values. 1201 * conditional jumps will be made that depend on those values.
1202 * However the length of the match is limited to the lookahead, so 1202 * However the length of the match is limited to the lookahead, so
1203 * the output of deflate is not affected by the uninitialized values. 1203 * the output of deflate is not affected by the uninitialized values.
1204 */ 1204 */
1205#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) 1205#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1206 /* This code assumes sizeof(unsigned short) == 2. Do not use 1206 /* This code assumes sizeof(unsigned short) == 2. Do not use
1207 * UNALIGNED_OK if your compiler uses a different size. 1207 * UNALIGNED_OK if your compiler uses a different size.
1208 */ 1208 */
1209 if (*(ushf*)(match+best_len-1) != scan_end || 1209 if (*(ushf*)(match+best_len-1) != scan_end ||
1210 *(ushf*)match != scan_start) continue; 1210 *(ushf*)match != scan_start) continue;
1211 1211
1212 /* It is not necessary to compare scan[2] and match[2] since they are 1212 /* It is not necessary to compare scan[2] and match[2] since they are
1213 * always equal when the other bytes match, given that the hash keys 1213 * always equal when the other bytes match, given that the hash keys
1214 * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at 1214 * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
1215 * strstart+3, +5, ... up to strstart+257. We check for insufficient 1215 * strstart+3, +5, ... up to strstart+257. We check for insufficient
1216 * lookahead only every 4th comparison; the 128th check will be made 1216 * lookahead only every 4th comparison; the 128th check will be made
1217 * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is 1217 * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
1218 * necessary to put more guard bytes at the end of the window, or 1218 * necessary to put more guard bytes at the end of the window, or
1219 * to check more often for insufficient lookahead. 1219 * to check more often for insufficient lookahead.
1220 */ 1220 */
1221 Assert(scan[2] == match[2], "scan[2]?"); 1221 Assert(scan[2] == match[2], "scan[2]?");
1222 scan++, match++; 1222 scan++, match++;
1223 do { 1223 do {
1224 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1224 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1225 *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1225 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1226 *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1226 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1227 *(ushf*)(scan+=2) == *(ushf*)(match+=2) && 1227 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1228 scan < strend); 1228 scan < strend);
1229 /* The funny "do {}" generates better code on most compilers */ 1229 /* The funny "do {}" generates better code on most compilers */
1230 1230
1231 /* Here, scan <= window+strstart+257 */ 1231 /* Here, scan <= window+strstart+257 */
1232 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1232 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1233 if (*scan == *match) scan++; 1233 if (*scan == *match) scan++;
1234 1234
1235 len = (MAX_MATCH - 1) - (int)(strend-scan); 1235 len = (MAX_MATCH - 1) - (int)(strend-scan);
1236 scan = strend - (MAX_MATCH-1); 1236 scan = strend - (MAX_MATCH-1);
1237 1237
1238#else /* UNALIGNED_OK */ 1238#else /* UNALIGNED_OK */
1239 1239
1240 if (match[best_len] != scan_end || 1240 if (match[best_len] != scan_end ||
1241 match[best_len-1] != scan_end1 || 1241 match[best_len-1] != scan_end1 ||
1242 *match != *scan || 1242 *match != *scan ||
1243 *++match != scan[1]) continue; 1243 *++match != scan[1]) continue;
1244 1244
1245 /* The check at best_len-1 can be removed because it will be made 1245 /* The check at best_len-1 can be removed because it will be made
1246 * again later. (This heuristic is not always a win.) 1246 * again later. (This heuristic is not always a win.)
1247 * It is not necessary to compare scan[2] and match[2] since they 1247 * It is not necessary to compare scan[2] and match[2] since they
1248 * are always equal when the other bytes match, given that 1248 * are always equal when the other bytes match, given that
1249 * the hash keys are equal and that HASH_BITS >= 8. 1249 * the hash keys are equal and that HASH_BITS >= 8.
1250 */ 1250 */
1251 scan += 2, match++; 1251 scan += 2, match++;
1252 Assert(*scan == *match, "match[2]?"); 1252 Assert(*scan == *match, "match[2]?");
1253 1253
1254 /* We check for insufficient lookahead only every 8th comparison; 1254 /* We check for insufficient lookahead only every 8th comparison;
1255 * the 256th check will be made at strstart+258. 1255 * the 256th check will be made at strstart+258.
1256 */ 1256 */
1257 do { 1257 do {
1258 } while (*++scan == *++match && *++scan == *++match && 1258 } while (*++scan == *++match && *++scan == *++match &&
1259 *++scan == *++match && *++scan == *++match && 1259 *++scan == *++match && *++scan == *++match &&
1260 *++scan == *++match && *++scan == *++match && 1260 *++scan == *++match && *++scan == *++match &&
1261 *++scan == *++match && *++scan == *++match && 1261 *++scan == *++match && *++scan == *++match &&
1262 scan < strend); 1262 scan < strend);
1263 1263
1264 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1264 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1265 1265
1266 len = MAX_MATCH - (int)(strend - scan); 1266 len = MAX_MATCH - (int)(strend - scan);
1267 scan = strend - MAX_MATCH; 1267 scan = strend - MAX_MATCH;
1268 1268
1269#endif /* UNALIGNED_OK */ 1269#endif /* UNALIGNED_OK */
1270 1270
1271 if (len > best_len) { 1271 if (len > best_len) {
1272 s->match_start = cur_match; 1272 s->match_start = cur_match;
1273 best_len = len; 1273 best_len = len;
1274 if (len >= nice_match) break; 1274 if (len >= nice_match) break;
1275#ifdef UNALIGNED_OK 1275#ifdef UNALIGNED_OK
1276 scan_end = *(ushf*)(scan+best_len-1); 1276 scan_end = *(ushf*)(scan+best_len-1);
1277#else 1277#else
1278 scan_end1 = scan[best_len-1]; 1278 scan_end1 = scan[best_len-1];
1279 scan_end = scan[best_len]; 1279 scan_end = scan[best_len];
1280#endif 1280#endif
1281 } 1281 }
1282 } while ((cur_match = prev[cur_match & wmask]) > limit 1282 } while ((cur_match = prev[cur_match & wmask]) > limit
1283 && --chain_length != 0); 1283 && --chain_length != 0);
1284 1284
1285 if ((uInt)best_len <= s->lookahead) return (uInt)best_len; 1285 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1286 return s->lookahead; 1286 return s->lookahead;
1287} 1287}
1288#endif /* ASMV */ 1288#endif /* ASMV */
1289 1289
1290#else /* FASTEST */ 1290#else /* FASTEST */
1291 1291
1292/* --------------------------------------------------------------------------- 1292/* ---------------------------------------------------------------------------
1293 * Optimized version for FASTEST only 1293 * Optimized version for FASTEST only
1294 */ 1294 */
1295local uInt longest_match(s, cur_match) 1295local uInt longest_match(s, cur_match)
1296 deflate_state *s; 1296 deflate_state *s;
1297 IPos cur_match; /* current match */ 1297 IPos cur_match; /* current match */
1298{ 1298{
1299 register Bytef *scan = s->window + s->strstart; /* current string */ 1299 register Bytef *scan = s->window + s->strstart; /* current string */
1300 register Bytef *match; /* matched string */ 1300 register Bytef *match; /* matched string */
1301 register int len; /* length of current match */ 1301 register int len; /* length of current match */
1302 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 1302 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1303 1303
1304 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 1304 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1305 * It is easy to get rid of this optimization if necessary. 1305 * It is easy to get rid of this optimization if necessary.
1306 */ 1306 */
1307 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 1307 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1308 1308
1309 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 1309 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1310 1310
1311 Assert(cur_match < s->strstart, "no future"); 1311 Assert(cur_match < s->strstart, "no future");
1312 1312
1313 match = s->window + cur_match; 1313 match = s->window + cur_match;
1314 1314
1315 /* Return failure if the match length is less than 2: 1315 /* Return failure if the match length is less than 2:
1316 */ 1316 */
1317 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; 1317 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
1318 1318
1319 /* The check at best_len-1 can be removed because it will be made 1319 /* The check at best_len-1 can be removed because it will be made
1320 * again later. (This heuristic is not always a win.) 1320 * again later. (This heuristic is not always a win.)
1321 * It is not necessary to compare scan[2] and match[2] since they 1321 * It is not necessary to compare scan[2] and match[2] since they
1322 * are always equal when the other bytes match, given that 1322 * are always equal when the other bytes match, given that
1323 * the hash keys are equal and that HASH_BITS >= 8. 1323 * the hash keys are equal and that HASH_BITS >= 8.
1324 */ 1324 */
1325 scan += 2, match += 2; 1325 scan += 2, match += 2;
1326 Assert(*scan == *match, "match[2]?"); 1326 Assert(*scan == *match, "match[2]?");
1327 1327
1328 /* We check for insufficient lookahead only every 8th comparison; 1328 /* We check for insufficient lookahead only every 8th comparison;
1329 * the 256th check will be made at strstart+258. 1329 * the 256th check will be made at strstart+258.
1330 */ 1330 */
1331 do { 1331 do {
1332 } while (*++scan == *++match && *++scan == *++match && 1332 } while (*++scan == *++match && *++scan == *++match &&
1333 *++scan == *++match && *++scan == *++match && 1333 *++scan == *++match && *++scan == *++match &&
1334 *++scan == *++match && *++scan == *++match && 1334 *++scan == *++match && *++scan == *++match &&
1335 *++scan == *++match && *++scan == *++match && 1335 *++scan == *++match && *++scan == *++match &&
1336 scan < strend); 1336 scan < strend);
1337 1337
1338 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1338 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1339 1339
1340 len = MAX_MATCH - (int)(strend - scan); 1340 len = MAX_MATCH - (int)(strend - scan);
1341 1341
1342 if (len < MIN_MATCH) return MIN_MATCH - 1; 1342 if (len < MIN_MATCH) return MIN_MATCH - 1;
1343 1343
1344 s->match_start = cur_match; 1344 s->match_start = cur_match;
1345 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; 1345 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
1346} 1346}
1347 1347
1348#endif /* FASTEST */ 1348#endif /* FASTEST */
1349 1349
1350#ifdef DEBUG 1350#ifdef DEBUG
1351/* =========================================================================== 1351/* ===========================================================================
1352 * Check that the match at match_start is indeed a match. 1352 * Check that the match at match_start is indeed a match.
1353 */ 1353 */
1354local void check_match(s, start, match, length) 1354local void check_match(s, start, match, length)
1355 deflate_state *s; 1355 deflate_state *s;
1356 IPos start, match; 1356 IPos start, match;
1357 int length; 1357 int length;
1358{ 1358{
1359 /* check that the match is indeed a match */ 1359 /* check that the match is indeed a match */
1360 if (zmemcmp(s->window + match, 1360 if (zmemcmp(s->window + match,
1361 s->window + start, length) != EQUAL) { 1361 s->window + start, length) != EQUAL) {
1362 fprintf(stderr, " start %u, match %u, length %d\n", 1362 fprintf(stderr, " start %u, match %u, length %d\n",
1363 start, match, length); 1363 start, match, length);
1364 do { 1364 do {
1365 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); 1365 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1366 } while (--length != 0); 1366 } while (--length != 0);
1367 z_error("invalid match"); 1367 z_error("invalid match");
1368 } 1368 }
1369 if (z_verbose > 1) { 1369 if (z_verbose > 1) {
1370 fprintf(stderr,"\\[%d,%d]", start-match, length); 1370 fprintf(stderr,"\\[%d,%d]", start-match, length);
1371 do { putc(s->window[start++], stderr); } while (--length != 0); 1371 do { putc(s->window[start++], stderr); } while (--length != 0);
1372 } 1372 }
1373} 1373}
1374#else 1374#else
1375# define check_match(s, start, match, length) 1375# define check_match(s, start, match, length)
1376#endif /* DEBUG */ 1376#endif /* DEBUG */
1377 1377
1378/* =========================================================================== 1378/* ===========================================================================
1379 * Fill the window when the lookahead becomes insufficient. 1379 * Fill the window when the lookahead becomes insufficient.
1380 * Updates strstart and lookahead. 1380 * Updates strstart and lookahead.
1381 * 1381 *
1382 * IN assertion: lookahead < MIN_LOOKAHEAD 1382 * IN assertion: lookahead < MIN_LOOKAHEAD
1383 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD 1383 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
1384 * At least one byte has been read, or avail_in == 0; reads are 1384 * At least one byte has been read, or avail_in == 0; reads are
1385 * performed for at least two bytes (required for the zip translate_eol 1385 * performed for at least two bytes (required for the zip translate_eol
1386 * option -- not supported here). 1386 * option -- not supported here).
1387 */ 1387 */
1388local void fill_window(s) 1388local void fill_window(s)
1389 deflate_state *s; 1389 deflate_state *s;
1390{ 1390{
1391 register unsigned n, m; 1391 register unsigned n, m;
1392 register Posf *p; 1392 register Posf *p;
1393 unsigned more; /* Amount of free space at the end of the window. */ 1393 unsigned more; /* Amount of free space at the end of the window. */
1394 uInt wsize = s->w_size; 1394 uInt wsize = s->w_size;
1395 1395
1396 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); 1396 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1397 1397
1398 do { 1398 do {
1399 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); 1399 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1400 1400
1401 /* Deal with !@#$% 64K limit: */ 1401 /* Deal with !@#$% 64K limit: */
1402 if (sizeof(int) <= 2) { 1402 if (sizeof(int) <= 2) {
1403 if (more == 0 && s->strstart == 0 && s->lookahead == 0) { 1403 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1404 more = wsize; 1404 more = wsize;
1405 1405
1406 } else if (more == (unsigned)(-1)) { 1406 } else if (more == (unsigned)(-1)) {
1407 /* Very unlikely, but possible on 16 bit machine if 1407 /* Very unlikely, but possible on 16 bit machine if
1408 * strstart == 0 && lookahead == 1 (input done a byte at time) 1408 * strstart == 0 && lookahead == 1 (input done a byte at time)
1409 */ 1409 */
1410 more--; 1410 more--;
1411 } 1411 }
1412 } 1412 }
1413 1413
1414 /* If the window is almost full and there is insufficient lookahead, 1414 /* If the window is almost full and there is insufficient lookahead,
1415 * move the upper half to the lower one to make room in the upper half. 1415 * move the upper half to the lower one to make room in the upper half.
1416 */ 1416 */
1417 if (s->strstart >= wsize+MAX_DIST(s)) { 1417 if (s->strstart >= wsize+MAX_DIST(s)) {
1418 1418
1419 zmemcpy(s->window, s->window+wsize, (unsigned)wsize); 1419 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1420 s->match_start -= wsize; 1420 s->match_start -= wsize;
1421 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ 1421 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1422 s->block_start -= (long) wsize; 1422 s->block_start -= (long) wsize;
1423 1423
1424 /* Slide the hash table (could be avoided with 32 bit values 1424 /* Slide the hash table (could be avoided with 32 bit values
1425 at the expense of memory usage). We slide even when level == 0 1425 at the expense of memory usage). We slide even when level == 0
1426 to keep the hash table consistent if we switch back to level > 0 1426 to keep the hash table consistent if we switch back to level > 0
1427 later. (Using level 0 permanently is not an optimal usage of 1427 later. (Using level 0 permanently is not an optimal usage of
1428 zlib, so we don't care about this pathological case.) 1428 zlib, so we don't care about this pathological case.)
1429 */ 1429 */
1430 n = s->hash_size; 1430 n = s->hash_size;
1431 p = &s->head[n]; 1431 p = &s->head[n];
1432 do { 1432 do {
1433 m = *--p; 1433 m = *--p;
1434 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1434 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1435 } while (--n); 1435 } while (--n);
1436 1436
1437 n = wsize; 1437 n = wsize;
1438#ifndef FASTEST 1438#ifndef FASTEST
1439 p = &s->prev[n]; 1439 p = &s->prev[n];
1440 do { 1440 do {
1441 m = *--p; 1441 m = *--p;
1442 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1442 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1443 /* If n is not on any hash chain, prev[n] is garbage but 1443 /* If n is not on any hash chain, prev[n] is garbage but
1444 * its value will never be used. 1444 * its value will never be used.
1445 */ 1445 */
1446 } while (--n); 1446 } while (--n);
1447#endif 1447#endif
1448 more += wsize; 1448 more += wsize;
1449 } 1449 }
1450 if (s->strm->avail_in == 0) break; 1450 if (s->strm->avail_in == 0) break;
1451 1451
1452 /* If there was no sliding: 1452 /* If there was no sliding:
1453 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && 1453 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1454 * more == window_size - lookahead - strstart 1454 * more == window_size - lookahead - strstart
1455 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) 1455 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1456 * => more >= window_size - 2*WSIZE + 2 1456 * => more >= window_size - 2*WSIZE + 2
1457 * In the BIG_MEM or MMAP case (not yet supported), 1457 * In the BIG_MEM or MMAP case (not yet supported),
1458 * window_size == input_size + MIN_LOOKAHEAD && 1458 * window_size == input_size + MIN_LOOKAHEAD &&
1459 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. 1459 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1460 * Otherwise, window_size == 2*WSIZE so more >= 2. 1460 * Otherwise, window_size == 2*WSIZE so more >= 2.
1461 * If there was sliding, more >= WSIZE. So in all cases, more >= 2. 1461 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1462 */ 1462 */
1463 Assert(more >= 2, "more < 2"); 1463 Assert(more >= 2, "more < 2");
1464 1464
1465 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); 1465 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1466 s->lookahead += n; 1466 s->lookahead += n;
1467 1467
1468 /* Initialize the hash value now that we have some input: */ 1468 /* Initialize the hash value now that we have some input: */
1469 if (s->lookahead + s->insert >= MIN_MATCH) { 1469 if (s->lookahead + s->insert >= MIN_MATCH) {
1470 uInt str = s->strstart - s->insert; 1470 uInt str = s->strstart - s->insert;
1471 s->ins_h = s->window[str]; 1471 s->ins_h = s->window[str];
1472 UPDATE_HASH(s, s->ins_h, s->window[str + 1]); 1472 UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1473#if MIN_MATCH != 3 1473#if MIN_MATCH != 3
1474 Call UPDATE_HASH() MIN_MATCH-3 more times 1474 Call UPDATE_HASH() MIN_MATCH-3 more times
1475#endif 1475#endif
1476 while (s->insert) { 1476 while (s->insert) {
1477 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); 1477 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1478#ifndef FASTEST 1478#ifndef FASTEST
1479 s->prev[str & s->w_mask] = s->head[s->ins_h]; 1479 s->prev[str & s->w_mask] = s->head[s->ins_h];
1480#endif 1480#endif
1481 s->head[s->ins_h] = (Pos)str; 1481 s->head[s->ins_h] = (Pos)str;
1482 str++; 1482 str++;
1483 s->insert--; 1483 s->insert--;
1484 if (s->lookahead + s->insert < MIN_MATCH) 1484 if (s->lookahead + s->insert < MIN_MATCH)
1485 break; 1485 break;
1486 } 1486 }
1487 } 1487 }
1488 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, 1488 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1489 * but this is not important since only literal bytes will be emitted. 1489 * but this is not important since only literal bytes will be emitted.
1490 */ 1490 */
1491 1491
1492 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); 1492 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1493 1493
1494 /* If the WIN_INIT bytes after the end of the current data have never been 1494 /* If the WIN_INIT bytes after the end of the current data have never been
1495 * written, then zero those bytes in order to avoid memory check reports of 1495 * written, then zero those bytes in order to avoid memory check reports of
1496 * the use of uninitialized (or uninitialised as Julian writes) bytes by 1496 * the use of uninitialized (or uninitialised as Julian writes) bytes by
1497 * the longest match routines. Update the high water mark for the next 1497 * the longest match routines. Update the high water mark for the next
1498 * time through here. WIN_INIT is set to MAX_MATCH since the longest match 1498 * time through here. WIN_INIT is set to MAX_MATCH since the longest match
1499 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. 1499 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
1500 */ 1500 */
1501 if (s->high_water < s->window_size) { 1501 if (s->high_water < s->window_size) {
1502 ulg curr = s->strstart + (ulg)(s->lookahead); 1502 ulg curr = s->strstart + (ulg)(s->lookahead);
1503 ulg init; 1503 ulg init;
1504 1504
1505 if (s->high_water < curr) { 1505 if (s->high_water < curr) {
1506 /* Previous high water mark below current data -- zero WIN_INIT 1506 /* Previous high water mark below current data -- zero WIN_INIT
1507 * bytes or up to end of window, whichever is less. 1507 * bytes or up to end of window, whichever is less.
1508 */ 1508 */
1509 init = s->window_size - curr; 1509 init = s->window_size - curr;
1510 if (init > WIN_INIT) 1510 if (init > WIN_INIT)
1511 init = WIN_INIT; 1511 init = WIN_INIT;
1512 zmemzero(s->window + curr, (unsigned)init); 1512 zmemzero(s->window + curr, (unsigned)init);
1513 s->high_water = curr + init; 1513 s->high_water = curr + init;
1514 } 1514 }
1515 else if (s->high_water < (ulg)curr + WIN_INIT) { 1515 else if (s->high_water < (ulg)curr + WIN_INIT) {
1516 /* High water mark at or above current data, but below current data 1516 /* High water mark at or above current data, but below current data
1517 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up 1517 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
1518 * to end of window, whichever is less. 1518 * to end of window, whichever is less.
1519 */ 1519 */
1520 init = (ulg)curr + WIN_INIT - s->high_water; 1520 init = (ulg)curr + WIN_INIT - s->high_water;
1521 if (init > s->window_size - s->high_water) 1521 if (init > s->window_size - s->high_water)
1522 init = s->window_size - s->high_water; 1522 init = s->window_size - s->high_water;
1523 zmemzero(s->window + s->high_water, (unsigned)init); 1523 zmemzero(s->window + s->high_water, (unsigned)init);
1524 s->high_water += init; 1524 s->high_water += init;
1525 } 1525 }
1526 } 1526 }
1527 1527
1528 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, 1528 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1529 "not enough room for search"); 1529 "not enough room for search");
1530} 1530}
1531 1531
1532/* =========================================================================== 1532/* ===========================================================================
1533 * Flush the current block, with given end-of-file flag. 1533 * Flush the current block, with given end-of-file flag.
1534 * IN assertion: strstart is set to the end of the current match. 1534 * IN assertion: strstart is set to the end of the current match.
1535 */ 1535 */
1536#define FLUSH_BLOCK_ONLY(s, last) { \ 1536#define FLUSH_BLOCK_ONLY(s, last) { \
1537 _tr_flush_block(s, (s->block_start >= 0L ? \ 1537 _tr_flush_block(s, (s->block_start >= 0L ? \
1538 (charf *)&s->window[(unsigned)s->block_start] : \ 1538 (charf *)&s->window[(unsigned)s->block_start] : \
1539 (charf *)Z_NULL), \ 1539 (charf *)Z_NULL), \
1540 (ulg)((long)s->strstart - s->block_start), \ 1540 (ulg)((long)s->strstart - s->block_start), \
1541 (last)); \ 1541 (last)); \
1542 s->block_start = s->strstart; \ 1542 s->block_start = s->strstart; \
1543 flush_pending(s->strm); \ 1543 flush_pending(s->strm); \
1544 Tracev((stderr,"[FLUSH]")); \ 1544 Tracev((stderr,"[FLUSH]")); \
1545} 1545}
1546 1546
1547/* Same but force premature exit if necessary. */ 1547/* Same but force premature exit if necessary. */
1548#define FLUSH_BLOCK(s, last) { \ 1548#define FLUSH_BLOCK(s, last) { \
1549 FLUSH_BLOCK_ONLY(s, last); \ 1549 FLUSH_BLOCK_ONLY(s, last); \
1550 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ 1550 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1551} 1551}
1552 1552
1553/* =========================================================================== 1553/* ===========================================================================
1554 * Copy without compression as much as possible from the input stream, return 1554 * Copy without compression as much as possible from the input stream, return
1555 * the current block state. 1555 * the current block state.
1556 * This function does not insert new strings in the dictionary since 1556 * This function does not insert new strings in the dictionary since
1557 * uncompressible data is probably not useful. This function is used 1557 * uncompressible data is probably not useful. This function is used
1558 * only for the level=0 compression option. 1558 * only for the level=0 compression option.
1559 * NOTE: this function should be optimized to avoid extra copying from 1559 * NOTE: this function should be optimized to avoid extra copying from
1560 * window to pending_buf. 1560 * window to pending_buf.
1561 */ 1561 */
1562local block_state deflate_stored(s, flush) 1562local block_state deflate_stored(s, flush)
1563 deflate_state *s; 1563 deflate_state *s;
1564 int flush; 1564 int flush;
1565{ 1565{
1566 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 1566 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
1567 * to pending_buf_size, and each stored block has a 5 byte header: 1567 * to pending_buf_size, and each stored block has a 5 byte header:
1568 */ 1568 */
1569 ulg max_block_size = 0xffff; 1569 ulg max_block_size = 0xffff;
1570 ulg max_start; 1570 ulg max_start;
1571 1571
1572 if (max_block_size > s->pending_buf_size - 5) { 1572 if (max_block_size > s->pending_buf_size - 5) {
1573 max_block_size = s->pending_buf_size - 5; 1573 max_block_size = s->pending_buf_size - 5;
1574 } 1574 }
1575 1575
1576 /* Copy as much as possible from input to output: */ 1576 /* Copy as much as possible from input to output: */
1577 for (;;) { 1577 for (;;) {
1578 /* Fill the window as much as possible: */ 1578 /* Fill the window as much as possible: */
1579 if (s->lookahead <= 1) { 1579 if (s->lookahead <= 1) {
1580 1580
1581 Assert(s->strstart < s->w_size+MAX_DIST(s) || 1581 Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1582 s->block_start >= (long)s->w_size, "slide too late"); 1582 s->block_start >= (long)s->w_size, "slide too late");
1583 1583
1584 fill_window(s); 1584 fill_window(s);
1585 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; 1585 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1586 1586
1587 if (s->lookahead == 0) break; /* flush the current block */ 1587 if (s->lookahead == 0) break; /* flush the current block */
1588 } 1588 }
1589 Assert(s->block_start >= 0L, "block gone"); 1589 Assert(s->block_start >= 0L, "block gone");
1590 1590
1591 s->strstart += s->lookahead; 1591 s->strstart += s->lookahead;
1592 s->lookahead = 0; 1592 s->lookahead = 0;
1593 1593
1594 /* Emit a stored block if pending_buf will be full: */ 1594 /* Emit a stored block if pending_buf will be full: */
1595 max_start = s->block_start + max_block_size; 1595 max_start = s->block_start + max_block_size;
1596 if (s->strstart == 0 || (ulg)s->strstart >= max_start) { 1596 if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1597 /* strstart == 0 is possible when wraparound on 16-bit machine */ 1597 /* strstart == 0 is possible when wraparound on 16-bit machine */
1598 s->lookahead = (uInt)(s->strstart - max_start); 1598 s->lookahead = (uInt)(s->strstart - max_start);
1599 s->strstart = (uInt)max_start; 1599 s->strstart = (uInt)max_start;
1600 FLUSH_BLOCK(s, 0); 1600 FLUSH_BLOCK(s, 0);
1601 } 1601 }
1602 /* Flush if we may have to slide, otherwise block_start may become 1602 /* Flush if we may have to slide, otherwise block_start may become
1603 * negative and the data will be gone: 1603 * negative and the data will be gone:
1604 */ 1604 */
1605 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { 1605 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1606 FLUSH_BLOCK(s, 0); 1606 FLUSH_BLOCK(s, 0);
1607 } 1607 }
1608 } 1608 }
1609 s->insert = 0; 1609 s->insert = 0;
1610 if (flush == Z_FINISH) { 1610 if (flush == Z_FINISH) {
1611 FLUSH_BLOCK(s, 1); 1611 FLUSH_BLOCK(s, 1);
1612 return finish_done; 1612 return finish_done;
1613 } 1613 }
1614 if ((long)s->strstart > s->block_start) 1614 if ((long)s->strstart > s->block_start)
1615 FLUSH_BLOCK(s, 0); 1615 FLUSH_BLOCK(s, 0);
1616 return block_done; 1616 return block_done;
1617} 1617}
1618 1618
1619/* =========================================================================== 1619/* ===========================================================================
1620 * Compress as much as possible from the input stream, return the current 1620 * Compress as much as possible from the input stream, return the current
1621 * block state. 1621 * block state.
1622 * This function does not perform lazy evaluation of matches and inserts 1622 * This function does not perform lazy evaluation of matches and inserts
1623 * new strings in the dictionary only for unmatched strings or for short 1623 * new strings in the dictionary only for unmatched strings or for short
1624 * matches. It is used only for the fast compression options. 1624 * matches. It is used only for the fast compression options.
1625 */ 1625 */
1626local block_state deflate_fast(s, flush) 1626local block_state deflate_fast(s, flush)
1627 deflate_state *s; 1627 deflate_state *s;
1628 int flush; 1628 int flush;
1629{ 1629{
1630 IPos hash_head; /* head of the hash chain */ 1630 IPos hash_head; /* head of the hash chain */
1631 int bflush; /* set if current block must be flushed */ 1631 int bflush; /* set if current block must be flushed */
1632 1632
1633 for (;;) { 1633 for (;;) {
1634 /* Make sure that we always have enough lookahead, except 1634 /* Make sure that we always have enough lookahead, except
1635 * at the end of the input file. We need MAX_MATCH bytes 1635 * at the end of the input file. We need MAX_MATCH bytes
1636 * for the next match, plus MIN_MATCH bytes to insert the 1636 * for the next match, plus MIN_MATCH bytes to insert the
1637 * string following the next match. 1637 * string following the next match.
1638 */ 1638 */
1639 if (s->lookahead < MIN_LOOKAHEAD) { 1639 if (s->lookahead < MIN_LOOKAHEAD) {
1640 fill_window(s); 1640 fill_window(s);
1641 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1641 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1642 return need_more; 1642 return need_more;
1643 } 1643 }
1644 if (s->lookahead == 0) break; /* flush the current block */ 1644 if (s->lookahead == 0) break; /* flush the current block */
1645 } 1645 }
1646 1646
1647 /* Insert the string window[strstart .. strstart+2] in the 1647 /* Insert the string window[strstart .. strstart+2] in the
1648 * dictionary, and set hash_head to the head of the hash chain: 1648 * dictionary, and set hash_head to the head of the hash chain:
1649 */ 1649 */
1650 hash_head = NIL; 1650 hash_head = NIL;
1651 if (s->lookahead >= MIN_MATCH) { 1651 if (s->lookahead >= MIN_MATCH) {
1652 INSERT_STRING(s, s->strstart, hash_head); 1652 INSERT_STRING(s, s->strstart, hash_head);
1653 } 1653 }
1654 1654
1655 /* Find the longest match, discarding those <= prev_length. 1655 /* Find the longest match, discarding those <= prev_length.
1656 * At this point we have always match_length < MIN_MATCH 1656 * At this point we have always match_length < MIN_MATCH
1657 */ 1657 */
1658 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { 1658 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1659 /* To simplify the code, we prevent matches with the string 1659 /* To simplify the code, we prevent matches with the string
1660 * of window index 0 (in particular we have to avoid a match 1660 * of window index 0 (in particular we have to avoid a match
1661 * of the string with itself at the start of the input file). 1661 * of the string with itself at the start of the input file).
1662 */ 1662 */
1663 s->match_length = longest_match (s, hash_head); 1663 s->match_length = longest_match (s, hash_head);
1664 /* longest_match() sets match_start */ 1664 /* longest_match() sets match_start */
1665 } 1665 }
1666 if (s->match_length >= MIN_MATCH) { 1666 if (s->match_length >= MIN_MATCH) {
1667 check_match(s, s->strstart, s->match_start, s->match_length); 1667 check_match(s, s->strstart, s->match_start, s->match_length);
1668 1668
1669 _tr_tally_dist(s, s->strstart - s->match_start, 1669 _tr_tally_dist(s, s->strstart - s->match_start,
1670 s->match_length - MIN_MATCH, bflush); 1670 s->match_length - MIN_MATCH, bflush);
1671 1671
1672 s->lookahead -= s->match_length; 1672 s->lookahead -= s->match_length;
1673 1673
1674 /* Insert new strings in the hash table only if the match length 1674 /* Insert new strings in the hash table only if the match length
1675 * is not too large. This saves time but degrades compression. 1675 * is not too large. This saves time but degrades compression.
1676 */ 1676 */
1677#ifndef FASTEST 1677#ifndef FASTEST
1678 if (s->match_length <= s->max_insert_length && 1678 if (s->match_length <= s->max_insert_length &&
1679 s->lookahead >= MIN_MATCH) { 1679 s->lookahead >= MIN_MATCH) {
1680 s->match_length--; /* string at strstart already in table */ 1680 s->match_length--; /* string at strstart already in table */
1681 do { 1681 do {
1682 s->strstart++; 1682 s->strstart++;
1683 INSERT_STRING(s, s->strstart, hash_head); 1683 INSERT_STRING(s, s->strstart, hash_head);
1684 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1684 /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1685 * always MIN_MATCH bytes ahead. 1685 * always MIN_MATCH bytes ahead.
1686 */ 1686 */
1687 } while (--s->match_length != 0); 1687 } while (--s->match_length != 0);
1688 s->strstart++; 1688 s->strstart++;
1689 } else 1689 } else
1690#endif 1690#endif
1691 { 1691 {
1692 s->strstart += s->match_length; 1692 s->strstart += s->match_length;
1693 s->match_length = 0; 1693 s->match_length = 0;
1694 s->ins_h = s->window[s->strstart]; 1694 s->ins_h = s->window[s->strstart];
1695 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 1695 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1696#if MIN_MATCH != 3 1696#if MIN_MATCH != 3
1697 Call UPDATE_HASH() MIN_MATCH-3 more times 1697 Call UPDATE_HASH() MIN_MATCH-3 more times
1698#endif 1698#endif
1699 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not 1699 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
1700 * matter since it will be recomputed at next deflate call. 1700 * matter since it will be recomputed at next deflate call.
1701 */ 1701 */
1702 } 1702 }
1703 } else { 1703 } else {
1704 /* No match, output a literal byte */ 1704 /* No match, output a literal byte */
1705 Tracevv((stderr,"%c", s->window[s->strstart])); 1705 Tracevv((stderr,"%c", s->window[s->strstart]));
1706 _tr_tally_lit (s, s->window[s->strstart], bflush); 1706 _tr_tally_lit (s, s->window[s->strstart], bflush);
1707 s->lookahead--; 1707 s->lookahead--;
1708 s->strstart++; 1708 s->strstart++;
1709 } 1709 }
1710 if (bflush) FLUSH_BLOCK(s, 0); 1710 if (bflush) FLUSH_BLOCK(s, 0);
1711 } 1711 }
1712 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; 1712 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1713 if (flush == Z_FINISH) { 1713 if (flush == Z_FINISH) {
1714 FLUSH_BLOCK(s, 1); 1714 FLUSH_BLOCK(s, 1);
1715 return finish_done; 1715 return finish_done;
1716 } 1716 }
1717 if (s->last_lit) 1717 if (s->last_lit)
1718 FLUSH_BLOCK(s, 0); 1718 FLUSH_BLOCK(s, 0);
1719 return block_done; 1719 return block_done;
1720} 1720}
1721 1721
1722#ifndef FASTEST 1722#ifndef FASTEST
1723/* =========================================================================== 1723/* ===========================================================================
1724 * Same as above, but achieves better compression. We use a lazy 1724 * Same as above, but achieves better compression. We use a lazy
1725 * evaluation for matches: a match is finally adopted only if there is 1725 * evaluation for matches: a match is finally adopted only if there is
1726 * no better match at the next window position. 1726 * no better match at the next window position.
1727 */ 1727 */
1728local block_state deflate_slow(s, flush) 1728local block_state deflate_slow(s, flush)
1729 deflate_state *s; 1729 deflate_state *s;
1730 int flush; 1730 int flush;
1731{ 1731{
1732 IPos hash_head; /* head of hash chain */ 1732 IPos hash_head; /* head of hash chain */
1733 int bflush; /* set if current block must be flushed */ 1733 int bflush; /* set if current block must be flushed */
1734 1734
1735 /* Process the input block. */ 1735 /* Process the input block. */
1736 for (;;) { 1736 for (;;) {
1737 /* Make sure that we always have enough lookahead, except 1737 /* Make sure that we always have enough lookahead, except
1738 * at the end of the input file. We need MAX_MATCH bytes 1738 * at the end of the input file. We need MAX_MATCH bytes
1739 * for the next match, plus MIN_MATCH bytes to insert the 1739 * for the next match, plus MIN_MATCH bytes to insert the
1740 * string following the next match. 1740 * string following the next match.
1741 */ 1741 */
1742 if (s->lookahead < MIN_LOOKAHEAD) { 1742 if (s->lookahead < MIN_LOOKAHEAD) {
1743 fill_window(s); 1743 fill_window(s);
1744 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { 1744 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1745 return need_more; 1745 return need_more;
1746 } 1746 }
1747 if (s->lookahead == 0) break; /* flush the current block */ 1747 if (s->lookahead == 0) break; /* flush the current block */
1748 } 1748 }
1749 1749
1750 /* Insert the string window[strstart .. strstart+2] in the 1750 /* Insert the string window[strstart .. strstart+2] in the
1751 * dictionary, and set hash_head to the head of the hash chain: 1751 * dictionary, and set hash_head to the head of the hash chain:
1752 */ 1752 */
1753 hash_head = NIL; 1753 hash_head = NIL;
1754 if (s->lookahead >= MIN_MATCH) { 1754 if (s->lookahead >= MIN_MATCH) {
1755 INSERT_STRING(s, s->strstart, hash_head); 1755 INSERT_STRING(s, s->strstart, hash_head);
1756 } 1756 }
1757 1757
1758 /* Find the longest match, discarding those <= prev_length. 1758 /* Find the longest match, discarding those <= prev_length.
1759 */ 1759 */
1760 s->prev_length = s->match_length, s->prev_match = s->match_start; 1760 s->prev_length = s->match_length, s->prev_match = s->match_start;
1761 s->match_length = MIN_MATCH-1; 1761 s->match_length = MIN_MATCH-1;
1762 1762
1763 if (hash_head != NIL && s->prev_length < s->max_lazy_match && 1763 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
1764 s->strstart - hash_head <= MAX_DIST(s)) { 1764 s->strstart - hash_head <= MAX_DIST(s)) {
1765 /* To simplify the code, we prevent matches with the string 1765 /* To simplify the code, we prevent matches with the string
1766 * of window index 0 (in particular we have to avoid a match 1766 * of window index 0 (in particular we have to avoid a match
1767 * of the string with itself at the start of the input file). 1767 * of the string with itself at the start of the input file).
1768 */ 1768 */
1769 s->match_length = longest_match (s, hash_head); 1769 s->match_length = longest_match (s, hash_head);
1770 /* longest_match() sets match_start */ 1770 /* longest_match() sets match_start */
1771 1771
1772 if (s->match_length <= 5 && (s->strategy == Z_FILTERED 1772 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
1773#if TOO_FAR <= 32767 1773#if TOO_FAR <= 32767
1774 || (s->match_length == MIN_MATCH && 1774 || (s->match_length == MIN_MATCH &&
1775 s->strstart - s->match_start > TOO_FAR) 1775 s->strstart - s->match_start > TOO_FAR)
1776#endif 1776#endif
1777 )) { 1777 )) {
1778 1778
1779 /* If prev_match is also MIN_MATCH, match_start is garbage 1779 /* If prev_match is also MIN_MATCH, match_start is garbage
1780 * but we will ignore the current match anyway. 1780 * but we will ignore the current match anyway.
1781 */ 1781 */
1782 s->match_length = MIN_MATCH-1; 1782 s->match_length = MIN_MATCH-1;
1783 } 1783 }
1784 } 1784 }
1785 /* If there was a match at the previous step and the current 1785 /* If there was a match at the previous step and the current
1786 * match is not better, output the previous match: 1786 * match is not better, output the previous match:
1787 */ 1787 */
1788 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 1788 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
1789 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 1789 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
1790 /* Do not insert strings in hash table beyond this. */ 1790 /* Do not insert strings in hash table beyond this. */
1791 1791
1792 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1792 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1793 1793
1794 _tr_tally_dist(s, s->strstart -1 - s->prev_match, 1794 _tr_tally_dist(s, s->strstart -1 - s->prev_match,
1795 s->prev_length - MIN_MATCH, bflush); 1795 s->prev_length - MIN_MATCH, bflush);
1796 1796
1797 /* Insert in hash table all strings up to the end of the match. 1797 /* Insert in hash table all strings up to the end of the match.
1798 * strstart-1 and strstart are already inserted. If there is not 1798 * strstart-1 and strstart are already inserted. If there is not
1799 * enough lookahead, the last two strings are not inserted in 1799 * enough lookahead, the last two strings are not inserted in
1800 * the hash table. 1800 * the hash table.
1801 */ 1801 */
1802 s->lookahead -= s->prev_length-1; 1802 s->lookahead -= s->prev_length-1;
1803 s->prev_length -= 2; 1803 s->prev_length -= 2;
1804 do { 1804 do {
1805 if (++s->strstart <= max_insert) { 1805 if (++s->strstart <= max_insert) {
1806 INSERT_STRING(s, s->strstart, hash_head); 1806 INSERT_STRING(s, s->strstart, hash_head);
1807 } 1807 }
1808 } while (--s->prev_length != 0); 1808 } while (--s->prev_length != 0);
1809 s->match_available = 0; 1809 s->match_available = 0;
1810 s->match_length = MIN_MATCH-1; 1810 s->match_length = MIN_MATCH-1;
1811 s->strstart++; 1811 s->strstart++;
1812 1812
1813 if (bflush) FLUSH_BLOCK(s, 0); 1813 if (bflush) FLUSH_BLOCK(s, 0);
1814 1814
1815 } else if (s->match_available) { 1815 } else if (s->match_available) {
1816 /* If there was no match at the previous position, output a 1816 /* If there was no match at the previous position, output a
1817 * single literal. If there was a match but the current match 1817 * single literal. If there was a match but the current match
1818 * is longer, truncate the previous match to a single literal. 1818 * is longer, truncate the previous match to a single literal.
1819 */ 1819 */
1820 Tracevv((stderr,"%c", s->window[s->strstart-1])); 1820 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1821 _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1821 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1822 if (bflush) { 1822 if (bflush) {
1823 FLUSH_BLOCK_ONLY(s, 0); 1823 FLUSH_BLOCK_ONLY(s, 0);
1824 } 1824 }
1825 s->strstart++; 1825 s->strstart++;
1826 s->lookahead--; 1826 s->lookahead--;
1827 if (s->strm->avail_out == 0) return need_more; 1827 if (s->strm->avail_out == 0) return need_more;
1828 } else { 1828 } else {
1829 /* There is no previous match to compare with, wait for 1829 /* There is no previous match to compare with, wait for
1830 * the next step to decide. 1830 * the next step to decide.
1831 */ 1831 */
1832 s->match_available = 1; 1832 s->match_available = 1;
1833 s->strstart++; 1833 s->strstart++;
1834 s->lookahead--; 1834 s->lookahead--;
1835 } 1835 }
1836 } 1836 }
1837 Assert (flush != Z_NO_FLUSH, "no flush?"); 1837 Assert (flush != Z_NO_FLUSH, "no flush?");
1838 if (s->match_available) { 1838 if (s->match_available) {
1839 Tracevv((stderr,"%c", s->window[s->strstart-1])); 1839 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1840 _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1840 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1841 s->match_available = 0; 1841 s->match_available = 0;
1842 } 1842 }
1843 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; 1843 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1844 if (flush == Z_FINISH) { 1844 if (flush == Z_FINISH) {
1845 FLUSH_BLOCK(s, 1); 1845 FLUSH_BLOCK(s, 1);
1846 return finish_done; 1846 return finish_done;
1847 } 1847 }
1848 if (s->last_lit) 1848 if (s->last_lit)
1849 FLUSH_BLOCK(s, 0); 1849 FLUSH_BLOCK(s, 0);
1850 return block_done; 1850 return block_done;
1851} 1851}
1852#endif /* FASTEST */ 1852#endif /* FASTEST */
1853 1853
1854/* =========================================================================== 1854/* ===========================================================================
1855 * For Z_RLE, simply look for runs of bytes, generate matches only of distance 1855 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
1856 * one. Do not maintain a hash table. (It will be regenerated if this run of 1856 * one. Do not maintain a hash table. (It will be regenerated if this run of
1857 * deflate switches away from Z_RLE.) 1857 * deflate switches away from Z_RLE.)
1858 */ 1858 */
1859local block_state deflate_rle(s, flush) 1859local block_state deflate_rle(s, flush)
1860 deflate_state *s; 1860 deflate_state *s;
1861 int flush; 1861 int flush;
1862{ 1862{
1863 int bflush; /* set if current block must be flushed */ 1863 int bflush; /* set if current block must be flushed */
1864 uInt prev; /* byte at distance one to match */ 1864 uInt prev; /* byte at distance one to match */
1865 Bytef *scan, *strend; /* scan goes up to strend for length of run */ 1865 Bytef *scan, *strend; /* scan goes up to strend for length of run */
1866 1866
1867 for (;;) { 1867 for (;;) {
1868 /* Make sure that we always have enough lookahead, except 1868 /* Make sure that we always have enough lookahead, except
1869 * at the end of the input file. We need MAX_MATCH bytes 1869 * at the end of the input file. We need MAX_MATCH bytes
1870 * for the longest run, plus one for the unrolled loop. 1870 * for the longest run, plus one for the unrolled loop.
1871 */ 1871 */
1872 if (s->lookahead <= MAX_MATCH) { 1872 if (s->lookahead <= MAX_MATCH) {
1873 fill_window(s); 1873 fill_window(s);
1874 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { 1874 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
1875 return need_more; 1875 return need_more;
1876 } 1876 }
1877 if (s->lookahead == 0) break; /* flush the current block */ 1877 if (s->lookahead == 0) break; /* flush the current block */
1878 } 1878 }
1879 1879
1880 /* See how many times the previous byte repeats */ 1880 /* See how many times the previous byte repeats */
1881 s->match_length = 0; 1881 s->match_length = 0;
1882 if (s->lookahead >= MIN_MATCH && s->strstart > 0) { 1882 if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
1883 scan = s->window + s->strstart - 1; 1883 scan = s->window + s->strstart - 1;
1884 prev = *scan; 1884 prev = *scan;
1885 if (prev == *++scan && prev == *++scan && prev == *++scan) { 1885 if (prev == *++scan && prev == *++scan && prev == *++scan) {
1886 strend = s->window + s->strstart + MAX_MATCH; 1886 strend = s->window + s->strstart + MAX_MATCH;
1887 do { 1887 do {
1888 } while (prev == *++scan && prev == *++scan && 1888 } while (prev == *++scan && prev == *++scan &&
1889 prev == *++scan && prev == *++scan && 1889 prev == *++scan && prev == *++scan &&
1890 prev == *++scan && prev == *++scan && 1890 prev == *++scan && prev == *++scan &&
1891 prev == *++scan && prev == *++scan && 1891 prev == *++scan && prev == *++scan &&
1892 scan < strend); 1892 scan < strend);
1893 s->match_length = MAX_MATCH - (int)(strend - scan); 1893 s->match_length = MAX_MATCH - (int)(strend - scan);
1894 if (s->match_length > s->lookahead) 1894 if (s->match_length > s->lookahead)
1895 s->match_length = s->lookahead; 1895 s->match_length = s->lookahead;
1896 } 1896 }
1897 Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); 1897 Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1898 } 1898 }
1899 1899
1900 /* Emit match if have run of MIN_MATCH or longer, else emit literal */ 1900 /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1901 if (s->match_length >= MIN_MATCH) { 1901 if (s->match_length >= MIN_MATCH) {
1902 check_match(s, s->strstart, s->strstart - 1, s->match_length); 1902 check_match(s, s->strstart, s->strstart - 1, s->match_length);
1903 1903
1904 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); 1904 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
1905 1905
1906 s->lookahead -= s->match_length; 1906 s->lookahead -= s->match_length;
1907 s->strstart += s->match_length; 1907 s->strstart += s->match_length;
1908 s->match_length = 0; 1908 s->match_length = 0;
1909 } else { 1909 } else {
1910 /* No match, output a literal byte */ 1910 /* No match, output a literal byte */
1911 Tracevv((stderr,"%c", s->window[s->strstart])); 1911 Tracevv((stderr,"%c", s->window[s->strstart]));
1912 _tr_tally_lit (s, s->window[s->strstart], bflush); 1912 _tr_tally_lit (s, s->window[s->strstart], bflush);
1913 s->lookahead--; 1913 s->lookahead--;
1914 s->strstart++; 1914 s->strstart++;
1915 } 1915 }
1916 if (bflush) FLUSH_BLOCK(s, 0); 1916 if (bflush) FLUSH_BLOCK(s, 0);
1917 } 1917 }
1918 s->insert = 0; 1918 s->insert = 0;
1919 if (flush == Z_FINISH) { 1919 if (flush == Z_FINISH) {
1920 FLUSH_BLOCK(s, 1); 1920 FLUSH_BLOCK(s, 1);
1921 return finish_done; 1921 return finish_done;
1922 } 1922 }
1923 if (s->last_lit) 1923 if (s->last_lit)
1924 FLUSH_BLOCK(s, 0); 1924 FLUSH_BLOCK(s, 0);
1925 return block_done; 1925 return block_done;
1926} 1926}
1927 1927
1928/* =========================================================================== 1928/* ===========================================================================
1929 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. 1929 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
1930 * (It will be regenerated if this run of deflate switches away from Huffman.) 1930 * (It will be regenerated if this run of deflate switches away from Huffman.)
1931 */ 1931 */
1932local block_state deflate_huff(s, flush) 1932local block_state deflate_huff(s, flush)
1933 deflate_state *s; 1933 deflate_state *s;
1934 int flush; 1934 int flush;
1935{ 1935{
1936 int bflush; /* set if current block must be flushed */ 1936 int bflush; /* set if current block must be flushed */
1937 1937
1938 for (;;) { 1938 for (;;) {
1939 /* Make sure that we have a literal to write. */ 1939 /* Make sure that we have a literal to write. */
1940 if (s->lookahead == 0) { 1940 if (s->lookahead == 0) {
1941 fill_window(s); 1941 fill_window(s);
1942 if (s->lookahead == 0) { 1942 if (s->lookahead == 0) {
1943 if (flush == Z_NO_FLUSH) 1943 if (flush == Z_NO_FLUSH)
1944 return need_more; 1944 return need_more;
1945 break; /* flush the current block */ 1945 break; /* flush the current block */
1946 } 1946 }
1947 } 1947 }
1948 1948
1949 /* Output a literal byte */ 1949 /* Output a literal byte */
1950 s->match_length = 0; 1950 s->match_length = 0;
1951 Tracevv((stderr,"%c", s->window[s->strstart])); 1951 Tracevv((stderr,"%c", s->window[s->strstart]));
1952 _tr_tally_lit (s, s->window[s->strstart], bflush); 1952 _tr_tally_lit (s, s->window[s->strstart], bflush);
1953 s->lookahead--; 1953 s->lookahead--;
1954 s->strstart++; 1954 s->strstart++;
1955 if (bflush) FLUSH_BLOCK(s, 0); 1955 if (bflush) FLUSH_BLOCK(s, 0);
1956 } 1956 }
1957 s->insert = 0; 1957 s->insert = 0;
1958 if (flush == Z_FINISH) { 1958 if (flush == Z_FINISH) {
1959 FLUSH_BLOCK(s, 1); 1959 FLUSH_BLOCK(s, 1);
1960 return finish_done; 1960 return finish_done;
1961 } 1961 }
1962 if (s->last_lit) 1962 if (s->last_lit)
1963 FLUSH_BLOCK(s, 0); 1963 FLUSH_BLOCK(s, 0);
1964 return block_done; 1964 return block_done;
1965} 1965}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.h
index 256caca..fbac44d 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/deflate.h
@@ -1,346 +1,346 @@
1/* deflate.h -- internal compression state 1/* deflate.h -- internal compression state
2 * Copyright (C) 1995-2012 Jean-loup Gailly 2 * Copyright (C) 1995-2012 Jean-loup Gailly
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* WARNING: this file should *not* be used by applications. It is 6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is 7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11/* @(#) $Id$ */ 11/* @(#) $Id$ */
12 12
13#ifndef DEFLATE_H 13#ifndef DEFLATE_H
14#define DEFLATE_H 14#define DEFLATE_H
15 15
16#include "zutil.h" 16#include "zutil.h"
17 17
18/* define NO_GZIP when compiling if you want to disable gzip header and 18/* define NO_GZIP when compiling if you want to disable gzip header and
19 trailer creation by deflate(). NO_GZIP would be used to avoid linking in 19 trailer creation by deflate(). NO_GZIP would be used to avoid linking in
20 the crc code when it is not needed. For shared libraries, gzip encoding 20 the crc code when it is not needed. For shared libraries, gzip encoding
21 should be left enabled. */ 21 should be left enabled. */
22#ifndef NO_GZIP 22#ifndef NO_GZIP
23# define GZIP 23# define GZIP
24#endif 24#endif
25 25
26/* =========================================================================== 26/* ===========================================================================
27 * Internal compression state. 27 * Internal compression state.
28 */ 28 */
29 29
30#define LENGTH_CODES 29 30#define LENGTH_CODES 29
31/* number of length codes, not counting the special END_BLOCK code */ 31/* number of length codes, not counting the special END_BLOCK code */
32 32
33#define LITERALS 256 33#define LITERALS 256
34/* number of literal bytes 0..255 */ 34/* number of literal bytes 0..255 */
35 35
36#define L_CODES (LITERALS+1+LENGTH_CODES) 36#define L_CODES (LITERALS+1+LENGTH_CODES)
37/* number of Literal or Length codes, including the END_BLOCK code */ 37/* number of Literal or Length codes, including the END_BLOCK code */
38 38
39#define D_CODES 30 39#define D_CODES 30
40/* number of distance codes */ 40/* number of distance codes */
41 41
42#define BL_CODES 19 42#define BL_CODES 19
43/* number of codes used to transfer the bit lengths */ 43/* number of codes used to transfer the bit lengths */
44 44
45#define HEAP_SIZE (2*L_CODES+1) 45#define HEAP_SIZE (2*L_CODES+1)
46/* maximum heap size */ 46/* maximum heap size */
47 47
48#define MAX_BITS 15 48#define MAX_BITS 15
49/* All codes must not exceed MAX_BITS bits */ 49/* All codes must not exceed MAX_BITS bits */
50 50
51#define Buf_size 16 51#define Buf_size 16
52/* size of bit buffer in bi_buf */ 52/* size of bit buffer in bi_buf */
53 53
54#define INIT_STATE 42 54#define INIT_STATE 42
55#define EXTRA_STATE 69 55#define EXTRA_STATE 69
56#define NAME_STATE 73 56#define NAME_STATE 73
57#define COMMENT_STATE 91 57#define COMMENT_STATE 91
58#define HCRC_STATE 103 58#define HCRC_STATE 103
59#define BUSY_STATE 113 59#define BUSY_STATE 113
60#define FINISH_STATE 666 60#define FINISH_STATE 666
61/* Stream status */ 61/* Stream status */
62 62
63 63
64/* Data structure describing a single value and its code string. */ 64/* Data structure describing a single value and its code string. */
65typedef struct ct_data_s { 65typedef struct ct_data_s {
66 union { 66 union {
67 ush freq; /* frequency count */ 67 ush freq; /* frequency count */
68 ush code; /* bit string */ 68 ush code; /* bit string */
69 } fc; 69 } fc;
70 union { 70 union {
71 ush dad; /* father node in Huffman tree */ 71 ush dad; /* father node in Huffman tree */
72 ush len; /* length of bit string */ 72 ush len; /* length of bit string */
73 } dl; 73 } dl;
74} FAR ct_data; 74} FAR ct_data;
75 75
76#define Freq fc.freq 76#define Freq fc.freq
77#define Code fc.code 77#define Code fc.code
78#define Dad dl.dad 78#define Dad dl.dad
79#define Len dl.len 79#define Len dl.len
80 80
81typedef struct static_tree_desc_s static_tree_desc; 81typedef struct static_tree_desc_s static_tree_desc;
82 82
83typedef struct tree_desc_s { 83typedef struct tree_desc_s {
84 ct_data *dyn_tree; /* the dynamic tree */ 84 ct_data *dyn_tree; /* the dynamic tree */
85 int max_code; /* largest code with non zero frequency */ 85 int max_code; /* largest code with non zero frequency */
86 static_tree_desc *stat_desc; /* the corresponding static tree */ 86 static_tree_desc *stat_desc; /* the corresponding static tree */
87} FAR tree_desc; 87} FAR tree_desc;
88 88
89typedef ush Pos; 89typedef ush Pos;
90typedef Pos FAR Posf; 90typedef Pos FAR Posf;
91typedef unsigned IPos; 91typedef unsigned IPos;
92 92
93/* A Pos is an index in the character window. We use short instead of int to 93/* A Pos is an index in the character window. We use short instead of int to
94 * save space in the various tables. IPos is used only for parameter passing. 94 * save space in the various tables. IPos is used only for parameter passing.
95 */ 95 */
96 96
97typedef struct internal_state { 97typedef struct internal_state {
98 z_streamp strm; /* pointer back to this zlib stream */ 98 z_streamp strm; /* pointer back to this zlib stream */
99 int status; /* as the name implies */ 99 int status; /* as the name implies */
100 Bytef *pending_buf; /* output still pending */ 100 Bytef *pending_buf; /* output still pending */
101 ulg pending_buf_size; /* size of pending_buf */ 101 ulg pending_buf_size; /* size of pending_buf */
102 Bytef *pending_out; /* next pending byte to output to the stream */ 102 Bytef *pending_out; /* next pending byte to output to the stream */
103 uInt pending; /* nb of bytes in the pending buffer */ 103 uInt pending; /* nb of bytes in the pending buffer */
104 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 104 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
105 gz_headerp gzhead; /* gzip header information to write */ 105 gz_headerp gzhead; /* gzip header information to write */
106 uInt gzindex; /* where in extra, name, or comment */ 106 uInt gzindex; /* where in extra, name, or comment */
107 Byte method; /* STORED (for zip only) or DEFLATED */ 107 Byte method; /* STORED (for zip only) or DEFLATED */
108 int last_flush; /* value of flush param for previous deflate call */ 108 int last_flush; /* value of flush param for previous deflate call */
109 109
110 /* used by deflate.c: */ 110 /* used by deflate.c: */
111 111
112 uInt w_size; /* LZ77 window size (32K by default) */ 112 uInt w_size; /* LZ77 window size (32K by default) */
113 uInt w_bits; /* log2(w_size) (8..16) */ 113 uInt w_bits; /* log2(w_size) (8..16) */
114 uInt w_mask; /* w_size - 1 */ 114 uInt w_mask; /* w_size - 1 */
115 115
116 Bytef *window; 116 Bytef *window;
117 /* Sliding window. Input bytes are read into the second half of the window, 117 /* Sliding window. Input bytes are read into the second half of the window,
118 * and move to the first half later to keep a dictionary of at least wSize 118 * and move to the first half later to keep a dictionary of at least wSize
119 * bytes. With this organization, matches are limited to a distance of 119 * bytes. With this organization, matches are limited to a distance of
120 * wSize-MAX_MATCH bytes, but this ensures that IO is always 120 * wSize-MAX_MATCH bytes, but this ensures that IO is always
121 * performed with a length multiple of the block size. Also, it limits 121 * performed with a length multiple of the block size. Also, it limits
122 * the window size to 64K, which is quite useful on MSDOS. 122 * the window size to 64K, which is quite useful on MSDOS.
123 * To do: use the user input buffer as sliding window. 123 * To do: use the user input buffer as sliding window.
124 */ 124 */
125 125
126 ulg window_size; 126 ulg window_size;
127 /* Actual size of window: 2*wSize, except when the user input buffer 127 /* Actual size of window: 2*wSize, except when the user input buffer
128 * is directly used as sliding window. 128 * is directly used as sliding window.
129 */ 129 */
130 130
131 Posf *prev; 131 Posf *prev;
132 /* Link to older string with same hash index. To limit the size of this 132 /* Link to older string with same hash index. To limit the size of this
133 * array to 64K, this link is maintained only for the last 32K strings. 133 * array to 64K, this link is maintained only for the last 32K strings.
134 * An index in this array is thus a window index modulo 32K. 134 * An index in this array is thus a window index modulo 32K.
135 */ 135 */
136 136
137 Posf *head; /* Heads of the hash chains or NIL. */ 137 Posf *head; /* Heads of the hash chains or NIL. */
138 138
139 uInt ins_h; /* hash index of string to be inserted */ 139 uInt ins_h; /* hash index of string to be inserted */
140 uInt hash_size; /* number of elements in hash table */ 140 uInt hash_size; /* number of elements in hash table */
141 uInt hash_bits; /* log2(hash_size) */ 141 uInt hash_bits; /* log2(hash_size) */
142 uInt hash_mask; /* hash_size-1 */ 142 uInt hash_mask; /* hash_size-1 */
143 143
144 uInt hash_shift; 144 uInt hash_shift;
145 /* Number of bits by which ins_h must be shifted at each input 145 /* Number of bits by which ins_h must be shifted at each input
146 * step. It must be such that after MIN_MATCH steps, the oldest 146 * step. It must be such that after MIN_MATCH steps, the oldest
147 * byte no longer takes part in the hash key, that is: 147 * byte no longer takes part in the hash key, that is:
148 * hash_shift * MIN_MATCH >= hash_bits 148 * hash_shift * MIN_MATCH >= hash_bits
149 */ 149 */
150 150
151 long block_start; 151 long block_start;
152 /* Window position at the beginning of the current output block. Gets 152 /* Window position at the beginning of the current output block. Gets
153 * negative when the window is moved backwards. 153 * negative when the window is moved backwards.
154 */ 154 */
155 155
156 uInt match_length; /* length of best match */ 156 uInt match_length; /* length of best match */
157 IPos prev_match; /* previous match */ 157 IPos prev_match; /* previous match */
158 int match_available; /* set if previous match exists */ 158 int match_available; /* set if previous match exists */
159 uInt strstart; /* start of string to insert */ 159 uInt strstart; /* start of string to insert */
160 uInt match_start; /* start of matching string */ 160 uInt match_start; /* start of matching string */
161 uInt lookahead; /* number of valid bytes ahead in window */ 161 uInt lookahead; /* number of valid bytes ahead in window */
162 162
163 uInt prev_length; 163 uInt prev_length;
164 /* Length of the best match at previous step. Matches not greater than this 164 /* Length of the best match at previous step. Matches not greater than this
165 * are discarded. This is used in the lazy match evaluation. 165 * are discarded. This is used in the lazy match evaluation.
166 */ 166 */
167 167
168 uInt max_chain_length; 168 uInt max_chain_length;
169 /* To speed up deflation, hash chains are never searched beyond this 169 /* To speed up deflation, hash chains are never searched beyond this
170 * length. A higher limit improves compression ratio but degrades the 170 * length. A higher limit improves compression ratio but degrades the
171 * speed. 171 * speed.
172 */ 172 */
173 173
174 uInt max_lazy_match; 174 uInt max_lazy_match;
175 /* Attempt to find a better match only when the current match is strictly 175 /* Attempt to find a better match only when the current match is strictly
176 * smaller than this value. This mechanism is used only for compression 176 * smaller than this value. This mechanism is used only for compression
177 * levels >= 4. 177 * levels >= 4.
178 */ 178 */
179# define max_insert_length max_lazy_match 179# define max_insert_length max_lazy_match
180 /* Insert new strings in the hash table only if the match length is not 180 /* Insert new strings in the hash table only if the match length is not
181 * greater than this length. This saves time but degrades compression. 181 * greater than this length. This saves time but degrades compression.
182 * max_insert_length is used only for compression levels <= 3. 182 * max_insert_length is used only for compression levels <= 3.
183 */ 183 */
184 184
185 int level; /* compression level (1..9) */ 185 int level; /* compression level (1..9) */
186 int strategy; /* favor or force Huffman coding*/ 186 int strategy; /* favor or force Huffman coding*/
187 187
188 uInt good_match; 188 uInt good_match;
189 /* Use a faster search when the previous match is longer than this */ 189 /* Use a faster search when the previous match is longer than this */
190 190
191 int nice_match; /* Stop searching when current match exceeds this */ 191 int nice_match; /* Stop searching when current match exceeds this */
192 192
193 /* used by trees.c: */ 193 /* used by trees.c: */
194 /* Didn't use ct_data typedef below to suppress compiler warning */ 194 /* Didn't use ct_data typedef below to suppress compiler warning */
195 struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 195 struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
196 struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 196 struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
197 struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 197 struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
198 198
199 struct tree_desc_s l_desc; /* desc. for literal tree */ 199 struct tree_desc_s l_desc; /* desc. for literal tree */
200 struct tree_desc_s d_desc; /* desc. for distance tree */ 200 struct tree_desc_s d_desc; /* desc. for distance tree */
201 struct tree_desc_s bl_desc; /* desc. for bit length tree */ 201 struct tree_desc_s bl_desc; /* desc. for bit length tree */
202 202
203 ush bl_count[MAX_BITS+1]; 203 ush bl_count[MAX_BITS+1];
204 /* number of codes at each bit length for an optimal tree */ 204 /* number of codes at each bit length for an optimal tree */
205 205
206 int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 206 int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
207 int heap_len; /* number of elements in the heap */ 207 int heap_len; /* number of elements in the heap */
208 int heap_max; /* element of largest frequency */ 208 int heap_max; /* element of largest frequency */
209 /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 209 /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
210 * The same heap array is used to build all trees. 210 * The same heap array is used to build all trees.
211 */ 211 */
212 212
213 uch depth[2*L_CODES+1]; 213 uch depth[2*L_CODES+1];
214 /* Depth of each subtree used as tie breaker for trees of equal frequency 214 /* Depth of each subtree used as tie breaker for trees of equal frequency
215 */ 215 */
216 216
217 uchf *l_buf; /* buffer for literals or lengths */ 217 uchf *l_buf; /* buffer for literals or lengths */
218 218
219 uInt lit_bufsize; 219 uInt lit_bufsize;
220 /* Size of match buffer for literals/lengths. There are 4 reasons for 220 /* Size of match buffer for literals/lengths. There are 4 reasons for
221 * limiting lit_bufsize to 64K: 221 * limiting lit_bufsize to 64K:
222 * - frequencies can be kept in 16 bit counters 222 * - frequencies can be kept in 16 bit counters
223 * - if compression is not successful for the first block, all input 223 * - if compression is not successful for the first block, all input
224 * data is still in the window so we can still emit a stored block even 224 * data is still in the window so we can still emit a stored block even
225 * when input comes from standard input. (This can also be done for 225 * when input comes from standard input. (This can also be done for
226 * all blocks if lit_bufsize is not greater than 32K.) 226 * all blocks if lit_bufsize is not greater than 32K.)
227 * - if compression is not successful for a file smaller than 64K, we can 227 * - if compression is not successful for a file smaller than 64K, we can
228 * even emit a stored file instead of a stored block (saving 5 bytes). 228 * even emit a stored file instead of a stored block (saving 5 bytes).
229 * This is applicable only for zip (not gzip or zlib). 229 * This is applicable only for zip (not gzip or zlib).
230 * - creating new Huffman trees less frequently may not provide fast 230 * - creating new Huffman trees less frequently may not provide fast
231 * adaptation to changes in the input data statistics. (Take for 231 * adaptation to changes in the input data statistics. (Take for
232 * example a binary file with poorly compressible code followed by 232 * example a binary file with poorly compressible code followed by
233 * a highly compressible string table.) Smaller buffer sizes give 233 * a highly compressible string table.) Smaller buffer sizes give
234 * fast adaptation but have of course the overhead of transmitting 234 * fast adaptation but have of course the overhead of transmitting
235 * trees more frequently. 235 * trees more frequently.
236 * - I can't count above 4 236 * - I can't count above 4
237 */ 237 */
238 238
239 uInt last_lit; /* running index in l_buf */ 239 uInt last_lit; /* running index in l_buf */
240 240
241 ushf *d_buf; 241 ushf *d_buf;
242 /* Buffer for distances. To simplify the code, d_buf and l_buf have 242 /* Buffer for distances. To simplify the code, d_buf and l_buf have
243 * the same number of elements. To use different lengths, an extra flag 243 * the same number of elements. To use different lengths, an extra flag
244 * array would be necessary. 244 * array would be necessary.
245 */ 245 */
246 246
247 ulg opt_len; /* bit length of current block with optimal trees */ 247 ulg opt_len; /* bit length of current block with optimal trees */
248 ulg static_len; /* bit length of current block with static trees */ 248 ulg static_len; /* bit length of current block with static trees */
249 uInt matches; /* number of string matches in current block */ 249 uInt matches; /* number of string matches in current block */
250 uInt insert; /* bytes at end of window left to insert */ 250 uInt insert; /* bytes at end of window left to insert */
251 251
252#ifdef DEBUG 252#ifdef DEBUG
253 ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 253 ulg compressed_len; /* total bit length of compressed file mod 2^32 */
254 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ 254 ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
255#endif 255#endif
256 256
257 ush bi_buf; 257 ush bi_buf;
258 /* Output buffer. bits are inserted starting at the bottom (least 258 /* Output buffer. bits are inserted starting at the bottom (least
259 * significant bits). 259 * significant bits).
260 */ 260 */
261 int bi_valid; 261 int bi_valid;
262 /* Number of valid bits in bi_buf. All bits above the last valid bit 262 /* Number of valid bits in bi_buf. All bits above the last valid bit
263 * are always zero. 263 * are always zero.
264 */ 264 */
265 265
266 ulg high_water; 266 ulg high_water;
267 /* High water mark offset in window for initialized bytes -- bytes above 267 /* High water mark offset in window for initialized bytes -- bytes above
268 * this are set to zero in order to avoid memory check warnings when 268 * this are set to zero in order to avoid memory check warnings when
269 * longest match routines access bytes past the input. This is then 269 * longest match routines access bytes past the input. This is then
270 * updated to the new high water mark. 270 * updated to the new high water mark.
271 */ 271 */
272 272
273} FAR deflate_state; 273} FAR deflate_state;
274 274
275/* Output a byte on the stream. 275/* Output a byte on the stream.
276 * IN assertion: there is enough room in pending_buf. 276 * IN assertion: there is enough room in pending_buf.
277 */ 277 */
278#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} 278#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
279 279
280 280
281#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 281#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
282/* Minimum amount of lookahead, except at the end of the input file. 282/* Minimum amount of lookahead, except at the end of the input file.
283 * See deflate.c for comments about the MIN_MATCH+1. 283 * See deflate.c for comments about the MIN_MATCH+1.
284 */ 284 */
285 285
286#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) 286#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
287/* In order to simplify the code, particularly on 16 bit machines, match 287/* In order to simplify the code, particularly on 16 bit machines, match
288 * distances are limited to MAX_DIST instead of WSIZE. 288 * distances are limited to MAX_DIST instead of WSIZE.
289 */ 289 */
290 290
291#define WIN_INIT MAX_MATCH 291#define WIN_INIT MAX_MATCH
292/* Number of bytes after end of data in window to initialize in order to avoid 292/* Number of bytes after end of data in window to initialize in order to avoid
293 memory checker errors from longest match routines */ 293 memory checker errors from longest match routines */
294 294
295 /* in trees.c */ 295 /* in trees.c */
296void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); 296void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
297int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 297int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
298void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, 298void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
299 ulg stored_len, int last)); 299 ulg stored_len, int last));
300void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); 300void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
301void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); 301void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
302void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, 302void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
303 ulg stored_len, int last)); 303 ulg stored_len, int last));
304 304
305#define d_code(dist) \ 305#define d_code(dist) \
306 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 306 ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
307/* Mapping from a distance to a distance code. dist is the distance - 1 and 307/* Mapping from a distance to a distance code. dist is the distance - 1 and
308 * must not have side effects. _dist_code[256] and _dist_code[257] are never 308 * must not have side effects. _dist_code[256] and _dist_code[257] are never
309 * used. 309 * used.
310 */ 310 */
311 311
312#ifndef DEBUG 312#ifndef DEBUG
313/* Inline versions of _tr_tally for speed: */ 313/* Inline versions of _tr_tally for speed: */
314 314
315#if defined(GEN_TREES_H) || !defined(STDC) 315#if defined(GEN_TREES_H) || !defined(STDC)
316 extern uch ZLIB_INTERNAL _length_code[]; 316 extern uch ZLIB_INTERNAL _length_code[];
317 extern uch ZLIB_INTERNAL _dist_code[]; 317 extern uch ZLIB_INTERNAL _dist_code[];
318#else 318#else
319 extern const uch ZLIB_INTERNAL _length_code[]; 319 extern const uch ZLIB_INTERNAL _length_code[];
320 extern const uch ZLIB_INTERNAL _dist_code[]; 320 extern const uch ZLIB_INTERNAL _dist_code[];
321#endif 321#endif
322 322
323# define _tr_tally_lit(s, c, flush) \ 323# define _tr_tally_lit(s, c, flush) \
324 { uch cc = (c); \ 324 { uch cc = (c); \
325 s->d_buf[s->last_lit] = 0; \ 325 s->d_buf[s->last_lit] = 0; \
326 s->l_buf[s->last_lit++] = cc; \ 326 s->l_buf[s->last_lit++] = cc; \
327 s->dyn_ltree[cc].Freq++; \ 327 s->dyn_ltree[cc].Freq++; \
328 flush = (s->last_lit == s->lit_bufsize-1); \ 328 flush = (s->last_lit == s->lit_bufsize-1); \
329 } 329 }
330# define _tr_tally_dist(s, distance, length, flush) \ 330# define _tr_tally_dist(s, distance, length, flush) \
331 { uch len = (length); \ 331 { uch len = (length); \
332 ush dist = (distance); \ 332 ush dist = (distance); \
333 s->d_buf[s->last_lit] = dist; \ 333 s->d_buf[s->last_lit] = dist; \
334 s->l_buf[s->last_lit++] = len; \ 334 s->l_buf[s->last_lit++] = len; \
335 dist--; \ 335 dist--; \
336 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 336 s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
337 s->dyn_dtree[d_code(dist)].Freq++; \ 337 s->dyn_dtree[d_code(dist)].Freq++; \
338 flush = (s->last_lit == s->lit_bufsize-1); \ 338 flush = (s->last_lit == s->lit_bufsize-1); \
339 } 339 }
340#else 340#else
341# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 341# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
342# define _tr_tally_dist(s, distance, length, flush) \ 342# define _tr_tally_dist(s, distance, length, flush) \
343 flush = _tr_tally(s, distance, length) 343 flush = _tr_tally(s, distance, length)
344#endif 344#endif
345 345
346#endif /* DEFLATE_H */ 346#endif /* DEFLATE_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/infback.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/infback.c
index 2cc16dd..981aff1 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/infback.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/infback.c
@@ -1,640 +1,640 @@
1/* infback.c -- inflate using a call-back interface 1/* infback.c -- inflate using a call-back interface
2 * Copyright (C) 1995-2011 Mark Adler 2 * Copyright (C) 1995-2011 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* 6/*
7 This code is largely copied from inflate.c. Normally either infback.o or 7 This code is largely copied from inflate.c. Normally either infback.o or
8 inflate.o would be linked into an application--not both. The interface 8 inflate.o would be linked into an application--not both. The interface
9 with inffast.c is retained so that optimized assembler-coded versions of 9 with inffast.c is retained so that optimized assembler-coded versions of
10 inflate_fast() can be used with either inflate.c or infback.c. 10 inflate_fast() can be used with either inflate.c or infback.c.
11 */ 11 */
12 12
13#include "zutil.h" 13#include "zutil.h"
14#include "inftrees.h" 14#include "inftrees.h"
15#include "inflate.h" 15#include "inflate.h"
16#include "inffast.h" 16#include "inffast.h"
17 17
18/* function prototypes */ 18/* function prototypes */
19local void fixedtables OF((struct inflate_state FAR *state)); 19local void fixedtables OF((struct inflate_state FAR *state));
20 20
21/* 21/*
22 strm provides memory allocation functions in zalloc and zfree, or 22 strm provides memory allocation functions in zalloc and zfree, or
23 Z_NULL to use the library memory allocation functions. 23 Z_NULL to use the library memory allocation functions.
24 24
25 windowBits is in the range 8..15, and window is a user-supplied 25 windowBits is in the range 8..15, and window is a user-supplied
26 window and output buffer that is 2**windowBits bytes. 26 window and output buffer that is 2**windowBits bytes.
27 */ 27 */
28int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) 28int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
29z_streamp strm; 29z_streamp strm;
30int windowBits; 30int windowBits;
31unsigned char FAR *window; 31unsigned char FAR *window;
32const char *version; 32const char *version;
33int stream_size; 33int stream_size;
34{ 34{
35 struct inflate_state FAR *state; 35 struct inflate_state FAR *state;
36 36
37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 37 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
38 stream_size != (int)(sizeof(z_stream))) 38 stream_size != (int)(sizeof(z_stream)))
39 return Z_VERSION_ERROR; 39 return Z_VERSION_ERROR;
40 if (strm == Z_NULL || window == Z_NULL || 40 if (strm == Z_NULL || window == Z_NULL ||
41 windowBits < 8 || windowBits > 15) 41 windowBits < 8 || windowBits > 15)
42 return Z_STREAM_ERROR; 42 return Z_STREAM_ERROR;
43 strm->msg = Z_NULL; /* in case we return an error */ 43 strm->msg = Z_NULL; /* in case we return an error */
44 if (strm->zalloc == (alloc_func)0) { 44 if (strm->zalloc == (alloc_func)0) {
45#ifdef Z_SOLO 45#ifdef Z_SOLO
46 return Z_STREAM_ERROR; 46 return Z_STREAM_ERROR;
47#else 47#else
48 strm->zalloc = zcalloc; 48 strm->zalloc = zcalloc;
49 strm->opaque = (voidpf)0; 49 strm->opaque = (voidpf)0;
50#endif 50#endif
51 } 51 }
52 if (strm->zfree == (free_func)0) 52 if (strm->zfree == (free_func)0)
53#ifdef Z_SOLO 53#ifdef Z_SOLO
54 return Z_STREAM_ERROR; 54 return Z_STREAM_ERROR;
55#else 55#else
56 strm->zfree = zcfree; 56 strm->zfree = zcfree;
57#endif 57#endif
58 state = (struct inflate_state FAR *)ZALLOC(strm, 1, 58 state = (struct inflate_state FAR *)ZALLOC(strm, 1,
59 sizeof(struct inflate_state)); 59 sizeof(struct inflate_state));
60 if (state == Z_NULL) return Z_MEM_ERROR; 60 if (state == Z_NULL) return Z_MEM_ERROR;
61 Tracev((stderr, "inflate: allocated\n")); 61 Tracev((stderr, "inflate: allocated\n"));
62 strm->state = (struct internal_state FAR *)state; 62 strm->state = (struct internal_state FAR *)state;
63 state->dmax = 32768U; 63 state->dmax = 32768U;
64 state->wbits = windowBits; 64 state->wbits = windowBits;
65 state->wsize = 1U << windowBits; 65 state->wsize = 1U << windowBits;
66 state->window = window; 66 state->window = window;
67 state->wnext = 0; 67 state->wnext = 0;
68 state->whave = 0; 68 state->whave = 0;
69 return Z_OK; 69 return Z_OK;
70} 70}
71 71
72/* 72/*
73 Return state with length and distance decoding tables and index sizes set to 73 Return state with length and distance decoding tables and index sizes set to
74 fixed code decoding. Normally this returns fixed tables from inffixed.h. 74 fixed code decoding. Normally this returns fixed tables from inffixed.h.
75 If BUILDFIXED is defined, then instead this routine builds the tables the 75 If BUILDFIXED is defined, then instead this routine builds the tables the
76 first time it's called, and returns those tables the first time and 76 first time it's called, and returns those tables the first time and
77 thereafter. This reduces the size of the code by about 2K bytes, in 77 thereafter. This reduces the size of the code by about 2K bytes, in
78 exchange for a little execution time. However, BUILDFIXED should not be 78 exchange for a little execution time. However, BUILDFIXED should not be
79 used for threaded applications, since the rewriting of the tables and virgin 79 used for threaded applications, since the rewriting of the tables and virgin
80 may not be thread-safe. 80 may not be thread-safe.
81 */ 81 */
82local void fixedtables(state) 82local void fixedtables(state)
83struct inflate_state FAR *state; 83struct inflate_state FAR *state;
84{ 84{
85#ifdef BUILDFIXED 85#ifdef BUILDFIXED
86 static int virgin = 1; 86 static int virgin = 1;
87 static code *lenfix, *distfix; 87 static code *lenfix, *distfix;
88 static code fixed[544]; 88 static code fixed[544];
89 89
90 /* build fixed huffman tables if first call (may not be thread safe) */ 90 /* build fixed huffman tables if first call (may not be thread safe) */
91 if (virgin) { 91 if (virgin) {
92 unsigned sym, bits; 92 unsigned sym, bits;
93 static code *next; 93 static code *next;
94 94
95 /* literal/length table */ 95 /* literal/length table */
96 sym = 0; 96 sym = 0;
97 while (sym < 144) state->lens[sym++] = 8; 97 while (sym < 144) state->lens[sym++] = 8;
98 while (sym < 256) state->lens[sym++] = 9; 98 while (sym < 256) state->lens[sym++] = 9;
99 while (sym < 280) state->lens[sym++] = 7; 99 while (sym < 280) state->lens[sym++] = 7;
100 while (sym < 288) state->lens[sym++] = 8; 100 while (sym < 288) state->lens[sym++] = 8;
101 next = fixed; 101 next = fixed;
102 lenfix = next; 102 lenfix = next;
103 bits = 9; 103 bits = 9;
104 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); 104 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
105 105
106 /* distance table */ 106 /* distance table */
107 sym = 0; 107 sym = 0;
108 while (sym < 32) state->lens[sym++] = 5; 108 while (sym < 32) state->lens[sym++] = 5;
109 distfix = next; 109 distfix = next;
110 bits = 5; 110 bits = 5;
111 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); 111 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
112 112
113 /* do this just once */ 113 /* do this just once */
114 virgin = 0; 114 virgin = 0;
115 } 115 }
116#else /* !BUILDFIXED */ 116#else /* !BUILDFIXED */
117# include "inffixed.h" 117# include "inffixed.h"
118#endif /* BUILDFIXED */ 118#endif /* BUILDFIXED */
119 state->lencode = lenfix; 119 state->lencode = lenfix;
120 state->lenbits = 9; 120 state->lenbits = 9;
121 state->distcode = distfix; 121 state->distcode = distfix;
122 state->distbits = 5; 122 state->distbits = 5;
123} 123}
124 124
125/* Macros for inflateBack(): */ 125/* Macros for inflateBack(): */
126 126
127/* Load returned state from inflate_fast() */ 127/* Load returned state from inflate_fast() */
128#define LOAD() \ 128#define LOAD() \
129 do { \ 129 do { \
130 put = strm->next_out; \ 130 put = strm->next_out; \
131 left = strm->avail_out; \ 131 left = strm->avail_out; \
132 next = strm->next_in; \ 132 next = strm->next_in; \
133 have = strm->avail_in; \ 133 have = strm->avail_in; \
134 hold = state->hold; \ 134 hold = state->hold; \
135 bits = state->bits; \ 135 bits = state->bits; \
136 } while (0) 136 } while (0)
137 137
138/* Set state from registers for inflate_fast() */ 138/* Set state from registers for inflate_fast() */
139#define RESTORE() \ 139#define RESTORE() \
140 do { \ 140 do { \
141 strm->next_out = put; \ 141 strm->next_out = put; \
142 strm->avail_out = left; \ 142 strm->avail_out = left; \
143 strm->next_in = next; \ 143 strm->next_in = next; \
144 strm->avail_in = have; \ 144 strm->avail_in = have; \
145 state->hold = hold; \ 145 state->hold = hold; \
146 state->bits = bits; \ 146 state->bits = bits; \
147 } while (0) 147 } while (0)
148 148
149/* Clear the input bit accumulator */ 149/* Clear the input bit accumulator */
150#define INITBITS() \ 150#define INITBITS() \
151 do { \ 151 do { \
152 hold = 0; \ 152 hold = 0; \
153 bits = 0; \ 153 bits = 0; \
154 } while (0) 154 } while (0)
155 155
156/* Assure that some input is available. If input is requested, but denied, 156/* Assure that some input is available. If input is requested, but denied,
157 then return a Z_BUF_ERROR from inflateBack(). */ 157 then return a Z_BUF_ERROR from inflateBack(). */
158#define PULL() \ 158#define PULL() \
159 do { \ 159 do { \
160 if (have == 0) { \ 160 if (have == 0) { \
161 have = in(in_desc, &next); \ 161 have = in(in_desc, &next); \
162 if (have == 0) { \ 162 if (have == 0) { \
163 next = Z_NULL; \ 163 next = Z_NULL; \
164 ret = Z_BUF_ERROR; \ 164 ret = Z_BUF_ERROR; \
165 goto inf_leave; \ 165 goto inf_leave; \
166 } \ 166 } \
167 } \ 167 } \
168 } while (0) 168 } while (0)
169 169
170/* Get a byte of input into the bit accumulator, or return from inflateBack() 170/* Get a byte of input into the bit accumulator, or return from inflateBack()
171 with an error if there is no input available. */ 171 with an error if there is no input available. */
172#define PULLBYTE() \ 172#define PULLBYTE() \
173 do { \ 173 do { \
174 PULL(); \ 174 PULL(); \
175 have--; \ 175 have--; \
176 hold += (unsigned long)(*next++) << bits; \ 176 hold += (unsigned long)(*next++) << bits; \
177 bits += 8; \ 177 bits += 8; \
178 } while (0) 178 } while (0)
179 179
180/* Assure that there are at least n bits in the bit accumulator. If there is 180/* Assure that there are at least n bits in the bit accumulator. If there is
181 not enough available input to do that, then return from inflateBack() with 181 not enough available input to do that, then return from inflateBack() with
182 an error. */ 182 an error. */
183#define NEEDBITS(n) \ 183#define NEEDBITS(n) \
184 do { \ 184 do { \
185 while (bits < (unsigned)(n)) \ 185 while (bits < (unsigned)(n)) \
186 PULLBYTE(); \ 186 PULLBYTE(); \
187 } while (0) 187 } while (0)
188 188
189/* Return the low n bits of the bit accumulator (n < 16) */ 189/* Return the low n bits of the bit accumulator (n < 16) */
190#define BITS(n) \ 190#define BITS(n) \
191 ((unsigned)hold & ((1U << (n)) - 1)) 191 ((unsigned)hold & ((1U << (n)) - 1))
192 192
193/* Remove n bits from the bit accumulator */ 193/* Remove n bits from the bit accumulator */
194#define DROPBITS(n) \ 194#define DROPBITS(n) \
195 do { \ 195 do { \
196 hold >>= (n); \ 196 hold >>= (n); \
197 bits -= (unsigned)(n); \ 197 bits -= (unsigned)(n); \
198 } while (0) 198 } while (0)
199 199
200/* Remove zero to seven bits as needed to go to a byte boundary */ 200/* Remove zero to seven bits as needed to go to a byte boundary */
201#define BYTEBITS() \ 201#define BYTEBITS() \
202 do { \ 202 do { \
203 hold >>= bits & 7; \ 203 hold >>= bits & 7; \
204 bits -= bits & 7; \ 204 bits -= bits & 7; \
205 } while (0) 205 } while (0)
206 206
207/* Assure that some output space is available, by writing out the window 207/* Assure that some output space is available, by writing out the window
208 if it's full. If the write fails, return from inflateBack() with a 208 if it's full. If the write fails, return from inflateBack() with a
209 Z_BUF_ERROR. */ 209 Z_BUF_ERROR. */
210#define ROOM() \ 210#define ROOM() \
211 do { \ 211 do { \
212 if (left == 0) { \ 212 if (left == 0) { \
213 put = state->window; \ 213 put = state->window; \
214 left = state->wsize; \ 214 left = state->wsize; \
215 state->whave = left; \ 215 state->whave = left; \
216 if (out(out_desc, put, left)) { \ 216 if (out(out_desc, put, left)) { \
217 ret = Z_BUF_ERROR; \ 217 ret = Z_BUF_ERROR; \
218 goto inf_leave; \ 218 goto inf_leave; \
219 } \ 219 } \
220 } \ 220 } \
221 } while (0) 221 } while (0)
222 222
223/* 223/*
224 strm provides the memory allocation functions and window buffer on input, 224 strm provides the memory allocation functions and window buffer on input,
225 and provides information on the unused input on return. For Z_DATA_ERROR 225 and provides information on the unused input on return. For Z_DATA_ERROR
226 returns, strm will also provide an error message. 226 returns, strm will also provide an error message.
227 227
228 in() and out() are the call-back input and output functions. When 228 in() and out() are the call-back input and output functions. When
229 inflateBack() needs more input, it calls in(). When inflateBack() has 229 inflateBack() needs more input, it calls in(). When inflateBack() has
230 filled the window with output, or when it completes with data in the 230 filled the window with output, or when it completes with data in the
231 window, it calls out() to write out the data. The application must not 231 window, it calls out() to write out the data. The application must not
232 change the provided input until in() is called again or inflateBack() 232 change the provided input until in() is called again or inflateBack()
233 returns. The application must not change the window/output buffer until 233 returns. The application must not change the window/output buffer until
234 inflateBack() returns. 234 inflateBack() returns.
235 235
236 in() and out() are called with a descriptor parameter provided in the 236 in() and out() are called with a descriptor parameter provided in the
237 inflateBack() call. This parameter can be a structure that provides the 237 inflateBack() call. This parameter can be a structure that provides the
238 information required to do the read or write, as well as accumulated 238 information required to do the read or write, as well as accumulated
239 information on the input and output such as totals and check values. 239 information on the input and output such as totals and check values.
240 240
241 in() should return zero on failure. out() should return non-zero on 241 in() should return zero on failure. out() should return non-zero on
242 failure. If either in() or out() fails, than inflateBack() returns a 242 failure. If either in() or out() fails, than inflateBack() returns a
243 Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it 243 Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
244 was in() or out() that caused in the error. Otherwise, inflateBack() 244 was in() or out() that caused in the error. Otherwise, inflateBack()
245 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format 245 returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
246 error, or Z_MEM_ERROR if it could not allocate memory for the state. 246 error, or Z_MEM_ERROR if it could not allocate memory for the state.
247 inflateBack() can also return Z_STREAM_ERROR if the input parameters 247 inflateBack() can also return Z_STREAM_ERROR if the input parameters
248 are not correct, i.e. strm is Z_NULL or the state was not initialized. 248 are not correct, i.e. strm is Z_NULL or the state was not initialized.
249 */ 249 */
250int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) 250int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
251z_streamp strm; 251z_streamp strm;
252in_func in; 252in_func in;
253void FAR *in_desc; 253void FAR *in_desc;
254out_func out; 254out_func out;
255void FAR *out_desc; 255void FAR *out_desc;
256{ 256{
257 struct inflate_state FAR *state; 257 struct inflate_state FAR *state;
258 unsigned char FAR *next; /* next input */ 258 unsigned char FAR *next; /* next input */
259 unsigned char FAR *put; /* next output */ 259 unsigned char FAR *put; /* next output */
260 unsigned have, left; /* available input and output */ 260 unsigned have, left; /* available input and output */
261 unsigned long hold; /* bit buffer */ 261 unsigned long hold; /* bit buffer */
262 unsigned bits; /* bits in bit buffer */ 262 unsigned bits; /* bits in bit buffer */
263 unsigned copy; /* number of stored or match bytes to copy */ 263 unsigned copy; /* number of stored or match bytes to copy */
264 unsigned char FAR *from; /* where to copy match bytes from */ 264 unsigned char FAR *from; /* where to copy match bytes from */
265 code here; /* current decoding table entry */ 265 code here; /* current decoding table entry */
266 code last; /* parent table entry */ 266 code last; /* parent table entry */
267 unsigned len; /* length to copy for repeats, bits to drop */ 267 unsigned len; /* length to copy for repeats, bits to drop */
268 int ret; /* return code */ 268 int ret; /* return code */
269 static const unsigned short order[19] = /* permutation of code lengths */ 269 static const unsigned short order[19] = /* permutation of code lengths */
270 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 270 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
271 271
272 /* Check that the strm exists and that the state was initialized */ 272 /* Check that the strm exists and that the state was initialized */
273 if (strm == Z_NULL || strm->state == Z_NULL) 273 if (strm == Z_NULL || strm->state == Z_NULL)
274 return Z_STREAM_ERROR; 274 return Z_STREAM_ERROR;
275 state = (struct inflate_state FAR *)strm->state; 275 state = (struct inflate_state FAR *)strm->state;
276 276
277 /* Reset the state */ 277 /* Reset the state */
278 strm->msg = Z_NULL; 278 strm->msg = Z_NULL;
279 state->mode = TYPE; 279 state->mode = TYPE;
280 state->last = 0; 280 state->last = 0;
281 state->whave = 0; 281 state->whave = 0;
282 next = strm->next_in; 282 next = strm->next_in;
283 have = next != Z_NULL ? strm->avail_in : 0; 283 have = next != Z_NULL ? strm->avail_in : 0;
284 hold = 0; 284 hold = 0;
285 bits = 0; 285 bits = 0;
286 put = state->window; 286 put = state->window;
287 left = state->wsize; 287 left = state->wsize;
288 288
289 /* Inflate until end of block marked as last */ 289 /* Inflate until end of block marked as last */
290 for (;;) 290 for (;;)
291 switch (state->mode) { 291 switch (state->mode) {
292 case TYPE: 292 case TYPE:
293 /* determine and dispatch block type */ 293 /* determine and dispatch block type */
294 if (state->last) { 294 if (state->last) {
295 BYTEBITS(); 295 BYTEBITS();
296 state->mode = DONE; 296 state->mode = DONE;
297 break; 297 break;
298 } 298 }
299 NEEDBITS(3); 299 NEEDBITS(3);
300 state->last = BITS(1); 300 state->last = BITS(1);
301 DROPBITS(1); 301 DROPBITS(1);
302 switch (BITS(2)) { 302 switch (BITS(2)) {
303 case 0: /* stored block */ 303 case 0: /* stored block */
304 Tracev((stderr, "inflate: stored block%s\n", 304 Tracev((stderr, "inflate: stored block%s\n",
305 state->last ? " (last)" : "")); 305 state->last ? " (last)" : ""));
306 state->mode = STORED; 306 state->mode = STORED;
307 break; 307 break;
308 case 1: /* fixed block */ 308 case 1: /* fixed block */
309 fixedtables(state); 309 fixedtables(state);
310 Tracev((stderr, "inflate: fixed codes block%s\n", 310 Tracev((stderr, "inflate: fixed codes block%s\n",
311 state->last ? " (last)" : "")); 311 state->last ? " (last)" : ""));
312 state->mode = LEN; /* decode codes */ 312 state->mode = LEN; /* decode codes */
313 break; 313 break;
314 case 2: /* dynamic block */ 314 case 2: /* dynamic block */
315 Tracev((stderr, "inflate: dynamic codes block%s\n", 315 Tracev((stderr, "inflate: dynamic codes block%s\n",
316 state->last ? " (last)" : "")); 316 state->last ? " (last)" : ""));
317 state->mode = TABLE; 317 state->mode = TABLE;
318 break; 318 break;
319 case 3: 319 case 3:
320 strm->msg = (char *)"invalid block type"; 320 strm->msg = (char *)"invalid block type";
321 state->mode = BAD; 321 state->mode = BAD;
322 } 322 }
323 DROPBITS(2); 323 DROPBITS(2);
324 break; 324 break;
325 325
326 case STORED: 326 case STORED:
327 /* get and verify stored block length */ 327 /* get and verify stored block length */
328 BYTEBITS(); /* go to byte boundary */ 328 BYTEBITS(); /* go to byte boundary */
329 NEEDBITS(32); 329 NEEDBITS(32);
330 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 330 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
331 strm->msg = (char *)"invalid stored block lengths"; 331 strm->msg = (char *)"invalid stored block lengths";
332 state->mode = BAD; 332 state->mode = BAD;
333 break; 333 break;
334 } 334 }
335 state->length = (unsigned)hold & 0xffff; 335 state->length = (unsigned)hold & 0xffff;
336 Tracev((stderr, "inflate: stored length %u\n", 336 Tracev((stderr, "inflate: stored length %u\n",
337 state->length)); 337 state->length));
338 INITBITS(); 338 INITBITS();
339 339
340 /* copy stored block from input to output */ 340 /* copy stored block from input to output */
341 while (state->length != 0) { 341 while (state->length != 0) {
342 copy = state->length; 342 copy = state->length;
343 PULL(); 343 PULL();
344 ROOM(); 344 ROOM();
345 if (copy > have) copy = have; 345 if (copy > have) copy = have;
346 if (copy > left) copy = left; 346 if (copy > left) copy = left;
347 zmemcpy(put, next, copy); 347 zmemcpy(put, next, copy);
348 have -= copy; 348 have -= copy;
349 next += copy; 349 next += copy;
350 left -= copy; 350 left -= copy;
351 put += copy; 351 put += copy;
352 state->length -= copy; 352 state->length -= copy;
353 } 353 }
354 Tracev((stderr, "inflate: stored end\n")); 354 Tracev((stderr, "inflate: stored end\n"));
355 state->mode = TYPE; 355 state->mode = TYPE;
356 break; 356 break;
357 357
358 case TABLE: 358 case TABLE:
359 /* get dynamic table entries descriptor */ 359 /* get dynamic table entries descriptor */
360 NEEDBITS(14); 360 NEEDBITS(14);
361 state->nlen = BITS(5) + 257; 361 state->nlen = BITS(5) + 257;
362 DROPBITS(5); 362 DROPBITS(5);
363 state->ndist = BITS(5) + 1; 363 state->ndist = BITS(5) + 1;
364 DROPBITS(5); 364 DROPBITS(5);
365 state->ncode = BITS(4) + 4; 365 state->ncode = BITS(4) + 4;
366 DROPBITS(4); 366 DROPBITS(4);
367#ifndef PKZIP_BUG_WORKAROUND 367#ifndef PKZIP_BUG_WORKAROUND
368 if (state->nlen > 286 || state->ndist > 30) { 368 if (state->nlen > 286 || state->ndist > 30) {
369 strm->msg = (char *)"too many length or distance symbols"; 369 strm->msg = (char *)"too many length or distance symbols";
370 state->mode = BAD; 370 state->mode = BAD;
371 break; 371 break;
372 } 372 }
373#endif 373#endif
374 Tracev((stderr, "inflate: table sizes ok\n")); 374 Tracev((stderr, "inflate: table sizes ok\n"));
375 375
376 /* get code length code lengths (not a typo) */ 376 /* get code length code lengths (not a typo) */
377 state->have = 0; 377 state->have = 0;
378 while (state->have < state->ncode) { 378 while (state->have < state->ncode) {
379 NEEDBITS(3); 379 NEEDBITS(3);
380 state->lens[order[state->have++]] = (unsigned short)BITS(3); 380 state->lens[order[state->have++]] = (unsigned short)BITS(3);
381 DROPBITS(3); 381 DROPBITS(3);
382 } 382 }
383 while (state->have < 19) 383 while (state->have < 19)
384 state->lens[order[state->have++]] = 0; 384 state->lens[order[state->have++]] = 0;
385 state->next = state->codes; 385 state->next = state->codes;
386 state->lencode = (code const FAR *)(state->next); 386 state->lencode = (code const FAR *)(state->next);
387 state->lenbits = 7; 387 state->lenbits = 7;
388 ret = inflate_table(CODES, state->lens, 19, &(state->next), 388 ret = inflate_table(CODES, state->lens, 19, &(state->next),
389 &(state->lenbits), state->work); 389 &(state->lenbits), state->work);
390 if (ret) { 390 if (ret) {
391 strm->msg = (char *)"invalid code lengths set"; 391 strm->msg = (char *)"invalid code lengths set";
392 state->mode = BAD; 392 state->mode = BAD;
393 break; 393 break;
394 } 394 }
395 Tracev((stderr, "inflate: code lengths ok\n")); 395 Tracev((stderr, "inflate: code lengths ok\n"));
396 396
397 /* get length and distance code code lengths */ 397 /* get length and distance code code lengths */
398 state->have = 0; 398 state->have = 0;
399 while (state->have < state->nlen + state->ndist) { 399 while (state->have < state->nlen + state->ndist) {
400 for (;;) { 400 for (;;) {
401 here = state->lencode[BITS(state->lenbits)]; 401 here = state->lencode[BITS(state->lenbits)];
402 if ((unsigned)(here.bits) <= bits) break; 402 if ((unsigned)(here.bits) <= bits) break;
403 PULLBYTE(); 403 PULLBYTE();
404 } 404 }
405 if (here.val < 16) { 405 if (here.val < 16) {
406 DROPBITS(here.bits); 406 DROPBITS(here.bits);
407 state->lens[state->have++] = here.val; 407 state->lens[state->have++] = here.val;
408 } 408 }
409 else { 409 else {
410 if (here.val == 16) { 410 if (here.val == 16) {
411 NEEDBITS(here.bits + 2); 411 NEEDBITS(here.bits + 2);
412 DROPBITS(here.bits); 412 DROPBITS(here.bits);
413 if (state->have == 0) { 413 if (state->have == 0) {
414 strm->msg = (char *)"invalid bit length repeat"; 414 strm->msg = (char *)"invalid bit length repeat";
415 state->mode = BAD; 415 state->mode = BAD;
416 break; 416 break;
417 } 417 }
418 len = (unsigned)(state->lens[state->have - 1]); 418 len = (unsigned)(state->lens[state->have - 1]);
419 copy = 3 + BITS(2); 419 copy = 3 + BITS(2);
420 DROPBITS(2); 420 DROPBITS(2);
421 } 421 }
422 else if (here.val == 17) { 422 else if (here.val == 17) {
423 NEEDBITS(here.bits + 3); 423 NEEDBITS(here.bits + 3);
424 DROPBITS(here.bits); 424 DROPBITS(here.bits);
425 len = 0; 425 len = 0;
426 copy = 3 + BITS(3); 426 copy = 3 + BITS(3);
427 DROPBITS(3); 427 DROPBITS(3);
428 } 428 }
429 else { 429 else {
430 NEEDBITS(here.bits + 7); 430 NEEDBITS(here.bits + 7);
431 DROPBITS(here.bits); 431 DROPBITS(here.bits);
432 len = 0; 432 len = 0;
433 copy = 11 + BITS(7); 433 copy = 11 + BITS(7);
434 DROPBITS(7); 434 DROPBITS(7);
435 } 435 }
436 if (state->have + copy > state->nlen + state->ndist) { 436 if (state->have + copy > state->nlen + state->ndist) {
437 strm->msg = (char *)"invalid bit length repeat"; 437 strm->msg = (char *)"invalid bit length repeat";
438 state->mode = BAD; 438 state->mode = BAD;
439 break; 439 break;
440 } 440 }
441 while (copy--) 441 while (copy--)
442 state->lens[state->have++] = (unsigned short)len; 442 state->lens[state->have++] = (unsigned short)len;
443 } 443 }
444 } 444 }
445 445
446 /* handle error breaks in while */ 446 /* handle error breaks in while */
447 if (state->mode == BAD) break; 447 if (state->mode == BAD) break;
448 448
449 /* check for end-of-block code (better have one) */ 449 /* check for end-of-block code (better have one) */
450 if (state->lens[256] == 0) { 450 if (state->lens[256] == 0) {
451 strm->msg = (char *)"invalid code -- missing end-of-block"; 451 strm->msg = (char *)"invalid code -- missing end-of-block";
452 state->mode = BAD; 452 state->mode = BAD;
453 break; 453 break;
454 } 454 }
455 455
456 /* build code tables -- note: do not change the lenbits or distbits 456 /* build code tables -- note: do not change the lenbits or distbits
457 values here (9 and 6) without reading the comments in inftrees.h 457 values here (9 and 6) without reading the comments in inftrees.h
458 concerning the ENOUGH constants, which depend on those values */ 458 concerning the ENOUGH constants, which depend on those values */
459 state->next = state->codes; 459 state->next = state->codes;
460 state->lencode = (code const FAR *)(state->next); 460 state->lencode = (code const FAR *)(state->next);
461 state->lenbits = 9; 461 state->lenbits = 9;
462 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 462 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
463 &(state->lenbits), state->work); 463 &(state->lenbits), state->work);
464 if (ret) { 464 if (ret) {
465 strm->msg = (char *)"invalid literal/lengths set"; 465 strm->msg = (char *)"invalid literal/lengths set";
466 state->mode = BAD; 466 state->mode = BAD;
467 break; 467 break;
468 } 468 }
469 state->distcode = (code const FAR *)(state->next); 469 state->distcode = (code const FAR *)(state->next);
470 state->distbits = 6; 470 state->distbits = 6;
471 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 471 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
472 &(state->next), &(state->distbits), state->work); 472 &(state->next), &(state->distbits), state->work);
473 if (ret) { 473 if (ret) {
474 strm->msg = (char *)"invalid distances set"; 474 strm->msg = (char *)"invalid distances set";
475 state->mode = BAD; 475 state->mode = BAD;
476 break; 476 break;
477 } 477 }
478 Tracev((stderr, "inflate: codes ok\n")); 478 Tracev((stderr, "inflate: codes ok\n"));
479 state->mode = LEN; 479 state->mode = LEN;
480 480
481 case LEN: 481 case LEN:
482 /* use inflate_fast() if we have enough input and output */ 482 /* use inflate_fast() if we have enough input and output */
483 if (have >= 6 && left >= 258) { 483 if (have >= 6 && left >= 258) {
484 RESTORE(); 484 RESTORE();
485 if (state->whave < state->wsize) 485 if (state->whave < state->wsize)
486 state->whave = state->wsize - left; 486 state->whave = state->wsize - left;
487 inflate_fast(strm, state->wsize); 487 inflate_fast(strm, state->wsize);
488 LOAD(); 488 LOAD();
489 break; 489 break;
490 } 490 }
491 491
492 /* get a literal, length, or end-of-block code */ 492 /* get a literal, length, or end-of-block code */
493 for (;;) { 493 for (;;) {
494 here = state->lencode[BITS(state->lenbits)]; 494 here = state->lencode[BITS(state->lenbits)];
495 if ((unsigned)(here.bits) <= bits) break; 495 if ((unsigned)(here.bits) <= bits) break;
496 PULLBYTE(); 496 PULLBYTE();
497 } 497 }
498 if (here.op && (here.op & 0xf0) == 0) { 498 if (here.op && (here.op & 0xf0) == 0) {
499 last = here; 499 last = here;
500 for (;;) { 500 for (;;) {
501 here = state->lencode[last.val + 501 here = state->lencode[last.val +
502 (BITS(last.bits + last.op) >> last.bits)]; 502 (BITS(last.bits + last.op) >> last.bits)];
503 if ((unsigned)(last.bits + here.bits) <= bits) break; 503 if ((unsigned)(last.bits + here.bits) <= bits) break;
504 PULLBYTE(); 504 PULLBYTE();
505 } 505 }
506 DROPBITS(last.bits); 506 DROPBITS(last.bits);
507 } 507 }
508 DROPBITS(here.bits); 508 DROPBITS(here.bits);
509 state->length = (unsigned)here.val; 509 state->length = (unsigned)here.val;
510 510
511 /* process literal */ 511 /* process literal */
512 if (here.op == 0) { 512 if (here.op == 0) {
513 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 513 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
514 "inflate: literal '%c'\n" : 514 "inflate: literal '%c'\n" :
515 "inflate: literal 0x%02x\n", here.val)); 515 "inflate: literal 0x%02x\n", here.val));
516 ROOM(); 516 ROOM();
517 *put++ = (unsigned char)(state->length); 517 *put++ = (unsigned char)(state->length);
518 left--; 518 left--;
519 state->mode = LEN; 519 state->mode = LEN;
520 break; 520 break;
521 } 521 }
522 522
523 /* process end of block */ 523 /* process end of block */
524 if (here.op & 32) { 524 if (here.op & 32) {
525 Tracevv((stderr, "inflate: end of block\n")); 525 Tracevv((stderr, "inflate: end of block\n"));
526 state->mode = TYPE; 526 state->mode = TYPE;
527 break; 527 break;
528 } 528 }
529 529
530 /* invalid code */ 530 /* invalid code */
531 if (here.op & 64) { 531 if (here.op & 64) {
532 strm->msg = (char *)"invalid literal/length code"; 532 strm->msg = (char *)"invalid literal/length code";
533 state->mode = BAD; 533 state->mode = BAD;
534 break; 534 break;
535 } 535 }
536 536
537 /* length code -- get extra bits, if any */ 537 /* length code -- get extra bits, if any */
538 state->extra = (unsigned)(here.op) & 15; 538 state->extra = (unsigned)(here.op) & 15;
539 if (state->extra != 0) { 539 if (state->extra != 0) {
540 NEEDBITS(state->extra); 540 NEEDBITS(state->extra);
541 state->length += BITS(state->extra); 541 state->length += BITS(state->extra);
542 DROPBITS(state->extra); 542 DROPBITS(state->extra);
543 } 543 }
544 Tracevv((stderr, "inflate: length %u\n", state->length)); 544 Tracevv((stderr, "inflate: length %u\n", state->length));
545 545
546 /* get distance code */ 546 /* get distance code */
547 for (;;) { 547 for (;;) {
548 here = state->distcode[BITS(state->distbits)]; 548 here = state->distcode[BITS(state->distbits)];
549 if ((unsigned)(here.bits) <= bits) break; 549 if ((unsigned)(here.bits) <= bits) break;
550 PULLBYTE(); 550 PULLBYTE();
551 } 551 }
552 if ((here.op & 0xf0) == 0) { 552 if ((here.op & 0xf0) == 0) {
553 last = here; 553 last = here;
554 for (;;) { 554 for (;;) {
555 here = state->distcode[last.val + 555 here = state->distcode[last.val +
556 (BITS(last.bits + last.op) >> last.bits)]; 556 (BITS(last.bits + last.op) >> last.bits)];
557 if ((unsigned)(last.bits + here.bits) <= bits) break; 557 if ((unsigned)(last.bits + here.bits) <= bits) break;
558 PULLBYTE(); 558 PULLBYTE();
559 } 559 }
560 DROPBITS(last.bits); 560 DROPBITS(last.bits);
561 } 561 }
562 DROPBITS(here.bits); 562 DROPBITS(here.bits);
563 if (here.op & 64) { 563 if (here.op & 64) {
564 strm->msg = (char *)"invalid distance code"; 564 strm->msg = (char *)"invalid distance code";
565 state->mode = BAD; 565 state->mode = BAD;
566 break; 566 break;
567 } 567 }
568 state->offset = (unsigned)here.val; 568 state->offset = (unsigned)here.val;
569 569
570 /* get distance extra bits, if any */ 570 /* get distance extra bits, if any */
571 state->extra = (unsigned)(here.op) & 15; 571 state->extra = (unsigned)(here.op) & 15;
572 if (state->extra != 0) { 572 if (state->extra != 0) {
573 NEEDBITS(state->extra); 573 NEEDBITS(state->extra);
574 state->offset += BITS(state->extra); 574 state->offset += BITS(state->extra);
575 DROPBITS(state->extra); 575 DROPBITS(state->extra);
576 } 576 }
577 if (state->offset > state->wsize - (state->whave < state->wsize ? 577 if (state->offset > state->wsize - (state->whave < state->wsize ?
578 left : 0)) { 578 left : 0)) {
579 strm->msg = (char *)"invalid distance too far back"; 579 strm->msg = (char *)"invalid distance too far back";
580 state->mode = BAD; 580 state->mode = BAD;
581 break; 581 break;
582 } 582 }
583 Tracevv((stderr, "inflate: distance %u\n", state->offset)); 583 Tracevv((stderr, "inflate: distance %u\n", state->offset));
584 584
585 /* copy match from window to output */ 585 /* copy match from window to output */
586 do { 586 do {
587 ROOM(); 587 ROOM();
588 copy = state->wsize - state->offset; 588 copy = state->wsize - state->offset;
589 if (copy < left) { 589 if (copy < left) {
590 from = put + copy; 590 from = put + copy;
591 copy = left - copy; 591 copy = left - copy;
592 } 592 }
593 else { 593 else {
594 from = put - state->offset; 594 from = put - state->offset;
595 copy = left; 595 copy = left;
596 } 596 }
597 if (copy > state->length) copy = state->length; 597 if (copy > state->length) copy = state->length;
598 state->length -= copy; 598 state->length -= copy;
599 left -= copy; 599 left -= copy;
600 do { 600 do {
601 *put++ = *from++; 601 *put++ = *from++;
602 } while (--copy); 602 } while (--copy);
603 } while (state->length != 0); 603 } while (state->length != 0);
604 break; 604 break;
605 605
606 case DONE: 606 case DONE:
607 /* inflate stream terminated properly -- write leftover output */ 607 /* inflate stream terminated properly -- write leftover output */
608 ret = Z_STREAM_END; 608 ret = Z_STREAM_END;
609 if (left < state->wsize) { 609 if (left < state->wsize) {
610 if (out(out_desc, state->window, state->wsize - left)) 610 if (out(out_desc, state->window, state->wsize - left))
611 ret = Z_BUF_ERROR; 611 ret = Z_BUF_ERROR;
612 } 612 }
613 goto inf_leave; 613 goto inf_leave;
614 614
615 case BAD: 615 case BAD:
616 ret = Z_DATA_ERROR; 616 ret = Z_DATA_ERROR;
617 goto inf_leave; 617 goto inf_leave;
618 618
619 default: /* can't happen, but makes compilers happy */ 619 default: /* can't happen, but makes compilers happy */
620 ret = Z_STREAM_ERROR; 620 ret = Z_STREAM_ERROR;
621 goto inf_leave; 621 goto inf_leave;
622 } 622 }
623 623
624 /* Return unused input */ 624 /* Return unused input */
625 inf_leave: 625 inf_leave:
626 strm->next_in = next; 626 strm->next_in = next;
627 strm->avail_in = have; 627 strm->avail_in = have;
628 return ret; 628 return ret;
629} 629}
630 630
631int ZEXPORT inflateBackEnd(strm) 631int ZEXPORT inflateBackEnd(strm)
632z_streamp strm; 632z_streamp strm;
633{ 633{
634 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 634 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
635 return Z_STREAM_ERROR; 635 return Z_STREAM_ERROR;
636 ZFREE(strm, strm->state); 636 ZFREE(strm, strm->state);
637 strm->state = Z_NULL; 637 strm->state = Z_NULL;
638 Tracev((stderr, "inflate: end\n")); 638 Tracev((stderr, "inflate: end\n"));
639 return Z_OK; 639 return Z_OK;
640} 640}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.c
index 2dfd412..2f1d60b 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.c
@@ -1,340 +1,340 @@
1/* inffast.c -- fast decoding 1/* inffast.c -- fast decoding
2 * Copyright (C) 1995-2008, 2010 Mark Adler 2 * Copyright (C) 1995-2008, 2010 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6#include "zutil.h" 6#include "zutil.h"
7#include "inftrees.h" 7#include "inftrees.h"
8#include "inflate.h" 8#include "inflate.h"
9#include "inffast.h" 9#include "inffast.h"
10 10
11#ifndef ASMINF 11#ifndef ASMINF
12 12
13/* Allow machine dependent optimization for post-increment or pre-increment. 13/* Allow machine dependent optimization for post-increment or pre-increment.
14 Based on testing to date, 14 Based on testing to date,
15 Pre-increment preferred for: 15 Pre-increment preferred for:
16 - PowerPC G3 (Adler) 16 - PowerPC G3 (Adler)
17 - MIPS R5000 (Randers-Pehrson) 17 - MIPS R5000 (Randers-Pehrson)
18 Post-increment preferred for: 18 Post-increment preferred for:
19 - none 19 - none
20 No measurable difference: 20 No measurable difference:
21 - Pentium III (Anderson) 21 - Pentium III (Anderson)
22 - M68060 (Nikl) 22 - M68060 (Nikl)
23 */ 23 */
24#ifdef POSTINC 24#ifdef POSTINC
25# define OFF 0 25# define OFF 0
26# define PUP(a) *(a)++ 26# define PUP(a) *(a)++
27#else 27#else
28# define OFF 1 28# define OFF 1
29# define PUP(a) *++(a) 29# define PUP(a) *++(a)
30#endif 30#endif
31 31
32/* 32/*
33 Decode literal, length, and distance codes and write out the resulting 33 Decode literal, length, and distance codes and write out the resulting
34 literal and match bytes until either not enough input or output is 34 literal and match bytes until either not enough input or output is
35 available, an end-of-block is encountered, or a data error is encountered. 35 available, an end-of-block is encountered, or a data error is encountered.
36 When large enough input and output buffers are supplied to inflate(), for 36 When large enough input and output buffers are supplied to inflate(), for
37 example, a 16K input buffer and a 64K output buffer, more than 95% of the 37 example, a 16K input buffer and a 64K output buffer, more than 95% of the
38 inflate execution time is spent in this routine. 38 inflate execution time is spent in this routine.
39 39
40 Entry assumptions: 40 Entry assumptions:
41 41
42 state->mode == LEN 42 state->mode == LEN
43 strm->avail_in >= 6 43 strm->avail_in >= 6
44 strm->avail_out >= 258 44 strm->avail_out >= 258
45 start >= strm->avail_out 45 start >= strm->avail_out
46 state->bits < 8 46 state->bits < 8
47 47
48 On return, state->mode is one of: 48 On return, state->mode is one of:
49 49
50 LEN -- ran out of enough output space or enough available input 50 LEN -- ran out of enough output space or enough available input
51 TYPE -- reached end of block code, inflate() to interpret next block 51 TYPE -- reached end of block code, inflate() to interpret next block
52 BAD -- error in block data 52 BAD -- error in block data
53 53
54 Notes: 54 Notes:
55 55
56 - The maximum input bits used by a length/distance pair is 15 bits for the 56 - The maximum input bits used by a length/distance pair is 15 bits for the
57 length code, 5 bits for the length extra, 15 bits for the distance code, 57 length code, 5 bits for the length extra, 15 bits for the distance code,
58 and 13 bits for the distance extra. This totals 48 bits, or six bytes. 58 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
59 Therefore if strm->avail_in >= 6, then there is enough input to avoid 59 Therefore if strm->avail_in >= 6, then there is enough input to avoid
60 checking for available input while decoding. 60 checking for available input while decoding.
61 61
62 - The maximum bytes that a single length/distance pair can output is 258 62 - The maximum bytes that a single length/distance pair can output is 258
63 bytes, which is the maximum length that can be coded. inflate_fast() 63 bytes, which is the maximum length that can be coded. inflate_fast()
64 requires strm->avail_out >= 258 for each loop to avoid checking for 64 requires strm->avail_out >= 258 for each loop to avoid checking for
65 output space. 65 output space.
66 */ 66 */
67void ZLIB_INTERNAL inflate_fast(strm, start) 67void ZLIB_INTERNAL inflate_fast(strm, start)
68z_streamp strm; 68z_streamp strm;
69unsigned start; /* inflate()'s starting value for strm->avail_out */ 69unsigned start; /* inflate()'s starting value for strm->avail_out */
70{ 70{
71 struct inflate_state FAR *state; 71 struct inflate_state FAR *state;
72 unsigned char FAR *in; /* local strm->next_in */ 72 unsigned char FAR *in; /* local strm->next_in */
73 unsigned char FAR *last; /* while in < last, enough input available */ 73 unsigned char FAR *last; /* while in < last, enough input available */
74 unsigned char FAR *out; /* local strm->next_out */ 74 unsigned char FAR *out; /* local strm->next_out */
75 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 75 unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
76 unsigned char FAR *end; /* while out < end, enough space available */ 76 unsigned char FAR *end; /* while out < end, enough space available */
77#ifdef INFLATE_STRICT 77#ifdef INFLATE_STRICT
78 unsigned dmax; /* maximum distance from zlib header */ 78 unsigned dmax; /* maximum distance from zlib header */
79#endif 79#endif
80 unsigned wsize; /* window size or zero if not using window */ 80 unsigned wsize; /* window size or zero if not using window */
81 unsigned whave; /* valid bytes in the window */ 81 unsigned whave; /* valid bytes in the window */
82 unsigned wnext; /* window write index */ 82 unsigned wnext; /* window write index */
83 unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ 83 unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
84 unsigned long hold; /* local strm->hold */ 84 unsigned long hold; /* local strm->hold */
85 unsigned bits; /* local strm->bits */ 85 unsigned bits; /* local strm->bits */
86 code const FAR *lcode; /* local strm->lencode */ 86 code const FAR *lcode; /* local strm->lencode */
87 code const FAR *dcode; /* local strm->distcode */ 87 code const FAR *dcode; /* local strm->distcode */
88 unsigned lmask; /* mask for first level of length codes */ 88 unsigned lmask; /* mask for first level of length codes */
89 unsigned dmask; /* mask for first level of distance codes */ 89 unsigned dmask; /* mask for first level of distance codes */
90 code here; /* retrieved table entry */ 90 code here; /* retrieved table entry */
91 unsigned op; /* code bits, operation, extra bits, or */ 91 unsigned op; /* code bits, operation, extra bits, or */
92 /* window position, window bytes to copy */ 92 /* window position, window bytes to copy */
93 unsigned len; /* match length, unused bytes */ 93 unsigned len; /* match length, unused bytes */
94 unsigned dist; /* match distance */ 94 unsigned dist; /* match distance */
95 unsigned char FAR *from; /* where to copy match from */ 95 unsigned char FAR *from; /* where to copy match from */
96 96
97 /* copy state to local variables */ 97 /* copy state to local variables */
98 state = (struct inflate_state FAR *)strm->state; 98 state = (struct inflate_state FAR *)strm->state;
99 in = strm->next_in - OFF; 99 in = strm->next_in - OFF;
100 last = in + (strm->avail_in - 5); 100 last = in + (strm->avail_in - 5);
101 out = strm->next_out - OFF; 101 out = strm->next_out - OFF;
102 beg = out - (start - strm->avail_out); 102 beg = out - (start - strm->avail_out);
103 end = out + (strm->avail_out - 257); 103 end = out + (strm->avail_out - 257);
104#ifdef INFLATE_STRICT 104#ifdef INFLATE_STRICT
105 dmax = state->dmax; 105 dmax = state->dmax;
106#endif 106#endif
107 wsize = state->wsize; 107 wsize = state->wsize;
108 whave = state->whave; 108 whave = state->whave;
109 wnext = state->wnext; 109 wnext = state->wnext;
110 window = state->window; 110 window = state->window;
111 hold = state->hold; 111 hold = state->hold;
112 bits = state->bits; 112 bits = state->bits;
113 lcode = state->lencode; 113 lcode = state->lencode;
114 dcode = state->distcode; 114 dcode = state->distcode;
115 lmask = (1U << state->lenbits) - 1; 115 lmask = (1U << state->lenbits) - 1;
116 dmask = (1U << state->distbits) - 1; 116 dmask = (1U << state->distbits) - 1;
117 117
118 /* decode literals and length/distances until end-of-block or not enough 118 /* decode literals and length/distances until end-of-block or not enough
119 input data or output space */ 119 input data or output space */
120 do { 120 do {
121 if (bits < 15) { 121 if (bits < 15) {
122 hold += (unsigned long)(PUP(in)) << bits; 122 hold += (unsigned long)(PUP(in)) << bits;
123 bits += 8; 123 bits += 8;
124 hold += (unsigned long)(PUP(in)) << bits; 124 hold += (unsigned long)(PUP(in)) << bits;
125 bits += 8; 125 bits += 8;
126 } 126 }
127 here = lcode[hold & lmask]; 127 here = lcode[hold & lmask];
128 dolen: 128 dolen:
129 op = (unsigned)(here.bits); 129 op = (unsigned)(here.bits);
130 hold >>= op; 130 hold >>= op;
131 bits -= op; 131 bits -= op;
132 op = (unsigned)(here.op); 132 op = (unsigned)(here.op);
133 if (op == 0) { /* literal */ 133 if (op == 0) { /* literal */
134 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 134 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
135 "inflate: literal '%c'\n" : 135 "inflate: literal '%c'\n" :
136 "inflate: literal 0x%02x\n", here.val)); 136 "inflate: literal 0x%02x\n", here.val));
137 PUP(out) = (unsigned char)(here.val); 137 PUP(out) = (unsigned char)(here.val);
138 } 138 }
139 else if (op & 16) { /* length base */ 139 else if (op & 16) { /* length base */
140 len = (unsigned)(here.val); 140 len = (unsigned)(here.val);
141 op &= 15; /* number of extra bits */ 141 op &= 15; /* number of extra bits */
142 if (op) { 142 if (op) {
143 if (bits < op) { 143 if (bits < op) {
144 hold += (unsigned long)(PUP(in)) << bits; 144 hold += (unsigned long)(PUP(in)) << bits;
145 bits += 8; 145 bits += 8;
146 } 146 }
147 len += (unsigned)hold & ((1U << op) - 1); 147 len += (unsigned)hold & ((1U << op) - 1);
148 hold >>= op; 148 hold >>= op;
149 bits -= op; 149 bits -= op;
150 } 150 }
151 Tracevv((stderr, "inflate: length %u\n", len)); 151 Tracevv((stderr, "inflate: length %u\n", len));
152 if (bits < 15) { 152 if (bits < 15) {
153 hold += (unsigned long)(PUP(in)) << bits; 153 hold += (unsigned long)(PUP(in)) << bits;
154 bits += 8; 154 bits += 8;
155 hold += (unsigned long)(PUP(in)) << bits; 155 hold += (unsigned long)(PUP(in)) << bits;
156 bits += 8; 156 bits += 8;
157 } 157 }
158 here = dcode[hold & dmask]; 158 here = dcode[hold & dmask];
159 dodist: 159 dodist:
160 op = (unsigned)(here.bits); 160 op = (unsigned)(here.bits);
161 hold >>= op; 161 hold >>= op;
162 bits -= op; 162 bits -= op;
163 op = (unsigned)(here.op); 163 op = (unsigned)(here.op);
164 if (op & 16) { /* distance base */ 164 if (op & 16) { /* distance base */
165 dist = (unsigned)(here.val); 165 dist = (unsigned)(here.val);
166 op &= 15; /* number of extra bits */ 166 op &= 15; /* number of extra bits */
167 if (bits < op) { 167 if (bits < op) {
168 hold += (unsigned long)(PUP(in)) << bits; 168 hold += (unsigned long)(PUP(in)) << bits;
169 bits += 8; 169 bits += 8;
170 if (bits < op) { 170 if (bits < op) {
171 hold += (unsigned long)(PUP(in)) << bits; 171 hold += (unsigned long)(PUP(in)) << bits;
172 bits += 8; 172 bits += 8;
173 } 173 }
174 } 174 }
175 dist += (unsigned)hold & ((1U << op) - 1); 175 dist += (unsigned)hold & ((1U << op) - 1);
176#ifdef INFLATE_STRICT 176#ifdef INFLATE_STRICT
177 if (dist > dmax) { 177 if (dist > dmax) {
178 strm->msg = (char *)"invalid distance too far back"; 178 strm->msg = (char *)"invalid distance too far back";
179 state->mode = BAD; 179 state->mode = BAD;
180 break; 180 break;
181 } 181 }
182#endif 182#endif
183 hold >>= op; 183 hold >>= op;
184 bits -= op; 184 bits -= op;
185 Tracevv((stderr, "inflate: distance %u\n", dist)); 185 Tracevv((stderr, "inflate: distance %u\n", dist));
186 op = (unsigned)(out - beg); /* max distance in output */ 186 op = (unsigned)(out - beg); /* max distance in output */
187 if (dist > op) { /* see if copy from window */ 187 if (dist > op) { /* see if copy from window */
188 op = dist - op; /* distance back in window */ 188 op = dist - op; /* distance back in window */
189 if (op > whave) { 189 if (op > whave) {
190 if (state->sane) { 190 if (state->sane) {
191 strm->msg = 191 strm->msg =
192 (char *)"invalid distance too far back"; 192 (char *)"invalid distance too far back";
193 state->mode = BAD; 193 state->mode = BAD;
194 break; 194 break;
195 } 195 }
196#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 196#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
197 if (len <= op - whave) { 197 if (len <= op - whave) {
198 do { 198 do {
199 PUP(out) = 0; 199 PUP(out) = 0;
200 } while (--len); 200 } while (--len);
201 continue; 201 continue;
202 } 202 }
203 len -= op - whave; 203 len -= op - whave;
204 do { 204 do {
205 PUP(out) = 0; 205 PUP(out) = 0;
206 } while (--op > whave); 206 } while (--op > whave);
207 if (op == 0) { 207 if (op == 0) {
208 from = out - dist; 208 from = out - dist;
209 do { 209 do {
210 PUP(out) = PUP(from); 210 PUP(out) = PUP(from);
211 } while (--len); 211 } while (--len);
212 continue; 212 continue;
213 } 213 }
214#endif 214#endif
215 } 215 }
216 from = window - OFF; 216 from = window - OFF;
217 if (wnext == 0) { /* very common case */ 217 if (wnext == 0) { /* very common case */
218 from += wsize - op; 218 from += wsize - op;
219 if (op < len) { /* some from window */ 219 if (op < len) { /* some from window */
220 len -= op; 220 len -= op;
221 do { 221 do {
222 PUP(out) = PUP(from); 222 PUP(out) = PUP(from);
223 } while (--op); 223 } while (--op);
224 from = out - dist; /* rest from output */ 224 from = out - dist; /* rest from output */
225 } 225 }
226 } 226 }
227 else if (wnext < op) { /* wrap around window */ 227 else if (wnext < op) { /* wrap around window */
228 from += wsize + wnext - op; 228 from += wsize + wnext - op;
229 op -= wnext; 229 op -= wnext;
230 if (op < len) { /* some from end of window */ 230 if (op < len) { /* some from end of window */
231 len -= op; 231 len -= op;
232 do { 232 do {
233 PUP(out) = PUP(from); 233 PUP(out) = PUP(from);
234 } while (--op); 234 } while (--op);
235 from = window - OFF; 235 from = window - OFF;
236 if (wnext < len) { /* some from start of window */ 236 if (wnext < len) { /* some from start of window */
237 op = wnext; 237 op = wnext;
238 len -= op; 238 len -= op;
239 do { 239 do {
240 PUP(out) = PUP(from); 240 PUP(out) = PUP(from);
241 } while (--op); 241 } while (--op);
242 from = out - dist; /* rest from output */ 242 from = out - dist; /* rest from output */
243 } 243 }
244 } 244 }
245 } 245 }
246 else { /* contiguous in window */ 246 else { /* contiguous in window */
247 from += wnext - op; 247 from += wnext - op;
248 if (op < len) { /* some from window */ 248 if (op < len) { /* some from window */
249 len -= op; 249 len -= op;
250 do { 250 do {
251 PUP(out) = PUP(from); 251 PUP(out) = PUP(from);
252 } while (--op); 252 } while (--op);
253 from = out - dist; /* rest from output */ 253 from = out - dist; /* rest from output */
254 } 254 }
255 } 255 }
256 while (len > 2) { 256 while (len > 2) {
257 PUP(out) = PUP(from); 257 PUP(out) = PUP(from);
258 PUP(out) = PUP(from); 258 PUP(out) = PUP(from);
259 PUP(out) = PUP(from); 259 PUP(out) = PUP(from);
260 len -= 3; 260 len -= 3;
261 } 261 }
262 if (len) { 262 if (len) {
263 PUP(out) = PUP(from); 263 PUP(out) = PUP(from);
264 if (len > 1) 264 if (len > 1)
265 PUP(out) = PUP(from); 265 PUP(out) = PUP(from);
266 } 266 }
267 } 267 }
268 else { 268 else {
269 from = out - dist; /* copy direct from output */ 269 from = out - dist; /* copy direct from output */
270 do { /* minimum length is three */ 270 do { /* minimum length is three */
271 PUP(out) = PUP(from); 271 PUP(out) = PUP(from);
272 PUP(out) = PUP(from); 272 PUP(out) = PUP(from);
273 PUP(out) = PUP(from); 273 PUP(out) = PUP(from);
274 len -= 3; 274 len -= 3;
275 } while (len > 2); 275 } while (len > 2);
276 if (len) { 276 if (len) {
277 PUP(out) = PUP(from); 277 PUP(out) = PUP(from);
278 if (len > 1) 278 if (len > 1)
279 PUP(out) = PUP(from); 279 PUP(out) = PUP(from);
280 } 280 }
281 } 281 }
282 } 282 }
283 else if ((op & 64) == 0) { /* 2nd level distance code */ 283 else if ((op & 64) == 0) { /* 2nd level distance code */
284 here = dcode[here.val + (hold & ((1U << op) - 1))]; 284 here = dcode[here.val + (hold & ((1U << op) - 1))];
285 goto dodist; 285 goto dodist;
286 } 286 }
287 else { 287 else {
288 strm->msg = (char *)"invalid distance code"; 288 strm->msg = (char *)"invalid distance code";
289 state->mode = BAD; 289 state->mode = BAD;
290 break; 290 break;
291 } 291 }
292 } 292 }
293 else if ((op & 64) == 0) { /* 2nd level length code */ 293 else if ((op & 64) == 0) { /* 2nd level length code */
294 here = lcode[here.val + (hold & ((1U << op) - 1))]; 294 here = lcode[here.val + (hold & ((1U << op) - 1))];
295 goto dolen; 295 goto dolen;
296 } 296 }
297 else if (op & 32) { /* end-of-block */ 297 else if (op & 32) { /* end-of-block */
298 Tracevv((stderr, "inflate: end of block\n")); 298 Tracevv((stderr, "inflate: end of block\n"));
299 state->mode = TYPE; 299 state->mode = TYPE;
300 break; 300 break;
301 } 301 }
302 else { 302 else {
303 strm->msg = (char *)"invalid literal/length code"; 303 strm->msg = (char *)"invalid literal/length code";
304 state->mode = BAD; 304 state->mode = BAD;
305 break; 305 break;
306 } 306 }
307 } while (in < last && out < end); 307 } while (in < last && out < end);
308 308
309 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 309 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
310 len = bits >> 3; 310 len = bits >> 3;
311 in -= len; 311 in -= len;
312 bits -= len << 3; 312 bits -= len << 3;
313 hold &= (1U << bits) - 1; 313 hold &= (1U << bits) - 1;
314 314
315 /* update state and return */ 315 /* update state and return */
316 strm->next_in = in + OFF; 316 strm->next_in = in + OFF;
317 strm->next_out = out + OFF; 317 strm->next_out = out + OFF;
318 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 318 strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
319 strm->avail_out = (unsigned)(out < end ? 319 strm->avail_out = (unsigned)(out < end ?
320 257 + (end - out) : 257 - (out - end)); 320 257 + (end - out) : 257 - (out - end));
321 state->hold = hold; 321 state->hold = hold;
322 state->bits = bits; 322 state->bits = bits;
323 return; 323 return;
324} 324}
325 325
326/* 326/*
327 inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): 327 inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
328 - Using bit fields for code structure 328 - Using bit fields for code structure
329 - Different op definition to avoid & for extra bits (do & for table bits) 329 - Different op definition to avoid & for extra bits (do & for table bits)
330 - Three separate decoding do-loops for direct, window, and wnext == 0 330 - Three separate decoding do-loops for direct, window, and wnext == 0
331 - Special case for distance > 1 copies to do overlapped load and store copy 331 - Special case for distance > 1 copies to do overlapped load and store copy
332 - Explicit branch predictions (based on measured branch probabilities) 332 - Explicit branch predictions (based on measured branch probabilities)
333 - Deferring match copy and interspersed it with decoding subsequent codes 333 - Deferring match copy and interspersed it with decoding subsequent codes
334 - Swapping literal/length else 334 - Swapping literal/length else
335 - Swapping window/direct else 335 - Swapping window/direct else
336 - Larger unrolled copy loops (three is about right) 336 - Larger unrolled copy loops (three is about right)
337 - Moving len -= 3 statement into middle of loop 337 - Moving len -= 3 statement into middle of loop
338 */ 338 */
339 339
340#endif /* !ASMINF */ 340#endif /* !ASMINF */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.h
index e1e6db4..e5c1aa4 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffast.h
@@ -1,11 +1,11 @@
1/* inffast.h -- header to use inffast.c 1/* inffast.h -- header to use inffast.c
2 * Copyright (C) 1995-2003, 2010 Mark Adler 2 * Copyright (C) 1995-2003, 2010 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* WARNING: this file should *not* be used by applications. It is 6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is 7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 11void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffixed.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffixed.h
index 0b29a5a..d628327 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffixed.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inffixed.h
@@ -1,94 +1,94 @@
1 /* inffixed.h -- table for decoding fixed codes 1 /* inffixed.h -- table for decoding fixed codes
2 * Generated automatically by makefixed(). 2 * Generated automatically by makefixed().
3 */ 3 */
4 4
5 /* WARNING: this file should *not* be used by applications. 5 /* WARNING: this file should *not* be used by applications.
6 It is part of the implementation of this library and is 6 It is part of the implementation of this library and is
7 subject to change. Applications should only use zlib.h. 7 subject to change. Applications should only use zlib.h.
8 */ 8 */
9 9
10 static const code lenfix[512] = { 10 static const code lenfix[512] = {
11 {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 11 {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
12 {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 12 {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
13 {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 13 {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
14 {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 14 {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
15 {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 15 {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
16 {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 16 {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
17 {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 17 {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
18 {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 18 {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
19 {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 19 {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
20 {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 20 {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
21 {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 21 {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
22 {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 22 {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
23 {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 23 {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
24 {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 24 {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
25 {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 25 {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
26 {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 26 {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
27 {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 27 {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
28 {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 28 {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
29 {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 29 {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
30 {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 30 {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
31 {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 31 {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
32 {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 32 {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
33 {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 33 {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
34 {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 34 {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
35 {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 35 {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
36 {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 36 {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
37 {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 37 {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
38 {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 38 {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
39 {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 39 {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
40 {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 40 {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
41 {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 41 {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
42 {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 42 {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
43 {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 43 {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
44 {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 44 {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
45 {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 45 {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
46 {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 46 {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
47 {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 47 {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
48 {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 48 {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
49 {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 49 {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
50 {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 50 {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
51 {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 51 {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
52 {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 52 {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
53 {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 53 {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
54 {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 54 {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
55 {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 55 {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
56 {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 56 {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
57 {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 57 {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
58 {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 58 {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
59 {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 59 {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
60 {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 60 {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
61 {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 61 {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
62 {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 62 {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
63 {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 63 {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
64 {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 64 {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
65 {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 65 {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
66 {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 66 {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
67 {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 67 {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
68 {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 68 {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
69 {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 69 {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
70 {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 70 {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
71 {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 71 {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
72 {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 72 {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
73 {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 73 {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
74 {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 74 {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
75 {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 75 {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
76 {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 76 {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
77 {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 77 {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
78 {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 78 {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
79 {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 79 {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
80 {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 80 {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
81 {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 81 {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
82 {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 82 {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
83 {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 83 {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
84 {0,9,255} 84 {0,9,255}
85 }; 85 };
86 86
87 static const code distfix[32] = { 87 static const code distfix[32] = {
88 {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 88 {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
89 {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 89 {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
90 {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 90 {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
91 {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 91 {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
92 {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 92 {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
93 {22,5,193},{64,5,0} 93 {22,5,193},{64,5,0}
94 }; 94 };
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.c
index f547da5..47418a1 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.c
@@ -1,1496 +1,1496 @@
1/* inflate.c -- zlib decompression 1/* inflate.c -- zlib decompression
2 * Copyright (C) 1995-2012 Mark Adler 2 * Copyright (C) 1995-2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* 6/*
7 * Change history: 7 * Change history:
8 * 8 *
9 * 1.2.beta0 24 Nov 2002 9 * 1.2.beta0 24 Nov 2002
10 * - First version -- complete rewrite of inflate to simplify code, avoid 10 * - First version -- complete rewrite of inflate to simplify code, avoid
11 * creation of window when not needed, minimize use of window when it is 11 * creation of window when not needed, minimize use of window when it is
12 * needed, make inffast.c even faster, implement gzip decoding, and to 12 * needed, make inffast.c even faster, implement gzip decoding, and to
13 * improve code readability and style over the previous zlib inflate code 13 * improve code readability and style over the previous zlib inflate code
14 * 14 *
15 * 1.2.beta1 25 Nov 2002 15 * 1.2.beta1 25 Nov 2002
16 * - Use pointers for available input and output checking in inffast.c 16 * - Use pointers for available input and output checking in inffast.c
17 * - Remove input and output counters in inffast.c 17 * - Remove input and output counters in inffast.c
18 * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 18 * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
19 * - Remove unnecessary second byte pull from length extra in inffast.c 19 * - Remove unnecessary second byte pull from length extra in inffast.c
20 * - Unroll direct copy to three copies per loop in inffast.c 20 * - Unroll direct copy to three copies per loop in inffast.c
21 * 21 *
22 * 1.2.beta2 4 Dec 2002 22 * 1.2.beta2 4 Dec 2002
23 * - Change external routine names to reduce potential conflicts 23 * - Change external routine names to reduce potential conflicts
24 * - Correct filename to inffixed.h for fixed tables in inflate.c 24 * - Correct filename to inffixed.h for fixed tables in inflate.c
25 * - Make hbuf[] unsigned char to match parameter type in inflate.c 25 * - Make hbuf[] unsigned char to match parameter type in inflate.c
26 * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) 26 * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
27 * to avoid negation problem on Alphas (64 bit) in inflate.c 27 * to avoid negation problem on Alphas (64 bit) in inflate.c
28 * 28 *
29 * 1.2.beta3 22 Dec 2002 29 * 1.2.beta3 22 Dec 2002
30 * - Add comments on state->bits assertion in inffast.c 30 * - Add comments on state->bits assertion in inffast.c
31 * - Add comments on op field in inftrees.h 31 * - Add comments on op field in inftrees.h
32 * - Fix bug in reuse of allocated window after inflateReset() 32 * - Fix bug in reuse of allocated window after inflateReset()
33 * - Remove bit fields--back to byte structure for speed 33 * - Remove bit fields--back to byte structure for speed
34 * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths 34 * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
35 * - Change post-increments to pre-increments in inflate_fast(), PPC biased? 35 * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
36 * - Add compile time option, POSTINC, to use post-increments instead (Intel?) 36 * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
37 * - Make MATCH copy in inflate() much faster for when inflate_fast() not used 37 * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
38 * - Use local copies of stream next and avail values, as well as local bit 38 * - Use local copies of stream next and avail values, as well as local bit
39 * buffer and bit count in inflate()--for speed when inflate_fast() not used 39 * buffer and bit count in inflate()--for speed when inflate_fast() not used
40 * 40 *
41 * 1.2.beta4 1 Jan 2003 41 * 1.2.beta4 1 Jan 2003
42 * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings 42 * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
43 * - Move a comment on output buffer sizes from inffast.c to inflate.c 43 * - Move a comment on output buffer sizes from inffast.c to inflate.c
44 * - Add comments in inffast.c to introduce the inflate_fast() routine 44 * - Add comments in inffast.c to introduce the inflate_fast() routine
45 * - Rearrange window copies in inflate_fast() for speed and simplification 45 * - Rearrange window copies in inflate_fast() for speed and simplification
46 * - Unroll last copy for window match in inflate_fast() 46 * - Unroll last copy for window match in inflate_fast()
47 * - Use local copies of window variables in inflate_fast() for speed 47 * - Use local copies of window variables in inflate_fast() for speed
48 * - Pull out common wnext == 0 case for speed in inflate_fast() 48 * - Pull out common wnext == 0 case for speed in inflate_fast()
49 * - Make op and len in inflate_fast() unsigned for consistency 49 * - Make op and len in inflate_fast() unsigned for consistency
50 * - Add FAR to lcode and dcode declarations in inflate_fast() 50 * - Add FAR to lcode and dcode declarations in inflate_fast()
51 * - Simplified bad distance check in inflate_fast() 51 * - Simplified bad distance check in inflate_fast()
52 * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new 52 * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
53 * source file infback.c to provide a call-back interface to inflate for 53 * source file infback.c to provide a call-back interface to inflate for
54 * programs like gzip and unzip -- uses window as output buffer to avoid 54 * programs like gzip and unzip -- uses window as output buffer to avoid
55 * window copying 55 * window copying
56 * 56 *
57 * 1.2.beta5 1 Jan 2003 57 * 1.2.beta5 1 Jan 2003
58 * - Improved inflateBack() interface to allow the caller to provide initial 58 * - Improved inflateBack() interface to allow the caller to provide initial
59 * input in strm. 59 * input in strm.
60 * - Fixed stored blocks bug in inflateBack() 60 * - Fixed stored blocks bug in inflateBack()
61 * 61 *
62 * 1.2.beta6 4 Jan 2003 62 * 1.2.beta6 4 Jan 2003
63 * - Added comments in inffast.c on effectiveness of POSTINC 63 * - Added comments in inffast.c on effectiveness of POSTINC
64 * - Typecasting all around to reduce compiler warnings 64 * - Typecasting all around to reduce compiler warnings
65 * - Changed loops from while (1) or do {} while (1) to for (;;), again to 65 * - Changed loops from while (1) or do {} while (1) to for (;;), again to
66 * make compilers happy 66 * make compilers happy
67 * - Changed type of window in inflateBackInit() to unsigned char * 67 * - Changed type of window in inflateBackInit() to unsigned char *
68 * 68 *
69 * 1.2.beta7 27 Jan 2003 69 * 1.2.beta7 27 Jan 2003
70 * - Changed many types to unsigned or unsigned short to avoid warnings 70 * - Changed many types to unsigned or unsigned short to avoid warnings
71 * - Added inflateCopy() function 71 * - Added inflateCopy() function
72 * 72 *
73 * 1.2.0 9 Mar 2003 73 * 1.2.0 9 Mar 2003
74 * - Changed inflateBack() interface to provide separate opaque descriptors 74 * - Changed inflateBack() interface to provide separate opaque descriptors
75 * for the in() and out() functions 75 * for the in() and out() functions
76 * - Changed inflateBack() argument and in_func typedef to swap the length 76 * - Changed inflateBack() argument and in_func typedef to swap the length
77 * and buffer address return values for the input function 77 * and buffer address return values for the input function
78 * - Check next_in and next_out for Z_NULL on entry to inflate() 78 * - Check next_in and next_out for Z_NULL on entry to inflate()
79 * 79 *
80 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. 80 * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
81 */ 81 */
82 82
83#include "zutil.h" 83#include "zutil.h"
84#include "inftrees.h" 84#include "inftrees.h"
85#include "inflate.h" 85#include "inflate.h"
86#include "inffast.h" 86#include "inffast.h"
87 87
88#ifdef MAKEFIXED 88#ifdef MAKEFIXED
89# ifndef BUILDFIXED 89# ifndef BUILDFIXED
90# define BUILDFIXED 90# define BUILDFIXED
91# endif 91# endif
92#endif 92#endif
93 93
94/* function prototypes */ 94/* function prototypes */
95local void fixedtables OF((struct inflate_state FAR *state)); 95local void fixedtables OF((struct inflate_state FAR *state));
96local int updatewindow OF((z_streamp strm, unsigned out)); 96local int updatewindow OF((z_streamp strm, unsigned out));
97#ifdef BUILDFIXED 97#ifdef BUILDFIXED
98 void makefixed OF((void)); 98 void makefixed OF((void));
99#endif 99#endif
100local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, 100local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
101 unsigned len)); 101 unsigned len));
102 102
103int ZEXPORT inflateResetKeep(strm) 103int ZEXPORT inflateResetKeep(strm)
104z_streamp strm; 104z_streamp strm;
105{ 105{
106 struct inflate_state FAR *state; 106 struct inflate_state FAR *state;
107 107
108 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 108 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
109 state = (struct inflate_state FAR *)strm->state; 109 state = (struct inflate_state FAR *)strm->state;
110 strm->total_in = strm->total_out = state->total = 0; 110 strm->total_in = strm->total_out = state->total = 0;
111 strm->msg = Z_NULL; 111 strm->msg = Z_NULL;
112 if (state->wrap) /* to support ill-conceived Java test suite */ 112 if (state->wrap) /* to support ill-conceived Java test suite */
113 strm->adler = state->wrap & 1; 113 strm->adler = state->wrap & 1;
114 state->mode = HEAD; 114 state->mode = HEAD;
115 state->last = 0; 115 state->last = 0;
116 state->havedict = 0; 116 state->havedict = 0;
117 state->dmax = 32768U; 117 state->dmax = 32768U;
118 state->head = Z_NULL; 118 state->head = Z_NULL;
119 state->hold = 0; 119 state->hold = 0;
120 state->bits = 0; 120 state->bits = 0;
121 state->lencode = state->distcode = state->next = state->codes; 121 state->lencode = state->distcode = state->next = state->codes;
122 state->sane = 1; 122 state->sane = 1;
123 state->back = -1; 123 state->back = -1;
124 Tracev((stderr, "inflate: reset\n")); 124 Tracev((stderr, "inflate: reset\n"));
125 return Z_OK; 125 return Z_OK;
126} 126}
127 127
128int ZEXPORT inflateReset(strm) 128int ZEXPORT inflateReset(strm)
129z_streamp strm; 129z_streamp strm;
130{ 130{
131 struct inflate_state FAR *state; 131 struct inflate_state FAR *state;
132 132
133 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 133 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
134 state = (struct inflate_state FAR *)strm->state; 134 state = (struct inflate_state FAR *)strm->state;
135 state->wsize = 0; 135 state->wsize = 0;
136 state->whave = 0; 136 state->whave = 0;
137 state->wnext = 0; 137 state->wnext = 0;
138 return inflateResetKeep(strm); 138 return inflateResetKeep(strm);
139} 139}
140 140
141int ZEXPORT inflateReset2(strm, windowBits) 141int ZEXPORT inflateReset2(strm, windowBits)
142z_streamp strm; 142z_streamp strm;
143int windowBits; 143int windowBits;
144{ 144{
145 int wrap; 145 int wrap;
146 struct inflate_state FAR *state; 146 struct inflate_state FAR *state;
147 147
148 /* get the state */ 148 /* get the state */
149 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 149 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
150 state = (struct inflate_state FAR *)strm->state; 150 state = (struct inflate_state FAR *)strm->state;
151 151
152 /* extract wrap request from windowBits parameter */ 152 /* extract wrap request from windowBits parameter */
153 if (windowBits < 0) { 153 if (windowBits < 0) {
154 wrap = 0; 154 wrap = 0;
155 windowBits = -windowBits; 155 windowBits = -windowBits;
156 } 156 }
157 else { 157 else {
158 wrap = (windowBits >> 4) + 1; 158 wrap = (windowBits >> 4) + 1;
159#ifdef GUNZIP 159#ifdef GUNZIP
160 if (windowBits < 48) 160 if (windowBits < 48)
161 windowBits &= 15; 161 windowBits &= 15;
162#endif 162#endif
163 } 163 }
164 164
165 /* set number of window bits, free window if different */ 165 /* set number of window bits, free window if different */
166 if (windowBits && (windowBits < 8 || windowBits > 15)) 166 if (windowBits && (windowBits < 8 || windowBits > 15))
167 return Z_STREAM_ERROR; 167 return Z_STREAM_ERROR;
168 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { 168 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
169 ZFREE(strm, state->window); 169 ZFREE(strm, state->window);
170 state->window = Z_NULL; 170 state->window = Z_NULL;
171 } 171 }
172 172
173 /* update state and reset the rest of it */ 173 /* update state and reset the rest of it */
174 state->wrap = wrap; 174 state->wrap = wrap;
175 state->wbits = (unsigned)windowBits; 175 state->wbits = (unsigned)windowBits;
176 return inflateReset(strm); 176 return inflateReset(strm);
177} 177}
178 178
179int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) 179int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
180z_streamp strm; 180z_streamp strm;
181int windowBits; 181int windowBits;
182const char *version; 182const char *version;
183int stream_size; 183int stream_size;
184{ 184{
185 int ret; 185 int ret;
186 struct inflate_state FAR *state; 186 struct inflate_state FAR *state;
187 187
188 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || 188 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
189 stream_size != (int)(sizeof(z_stream))) 189 stream_size != (int)(sizeof(z_stream)))
190 return Z_VERSION_ERROR; 190 return Z_VERSION_ERROR;
191 if (strm == Z_NULL) return Z_STREAM_ERROR; 191 if (strm == Z_NULL) return Z_STREAM_ERROR;
192 strm->msg = Z_NULL; /* in case we return an error */ 192 strm->msg = Z_NULL; /* in case we return an error */
193 if (strm->zalloc == (alloc_func)0) { 193 if (strm->zalloc == (alloc_func)0) {
194#ifdef Z_SOLO 194#ifdef Z_SOLO
195 return Z_STREAM_ERROR; 195 return Z_STREAM_ERROR;
196#else 196#else
197 strm->zalloc = zcalloc; 197 strm->zalloc = zcalloc;
198 strm->opaque = (voidpf)0; 198 strm->opaque = (voidpf)0;
199#endif 199#endif
200 } 200 }
201 if (strm->zfree == (free_func)0) 201 if (strm->zfree == (free_func)0)
202#ifdef Z_SOLO 202#ifdef Z_SOLO
203 return Z_STREAM_ERROR; 203 return Z_STREAM_ERROR;
204#else 204#else
205 strm->zfree = zcfree; 205 strm->zfree = zcfree;
206#endif 206#endif
207 state = (struct inflate_state FAR *) 207 state = (struct inflate_state FAR *)
208 ZALLOC(strm, 1, sizeof(struct inflate_state)); 208 ZALLOC(strm, 1, sizeof(struct inflate_state));
209 if (state == Z_NULL) return Z_MEM_ERROR; 209 if (state == Z_NULL) return Z_MEM_ERROR;
210 Tracev((stderr, "inflate: allocated\n")); 210 Tracev((stderr, "inflate: allocated\n"));
211 strm->state = (struct internal_state FAR *)state; 211 strm->state = (struct internal_state FAR *)state;
212 state->window = Z_NULL; 212 state->window = Z_NULL;
213 ret = inflateReset2(strm, windowBits); 213 ret = inflateReset2(strm, windowBits);
214 if (ret != Z_OK) { 214 if (ret != Z_OK) {
215 ZFREE(strm, state); 215 ZFREE(strm, state);
216 strm->state = Z_NULL; 216 strm->state = Z_NULL;
217 } 217 }
218 return ret; 218 return ret;
219} 219}
220 220
221int ZEXPORT inflateInit_(strm, version, stream_size) 221int ZEXPORT inflateInit_(strm, version, stream_size)
222z_streamp strm; 222z_streamp strm;
223const char *version; 223const char *version;
224int stream_size; 224int stream_size;
225{ 225{
226 return inflateInit2_(strm, DEF_WBITS, version, stream_size); 226 return inflateInit2_(strm, DEF_WBITS, version, stream_size);
227} 227}
228 228
229int ZEXPORT inflatePrime(strm, bits, value) 229int ZEXPORT inflatePrime(strm, bits, value)
230z_streamp strm; 230z_streamp strm;
231int bits; 231int bits;
232int value; 232int value;
233{ 233{
234 struct inflate_state FAR *state; 234 struct inflate_state FAR *state;
235 235
236 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 236 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
237 state = (struct inflate_state FAR *)strm->state; 237 state = (struct inflate_state FAR *)strm->state;
238 if (bits < 0) { 238 if (bits < 0) {
239 state->hold = 0; 239 state->hold = 0;
240 state->bits = 0; 240 state->bits = 0;
241 return Z_OK; 241 return Z_OK;
242 } 242 }
243 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; 243 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
244 value &= (1L << bits) - 1; 244 value &= (1L << bits) - 1;
245 state->hold += value << state->bits; 245 state->hold += value << state->bits;
246 state->bits += bits; 246 state->bits += bits;
247 return Z_OK; 247 return Z_OK;
248} 248}
249 249
250/* 250/*
251 Return state with length and distance decoding tables and index sizes set to 251 Return state with length and distance decoding tables and index sizes set to
252 fixed code decoding. Normally this returns fixed tables from inffixed.h. 252 fixed code decoding. Normally this returns fixed tables from inffixed.h.
253 If BUILDFIXED is defined, then instead this routine builds the tables the 253 If BUILDFIXED is defined, then instead this routine builds the tables the
254 first time it's called, and returns those tables the first time and 254 first time it's called, and returns those tables the first time and
255 thereafter. This reduces the size of the code by about 2K bytes, in 255 thereafter. This reduces the size of the code by about 2K bytes, in
256 exchange for a little execution time. However, BUILDFIXED should not be 256 exchange for a little execution time. However, BUILDFIXED should not be
257 used for threaded applications, since the rewriting of the tables and virgin 257 used for threaded applications, since the rewriting of the tables and virgin
258 may not be thread-safe. 258 may not be thread-safe.
259 */ 259 */
260local void fixedtables(state) 260local void fixedtables(state)
261struct inflate_state FAR *state; 261struct inflate_state FAR *state;
262{ 262{
263#ifdef BUILDFIXED 263#ifdef BUILDFIXED
264 static int virgin = 1; 264 static int virgin = 1;
265 static code *lenfix, *distfix; 265 static code *lenfix, *distfix;
266 static code fixed[544]; 266 static code fixed[544];
267 267
268 /* build fixed huffman tables if first call (may not be thread safe) */ 268 /* build fixed huffman tables if first call (may not be thread safe) */
269 if (virgin) { 269 if (virgin) {
270 unsigned sym, bits; 270 unsigned sym, bits;
271 static code *next; 271 static code *next;
272 272
273 /* literal/length table */ 273 /* literal/length table */
274 sym = 0; 274 sym = 0;
275 while (sym < 144) state->lens[sym++] = 8; 275 while (sym < 144) state->lens[sym++] = 8;
276 while (sym < 256) state->lens[sym++] = 9; 276 while (sym < 256) state->lens[sym++] = 9;
277 while (sym < 280) state->lens[sym++] = 7; 277 while (sym < 280) state->lens[sym++] = 7;
278 while (sym < 288) state->lens[sym++] = 8; 278 while (sym < 288) state->lens[sym++] = 8;
279 next = fixed; 279 next = fixed;
280 lenfix = next; 280 lenfix = next;
281 bits = 9; 281 bits = 9;
282 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); 282 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
283 283
284 /* distance table */ 284 /* distance table */
285 sym = 0; 285 sym = 0;
286 while (sym < 32) state->lens[sym++] = 5; 286 while (sym < 32) state->lens[sym++] = 5;
287 distfix = next; 287 distfix = next;
288 bits = 5; 288 bits = 5;
289 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); 289 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
290 290
291 /* do this just once */ 291 /* do this just once */
292 virgin = 0; 292 virgin = 0;
293 } 293 }
294#else /* !BUILDFIXED */ 294#else /* !BUILDFIXED */
295# include "inffixed.h" 295# include "inffixed.h"
296#endif /* BUILDFIXED */ 296#endif /* BUILDFIXED */
297 state->lencode = lenfix; 297 state->lencode = lenfix;
298 state->lenbits = 9; 298 state->lenbits = 9;
299 state->distcode = distfix; 299 state->distcode = distfix;
300 state->distbits = 5; 300 state->distbits = 5;
301} 301}
302 302
303#ifdef MAKEFIXED 303#ifdef MAKEFIXED
304#include <stdio.h> 304#include <stdio.h>
305 305
306/* 306/*
307 Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also 307 Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
308 defines BUILDFIXED, so the tables are built on the fly. makefixed() writes 308 defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
309 those tables to stdout, which would be piped to inffixed.h. A small program 309 those tables to stdout, which would be piped to inffixed.h. A small program
310 can simply call makefixed to do this: 310 can simply call makefixed to do this:
311 311
312 void makefixed(void); 312 void makefixed(void);
313 313
314 int main(void) 314 int main(void)
315 { 315 {
316 makefixed(); 316 makefixed();
317 return 0; 317 return 0;
318 } 318 }
319 319
320 Then that can be linked with zlib built with MAKEFIXED defined and run: 320 Then that can be linked with zlib built with MAKEFIXED defined and run:
321 321
322 a.out > inffixed.h 322 a.out > inffixed.h
323 */ 323 */
324void makefixed() 324void makefixed()
325{ 325{
326 unsigned low, size; 326 unsigned low, size;
327 struct inflate_state state; 327 struct inflate_state state;
328 328
329 fixedtables(&state); 329 fixedtables(&state);
330 puts(" /* inffixed.h -- table for decoding fixed codes"); 330 puts(" /* inffixed.h -- table for decoding fixed codes");
331 puts(" * Generated automatically by makefixed()."); 331 puts(" * Generated automatically by makefixed().");
332 puts(" */"); 332 puts(" */");
333 puts(""); 333 puts("");
334 puts(" /* WARNING: this file should *not* be used by applications."); 334 puts(" /* WARNING: this file should *not* be used by applications.");
335 puts(" It is part of the implementation of this library and is"); 335 puts(" It is part of the implementation of this library and is");
336 puts(" subject to change. Applications should only use zlib.h."); 336 puts(" subject to change. Applications should only use zlib.h.");
337 puts(" */"); 337 puts(" */");
338 puts(""); 338 puts("");
339 size = 1U << 9; 339 size = 1U << 9;
340 printf(" static const code lenfix[%u] = {", size); 340 printf(" static const code lenfix[%u] = {", size);
341 low = 0; 341 low = 0;
342 for (;;) { 342 for (;;) {
343 if ((low % 7) == 0) printf("\n "); 343 if ((low % 7) == 0) printf("\n ");
344 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, 344 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
345 state.lencode[low].bits, state.lencode[low].val); 345 state.lencode[low].bits, state.lencode[low].val);
346 if (++low == size) break; 346 if (++low == size) break;
347 putchar(','); 347 putchar(',');
348 } 348 }
349 puts("\n };"); 349 puts("\n };");
350 size = 1U << 5; 350 size = 1U << 5;
351 printf("\n static const code distfix[%u] = {", size); 351 printf("\n static const code distfix[%u] = {", size);
352 low = 0; 352 low = 0;
353 for (;;) { 353 for (;;) {
354 if ((low % 6) == 0) printf("\n "); 354 if ((low % 6) == 0) printf("\n ");
355 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, 355 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
356 state.distcode[low].val); 356 state.distcode[low].val);
357 if (++low == size) break; 357 if (++low == size) break;
358 putchar(','); 358 putchar(',');
359 } 359 }
360 puts("\n };"); 360 puts("\n };");
361} 361}
362#endif /* MAKEFIXED */ 362#endif /* MAKEFIXED */
363 363
364/* 364/*
365 Update the window with the last wsize (normally 32K) bytes written before 365 Update the window with the last wsize (normally 32K) bytes written before
366 returning. If window does not exist yet, create it. This is only called 366 returning. If window does not exist yet, create it. This is only called
367 when a window is already in use, or when output has been written during this 367 when a window is already in use, or when output has been written during this
368 inflate call, but the end of the deflate stream has not been reached yet. 368 inflate call, but the end of the deflate stream has not been reached yet.
369 It is also called to create a window for dictionary data when a dictionary 369 It is also called to create a window for dictionary data when a dictionary
370 is loaded. 370 is loaded.
371 371
372 Providing output buffers larger than 32K to inflate() should provide a speed 372 Providing output buffers larger than 32K to inflate() should provide a speed
373 advantage, since only the last 32K of output is copied to the sliding window 373 advantage, since only the last 32K of output is copied to the sliding window
374 upon return from inflate(), and since all distances after the first 32K of 374 upon return from inflate(), and since all distances after the first 32K of
375 output will fall in the output data, making match copies simpler and faster. 375 output will fall in the output data, making match copies simpler and faster.
376 The advantage may be dependent on the size of the processor's data caches. 376 The advantage may be dependent on the size of the processor's data caches.
377 */ 377 */
378local int updatewindow(strm, out) 378local int updatewindow(strm, out)
379z_streamp strm; 379z_streamp strm;
380unsigned out; 380unsigned out;
381{ 381{
382 struct inflate_state FAR *state; 382 struct inflate_state FAR *state;
383 unsigned copy, dist; 383 unsigned copy, dist;
384 384
385 state = (struct inflate_state FAR *)strm->state; 385 state = (struct inflate_state FAR *)strm->state;
386 386
387 /* if it hasn't been done already, allocate space for the window */ 387 /* if it hasn't been done already, allocate space for the window */
388 if (state->window == Z_NULL) { 388 if (state->window == Z_NULL) {
389 state->window = (unsigned char FAR *) 389 state->window = (unsigned char FAR *)
390 ZALLOC(strm, 1U << state->wbits, 390 ZALLOC(strm, 1U << state->wbits,
391 sizeof(unsigned char)); 391 sizeof(unsigned char));
392 if (state->window == Z_NULL) return 1; 392 if (state->window == Z_NULL) return 1;
393 } 393 }
394 394
395 /* if window not in use yet, initialize */ 395 /* if window not in use yet, initialize */
396 if (state->wsize == 0) { 396 if (state->wsize == 0) {
397 state->wsize = 1U << state->wbits; 397 state->wsize = 1U << state->wbits;
398 state->wnext = 0; 398 state->wnext = 0;
399 state->whave = 0; 399 state->whave = 0;
400 } 400 }
401 401
402 /* copy state->wsize or less output bytes into the circular window */ 402 /* copy state->wsize or less output bytes into the circular window */
403 copy = out - strm->avail_out; 403 copy = out - strm->avail_out;
404 if (copy >= state->wsize) { 404 if (copy >= state->wsize) {
405 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); 405 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
406 state->wnext = 0; 406 state->wnext = 0;
407 state->whave = state->wsize; 407 state->whave = state->wsize;
408 } 408 }
409 else { 409 else {
410 dist = state->wsize - state->wnext; 410 dist = state->wsize - state->wnext;
411 if (dist > copy) dist = copy; 411 if (dist > copy) dist = copy;
412 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); 412 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
413 copy -= dist; 413 copy -= dist;
414 if (copy) { 414 if (copy) {
415 zmemcpy(state->window, strm->next_out - copy, copy); 415 zmemcpy(state->window, strm->next_out - copy, copy);
416 state->wnext = copy; 416 state->wnext = copy;
417 state->whave = state->wsize; 417 state->whave = state->wsize;
418 } 418 }
419 else { 419 else {
420 state->wnext += dist; 420 state->wnext += dist;
421 if (state->wnext == state->wsize) state->wnext = 0; 421 if (state->wnext == state->wsize) state->wnext = 0;
422 if (state->whave < state->wsize) state->whave += dist; 422 if (state->whave < state->wsize) state->whave += dist;
423 } 423 }
424 } 424 }
425 return 0; 425 return 0;
426} 426}
427 427
428/* Macros for inflate(): */ 428/* Macros for inflate(): */
429 429
430/* check function to use adler32() for zlib or crc32() for gzip */ 430/* check function to use adler32() for zlib or crc32() for gzip */
431#ifdef GUNZIP 431#ifdef GUNZIP
432# define UPDATE(check, buf, len) \ 432# define UPDATE(check, buf, len) \
433 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) 433 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
434#else 434#else
435# define UPDATE(check, buf, len) adler32(check, buf, len) 435# define UPDATE(check, buf, len) adler32(check, buf, len)
436#endif 436#endif
437 437
438/* check macros for header crc */ 438/* check macros for header crc */
439#ifdef GUNZIP 439#ifdef GUNZIP
440# define CRC2(check, word) \ 440# define CRC2(check, word) \
441 do { \ 441 do { \
442 hbuf[0] = (unsigned char)(word); \ 442 hbuf[0] = (unsigned char)(word); \
443 hbuf[1] = (unsigned char)((word) >> 8); \ 443 hbuf[1] = (unsigned char)((word) >> 8); \
444 check = crc32(check, hbuf, 2); \ 444 check = crc32(check, hbuf, 2); \
445 } while (0) 445 } while (0)
446 446
447# define CRC4(check, word) \ 447# define CRC4(check, word) \
448 do { \ 448 do { \
449 hbuf[0] = (unsigned char)(word); \ 449 hbuf[0] = (unsigned char)(word); \
450 hbuf[1] = (unsigned char)((word) >> 8); \ 450 hbuf[1] = (unsigned char)((word) >> 8); \
451 hbuf[2] = (unsigned char)((word) >> 16); \ 451 hbuf[2] = (unsigned char)((word) >> 16); \
452 hbuf[3] = (unsigned char)((word) >> 24); \ 452 hbuf[3] = (unsigned char)((word) >> 24); \
453 check = crc32(check, hbuf, 4); \ 453 check = crc32(check, hbuf, 4); \
454 } while (0) 454 } while (0)
455#endif 455#endif
456 456
457/* Load registers with state in inflate() for speed */ 457/* Load registers with state in inflate() for speed */
458#define LOAD() \ 458#define LOAD() \
459 do { \ 459 do { \
460 put = strm->next_out; \ 460 put = strm->next_out; \
461 left = strm->avail_out; \ 461 left = strm->avail_out; \
462 next = strm->next_in; \ 462 next = strm->next_in; \
463 have = strm->avail_in; \ 463 have = strm->avail_in; \
464 hold = state->hold; \ 464 hold = state->hold; \
465 bits = state->bits; \ 465 bits = state->bits; \
466 } while (0) 466 } while (0)
467 467
468/* Restore state from registers in inflate() */ 468/* Restore state from registers in inflate() */
469#define RESTORE() \ 469#define RESTORE() \
470 do { \ 470 do { \
471 strm->next_out = put; \ 471 strm->next_out = put; \
472 strm->avail_out = left; \ 472 strm->avail_out = left; \
473 strm->next_in = next; \ 473 strm->next_in = next; \
474 strm->avail_in = have; \ 474 strm->avail_in = have; \
475 state->hold = hold; \ 475 state->hold = hold; \
476 state->bits = bits; \ 476 state->bits = bits; \
477 } while (0) 477 } while (0)
478 478
479/* Clear the input bit accumulator */ 479/* Clear the input bit accumulator */
480#define INITBITS() \ 480#define INITBITS() \
481 do { \ 481 do { \
482 hold = 0; \ 482 hold = 0; \
483 bits = 0; \ 483 bits = 0; \
484 } while (0) 484 } while (0)
485 485
486/* Get a byte of input into the bit accumulator, or return from inflate() 486/* Get a byte of input into the bit accumulator, or return from inflate()
487 if there is no input available. */ 487 if there is no input available. */
488#define PULLBYTE() \ 488#define PULLBYTE() \
489 do { \ 489 do { \
490 if (have == 0) goto inf_leave; \ 490 if (have == 0) goto inf_leave; \
491 have--; \ 491 have--; \
492 hold += (unsigned long)(*next++) << bits; \ 492 hold += (unsigned long)(*next++) << bits; \
493 bits += 8; \ 493 bits += 8; \
494 } while (0) 494 } while (0)
495 495
496/* Assure that there are at least n bits in the bit accumulator. If there is 496/* Assure that there are at least n bits in the bit accumulator. If there is
497 not enough available input to do that, then return from inflate(). */ 497 not enough available input to do that, then return from inflate(). */
498#define NEEDBITS(n) \ 498#define NEEDBITS(n) \
499 do { \ 499 do { \
500 while (bits < (unsigned)(n)) \ 500 while (bits < (unsigned)(n)) \
501 PULLBYTE(); \ 501 PULLBYTE(); \
502 } while (0) 502 } while (0)
503 503
504/* Return the low n bits of the bit accumulator (n < 16) */ 504/* Return the low n bits of the bit accumulator (n < 16) */
505#define BITS(n) \ 505#define BITS(n) \
506 ((unsigned)hold & ((1U << (n)) - 1)) 506 ((unsigned)hold & ((1U << (n)) - 1))
507 507
508/* Remove n bits from the bit accumulator */ 508/* Remove n bits from the bit accumulator */
509#define DROPBITS(n) \ 509#define DROPBITS(n) \
510 do { \ 510 do { \
511 hold >>= (n); \ 511 hold >>= (n); \
512 bits -= (unsigned)(n); \ 512 bits -= (unsigned)(n); \
513 } while (0) 513 } while (0)
514 514
515/* Remove zero to seven bits as needed to go to a byte boundary */ 515/* Remove zero to seven bits as needed to go to a byte boundary */
516#define BYTEBITS() \ 516#define BYTEBITS() \
517 do { \ 517 do { \
518 hold >>= bits & 7; \ 518 hold >>= bits & 7; \
519 bits -= bits & 7; \ 519 bits -= bits & 7; \
520 } while (0) 520 } while (0)
521 521
522/* 522/*
523 inflate() uses a state machine to process as much input data and generate as 523 inflate() uses a state machine to process as much input data and generate as
524 much output data as possible before returning. The state machine is 524 much output data as possible before returning. The state machine is
525 structured roughly as follows: 525 structured roughly as follows:
526 526
527 for (;;) switch (state) { 527 for (;;) switch (state) {
528 ... 528 ...
529 case STATEn: 529 case STATEn:
530 if (not enough input data or output space to make progress) 530 if (not enough input data or output space to make progress)
531 return; 531 return;
532 ... make progress ... 532 ... make progress ...
533 state = STATEm; 533 state = STATEm;
534 break; 534 break;
535 ... 535 ...
536 } 536 }
537 537
538 so when inflate() is called again, the same case is attempted again, and 538 so when inflate() is called again, the same case is attempted again, and
539 if the appropriate resources are provided, the machine proceeds to the 539 if the appropriate resources are provided, the machine proceeds to the
540 next state. The NEEDBITS() macro is usually the way the state evaluates 540 next state. The NEEDBITS() macro is usually the way the state evaluates
541 whether it can proceed or should return. NEEDBITS() does the return if 541 whether it can proceed or should return. NEEDBITS() does the return if
542 the requested bits are not available. The typical use of the BITS macros 542 the requested bits are not available. The typical use of the BITS macros
543 is: 543 is:
544 544
545 NEEDBITS(n); 545 NEEDBITS(n);
546 ... do something with BITS(n) ... 546 ... do something with BITS(n) ...
547 DROPBITS(n); 547 DROPBITS(n);
548 548
549 where NEEDBITS(n) either returns from inflate() if there isn't enough 549 where NEEDBITS(n) either returns from inflate() if there isn't enough
550 input left to load n bits into the accumulator, or it continues. BITS(n) 550 input left to load n bits into the accumulator, or it continues. BITS(n)
551 gives the low n bits in the accumulator. When done, DROPBITS(n) drops 551 gives the low n bits in the accumulator. When done, DROPBITS(n) drops
552 the low n bits off the accumulator. INITBITS() clears the accumulator 552 the low n bits off the accumulator. INITBITS() clears the accumulator
553 and sets the number of available bits to zero. BYTEBITS() discards just 553 and sets the number of available bits to zero. BYTEBITS() discards just
554 enough bits to put the accumulator on a byte boundary. After BYTEBITS() 554 enough bits to put the accumulator on a byte boundary. After BYTEBITS()
555 and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. 555 and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
556 556
557 NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return 557 NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
558 if there is no input available. The decoding of variable length codes uses 558 if there is no input available. The decoding of variable length codes uses
559 PULLBYTE() directly in order to pull just enough bytes to decode the next 559 PULLBYTE() directly in order to pull just enough bytes to decode the next
560 code, and no more. 560 code, and no more.
561 561
562 Some states loop until they get enough input, making sure that enough 562 Some states loop until they get enough input, making sure that enough
563 state information is maintained to continue the loop where it left off 563 state information is maintained to continue the loop where it left off
564 if NEEDBITS() returns in the loop. For example, want, need, and keep 564 if NEEDBITS() returns in the loop. For example, want, need, and keep
565 would all have to actually be part of the saved state in case NEEDBITS() 565 would all have to actually be part of the saved state in case NEEDBITS()
566 returns: 566 returns:
567 567
568 case STATEw: 568 case STATEw:
569 while (want < need) { 569 while (want < need) {
570 NEEDBITS(n); 570 NEEDBITS(n);
571 keep[want++] = BITS(n); 571 keep[want++] = BITS(n);
572 DROPBITS(n); 572 DROPBITS(n);
573 } 573 }
574 state = STATEx; 574 state = STATEx;
575 case STATEx: 575 case STATEx:
576 576
577 As shown above, if the next state is also the next case, then the break 577 As shown above, if the next state is also the next case, then the break
578 is omitted. 578 is omitted.
579 579
580 A state may also return if there is not enough output space available to 580 A state may also return if there is not enough output space available to
581 complete that state. Those states are copying stored data, writing a 581 complete that state. Those states are copying stored data, writing a
582 literal byte, and copying a matching string. 582 literal byte, and copying a matching string.
583 583
584 When returning, a "goto inf_leave" is used to update the total counters, 584 When returning, a "goto inf_leave" is used to update the total counters,
585 update the check value, and determine whether any progress has been made 585 update the check value, and determine whether any progress has been made
586 during that inflate() call in order to return the proper return code. 586 during that inflate() call in order to return the proper return code.
587 Progress is defined as a change in either strm->avail_in or strm->avail_out. 587 Progress is defined as a change in either strm->avail_in or strm->avail_out.
588 When there is a window, goto inf_leave will update the window with the last 588 When there is a window, goto inf_leave will update the window with the last
589 output written. If a goto inf_leave occurs in the middle of decompression 589 output written. If a goto inf_leave occurs in the middle of decompression
590 and there is no window currently, goto inf_leave will create one and copy 590 and there is no window currently, goto inf_leave will create one and copy
591 output to the window for the next call of inflate(). 591 output to the window for the next call of inflate().
592 592
593 In this implementation, the flush parameter of inflate() only affects the 593 In this implementation, the flush parameter of inflate() only affects the
594 return code (per zlib.h). inflate() always writes as much as possible to 594 return code (per zlib.h). inflate() always writes as much as possible to
595 strm->next_out, given the space available and the provided input--the effect 595 strm->next_out, given the space available and the provided input--the effect
596 documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers 596 documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
597 the allocation of and copying into a sliding window until necessary, which 597 the allocation of and copying into a sliding window until necessary, which
598 provides the effect documented in zlib.h for Z_FINISH when the entire input 598 provides the effect documented in zlib.h for Z_FINISH when the entire input
599 stream available. So the only thing the flush parameter actually does is: 599 stream available. So the only thing the flush parameter actually does is:
600 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it 600 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
601 will return Z_BUF_ERROR if it has not reached the end of the stream. 601 will return Z_BUF_ERROR if it has not reached the end of the stream.
602 */ 602 */
603 603
604int ZEXPORT inflate(strm, flush) 604int ZEXPORT inflate(strm, flush)
605z_streamp strm; 605z_streamp strm;
606int flush; 606int flush;
607{ 607{
608 struct inflate_state FAR *state; 608 struct inflate_state FAR *state;
609 unsigned char FAR *next; /* next input */ 609 unsigned char FAR *next; /* next input */
610 unsigned char FAR *put; /* next output */ 610 unsigned char FAR *put; /* next output */
611 unsigned have, left; /* available input and output */ 611 unsigned have, left; /* available input and output */
612 unsigned long hold; /* bit buffer */ 612 unsigned long hold; /* bit buffer */
613 unsigned bits; /* bits in bit buffer */ 613 unsigned bits; /* bits in bit buffer */
614 unsigned in, out; /* save starting available input and output */ 614 unsigned in, out; /* save starting available input and output */
615 unsigned copy; /* number of stored or match bytes to copy */ 615 unsigned copy; /* number of stored or match bytes to copy */
616 unsigned char FAR *from; /* where to copy match bytes from */ 616 unsigned char FAR *from; /* where to copy match bytes from */
617 code here; /* current decoding table entry */ 617 code here; /* current decoding table entry */
618 code last; /* parent table entry */ 618 code last; /* parent table entry */
619 unsigned len; /* length to copy for repeats, bits to drop */ 619 unsigned len; /* length to copy for repeats, bits to drop */
620 int ret; /* return code */ 620 int ret; /* return code */
621#ifdef GUNZIP 621#ifdef GUNZIP
622 unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ 622 unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
623#endif 623#endif
624 static const unsigned short order[19] = /* permutation of code lengths */ 624 static const unsigned short order[19] = /* permutation of code lengths */
625 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 625 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
626 626
627 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || 627 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
628 (strm->next_in == Z_NULL && strm->avail_in != 0)) 628 (strm->next_in == Z_NULL && strm->avail_in != 0))
629 return Z_STREAM_ERROR; 629 return Z_STREAM_ERROR;
630 630
631 state = (struct inflate_state FAR *)strm->state; 631 state = (struct inflate_state FAR *)strm->state;
632 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ 632 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
633 LOAD(); 633 LOAD();
634 in = have; 634 in = have;
635 out = left; 635 out = left;
636 ret = Z_OK; 636 ret = Z_OK;
637 for (;;) 637 for (;;)
638 switch (state->mode) { 638 switch (state->mode) {
639 case HEAD: 639 case HEAD:
640 if (state->wrap == 0) { 640 if (state->wrap == 0) {
641 state->mode = TYPEDO; 641 state->mode = TYPEDO;
642 break; 642 break;
643 } 643 }
644 NEEDBITS(16); 644 NEEDBITS(16);
645#ifdef GUNZIP 645#ifdef GUNZIP
646 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ 646 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
647 state->check = crc32(0L, Z_NULL, 0); 647 state->check = crc32(0L, Z_NULL, 0);
648 CRC2(state->check, hold); 648 CRC2(state->check, hold);
649 INITBITS(); 649 INITBITS();
650 state->mode = FLAGS; 650 state->mode = FLAGS;
651 break; 651 break;
652 } 652 }
653 state->flags = 0; /* expect zlib header */ 653 state->flags = 0; /* expect zlib header */
654 if (state->head != Z_NULL) 654 if (state->head != Z_NULL)
655 state->head->done = -1; 655 state->head->done = -1;
656 if (!(state->wrap & 1) || /* check if zlib header allowed */ 656 if (!(state->wrap & 1) || /* check if zlib header allowed */
657#else 657#else
658 if ( 658 if (
659#endif 659#endif
660 ((BITS(8) << 8) + (hold >> 8)) % 31) { 660 ((BITS(8) << 8) + (hold >> 8)) % 31) {
661 strm->msg = (char *)"incorrect header check"; 661 strm->msg = (char *)"incorrect header check";
662 state->mode = BAD; 662 state->mode = BAD;
663 break; 663 break;
664 } 664 }
665 if (BITS(4) != Z_DEFLATED) { 665 if (BITS(4) != Z_DEFLATED) {
666 strm->msg = (char *)"unknown compression method"; 666 strm->msg = (char *)"unknown compression method";
667 state->mode = BAD; 667 state->mode = BAD;
668 break; 668 break;
669 } 669 }
670 DROPBITS(4); 670 DROPBITS(4);
671 len = BITS(4) + 8; 671 len = BITS(4) + 8;
672 if (state->wbits == 0) 672 if (state->wbits == 0)
673 state->wbits = len; 673 state->wbits = len;
674 else if (len > state->wbits) { 674 else if (len > state->wbits) {
675 strm->msg = (char *)"invalid window size"; 675 strm->msg = (char *)"invalid window size";
676 state->mode = BAD; 676 state->mode = BAD;
677 break; 677 break;
678 } 678 }
679 state->dmax = 1U << len; 679 state->dmax = 1U << len;
680 Tracev((stderr, "inflate: zlib header ok\n")); 680 Tracev((stderr, "inflate: zlib header ok\n"));
681 strm->adler = state->check = adler32(0L, Z_NULL, 0); 681 strm->adler = state->check = adler32(0L, Z_NULL, 0);
682 state->mode = hold & 0x200 ? DICTID : TYPE; 682 state->mode = hold & 0x200 ? DICTID : TYPE;
683 INITBITS(); 683 INITBITS();
684 break; 684 break;
685#ifdef GUNZIP 685#ifdef GUNZIP
686 case FLAGS: 686 case FLAGS:
687 NEEDBITS(16); 687 NEEDBITS(16);
688 state->flags = (int)(hold); 688 state->flags = (int)(hold);
689 if ((state->flags & 0xff) != Z_DEFLATED) { 689 if ((state->flags & 0xff) != Z_DEFLATED) {
690 strm->msg = (char *)"unknown compression method"; 690 strm->msg = (char *)"unknown compression method";
691 state->mode = BAD; 691 state->mode = BAD;
692 break; 692 break;
693 } 693 }
694 if (state->flags & 0xe000) { 694 if (state->flags & 0xe000) {
695 strm->msg = (char *)"unknown header flags set"; 695 strm->msg = (char *)"unknown header flags set";
696 state->mode = BAD; 696 state->mode = BAD;
697 break; 697 break;
698 } 698 }
699 if (state->head != Z_NULL) 699 if (state->head != Z_NULL)
700 state->head->text = (int)((hold >> 8) & 1); 700 state->head->text = (int)((hold >> 8) & 1);
701 if (state->flags & 0x0200) CRC2(state->check, hold); 701 if (state->flags & 0x0200) CRC2(state->check, hold);
702 INITBITS(); 702 INITBITS();
703 state->mode = TIME; 703 state->mode = TIME;
704 case TIME: 704 case TIME:
705 NEEDBITS(32); 705 NEEDBITS(32);
706 if (state->head != Z_NULL) 706 if (state->head != Z_NULL)
707 state->head->time = hold; 707 state->head->time = hold;
708 if (state->flags & 0x0200) CRC4(state->check, hold); 708 if (state->flags & 0x0200) CRC4(state->check, hold);
709 INITBITS(); 709 INITBITS();
710 state->mode = OS; 710 state->mode = OS;
711 case OS: 711 case OS:
712 NEEDBITS(16); 712 NEEDBITS(16);
713 if (state->head != Z_NULL) { 713 if (state->head != Z_NULL) {
714 state->head->xflags = (int)(hold & 0xff); 714 state->head->xflags = (int)(hold & 0xff);
715 state->head->os = (int)(hold >> 8); 715 state->head->os = (int)(hold >> 8);
716 } 716 }
717 if (state->flags & 0x0200) CRC2(state->check, hold); 717 if (state->flags & 0x0200) CRC2(state->check, hold);
718 INITBITS(); 718 INITBITS();
719 state->mode = EXLEN; 719 state->mode = EXLEN;
720 case EXLEN: 720 case EXLEN:
721 if (state->flags & 0x0400) { 721 if (state->flags & 0x0400) {
722 NEEDBITS(16); 722 NEEDBITS(16);
723 state->length = (unsigned)(hold); 723 state->length = (unsigned)(hold);
724 if (state->head != Z_NULL) 724 if (state->head != Z_NULL)
725 state->head->extra_len = (unsigned)hold; 725 state->head->extra_len = (unsigned)hold;
726 if (state->flags & 0x0200) CRC2(state->check, hold); 726 if (state->flags & 0x0200) CRC2(state->check, hold);
727 INITBITS(); 727 INITBITS();
728 } 728 }
729 else if (state->head != Z_NULL) 729 else if (state->head != Z_NULL)
730 state->head->extra = Z_NULL; 730 state->head->extra = Z_NULL;
731 state->mode = EXTRA; 731 state->mode = EXTRA;
732 case EXTRA: 732 case EXTRA:
733 if (state->flags & 0x0400) { 733 if (state->flags & 0x0400) {
734 copy = state->length; 734 copy = state->length;
735 if (copy > have) copy = have; 735 if (copy > have) copy = have;
736 if (copy) { 736 if (copy) {
737 if (state->head != Z_NULL && 737 if (state->head != Z_NULL &&
738 state->head->extra != Z_NULL) { 738 state->head->extra != Z_NULL) {
739 len = state->head->extra_len - state->length; 739 len = state->head->extra_len - state->length;
740 zmemcpy(state->head->extra + len, next, 740 zmemcpy(state->head->extra + len, next,
741 len + copy > state->head->extra_max ? 741 len + copy > state->head->extra_max ?
742 state->head->extra_max - len : copy); 742 state->head->extra_max - len : copy);
743 } 743 }
744 if (state->flags & 0x0200) 744 if (state->flags & 0x0200)
745 state->check = crc32(state->check, next, copy); 745 state->check = crc32(state->check, next, copy);
746 have -= copy; 746 have -= copy;
747 next += copy; 747 next += copy;
748 state->length -= copy; 748 state->length -= copy;
749 } 749 }
750 if (state->length) goto inf_leave; 750 if (state->length) goto inf_leave;
751 } 751 }
752 state->length = 0; 752 state->length = 0;
753 state->mode = NAME; 753 state->mode = NAME;
754 case NAME: 754 case NAME:
755 if (state->flags & 0x0800) { 755 if (state->flags & 0x0800) {
756 if (have == 0) goto inf_leave; 756 if (have == 0) goto inf_leave;
757 copy = 0; 757 copy = 0;
758 do { 758 do {
759 len = (unsigned)(next[copy++]); 759 len = (unsigned)(next[copy++]);
760 if (state->head != Z_NULL && 760 if (state->head != Z_NULL &&
761 state->head->name != Z_NULL && 761 state->head->name != Z_NULL &&
762 state->length < state->head->name_max) 762 state->length < state->head->name_max)
763 state->head->name[state->length++] = len; 763 state->head->name[state->length++] = len;
764 } while (len && copy < have); 764 } while (len && copy < have);
765 if (state->flags & 0x0200) 765 if (state->flags & 0x0200)
766 state->check = crc32(state->check, next, copy); 766 state->check = crc32(state->check, next, copy);
767 have -= copy; 767 have -= copy;
768 next += copy; 768 next += copy;
769 if (len) goto inf_leave; 769 if (len) goto inf_leave;
770 } 770 }
771 else if (state->head != Z_NULL) 771 else if (state->head != Z_NULL)
772 state->head->name = Z_NULL; 772 state->head->name = Z_NULL;
773 state->length = 0; 773 state->length = 0;
774 state->mode = COMMENT; 774 state->mode = COMMENT;
775 case COMMENT: 775 case COMMENT:
776 if (state->flags & 0x1000) { 776 if (state->flags & 0x1000) {
777 if (have == 0) goto inf_leave; 777 if (have == 0) goto inf_leave;
778 copy = 0; 778 copy = 0;
779 do { 779 do {
780 len = (unsigned)(next[copy++]); 780 len = (unsigned)(next[copy++]);
781 if (state->head != Z_NULL && 781 if (state->head != Z_NULL &&
782 state->head->comment != Z_NULL && 782 state->head->comment != Z_NULL &&
783 state->length < state->head->comm_max) 783 state->length < state->head->comm_max)
784 state->head->comment[state->length++] = len; 784 state->head->comment[state->length++] = len;
785 } while (len && copy < have); 785 } while (len && copy < have);
786 if (state->flags & 0x0200) 786 if (state->flags & 0x0200)
787 state->check = crc32(state->check, next, copy); 787 state->check = crc32(state->check, next, copy);
788 have -= copy; 788 have -= copy;
789 next += copy; 789 next += copy;
790 if (len) goto inf_leave; 790 if (len) goto inf_leave;
791 } 791 }
792 else if (state->head != Z_NULL) 792 else if (state->head != Z_NULL)
793 state->head->comment = Z_NULL; 793 state->head->comment = Z_NULL;
794 state->mode = HCRC; 794 state->mode = HCRC;
795 case HCRC: 795 case HCRC:
796 if (state->flags & 0x0200) { 796 if (state->flags & 0x0200) {
797 NEEDBITS(16); 797 NEEDBITS(16);
798 if (hold != (state->check & 0xffff)) { 798 if (hold != (state->check & 0xffff)) {
799 strm->msg = (char *)"header crc mismatch"; 799 strm->msg = (char *)"header crc mismatch";
800 state->mode = BAD; 800 state->mode = BAD;
801 break; 801 break;
802 } 802 }
803 INITBITS(); 803 INITBITS();
804 } 804 }
805 if (state->head != Z_NULL) { 805 if (state->head != Z_NULL) {
806 state->head->hcrc = (int)((state->flags >> 9) & 1); 806 state->head->hcrc = (int)((state->flags >> 9) & 1);
807 state->head->done = 1; 807 state->head->done = 1;
808 } 808 }
809 strm->adler = state->check = crc32(0L, Z_NULL, 0); 809 strm->adler = state->check = crc32(0L, Z_NULL, 0);
810 state->mode = TYPE; 810 state->mode = TYPE;
811 break; 811 break;
812#endif 812#endif
813 case DICTID: 813 case DICTID:
814 NEEDBITS(32); 814 NEEDBITS(32);
815 strm->adler = state->check = ZSWAP32(hold); 815 strm->adler = state->check = ZSWAP32(hold);
816 INITBITS(); 816 INITBITS();
817 state->mode = DICT; 817 state->mode = DICT;
818 case DICT: 818 case DICT:
819 if (state->havedict == 0) { 819 if (state->havedict == 0) {
820 RESTORE(); 820 RESTORE();
821 return Z_NEED_DICT; 821 return Z_NEED_DICT;
822 } 822 }
823 strm->adler = state->check = adler32(0L, Z_NULL, 0); 823 strm->adler = state->check = adler32(0L, Z_NULL, 0);
824 state->mode = TYPE; 824 state->mode = TYPE;
825 case TYPE: 825 case TYPE:
826 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; 826 if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave;
827 case TYPEDO: 827 case TYPEDO:
828 if (state->last) { 828 if (state->last) {
829 BYTEBITS(); 829 BYTEBITS();
830 state->mode = CHECK; 830 state->mode = CHECK;
831 break; 831 break;
832 } 832 }
833 NEEDBITS(3); 833 NEEDBITS(3);
834 state->last = BITS(1); 834 state->last = BITS(1);
835 DROPBITS(1); 835 DROPBITS(1);
836 switch (BITS(2)) { 836 switch (BITS(2)) {
837 case 0: /* stored block */ 837 case 0: /* stored block */
838 Tracev((stderr, "inflate: stored block%s\n", 838 Tracev((stderr, "inflate: stored block%s\n",
839 state->last ? " (last)" : "")); 839 state->last ? " (last)" : ""));
840 state->mode = STORED; 840 state->mode = STORED;
841 break; 841 break;
842 case 1: /* fixed block */ 842 case 1: /* fixed block */
843 fixedtables(state); 843 fixedtables(state);
844 Tracev((stderr, "inflate: fixed codes block%s\n", 844 Tracev((stderr, "inflate: fixed codes block%s\n",
845 state->last ? " (last)" : "")); 845 state->last ? " (last)" : ""));
846 state->mode = LEN_; /* decode codes */ 846 state->mode = LEN_; /* decode codes */
847 if (flush == Z_TREES) { 847 if (flush == Z_TREES) {
848 DROPBITS(2); 848 DROPBITS(2);
849 goto inf_leave; 849 goto inf_leave;
850 } 850 }
851 break; 851 break;
852 case 2: /* dynamic block */ 852 case 2: /* dynamic block */
853 Tracev((stderr, "inflate: dynamic codes block%s\n", 853 Tracev((stderr, "inflate: dynamic codes block%s\n",
854 state->last ? " (last)" : "")); 854 state->last ? " (last)" : ""));
855 state->mode = TABLE; 855 state->mode = TABLE;
856 break; 856 break;
857 case 3: 857 case 3:
858 strm->msg = (char *)"invalid block type"; 858 strm->msg = (char *)"invalid block type";
859 state->mode = BAD; 859 state->mode = BAD;
860 } 860 }
861 DROPBITS(2); 861 DROPBITS(2);
862 break; 862 break;
863 case STORED: 863 case STORED:
864 BYTEBITS(); /* go to byte boundary */ 864 BYTEBITS(); /* go to byte boundary */
865 NEEDBITS(32); 865 NEEDBITS(32);
866 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { 866 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
867 strm->msg = (char *)"invalid stored block lengths"; 867 strm->msg = (char *)"invalid stored block lengths";
868 state->mode = BAD; 868 state->mode = BAD;
869 break; 869 break;
870 } 870 }
871 state->length = (unsigned)hold & 0xffff; 871 state->length = (unsigned)hold & 0xffff;
872 Tracev((stderr, "inflate: stored length %u\n", 872 Tracev((stderr, "inflate: stored length %u\n",
873 state->length)); 873 state->length));
874 INITBITS(); 874 INITBITS();
875 state->mode = COPY_; 875 state->mode = COPY_;
876 if (flush == Z_TREES) goto inf_leave; 876 if (flush == Z_TREES) goto inf_leave;
877 case COPY_: 877 case COPY_:
878 state->mode = COPY; 878 state->mode = COPY;
879 case COPY: 879 case COPY:
880 copy = state->length; 880 copy = state->length;
881 if (copy) { 881 if (copy) {
882 if (copy > have) copy = have; 882 if (copy > have) copy = have;
883 if (copy > left) copy = left; 883 if (copy > left) copy = left;
884 if (copy == 0) goto inf_leave; 884 if (copy == 0) goto inf_leave;
885 zmemcpy(put, next, copy); 885 zmemcpy(put, next, copy);
886 have -= copy; 886 have -= copy;
887 next += copy; 887 next += copy;
888 left -= copy; 888 left -= copy;
889 put += copy; 889 put += copy;
890 state->length -= copy; 890 state->length -= copy;
891 break; 891 break;
892 } 892 }
893 Tracev((stderr, "inflate: stored end\n")); 893 Tracev((stderr, "inflate: stored end\n"));
894 state->mode = TYPE; 894 state->mode = TYPE;
895 break; 895 break;
896 case TABLE: 896 case TABLE:
897 NEEDBITS(14); 897 NEEDBITS(14);
898 state->nlen = BITS(5) + 257; 898 state->nlen = BITS(5) + 257;
899 DROPBITS(5); 899 DROPBITS(5);
900 state->ndist = BITS(5) + 1; 900 state->ndist = BITS(5) + 1;
901 DROPBITS(5); 901 DROPBITS(5);
902 state->ncode = BITS(4) + 4; 902 state->ncode = BITS(4) + 4;
903 DROPBITS(4); 903 DROPBITS(4);
904#ifndef PKZIP_BUG_WORKAROUND 904#ifndef PKZIP_BUG_WORKAROUND
905 if (state->nlen > 286 || state->ndist > 30) { 905 if (state->nlen > 286 || state->ndist > 30) {
906 strm->msg = (char *)"too many length or distance symbols"; 906 strm->msg = (char *)"too many length or distance symbols";
907 state->mode = BAD; 907 state->mode = BAD;
908 break; 908 break;
909 } 909 }
910#endif 910#endif
911 Tracev((stderr, "inflate: table sizes ok\n")); 911 Tracev((stderr, "inflate: table sizes ok\n"));
912 state->have = 0; 912 state->have = 0;
913 state->mode = LENLENS; 913 state->mode = LENLENS;
914 case LENLENS: 914 case LENLENS:
915 while (state->have < state->ncode) { 915 while (state->have < state->ncode) {
916 NEEDBITS(3); 916 NEEDBITS(3);
917 state->lens[order[state->have++]] = (unsigned short)BITS(3); 917 state->lens[order[state->have++]] = (unsigned short)BITS(3);
918 DROPBITS(3); 918 DROPBITS(3);
919 } 919 }
920 while (state->have < 19) 920 while (state->have < 19)
921 state->lens[order[state->have++]] = 0; 921 state->lens[order[state->have++]] = 0;
922 state->next = state->codes; 922 state->next = state->codes;
923 state->lencode = (code const FAR *)(state->next); 923 state->lencode = (code const FAR *)(state->next);
924 state->lenbits = 7; 924 state->lenbits = 7;
925 ret = inflate_table(CODES, state->lens, 19, &(state->next), 925 ret = inflate_table(CODES, state->lens, 19, &(state->next),
926 &(state->lenbits), state->work); 926 &(state->lenbits), state->work);
927 if (ret) { 927 if (ret) {
928 strm->msg = (char *)"invalid code lengths set"; 928 strm->msg = (char *)"invalid code lengths set";
929 state->mode = BAD; 929 state->mode = BAD;
930 break; 930 break;
931 } 931 }
932 Tracev((stderr, "inflate: code lengths ok\n")); 932 Tracev((stderr, "inflate: code lengths ok\n"));
933 state->have = 0; 933 state->have = 0;
934 state->mode = CODELENS; 934 state->mode = CODELENS;
935 case CODELENS: 935 case CODELENS:
936 while (state->have < state->nlen + state->ndist) { 936 while (state->have < state->nlen + state->ndist) {
937 for (;;) { 937 for (;;) {
938 here = state->lencode[BITS(state->lenbits)]; 938 here = state->lencode[BITS(state->lenbits)];
939 if ((unsigned)(here.bits) <= bits) break; 939 if ((unsigned)(here.bits) <= bits) break;
940 PULLBYTE(); 940 PULLBYTE();
941 } 941 }
942 if (here.val < 16) { 942 if (here.val < 16) {
943 DROPBITS(here.bits); 943 DROPBITS(here.bits);
944 state->lens[state->have++] = here.val; 944 state->lens[state->have++] = here.val;
945 } 945 }
946 else { 946 else {
947 if (here.val == 16) { 947 if (here.val == 16) {
948 NEEDBITS(here.bits + 2); 948 NEEDBITS(here.bits + 2);
949 DROPBITS(here.bits); 949 DROPBITS(here.bits);
950 if (state->have == 0) { 950 if (state->have == 0) {
951 strm->msg = (char *)"invalid bit length repeat"; 951 strm->msg = (char *)"invalid bit length repeat";
952 state->mode = BAD; 952 state->mode = BAD;
953 break; 953 break;
954 } 954 }
955 len = state->lens[state->have - 1]; 955 len = state->lens[state->have - 1];
956 copy = 3 + BITS(2); 956 copy = 3 + BITS(2);
957 DROPBITS(2); 957 DROPBITS(2);
958 } 958 }
959 else if (here.val == 17) { 959 else if (here.val == 17) {
960 NEEDBITS(here.bits + 3); 960 NEEDBITS(here.bits + 3);
961 DROPBITS(here.bits); 961 DROPBITS(here.bits);
962 len = 0; 962 len = 0;
963 copy = 3 + BITS(3); 963 copy = 3 + BITS(3);
964 DROPBITS(3); 964 DROPBITS(3);
965 } 965 }
966 else { 966 else {
967 NEEDBITS(here.bits + 7); 967 NEEDBITS(here.bits + 7);
968 DROPBITS(here.bits); 968 DROPBITS(here.bits);
969 len = 0; 969 len = 0;
970 copy = 11 + BITS(7); 970 copy = 11 + BITS(7);
971 DROPBITS(7); 971 DROPBITS(7);
972 } 972 }
973 if (state->have + copy > state->nlen + state->ndist) { 973 if (state->have + copy > state->nlen + state->ndist) {
974 strm->msg = (char *)"invalid bit length repeat"; 974 strm->msg = (char *)"invalid bit length repeat";
975 state->mode = BAD; 975 state->mode = BAD;
976 break; 976 break;
977 } 977 }
978 while (copy--) 978 while (copy--)
979 state->lens[state->have++] = (unsigned short)len; 979 state->lens[state->have++] = (unsigned short)len;
980 } 980 }
981 } 981 }
982 982
983 /* handle error breaks in while */ 983 /* handle error breaks in while */
984 if (state->mode == BAD) break; 984 if (state->mode == BAD) break;
985 985
986 /* check for end-of-block code (better have one) */ 986 /* check for end-of-block code (better have one) */
987 if (state->lens[256] == 0) { 987 if (state->lens[256] == 0) {
988 strm->msg = (char *)"invalid code -- missing end-of-block"; 988 strm->msg = (char *)"invalid code -- missing end-of-block";
989 state->mode = BAD; 989 state->mode = BAD;
990 break; 990 break;
991 } 991 }
992 992
993 /* build code tables -- note: do not change the lenbits or distbits 993 /* build code tables -- note: do not change the lenbits or distbits
994 values here (9 and 6) without reading the comments in inftrees.h 994 values here (9 and 6) without reading the comments in inftrees.h
995 concerning the ENOUGH constants, which depend on those values */ 995 concerning the ENOUGH constants, which depend on those values */
996 state->next = state->codes; 996 state->next = state->codes;
997 state->lencode = (code const FAR *)(state->next); 997 state->lencode = (code const FAR *)(state->next);
998 state->lenbits = 9; 998 state->lenbits = 9;
999 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), 999 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1000 &(state->lenbits), state->work); 1000 &(state->lenbits), state->work);
1001 if (ret) { 1001 if (ret) {
1002 strm->msg = (char *)"invalid literal/lengths set"; 1002 strm->msg = (char *)"invalid literal/lengths set";
1003 state->mode = BAD; 1003 state->mode = BAD;
1004 break; 1004 break;
1005 } 1005 }
1006 state->distcode = (code const FAR *)(state->next); 1006 state->distcode = (code const FAR *)(state->next);
1007 state->distbits = 6; 1007 state->distbits = 6;
1008 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, 1008 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1009 &(state->next), &(state->distbits), state->work); 1009 &(state->next), &(state->distbits), state->work);
1010 if (ret) { 1010 if (ret) {
1011 strm->msg = (char *)"invalid distances set"; 1011 strm->msg = (char *)"invalid distances set";
1012 state->mode = BAD; 1012 state->mode = BAD;
1013 break; 1013 break;
1014 } 1014 }
1015 Tracev((stderr, "inflate: codes ok\n")); 1015 Tracev((stderr, "inflate: codes ok\n"));
1016 state->mode = LEN_; 1016 state->mode = LEN_;
1017 if (flush == Z_TREES) goto inf_leave; 1017 if (flush == Z_TREES) goto inf_leave;
1018 case LEN_: 1018 case LEN_:
1019 state->mode = LEN; 1019 state->mode = LEN;
1020 case LEN: 1020 case LEN:
1021 if (have >= 6 && left >= 258) { 1021 if (have >= 6 && left >= 258) {
1022 RESTORE(); 1022 RESTORE();
1023 inflate_fast(strm, out); 1023 inflate_fast(strm, out);
1024 LOAD(); 1024 LOAD();
1025 if (state->mode == TYPE) 1025 if (state->mode == TYPE)
1026 state->back = -1; 1026 state->back = -1;
1027 break; 1027 break;
1028 } 1028 }
1029 state->back = 0; 1029 state->back = 0;
1030 for (;;) { 1030 for (;;) {
1031 here = state->lencode[BITS(state->lenbits)]; 1031 here = state->lencode[BITS(state->lenbits)];
1032 if ((unsigned)(here.bits) <= bits) break; 1032 if ((unsigned)(here.bits) <= bits) break;
1033 PULLBYTE(); 1033 PULLBYTE();
1034 } 1034 }
1035 if (here.op && (here.op & 0xf0) == 0) { 1035 if (here.op && (here.op & 0xf0) == 0) {
1036 last = here; 1036 last = here;
1037 for (;;) { 1037 for (;;) {
1038 here = state->lencode[last.val + 1038 here = state->lencode[last.val +
1039 (BITS(last.bits + last.op) >> last.bits)]; 1039 (BITS(last.bits + last.op) >> last.bits)];
1040 if ((unsigned)(last.bits + here.bits) <= bits) break; 1040 if ((unsigned)(last.bits + here.bits) <= bits) break;
1041 PULLBYTE(); 1041 PULLBYTE();
1042 } 1042 }
1043 DROPBITS(last.bits); 1043 DROPBITS(last.bits);
1044 state->back += last.bits; 1044 state->back += last.bits;
1045 } 1045 }
1046 DROPBITS(here.bits); 1046 DROPBITS(here.bits);
1047 state->back += here.bits; 1047 state->back += here.bits;
1048 state->length = (unsigned)here.val; 1048 state->length = (unsigned)here.val;
1049 if ((int)(here.op) == 0) { 1049 if ((int)(here.op) == 0) {
1050 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? 1050 Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1051 "inflate: literal '%c'\n" : 1051 "inflate: literal '%c'\n" :
1052 "inflate: literal 0x%02x\n", here.val)); 1052 "inflate: literal 0x%02x\n", here.val));
1053 state->mode = LIT; 1053 state->mode = LIT;
1054 break; 1054 break;
1055 } 1055 }
1056 if (here.op & 32) { 1056 if (here.op & 32) {
1057 Tracevv((stderr, "inflate: end of block\n")); 1057 Tracevv((stderr, "inflate: end of block\n"));
1058 state->back = -1; 1058 state->back = -1;
1059 state->mode = TYPE; 1059 state->mode = TYPE;
1060 break; 1060 break;
1061 } 1061 }
1062 if (here.op & 64) { 1062 if (here.op & 64) {
1063 strm->msg = (char *)"invalid literal/length code"; 1063 strm->msg = (char *)"invalid literal/length code";
1064 state->mode = BAD; 1064 state->mode = BAD;
1065 break; 1065 break;
1066 } 1066 }
1067 state->extra = (unsigned)(here.op) & 15; 1067 state->extra = (unsigned)(here.op) & 15;
1068 state->mode = LENEXT; 1068 state->mode = LENEXT;
1069 case LENEXT: 1069 case LENEXT:
1070 if (state->extra) { 1070 if (state->extra) {
1071 NEEDBITS(state->extra); 1071 NEEDBITS(state->extra);
1072 state->length += BITS(state->extra); 1072 state->length += BITS(state->extra);
1073 DROPBITS(state->extra); 1073 DROPBITS(state->extra);
1074 state->back += state->extra; 1074 state->back += state->extra;
1075 } 1075 }
1076 Tracevv((stderr, "inflate: length %u\n", state->length)); 1076 Tracevv((stderr, "inflate: length %u\n", state->length));
1077 state->was = state->length; 1077 state->was = state->length;
1078 state->mode = DIST; 1078 state->mode = DIST;
1079 case DIST: 1079 case DIST:
1080 for (;;) { 1080 for (;;) {
1081 here = state->distcode[BITS(state->distbits)]; 1081 here = state->distcode[BITS(state->distbits)];
1082 if ((unsigned)(here.bits) <= bits) break; 1082 if ((unsigned)(here.bits) <= bits) break;
1083 PULLBYTE(); 1083 PULLBYTE();
1084 } 1084 }
1085 if ((here.op & 0xf0) == 0) { 1085 if ((here.op & 0xf0) == 0) {
1086 last = here; 1086 last = here;
1087 for (;;) { 1087 for (;;) {
1088 here = state->distcode[last.val + 1088 here = state->distcode[last.val +
1089 (BITS(last.bits + last.op) >> last.bits)]; 1089 (BITS(last.bits + last.op) >> last.bits)];
1090 if ((unsigned)(last.bits + here.bits) <= bits) break; 1090 if ((unsigned)(last.bits + here.bits) <= bits) break;
1091 PULLBYTE(); 1091 PULLBYTE();
1092 } 1092 }
1093 DROPBITS(last.bits); 1093 DROPBITS(last.bits);
1094 state->back += last.bits; 1094 state->back += last.bits;
1095 } 1095 }
1096 DROPBITS(here.bits); 1096 DROPBITS(here.bits);
1097 state->back += here.bits; 1097 state->back += here.bits;
1098 if (here.op & 64) { 1098 if (here.op & 64) {
1099 strm->msg = (char *)"invalid distance code"; 1099 strm->msg = (char *)"invalid distance code";
1100 state->mode = BAD; 1100 state->mode = BAD;
1101 break; 1101 break;
1102 } 1102 }
1103 state->offset = (unsigned)here.val; 1103 state->offset = (unsigned)here.val;
1104 state->extra = (unsigned)(here.op) & 15; 1104 state->extra = (unsigned)(here.op) & 15;
1105 state->mode = DISTEXT; 1105 state->mode = DISTEXT;
1106 case DISTEXT: 1106 case DISTEXT:
1107 if (state->extra) { 1107 if (state->extra) {
1108 NEEDBITS(state->extra); 1108 NEEDBITS(state->extra);
1109 state->offset += BITS(state->extra); 1109 state->offset += BITS(state->extra);
1110 DROPBITS(state->extra); 1110 DROPBITS(state->extra);
1111 state->back += state->extra; 1111 state->back += state->extra;
1112 } 1112 }
1113#ifdef INFLATE_STRICT 1113#ifdef INFLATE_STRICT
1114 if (state->offset > state->dmax) { 1114 if (state->offset > state->dmax) {
1115 strm->msg = (char *)"invalid distance too far back"; 1115 strm->msg = (char *)"invalid distance too far back";
1116 state->mode = BAD; 1116 state->mode = BAD;
1117 break; 1117 break;
1118 } 1118 }
1119#endif 1119#endif
1120 Tracevv((stderr, "inflate: distance %u\n", state->offset)); 1120 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1121 state->mode = MATCH; 1121 state->mode = MATCH;
1122 case MATCH: 1122 case MATCH:
1123 if (left == 0) goto inf_leave; 1123 if (left == 0) goto inf_leave;
1124 copy = out - left; 1124 copy = out - left;
1125 if (state->offset > copy) { /* copy from window */ 1125 if (state->offset > copy) { /* copy from window */
1126 copy = state->offset - copy; 1126 copy = state->offset - copy;
1127 if (copy > state->whave) { 1127 if (copy > state->whave) {
1128 if (state->sane) { 1128 if (state->sane) {
1129 strm->msg = (char *)"invalid distance too far back"; 1129 strm->msg = (char *)"invalid distance too far back";
1130 state->mode = BAD; 1130 state->mode = BAD;
1131 break; 1131 break;
1132 } 1132 }
1133#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 1133#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1134 Trace((stderr, "inflate.c too far\n")); 1134 Trace((stderr, "inflate.c too far\n"));
1135 copy -= state->whave; 1135 copy -= state->whave;
1136 if (copy > state->length) copy = state->length; 1136 if (copy > state->length) copy = state->length;
1137 if (copy > left) copy = left; 1137 if (copy > left) copy = left;
1138 left -= copy; 1138 left -= copy;
1139 state->length -= copy; 1139 state->length -= copy;
1140 do { 1140 do {
1141 *put++ = 0; 1141 *put++ = 0;
1142 } while (--copy); 1142 } while (--copy);
1143 if (state->length == 0) state->mode = LEN; 1143 if (state->length == 0) state->mode = LEN;
1144 break; 1144 break;
1145#endif 1145#endif
1146 } 1146 }
1147 if (copy > state->wnext) { 1147 if (copy > state->wnext) {
1148 copy -= state->wnext; 1148 copy -= state->wnext;
1149 from = state->window + (state->wsize - copy); 1149 from = state->window + (state->wsize - copy);
1150 } 1150 }
1151 else 1151 else
1152 from = state->window + (state->wnext - copy); 1152 from = state->window + (state->wnext - copy);
1153 if (copy > state->length) copy = state->length; 1153 if (copy > state->length) copy = state->length;
1154 } 1154 }
1155 else { /* copy from output */ 1155 else { /* copy from output */
1156 from = put - state->offset; 1156 from = put - state->offset;
1157 copy = state->length; 1157 copy = state->length;
1158 } 1158 }
1159 if (copy > left) copy = left; 1159 if (copy > left) copy = left;
1160 left -= copy; 1160 left -= copy;
1161 state->length -= copy; 1161 state->length -= copy;
1162 do { 1162 do {
1163 *put++ = *from++; 1163 *put++ = *from++;
1164 } while (--copy); 1164 } while (--copy);
1165 if (state->length == 0) state->mode = LEN; 1165 if (state->length == 0) state->mode = LEN;
1166 break; 1166 break;
1167 case LIT: 1167 case LIT:
1168 if (left == 0) goto inf_leave; 1168 if (left == 0) goto inf_leave;
1169 *put++ = (unsigned char)(state->length); 1169 *put++ = (unsigned char)(state->length);
1170 left--; 1170 left--;
1171 state->mode = LEN; 1171 state->mode = LEN;
1172 break; 1172 break;
1173 case CHECK: 1173 case CHECK:
1174 if (state->wrap) { 1174 if (state->wrap) {
1175 NEEDBITS(32); 1175 NEEDBITS(32);
1176 out -= left; 1176 out -= left;
1177 strm->total_out += out; 1177 strm->total_out += out;
1178 state->total += out; 1178 state->total += out;
1179 if (out) 1179 if (out)
1180 strm->adler = state->check = 1180 strm->adler = state->check =
1181 UPDATE(state->check, put - out, out); 1181 UPDATE(state->check, put - out, out);
1182 out = left; 1182 out = left;
1183 if (( 1183 if ((
1184#ifdef GUNZIP 1184#ifdef GUNZIP
1185 state->flags ? hold : 1185 state->flags ? hold :
1186#endif 1186#endif
1187 ZSWAP32(hold)) != state->check) { 1187 ZSWAP32(hold)) != state->check) {
1188 strm->msg = (char *)"incorrect data check"; 1188 strm->msg = (char *)"incorrect data check";
1189 state->mode = BAD; 1189 state->mode = BAD;
1190 break; 1190 break;
1191 } 1191 }
1192 INITBITS(); 1192 INITBITS();
1193 Tracev((stderr, "inflate: check matches trailer\n")); 1193 Tracev((stderr, "inflate: check matches trailer\n"));
1194 } 1194 }
1195#ifdef GUNZIP 1195#ifdef GUNZIP
1196 state->mode = LENGTH; 1196 state->mode = LENGTH;
1197 case LENGTH: 1197 case LENGTH:
1198 if (state->wrap && state->flags) { 1198 if (state->wrap && state->flags) {
1199 NEEDBITS(32); 1199 NEEDBITS(32);
1200 if (hold != (state->total & 0xffffffffUL)) { 1200 if (hold != (state->total & 0xffffffffUL)) {
1201 strm->msg = (char *)"incorrect length check"; 1201 strm->msg = (char *)"incorrect length check";
1202 state->mode = BAD; 1202 state->mode = BAD;
1203 break; 1203 break;
1204 } 1204 }
1205 INITBITS(); 1205 INITBITS();
1206 Tracev((stderr, "inflate: length matches trailer\n")); 1206 Tracev((stderr, "inflate: length matches trailer\n"));
1207 } 1207 }
1208#endif 1208#endif
1209 state->mode = DONE; 1209 state->mode = DONE;
1210 case DONE: 1210 case DONE:
1211 ret = Z_STREAM_END; 1211 ret = Z_STREAM_END;
1212 goto inf_leave; 1212 goto inf_leave;
1213 case BAD: 1213 case BAD:
1214 ret = Z_DATA_ERROR; 1214 ret = Z_DATA_ERROR;
1215 goto inf_leave; 1215 goto inf_leave;
1216 case MEM: 1216 case MEM:
1217 return Z_MEM_ERROR; 1217 return Z_MEM_ERROR;
1218 case SYNC: 1218 case SYNC:
1219 default: 1219 default:
1220 return Z_STREAM_ERROR; 1220 return Z_STREAM_ERROR;
1221 } 1221 }
1222 1222
1223 /* 1223 /*
1224 Return from inflate(), updating the total counts and the check value. 1224 Return from inflate(), updating the total counts and the check value.
1225 If there was no progress during the inflate() call, return a buffer 1225 If there was no progress during the inflate() call, return a buffer
1226 error. Call updatewindow() to create and/or update the window state. 1226 error. Call updatewindow() to create and/or update the window state.
1227 Note: a memory error from inflate() is non-recoverable. 1227 Note: a memory error from inflate() is non-recoverable.
1228 */ 1228 */
1229 inf_leave: 1229 inf_leave:
1230 RESTORE(); 1230 RESTORE();
1231 if (state->wsize || (out != strm->avail_out && state->mode < BAD && 1231 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1232 (state->mode < CHECK || flush != Z_FINISH))) 1232 (state->mode < CHECK || flush != Z_FINISH)))
1233 if (updatewindow(strm, out)) { 1233 if (updatewindow(strm, out)) {
1234 state->mode = MEM; 1234 state->mode = MEM;
1235 return Z_MEM_ERROR; 1235 return Z_MEM_ERROR;
1236 } 1236 }
1237 in -= strm->avail_in; 1237 in -= strm->avail_in;
1238 out -= strm->avail_out; 1238 out -= strm->avail_out;
1239 strm->total_in += in; 1239 strm->total_in += in;
1240 strm->total_out += out; 1240 strm->total_out += out;
1241 state->total += out; 1241 state->total += out;
1242 if (state->wrap && out) 1242 if (state->wrap && out)
1243 strm->adler = state->check = 1243 strm->adler = state->check =
1244 UPDATE(state->check, strm->next_out - out, out); 1244 UPDATE(state->check, strm->next_out - out, out);
1245 strm->data_type = state->bits + (state->last ? 64 : 0) + 1245 strm->data_type = state->bits + (state->last ? 64 : 0) +
1246 (state->mode == TYPE ? 128 : 0) + 1246 (state->mode == TYPE ? 128 : 0) +
1247 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); 1247 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1248 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) 1248 if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
1249 ret = Z_BUF_ERROR; 1249 ret = Z_BUF_ERROR;
1250 return ret; 1250 return ret;
1251} 1251}
1252 1252
1253int ZEXPORT inflateEnd(strm) 1253int ZEXPORT inflateEnd(strm)
1254z_streamp strm; 1254z_streamp strm;
1255{ 1255{
1256 struct inflate_state FAR *state; 1256 struct inflate_state FAR *state;
1257 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) 1257 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1258 return Z_STREAM_ERROR; 1258 return Z_STREAM_ERROR;
1259 state = (struct inflate_state FAR *)strm->state; 1259 state = (struct inflate_state FAR *)strm->state;
1260 if (state->window != Z_NULL) ZFREE(strm, state->window); 1260 if (state->window != Z_NULL) ZFREE(strm, state->window);
1261 ZFREE(strm, strm->state); 1261 ZFREE(strm, strm->state);
1262 strm->state = Z_NULL; 1262 strm->state = Z_NULL;
1263 Tracev((stderr, "inflate: end\n")); 1263 Tracev((stderr, "inflate: end\n"));
1264 return Z_OK; 1264 return Z_OK;
1265} 1265}
1266 1266
1267int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) 1267int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
1268z_streamp strm; 1268z_streamp strm;
1269const Bytef *dictionary; 1269const Bytef *dictionary;
1270uInt dictLength; 1270uInt dictLength;
1271{ 1271{
1272 struct inflate_state FAR *state; 1272 struct inflate_state FAR *state;
1273 unsigned long dictid; 1273 unsigned long dictid;
1274 unsigned char *next; 1274 unsigned char *next;
1275 unsigned avail; 1275 unsigned avail;
1276 int ret; 1276 int ret;
1277 1277
1278 /* check state */ 1278 /* check state */
1279 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1279 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1280 state = (struct inflate_state FAR *)strm->state; 1280 state = (struct inflate_state FAR *)strm->state;
1281 if (state->wrap != 0 && state->mode != DICT) 1281 if (state->wrap != 0 && state->mode != DICT)
1282 return Z_STREAM_ERROR; 1282 return Z_STREAM_ERROR;
1283 1283
1284 /* check for correct dictionary identifier */ 1284 /* check for correct dictionary identifier */
1285 if (state->mode == DICT) { 1285 if (state->mode == DICT) {
1286 dictid = adler32(0L, Z_NULL, 0); 1286 dictid = adler32(0L, Z_NULL, 0);
1287 dictid = adler32(dictid, dictionary, dictLength); 1287 dictid = adler32(dictid, dictionary, dictLength);
1288 if (dictid != state->check) 1288 if (dictid != state->check)
1289 return Z_DATA_ERROR; 1289 return Z_DATA_ERROR;
1290 } 1290 }
1291 1291
1292 /* copy dictionary to window using updatewindow(), which will amend the 1292 /* copy dictionary to window using updatewindow(), which will amend the
1293 existing dictionary if appropriate */ 1293 existing dictionary if appropriate */
1294 next = strm->next_out; 1294 next = strm->next_out;
1295 avail = strm->avail_out; 1295 avail = strm->avail_out;
1296 strm->next_out = (Bytef *)dictionary + dictLength; 1296 strm->next_out = (Bytef *)dictionary + dictLength;
1297 strm->avail_out = 0; 1297 strm->avail_out = 0;
1298 ret = updatewindow(strm, dictLength); 1298 ret = updatewindow(strm, dictLength);
1299 strm->avail_out = avail; 1299 strm->avail_out = avail;
1300 strm->next_out = next; 1300 strm->next_out = next;
1301 if (ret) { 1301 if (ret) {
1302 state->mode = MEM; 1302 state->mode = MEM;
1303 return Z_MEM_ERROR; 1303 return Z_MEM_ERROR;
1304 } 1304 }
1305 state->havedict = 1; 1305 state->havedict = 1;
1306 Tracev((stderr, "inflate: dictionary set\n")); 1306 Tracev((stderr, "inflate: dictionary set\n"));
1307 return Z_OK; 1307 return Z_OK;
1308} 1308}
1309 1309
1310int ZEXPORT inflateGetHeader(strm, head) 1310int ZEXPORT inflateGetHeader(strm, head)
1311z_streamp strm; 1311z_streamp strm;
1312gz_headerp head; 1312gz_headerp head;
1313{ 1313{
1314 struct inflate_state FAR *state; 1314 struct inflate_state FAR *state;
1315 1315
1316 /* check state */ 1316 /* check state */
1317 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1317 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1318 state = (struct inflate_state FAR *)strm->state; 1318 state = (struct inflate_state FAR *)strm->state;
1319 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; 1319 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1320 1320
1321 /* save header structure */ 1321 /* save header structure */
1322 state->head = head; 1322 state->head = head;
1323 head->done = 0; 1323 head->done = 0;
1324 return Z_OK; 1324 return Z_OK;
1325} 1325}
1326 1326
1327/* 1327/*
1328 Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found 1328 Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
1329 or when out of input. When called, *have is the number of pattern bytes 1329 or when out of input. When called, *have is the number of pattern bytes
1330 found in order so far, in 0..3. On return *have is updated to the new 1330 found in order so far, in 0..3. On return *have is updated to the new
1331 state. If on return *have equals four, then the pattern was found and the 1331 state. If on return *have equals four, then the pattern was found and the
1332 return value is how many bytes were read including the last byte of the 1332 return value is how many bytes were read including the last byte of the
1333 pattern. If *have is less than four, then the pattern has not been found 1333 pattern. If *have is less than four, then the pattern has not been found
1334 yet and the return value is len. In the latter case, syncsearch() can be 1334 yet and the return value is len. In the latter case, syncsearch() can be
1335 called again with more data and the *have state. *have is initialized to 1335 called again with more data and the *have state. *have is initialized to
1336 zero for the first call. 1336 zero for the first call.
1337 */ 1337 */
1338local unsigned syncsearch(have, buf, len) 1338local unsigned syncsearch(have, buf, len)
1339unsigned FAR *have; 1339unsigned FAR *have;
1340unsigned char FAR *buf; 1340unsigned char FAR *buf;
1341unsigned len; 1341unsigned len;
1342{ 1342{
1343 unsigned got; 1343 unsigned got;
1344 unsigned next; 1344 unsigned next;
1345 1345
1346 got = *have; 1346 got = *have;
1347 next = 0; 1347 next = 0;
1348 while (next < len && got < 4) { 1348 while (next < len && got < 4) {
1349 if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) 1349 if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
1350 got++; 1350 got++;
1351 else if (buf[next]) 1351 else if (buf[next])
1352 got = 0; 1352 got = 0;
1353 else 1353 else
1354 got = 4 - got; 1354 got = 4 - got;
1355 next++; 1355 next++;
1356 } 1356 }
1357 *have = got; 1357 *have = got;
1358 return next; 1358 return next;
1359} 1359}
1360 1360
1361int ZEXPORT inflateSync(strm) 1361int ZEXPORT inflateSync(strm)
1362z_streamp strm; 1362z_streamp strm;
1363{ 1363{
1364 unsigned len; /* number of bytes to look at or looked at */ 1364 unsigned len; /* number of bytes to look at or looked at */
1365 unsigned long in, out; /* temporary to save total_in and total_out */ 1365 unsigned long in, out; /* temporary to save total_in and total_out */
1366 unsigned char buf[4]; /* to restore bit buffer to byte string */ 1366 unsigned char buf[4]; /* to restore bit buffer to byte string */
1367 struct inflate_state FAR *state; 1367 struct inflate_state FAR *state;
1368 1368
1369 /* check parameters */ 1369 /* check parameters */
1370 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1370 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1371 state = (struct inflate_state FAR *)strm->state; 1371 state = (struct inflate_state FAR *)strm->state;
1372 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; 1372 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1373 1373
1374 /* if first time, start search in bit buffer */ 1374 /* if first time, start search in bit buffer */
1375 if (state->mode != SYNC) { 1375 if (state->mode != SYNC) {
1376 state->mode = SYNC; 1376 state->mode = SYNC;
1377 state->hold <<= state->bits & 7; 1377 state->hold <<= state->bits & 7;
1378 state->bits -= state->bits & 7; 1378 state->bits -= state->bits & 7;
1379 len = 0; 1379 len = 0;
1380 while (state->bits >= 8) { 1380 while (state->bits >= 8) {
1381 buf[len++] = (unsigned char)(state->hold); 1381 buf[len++] = (unsigned char)(state->hold);
1382 state->hold >>= 8; 1382 state->hold >>= 8;
1383 state->bits -= 8; 1383 state->bits -= 8;
1384 } 1384 }
1385 state->have = 0; 1385 state->have = 0;
1386 syncsearch(&(state->have), buf, len); 1386 syncsearch(&(state->have), buf, len);
1387 } 1387 }
1388 1388
1389 /* search available input */ 1389 /* search available input */
1390 len = syncsearch(&(state->have), strm->next_in, strm->avail_in); 1390 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1391 strm->avail_in -= len; 1391 strm->avail_in -= len;
1392 strm->next_in += len; 1392 strm->next_in += len;
1393 strm->total_in += len; 1393 strm->total_in += len;
1394 1394
1395 /* return no joy or set up to restart inflate() on a new block */ 1395 /* return no joy or set up to restart inflate() on a new block */
1396 if (state->have != 4) return Z_DATA_ERROR; 1396 if (state->have != 4) return Z_DATA_ERROR;
1397 in = strm->total_in; out = strm->total_out; 1397 in = strm->total_in; out = strm->total_out;
1398 inflateReset(strm); 1398 inflateReset(strm);
1399 strm->total_in = in; strm->total_out = out; 1399 strm->total_in = in; strm->total_out = out;
1400 state->mode = TYPE; 1400 state->mode = TYPE;
1401 return Z_OK; 1401 return Z_OK;
1402} 1402}
1403 1403
1404/* 1404/*
1405 Returns true if inflate is currently at the end of a block generated by 1405 Returns true if inflate is currently at the end of a block generated by
1406 Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP 1406 Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
1407 implementation to provide an additional safety check. PPP uses 1407 implementation to provide an additional safety check. PPP uses
1408 Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored 1408 Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
1409 block. When decompressing, PPP checks that at the end of input packet, 1409 block. When decompressing, PPP checks that at the end of input packet,
1410 inflate is waiting for these length bytes. 1410 inflate is waiting for these length bytes.
1411 */ 1411 */
1412int ZEXPORT inflateSyncPoint(strm) 1412int ZEXPORT inflateSyncPoint(strm)
1413z_streamp strm; 1413z_streamp strm;
1414{ 1414{
1415 struct inflate_state FAR *state; 1415 struct inflate_state FAR *state;
1416 1416
1417 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1417 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1418 state = (struct inflate_state FAR *)strm->state; 1418 state = (struct inflate_state FAR *)strm->state;
1419 return state->mode == STORED && state->bits == 0; 1419 return state->mode == STORED && state->bits == 0;
1420} 1420}
1421 1421
1422int ZEXPORT inflateCopy(dest, source) 1422int ZEXPORT inflateCopy(dest, source)
1423z_streamp dest; 1423z_streamp dest;
1424z_streamp source; 1424z_streamp source;
1425{ 1425{
1426 struct inflate_state FAR *state; 1426 struct inflate_state FAR *state;
1427 struct inflate_state FAR *copy; 1427 struct inflate_state FAR *copy;
1428 unsigned char FAR *window; 1428 unsigned char FAR *window;
1429 unsigned wsize; 1429 unsigned wsize;
1430 1430
1431 /* check input */ 1431 /* check input */
1432 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || 1432 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1433 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) 1433 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1434 return Z_STREAM_ERROR; 1434 return Z_STREAM_ERROR;
1435 state = (struct inflate_state FAR *)source->state; 1435 state = (struct inflate_state FAR *)source->state;
1436 1436
1437 /* allocate space */ 1437 /* allocate space */
1438 copy = (struct inflate_state FAR *) 1438 copy = (struct inflate_state FAR *)
1439 ZALLOC(source, 1, sizeof(struct inflate_state)); 1439 ZALLOC(source, 1, sizeof(struct inflate_state));
1440 if (copy == Z_NULL) return Z_MEM_ERROR; 1440 if (copy == Z_NULL) return Z_MEM_ERROR;
1441 window = Z_NULL; 1441 window = Z_NULL;
1442 if (state->window != Z_NULL) { 1442 if (state->window != Z_NULL) {
1443 window = (unsigned char FAR *) 1443 window = (unsigned char FAR *)
1444 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); 1444 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1445 if (window == Z_NULL) { 1445 if (window == Z_NULL) {
1446 ZFREE(source, copy); 1446 ZFREE(source, copy);
1447 return Z_MEM_ERROR; 1447 return Z_MEM_ERROR;
1448 } 1448 }
1449 } 1449 }
1450 1450
1451 /* copy state */ 1451 /* copy state */
1452 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); 1452 zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
1453 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); 1453 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1454 if (state->lencode >= state->codes && 1454 if (state->lencode >= state->codes &&
1455 state->lencode <= state->codes + ENOUGH - 1) { 1455 state->lencode <= state->codes + ENOUGH - 1) {
1456 copy->lencode = copy->codes + (state->lencode - state->codes); 1456 copy->lencode = copy->codes + (state->lencode - state->codes);
1457 copy->distcode = copy->codes + (state->distcode - state->codes); 1457 copy->distcode = copy->codes + (state->distcode - state->codes);
1458 } 1458 }
1459 copy->next = copy->codes + (state->next - state->codes); 1459 copy->next = copy->codes + (state->next - state->codes);
1460 if (window != Z_NULL) { 1460 if (window != Z_NULL) {
1461 wsize = 1U << state->wbits; 1461 wsize = 1U << state->wbits;
1462 zmemcpy(window, state->window, wsize); 1462 zmemcpy(window, state->window, wsize);
1463 } 1463 }
1464 copy->window = window; 1464 copy->window = window;
1465 dest->state = (struct internal_state FAR *)copy; 1465 dest->state = (struct internal_state FAR *)copy;
1466 return Z_OK; 1466 return Z_OK;
1467} 1467}
1468 1468
1469int ZEXPORT inflateUndermine(strm, subvert) 1469int ZEXPORT inflateUndermine(strm, subvert)
1470z_streamp strm; 1470z_streamp strm;
1471int subvert; 1471int subvert;
1472{ 1472{
1473 struct inflate_state FAR *state; 1473 struct inflate_state FAR *state;
1474 1474
1475 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 1475 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1476 state = (struct inflate_state FAR *)strm->state; 1476 state = (struct inflate_state FAR *)strm->state;
1477 state->sane = !subvert; 1477 state->sane = !subvert;
1478#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR 1478#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1479 return Z_OK; 1479 return Z_OK;
1480#else 1480#else
1481 state->sane = 1; 1481 state->sane = 1;
1482 return Z_DATA_ERROR; 1482 return Z_DATA_ERROR;
1483#endif 1483#endif
1484} 1484}
1485 1485
1486long ZEXPORT inflateMark(strm) 1486long ZEXPORT inflateMark(strm)
1487z_streamp strm; 1487z_streamp strm;
1488{ 1488{
1489 struct inflate_state FAR *state; 1489 struct inflate_state FAR *state;
1490 1490
1491 if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; 1491 if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
1492 state = (struct inflate_state FAR *)strm->state; 1492 state = (struct inflate_state FAR *)strm->state;
1493 return ((long)(state->back) << 16) + 1493 return ((long)(state->back) << 16) +
1494 (state->mode == COPY ? state->length : 1494 (state->mode == COPY ? state->length :
1495 (state->mode == MATCH ? state->was - state->length : 0)); 1495 (state->mode == MATCH ? state->was - state->length : 0));
1496} 1496}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.h
index a8ef428..95f4986 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inflate.h
@@ -1,122 +1,122 @@
1/* inflate.h -- internal inflate state definition 1/* inflate.h -- internal inflate state definition
2 * Copyright (C) 1995-2009 Mark Adler 2 * Copyright (C) 1995-2009 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* WARNING: this file should *not* be used by applications. It is 6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is 7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11/* define NO_GZIP when compiling if you want to disable gzip header and 11/* define NO_GZIP when compiling if you want to disable gzip header and
12 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 12 trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
13 the crc code when it is not needed. For shared libraries, gzip decoding 13 the crc code when it is not needed. For shared libraries, gzip decoding
14 should be left enabled. */ 14 should be left enabled. */
15#ifndef NO_GZIP 15#ifndef NO_GZIP
16# define GUNZIP 16# define GUNZIP
17#endif 17#endif
18 18
19/* Possible inflate modes between inflate() calls */ 19/* Possible inflate modes between inflate() calls */
20typedef enum { 20typedef enum {
21 HEAD, /* i: waiting for magic header */ 21 HEAD, /* i: waiting for magic header */
22 FLAGS, /* i: waiting for method and flags (gzip) */ 22 FLAGS, /* i: waiting for method and flags (gzip) */
23 TIME, /* i: waiting for modification time (gzip) */ 23 TIME, /* i: waiting for modification time (gzip) */
24 OS, /* i: waiting for extra flags and operating system (gzip) */ 24 OS, /* i: waiting for extra flags and operating system (gzip) */
25 EXLEN, /* i: waiting for extra length (gzip) */ 25 EXLEN, /* i: waiting for extra length (gzip) */
26 EXTRA, /* i: waiting for extra bytes (gzip) */ 26 EXTRA, /* i: waiting for extra bytes (gzip) */
27 NAME, /* i: waiting for end of file name (gzip) */ 27 NAME, /* i: waiting for end of file name (gzip) */
28 COMMENT, /* i: waiting for end of comment (gzip) */ 28 COMMENT, /* i: waiting for end of comment (gzip) */
29 HCRC, /* i: waiting for header crc (gzip) */ 29 HCRC, /* i: waiting for header crc (gzip) */
30 DICTID, /* i: waiting for dictionary check value */ 30 DICTID, /* i: waiting for dictionary check value */
31 DICT, /* waiting for inflateSetDictionary() call */ 31 DICT, /* waiting for inflateSetDictionary() call */
32 TYPE, /* i: waiting for type bits, including last-flag bit */ 32 TYPE, /* i: waiting for type bits, including last-flag bit */
33 TYPEDO, /* i: same, but skip check to exit inflate on new block */ 33 TYPEDO, /* i: same, but skip check to exit inflate on new block */
34 STORED, /* i: waiting for stored size (length and complement) */ 34 STORED, /* i: waiting for stored size (length and complement) */
35 COPY_, /* i/o: same as COPY below, but only first time in */ 35 COPY_, /* i/o: same as COPY below, but only first time in */
36 COPY, /* i/o: waiting for input or output to copy stored block */ 36 COPY, /* i/o: waiting for input or output to copy stored block */
37 TABLE, /* i: waiting for dynamic block table lengths */ 37 TABLE, /* i: waiting for dynamic block table lengths */
38 LENLENS, /* i: waiting for code length code lengths */ 38 LENLENS, /* i: waiting for code length code lengths */
39 CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 CODELENS, /* i: waiting for length/lit and distance code lengths */
40 LEN_, /* i: same as LEN below, but only first time in */ 40 LEN_, /* i: same as LEN below, but only first time in */
41 LEN, /* i: waiting for length/lit/eob code */ 41 LEN, /* i: waiting for length/lit/eob code */
42 LENEXT, /* i: waiting for length extra bits */ 42 LENEXT, /* i: waiting for length extra bits */
43 DIST, /* i: waiting for distance code */ 43 DIST, /* i: waiting for distance code */
44 DISTEXT, /* i: waiting for distance extra bits */ 44 DISTEXT, /* i: waiting for distance extra bits */
45 MATCH, /* o: waiting for output space to copy string */ 45 MATCH, /* o: waiting for output space to copy string */
46 LIT, /* o: waiting for output space to write literal */ 46 LIT, /* o: waiting for output space to write literal */
47 CHECK, /* i: waiting for 32-bit check value */ 47 CHECK, /* i: waiting for 32-bit check value */
48 LENGTH, /* i: waiting for 32-bit length (gzip) */ 48 LENGTH, /* i: waiting for 32-bit length (gzip) */
49 DONE, /* finished check, done -- remain here until reset */ 49 DONE, /* finished check, done -- remain here until reset */
50 BAD, /* got a data error -- remain here until reset */ 50 BAD, /* got a data error -- remain here until reset */
51 MEM, /* got an inflate() memory error -- remain here until reset */ 51 MEM, /* got an inflate() memory error -- remain here until reset */
52 SYNC /* looking for synchronization bytes to restart inflate() */ 52 SYNC /* looking for synchronization bytes to restart inflate() */
53} inflate_mode; 53} inflate_mode;
54 54
55/* 55/*
56 State transitions between above modes - 56 State transitions between above modes -
57 57
58 (most modes can go to BAD or MEM on error -- not shown for clarity) 58 (most modes can go to BAD or MEM on error -- not shown for clarity)
59 59
60 Process header: 60 Process header:
61 HEAD -> (gzip) or (zlib) or (raw) 61 HEAD -> (gzip) or (zlib) or (raw)
62 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 62 (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
63 HCRC -> TYPE 63 HCRC -> TYPE
64 (zlib) -> DICTID or TYPE 64 (zlib) -> DICTID or TYPE
65 DICTID -> DICT -> TYPE 65 DICTID -> DICT -> TYPE
66 (raw) -> TYPEDO 66 (raw) -> TYPEDO
67 Read deflate blocks: 67 Read deflate blocks:
68 TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 68 TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
69 STORED -> COPY_ -> COPY -> TYPE 69 STORED -> COPY_ -> COPY -> TYPE
70 TABLE -> LENLENS -> CODELENS -> LEN_ 70 TABLE -> LENLENS -> CODELENS -> LEN_
71 LEN_ -> LEN 71 LEN_ -> LEN
72 Read deflate codes in fixed or dynamic block: 72 Read deflate codes in fixed or dynamic block:
73 LEN -> LENEXT or LIT or TYPE 73 LEN -> LENEXT or LIT or TYPE
74 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 74 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
75 LIT -> LEN 75 LIT -> LEN
76 Process trailer: 76 Process trailer:
77 CHECK -> LENGTH -> DONE 77 CHECK -> LENGTH -> DONE
78 */ 78 */
79 79
80/* state maintained between inflate() calls. Approximately 10K bytes. */ 80/* state maintained between inflate() calls. Approximately 10K bytes. */
81struct inflate_state { 81struct inflate_state {
82 inflate_mode mode; /* current inflate mode */ 82 inflate_mode mode; /* current inflate mode */
83 int last; /* true if processing last block */ 83 int last; /* true if processing last block */
84 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 84 int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
85 int havedict; /* true if dictionary provided */ 85 int havedict; /* true if dictionary provided */
86 int flags; /* gzip header method and flags (0 if zlib) */ 86 int flags; /* gzip header method and flags (0 if zlib) */
87 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 87 unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
88 unsigned long check; /* protected copy of check value */ 88 unsigned long check; /* protected copy of check value */
89 unsigned long total; /* protected copy of output count */ 89 unsigned long total; /* protected copy of output count */
90 gz_headerp head; /* where to save gzip header information */ 90 gz_headerp head; /* where to save gzip header information */
91 /* sliding window */ 91 /* sliding window */
92 unsigned wbits; /* log base 2 of requested window size */ 92 unsigned wbits; /* log base 2 of requested window size */
93 unsigned wsize; /* window size or zero if not using window */ 93 unsigned wsize; /* window size or zero if not using window */
94 unsigned whave; /* valid bytes in the window */ 94 unsigned whave; /* valid bytes in the window */
95 unsigned wnext; /* window write index */ 95 unsigned wnext; /* window write index */
96 unsigned char FAR *window; /* allocated sliding window, if needed */ 96 unsigned char FAR *window; /* allocated sliding window, if needed */
97 /* bit accumulator */ 97 /* bit accumulator */
98 unsigned long hold; /* input bit accumulator */ 98 unsigned long hold; /* input bit accumulator */
99 unsigned bits; /* number of bits in "in" */ 99 unsigned bits; /* number of bits in "in" */
100 /* for string and stored block copying */ 100 /* for string and stored block copying */
101 unsigned length; /* literal or length of data to copy */ 101 unsigned length; /* literal or length of data to copy */
102 unsigned offset; /* distance back to copy string from */ 102 unsigned offset; /* distance back to copy string from */
103 /* for table and code decoding */ 103 /* for table and code decoding */
104 unsigned extra; /* extra bits needed */ 104 unsigned extra; /* extra bits needed */
105 /* fixed and dynamic code tables */ 105 /* fixed and dynamic code tables */
106 code const FAR *lencode; /* starting table for length/literal codes */ 106 code const FAR *lencode; /* starting table for length/literal codes */
107 code const FAR *distcode; /* starting table for distance codes */ 107 code const FAR *distcode; /* starting table for distance codes */
108 unsigned lenbits; /* index bits for lencode */ 108 unsigned lenbits; /* index bits for lencode */
109 unsigned distbits; /* index bits for distcode */ 109 unsigned distbits; /* index bits for distcode */
110 /* dynamic table building */ 110 /* dynamic table building */
111 unsigned ncode; /* number of code length code lengths */ 111 unsigned ncode; /* number of code length code lengths */
112 unsigned nlen; /* number of length code lengths */ 112 unsigned nlen; /* number of length code lengths */
113 unsigned ndist; /* number of distance code lengths */ 113 unsigned ndist; /* number of distance code lengths */
114 unsigned have; /* number of code lengths in lens[] */ 114 unsigned have; /* number of code lengths in lens[] */
115 code FAR *next; /* next available space in codes[] */ 115 code FAR *next; /* next available space in codes[] */
116 unsigned short lens[320]; /* temporary storage for code lengths */ 116 unsigned short lens[320]; /* temporary storage for code lengths */
117 unsigned short work[288]; /* work area for code table building */ 117 unsigned short work[288]; /* work area for code table building */
118 code codes[ENOUGH]; /* space for code tables */ 118 code codes[ENOUGH]; /* space for code tables */
119 int sane; /* if false, allow invalid distance too far */ 119 int sane; /* if false, allow invalid distance too far */
120 int back; /* bits back of last unprocessed length/lit */ 120 int back; /* bits back of last unprocessed length/lit */
121 unsigned was; /* initial length of match */ 121 unsigned was; /* initial length of match */
122}; 122};
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.c
index 5f47a9e..7803d01 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.c
@@ -1,306 +1,306 @@
1/* inftrees.c -- generate Huffman trees for efficient decoding 1/* inftrees.c -- generate Huffman trees for efficient decoding
2 * Copyright (C) 1995-2012 Mark Adler 2 * Copyright (C) 1995-2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6#include "zutil.h" 6#include "zutil.h"
7#include "inftrees.h" 7#include "inftrees.h"
8 8
9#define MAXBITS 15 9#define MAXBITS 15
10 10
11const char inflate_copyright[] = 11const char inflate_copyright[] =
12 " inflate 1.2.7 Copyright 1995-2012 Mark Adler "; 12 " inflate 1.2.7 Copyright 1995-2012 Mark Adler ";
13/* 13/*
14 If you use the zlib library in a product, an acknowledgment is welcome 14 If you use the zlib library in a product, an acknowledgment is welcome
15 in the documentation of your product. If for some reason you cannot 15 in the documentation of your product. If for some reason you cannot
16 include such an acknowledgment, I would appreciate that you keep this 16 include such an acknowledgment, I would appreciate that you keep this
17 copyright string in the executable of your product. 17 copyright string in the executable of your product.
18 */ 18 */
19 19
20/* 20/*
21 Build a set of tables to decode the provided canonical Huffman code. 21 Build a set of tables to decode the provided canonical Huffman code.
22 The code lengths are lens[0..codes-1]. The result starts at *table, 22 The code lengths are lens[0..codes-1]. The result starts at *table,
23 whose indices are 0..2^bits-1. work is a writable array of at least 23 whose indices are 0..2^bits-1. work is a writable array of at least
24 lens shorts, which is used as a work area. type is the type of code 24 lens shorts, which is used as a work area. type is the type of code
25 to be generated, CODES, LENS, or DISTS. On return, zero is success, 25 to be generated, CODES, LENS, or DISTS. On return, zero is success,
26 -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 26 -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
27 on return points to the next available entry's address. bits is the 27 on return points to the next available entry's address. bits is the
28 requested root table index bits, and on return it is the actual root 28 requested root table index bits, and on return it is the actual root
29 table index bits. It will differ if the request is greater than the 29 table index bits. It will differ if the request is greater than the
30 longest code or if it is less than the shortest code. 30 longest code or if it is less than the shortest code.
31 */ 31 */
32int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) 32int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
33codetype type; 33codetype type;
34unsigned short FAR *lens; 34unsigned short FAR *lens;
35unsigned codes; 35unsigned codes;
36code FAR * FAR *table; 36code FAR * FAR *table;
37unsigned FAR *bits; 37unsigned FAR *bits;
38unsigned short FAR *work; 38unsigned short FAR *work;
39{ 39{
40 unsigned len; /* a code's length in bits */ 40 unsigned len; /* a code's length in bits */
41 unsigned sym; /* index of code symbols */ 41 unsigned sym; /* index of code symbols */
42 unsigned min, max; /* minimum and maximum code lengths */ 42 unsigned min, max; /* minimum and maximum code lengths */
43 unsigned root; /* number of index bits for root table */ 43 unsigned root; /* number of index bits for root table */
44 unsigned curr; /* number of index bits for current table */ 44 unsigned curr; /* number of index bits for current table */
45 unsigned drop; /* code bits to drop for sub-table */ 45 unsigned drop; /* code bits to drop for sub-table */
46 int left; /* number of prefix codes available */ 46 int left; /* number of prefix codes available */
47 unsigned used; /* code entries in table used */ 47 unsigned used; /* code entries in table used */
48 unsigned huff; /* Huffman code */ 48 unsigned huff; /* Huffman code */
49 unsigned incr; /* for incrementing code, index */ 49 unsigned incr; /* for incrementing code, index */
50 unsigned fill; /* index for replicating entries */ 50 unsigned fill; /* index for replicating entries */
51 unsigned low; /* low bits for current root entry */ 51 unsigned low; /* low bits for current root entry */
52 unsigned mask; /* mask for low root bits */ 52 unsigned mask; /* mask for low root bits */
53 code here; /* table entry for duplication */ 53 code here; /* table entry for duplication */
54 code FAR *next; /* next available space in table */ 54 code FAR *next; /* next available space in table */
55 const unsigned short FAR *base; /* base value table to use */ 55 const unsigned short FAR *base; /* base value table to use */
56 const unsigned short FAR *extra; /* extra bits table to use */ 56 const unsigned short FAR *extra; /* extra bits table to use */
57 int end; /* use base and extra for symbol > end */ 57 int end; /* use base and extra for symbol > end */
58 unsigned short count[MAXBITS+1]; /* number of codes of each length */ 58 unsigned short count[MAXBITS+1]; /* number of codes of each length */
59 unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 59 unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
60 static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 60 static const unsigned short lbase[31] = { /* Length codes 257..285 base */
61 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 61 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 62 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 63 static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 64 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68}; 65 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 78, 68};
66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 66 static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 67 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 68 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
69 8193, 12289, 16385, 24577, 0, 0}; 69 8193, 12289, 16385, 24577, 0, 0};
70 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 70 static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
71 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 71 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
72 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 72 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
73 28, 28, 29, 29, 64, 64}; 73 28, 28, 29, 29, 64, 64};
74 74
75 /* 75 /*
76 Process a set of code lengths to create a canonical Huffman code. The 76 Process a set of code lengths to create a canonical Huffman code. The
77 code lengths are lens[0..codes-1]. Each length corresponds to the 77 code lengths are lens[0..codes-1]. Each length corresponds to the
78 symbols 0..codes-1. The Huffman code is generated by first sorting the 78 symbols 0..codes-1. The Huffman code is generated by first sorting the
79 symbols by length from short to long, and retaining the symbol order 79 symbols by length from short to long, and retaining the symbol order
80 for codes with equal lengths. Then the code starts with all zero bits 80 for codes with equal lengths. Then the code starts with all zero bits
81 for the first code of the shortest length, and the codes are integer 81 for the first code of the shortest length, and the codes are integer
82 increments for the same length, and zeros are appended as the length 82 increments for the same length, and zeros are appended as the length
83 increases. For the deflate format, these bits are stored backwards 83 increases. For the deflate format, these bits are stored backwards
84 from their more natural integer increment ordering, and so when the 84 from their more natural integer increment ordering, and so when the
85 decoding tables are built in the large loop below, the integer codes 85 decoding tables are built in the large loop below, the integer codes
86 are incremented backwards. 86 are incremented backwards.
87 87
88 This routine assumes, but does not check, that all of the entries in 88 This routine assumes, but does not check, that all of the entries in
89 lens[] are in the range 0..MAXBITS. The caller must assure this. 89 lens[] are in the range 0..MAXBITS. The caller must assure this.
90 1..MAXBITS is interpreted as that code length. zero means that that 90 1..MAXBITS is interpreted as that code length. zero means that that
91 symbol does not occur in this code. 91 symbol does not occur in this code.
92 92
93 The codes are sorted by computing a count of codes for each length, 93 The codes are sorted by computing a count of codes for each length,
94 creating from that a table of starting indices for each length in the 94 creating from that a table of starting indices for each length in the
95 sorted table, and then entering the symbols in order in the sorted 95 sorted table, and then entering the symbols in order in the sorted
96 table. The sorted table is work[], with that space being provided by 96 table. The sorted table is work[], with that space being provided by
97 the caller. 97 the caller.
98 98
99 The length counts are used for other purposes as well, i.e. finding 99 The length counts are used for other purposes as well, i.e. finding
100 the minimum and maximum length codes, determining if there are any 100 the minimum and maximum length codes, determining if there are any
101 codes at all, checking for a valid set of lengths, and looking ahead 101 codes at all, checking for a valid set of lengths, and looking ahead
102 at length counts to determine sub-table sizes when building the 102 at length counts to determine sub-table sizes when building the
103 decoding tables. 103 decoding tables.
104 */ 104 */
105 105
106 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 106 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
107 for (len = 0; len <= MAXBITS; len++) 107 for (len = 0; len <= MAXBITS; len++)
108 count[len] = 0; 108 count[len] = 0;
109 for (sym = 0; sym < codes; sym++) 109 for (sym = 0; sym < codes; sym++)
110 count[lens[sym]]++; 110 count[lens[sym]]++;
111 111
112 /* bound code lengths, force root to be within code lengths */ 112 /* bound code lengths, force root to be within code lengths */
113 root = *bits; 113 root = *bits;
114 for (max = MAXBITS; max >= 1; max--) 114 for (max = MAXBITS; max >= 1; max--)
115 if (count[max] != 0) break; 115 if (count[max] != 0) break;
116 if (root > max) root = max; 116 if (root > max) root = max;
117 if (max == 0) { /* no symbols to code at all */ 117 if (max == 0) { /* no symbols to code at all */
118 here.op = (unsigned char)64; /* invalid code marker */ 118 here.op = (unsigned char)64; /* invalid code marker */
119 here.bits = (unsigned char)1; 119 here.bits = (unsigned char)1;
120 here.val = (unsigned short)0; 120 here.val = (unsigned short)0;
121 *(*table)++ = here; /* make a table to force an error */ 121 *(*table)++ = here; /* make a table to force an error */
122 *(*table)++ = here; 122 *(*table)++ = here;
123 *bits = 1; 123 *bits = 1;
124 return 0; /* no symbols, but wait for decoding to report error */ 124 return 0; /* no symbols, but wait for decoding to report error */
125 } 125 }
126 for (min = 1; min < max; min++) 126 for (min = 1; min < max; min++)
127 if (count[min] != 0) break; 127 if (count[min] != 0) break;
128 if (root < min) root = min; 128 if (root < min) root = min;
129 129
130 /* check for an over-subscribed or incomplete set of lengths */ 130 /* check for an over-subscribed or incomplete set of lengths */
131 left = 1; 131 left = 1;
132 for (len = 1; len <= MAXBITS; len++) { 132 for (len = 1; len <= MAXBITS; len++) {
133 left <<= 1; 133 left <<= 1;
134 left -= count[len]; 134 left -= count[len];
135 if (left < 0) return -1; /* over-subscribed */ 135 if (left < 0) return -1; /* over-subscribed */
136 } 136 }
137 if (left > 0 && (type == CODES || max != 1)) 137 if (left > 0 && (type == CODES || max != 1))
138 return -1; /* incomplete set */ 138 return -1; /* incomplete set */
139 139
140 /* generate offsets into symbol table for each length for sorting */ 140 /* generate offsets into symbol table for each length for sorting */
141 offs[1] = 0; 141 offs[1] = 0;
142 for (len = 1; len < MAXBITS; len++) 142 for (len = 1; len < MAXBITS; len++)
143 offs[len + 1] = offs[len] + count[len]; 143 offs[len + 1] = offs[len] + count[len];
144 144
145 /* sort symbols by length, by symbol order within each length */ 145 /* sort symbols by length, by symbol order within each length */
146 for (sym = 0; sym < codes; sym++) 146 for (sym = 0; sym < codes; sym++)
147 if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 147 if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
148 148
149 /* 149 /*
150 Create and fill in decoding tables. In this loop, the table being 150 Create and fill in decoding tables. In this loop, the table being
151 filled is at next and has curr index bits. The code being used is huff 151 filled is at next and has curr index bits. The code being used is huff
152 with length len. That code is converted to an index by dropping drop 152 with length len. That code is converted to an index by dropping drop
153 bits off of the bottom. For codes where len is less than drop + curr, 153 bits off of the bottom. For codes where len is less than drop + curr,
154 those top drop + curr - len bits are incremented through all values to 154 those top drop + curr - len bits are incremented through all values to
155 fill the table with replicated entries. 155 fill the table with replicated entries.
156 156
157 root is the number of index bits for the root table. When len exceeds 157 root is the number of index bits for the root table. When len exceeds
158 root, sub-tables are created pointed to by the root entry with an index 158 root, sub-tables are created pointed to by the root entry with an index
159 of the low root bits of huff. This is saved in low to check for when a 159 of the low root bits of huff. This is saved in low to check for when a
160 new sub-table should be started. drop is zero when the root table is 160 new sub-table should be started. drop is zero when the root table is
161 being filled, and drop is root when sub-tables are being filled. 161 being filled, and drop is root when sub-tables are being filled.
162 162
163 When a new sub-table is needed, it is necessary to look ahead in the 163 When a new sub-table is needed, it is necessary to look ahead in the
164 code lengths to determine what size sub-table is needed. The length 164 code lengths to determine what size sub-table is needed. The length
165 counts are used for this, and so count[] is decremented as codes are 165 counts are used for this, and so count[] is decremented as codes are
166 entered in the tables. 166 entered in the tables.
167 167
168 used keeps track of how many table entries have been allocated from the 168 used keeps track of how many table entries have been allocated from the
169 provided *table space. It is checked for LENS and DIST tables against 169 provided *table space. It is checked for LENS and DIST tables against
170 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in 170 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
171 the initial root table size constants. See the comments in inftrees.h 171 the initial root table size constants. See the comments in inftrees.h
172 for more information. 172 for more information.
173 173
174 sym increments through all symbols, and the loop terminates when 174 sym increments through all symbols, and the loop terminates when
175 all codes of length max, i.e. all codes, have been processed. This 175 all codes of length max, i.e. all codes, have been processed. This
176 routine permits incomplete codes, so another loop after this one fills 176 routine permits incomplete codes, so another loop after this one fills
177 in the rest of the decoding tables with invalid code markers. 177 in the rest of the decoding tables with invalid code markers.
178 */ 178 */
179 179
180 /* set up for code type */ 180 /* set up for code type */
181 switch (type) { 181 switch (type) {
182 case CODES: 182 case CODES:
183 base = extra = work; /* dummy value--not used */ 183 base = extra = work; /* dummy value--not used */
184 end = 19; 184 end = 19;
185 break; 185 break;
186 case LENS: 186 case LENS:
187 base = lbase; 187 base = lbase;
188 base -= 257; 188 base -= 257;
189 extra = lext; 189 extra = lext;
190 extra -= 257; 190 extra -= 257;
191 end = 256; 191 end = 256;
192 break; 192 break;
193 default: /* DISTS */ 193 default: /* DISTS */
194 base = dbase; 194 base = dbase;
195 extra = dext; 195 extra = dext;
196 end = -1; 196 end = -1;
197 } 197 }
198 198
199 /* initialize state for loop */ 199 /* initialize state for loop */
200 huff = 0; /* starting code */ 200 huff = 0; /* starting code */
201 sym = 0; /* starting code symbol */ 201 sym = 0; /* starting code symbol */
202 len = min; /* starting code length */ 202 len = min; /* starting code length */
203 next = *table; /* current table to fill in */ 203 next = *table; /* current table to fill in */
204 curr = root; /* current table index bits */ 204 curr = root; /* current table index bits */
205 drop = 0; /* current bits to drop from code for index */ 205 drop = 0; /* current bits to drop from code for index */
206 low = (unsigned)(-1); /* trigger new sub-table when len > root */ 206 low = (unsigned)(-1); /* trigger new sub-table when len > root */
207 used = 1U << root; /* use root table entries */ 207 used = 1U << root; /* use root table entries */
208 mask = used - 1; /* mask for comparing low */ 208 mask = used - 1; /* mask for comparing low */
209 209
210 /* check available table space */ 210 /* check available table space */
211 if ((type == LENS && used >= ENOUGH_LENS) || 211 if ((type == LENS && used >= ENOUGH_LENS) ||
212 (type == DISTS && used >= ENOUGH_DISTS)) 212 (type == DISTS && used >= ENOUGH_DISTS))
213 return 1; 213 return 1;
214 214
215 /* process all codes and make table entries */ 215 /* process all codes and make table entries */
216 for (;;) { 216 for (;;) {
217 /* create table entry */ 217 /* create table entry */
218 here.bits = (unsigned char)(len - drop); 218 here.bits = (unsigned char)(len - drop);
219 if ((int)(work[sym]) < end) { 219 if ((int)(work[sym]) < end) {
220 here.op = (unsigned char)0; 220 here.op = (unsigned char)0;
221 here.val = work[sym]; 221 here.val = work[sym];
222 } 222 }
223 else if ((int)(work[sym]) > end) { 223 else if ((int)(work[sym]) > end) {
224 here.op = (unsigned char)(extra[work[sym]]); 224 here.op = (unsigned char)(extra[work[sym]]);
225 here.val = base[work[sym]]; 225 here.val = base[work[sym]];
226 } 226 }
227 else { 227 else {
228 here.op = (unsigned char)(32 + 64); /* end of block */ 228 here.op = (unsigned char)(32 + 64); /* end of block */
229 here.val = 0; 229 here.val = 0;
230 } 230 }
231 231
232 /* replicate for those indices with low len bits equal to huff */ 232 /* replicate for those indices with low len bits equal to huff */
233 incr = 1U << (len - drop); 233 incr = 1U << (len - drop);
234 fill = 1U << curr; 234 fill = 1U << curr;
235 min = fill; /* save offset to next table */ 235 min = fill; /* save offset to next table */
236 do { 236 do {
237 fill -= incr; 237 fill -= incr;
238 next[(huff >> drop) + fill] = here; 238 next[(huff >> drop) + fill] = here;
239 } while (fill != 0); 239 } while (fill != 0);
240 240
241 /* backwards increment the len-bit code huff */ 241 /* backwards increment the len-bit code huff */
242 incr = 1U << (len - 1); 242 incr = 1U << (len - 1);
243 while (huff & incr) 243 while (huff & incr)
244 incr >>= 1; 244 incr >>= 1;
245 if (incr != 0) { 245 if (incr != 0) {
246 huff &= incr - 1; 246 huff &= incr - 1;
247 huff += incr; 247 huff += incr;
248 } 248 }
249 else 249 else
250 huff = 0; 250 huff = 0;
251 251
252 /* go to next symbol, update count, len */ 252 /* go to next symbol, update count, len */
253 sym++; 253 sym++;
254 if (--(count[len]) == 0) { 254 if (--(count[len]) == 0) {
255 if (len == max) break; 255 if (len == max) break;
256 len = lens[work[sym]]; 256 len = lens[work[sym]];
257 } 257 }
258 258
259 /* create new sub-table if needed */ 259 /* create new sub-table if needed */
260 if (len > root && (huff & mask) != low) { 260 if (len > root && (huff & mask) != low) {
261 /* if first time, transition to sub-tables */ 261 /* if first time, transition to sub-tables */
262 if (drop == 0) 262 if (drop == 0)
263 drop = root; 263 drop = root;
264 264
265 /* increment past last table */ 265 /* increment past last table */
266 next += min; /* here min is 1 << curr */ 266 next += min; /* here min is 1 << curr */
267 267
268 /* determine length of next table */ 268 /* determine length of next table */
269 curr = len - drop; 269 curr = len - drop;
270 left = (int)(1 << curr); 270 left = (int)(1 << curr);
271 while (curr + drop < max) { 271 while (curr + drop < max) {
272 left -= count[curr + drop]; 272 left -= count[curr + drop];
273 if (left <= 0) break; 273 if (left <= 0) break;
274 curr++; 274 curr++;
275 left <<= 1; 275 left <<= 1;
276 } 276 }
277 277
278 /* check for enough space */ 278 /* check for enough space */
279 used += 1U << curr; 279 used += 1U << curr;
280 if ((type == LENS && used >= ENOUGH_LENS) || 280 if ((type == LENS && used >= ENOUGH_LENS) ||
281 (type == DISTS && used >= ENOUGH_DISTS)) 281 (type == DISTS && used >= ENOUGH_DISTS))
282 return 1; 282 return 1;
283 283
284 /* point entry in root table to sub-table */ 284 /* point entry in root table to sub-table */
285 low = huff & mask; 285 low = huff & mask;
286 (*table)[low].op = (unsigned char)curr; 286 (*table)[low].op = (unsigned char)curr;
287 (*table)[low].bits = (unsigned char)root; 287 (*table)[low].bits = (unsigned char)root;
288 (*table)[low].val = (unsigned short)(next - *table); 288 (*table)[low].val = (unsigned short)(next - *table);
289 } 289 }
290 } 290 }
291 291
292 /* fill in remaining table entry if code is incomplete (guaranteed to have 292 /* fill in remaining table entry if code is incomplete (guaranteed to have
293 at most one remaining entry, since if the code is incomplete, the 293 at most one remaining entry, since if the code is incomplete, the
294 maximum code length that was allowed to get this far is one bit) */ 294 maximum code length that was allowed to get this far is one bit) */
295 if (huff != 0) { 295 if (huff != 0) {
296 here.op = (unsigned char)64; /* invalid code marker */ 296 here.op = (unsigned char)64; /* invalid code marker */
297 here.bits = (unsigned char)(len - drop); 297 here.bits = (unsigned char)(len - drop);
298 here.val = (unsigned short)0; 298 here.val = (unsigned short)0;
299 next[huff] = here; 299 next[huff] = here;
300 } 300 }
301 301
302 /* set return parameters */ 302 /* set return parameters */
303 *table += used; 303 *table += used;
304 *bits = root; 304 *bits = root;
305 return 0; 305 return 0;
306} 306}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.h
index a685d8c..baa53a0 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/inftrees.h
@@ -1,62 +1,62 @@
1/* inftrees.h -- header to use inftrees.c 1/* inftrees.h -- header to use inftrees.c
2 * Copyright (C) 1995-2005, 2010 Mark Adler 2 * Copyright (C) 1995-2005, 2010 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* WARNING: this file should *not* be used by applications. It is 6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is 7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11/* Structure for decoding tables. Each entry provides either the 11/* Structure for decoding tables. Each entry provides either the
12 information needed to do the operation requested by the code that 12 information needed to do the operation requested by the code that
13 indexed that table entry, or it provides a pointer to another 13 indexed that table entry, or it provides a pointer to another
14 table that indexes more bits of the code. op indicates whether 14 table that indexes more bits of the code. op indicates whether
15 the entry is a pointer to another table, a literal, a length or 15 the entry is a pointer to another table, a literal, a length or
16 distance, an end-of-block, or an invalid code. For a table 16 distance, an end-of-block, or an invalid code. For a table
17 pointer, the low four bits of op is the number of index bits of 17 pointer, the low four bits of op is the number of index bits of
18 that table. For a length or distance, the low four bits of op 18 that table. For a length or distance, the low four bits of op
19 is the number of extra bits to get after the code. bits is 19 is the number of extra bits to get after the code. bits is
20 the number of bits in this code or part of the code to drop off 20 the number of bits in this code or part of the code to drop off
21 of the bit buffer. val is the actual byte to output in the case 21 of the bit buffer. val is the actual byte to output in the case
22 of a literal, the base length or distance, or the offset from 22 of a literal, the base length or distance, or the offset from
23 the current table to the next table. Each entry is four bytes. */ 23 the current table to the next table. Each entry is four bytes. */
24typedef struct { 24typedef struct {
25 unsigned char op; /* operation, extra bits, table bits */ 25 unsigned char op; /* operation, extra bits, table bits */
26 unsigned char bits; /* bits in this part of the code */ 26 unsigned char bits; /* bits in this part of the code */
27 unsigned short val; /* offset in table or code value */ 27 unsigned short val; /* offset in table or code value */
28} code; 28} code;
29 29
30/* op values as set by inflate_table(): 30/* op values as set by inflate_table():
31 00000000 - literal 31 00000000 - literal
32 0000tttt - table link, tttt != 0 is the number of table index bits 32 0000tttt - table link, tttt != 0 is the number of table index bits
33 0001eeee - length or distance, eeee is the number of extra bits 33 0001eeee - length or distance, eeee is the number of extra bits
34 01100000 - end of block 34 01100000 - end of block
35 01000000 - invalid code 35 01000000 - invalid code
36 */ 36 */
37 37
38/* Maximum size of the dynamic table. The maximum number of code structures is 38/* Maximum size of the dynamic table. The maximum number of code structures is
39 1444, which is the sum of 852 for literal/length codes and 592 for distance 39 1444, which is the sum of 852 for literal/length codes and 592 for distance
40 codes. These values were found by exhaustive searches using the program 40 codes. These values were found by exhaustive searches using the program
41 examples/enough.c found in the zlib distribtution. The arguments to that 41 examples/enough.c found in the zlib distribtution. The arguments to that
42 program are the number of symbols, the initial root table size, and the 42 program are the number of symbols, the initial root table size, and the
43 maximum bit length of a code. "enough 286 9 15" for literal/length codes 43 maximum bit length of a code. "enough 286 9 15" for literal/length codes
44 returns returns 852, and "enough 30 6 15" for distance codes returns 592. 44 returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45 The initial root table size (9 or 6) is found in the fifth argument of the 45 The initial root table size (9 or 6) is found in the fifth argument of the
46 inflate_table() calls in inflate.c and infback.c. If the root table size is 46 inflate_table() calls in inflate.c and infback.c. If the root table size is
47 changed, then these maximum sizes would be need to be recalculated and 47 changed, then these maximum sizes would be need to be recalculated and
48 updated. */ 48 updated. */
49#define ENOUGH_LENS 852 49#define ENOUGH_LENS 852
50#define ENOUGH_DISTS 592 50#define ENOUGH_DISTS 592
51#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 51#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52 52
53/* Type of code to build for inflate_table() */ 53/* Type of code to build for inflate_table() */
54typedef enum { 54typedef enum {
55 CODES, 55 CODES,
56 LENS, 56 LENS,
57 DISTS 57 DISTS
58} codetype; 58} codetype;
59 59
60int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 60int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61 unsigned codes, code FAR * FAR *table, 61 unsigned codes, code FAR * FAR *table,
62 unsigned FAR *bits, unsigned short FAR *work)); 62 unsigned FAR *bits, unsigned short FAR *work));
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.c
index 8ac7a90..8c32b21 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.c
@@ -1,1224 +1,1224 @@
1/* trees.c -- output deflated data using Huffman coding 1/* trees.c -- output deflated data using Huffman coding
2 * Copyright (C) 1995-2012 Jean-loup Gailly 2 * Copyright (C) 1995-2012 Jean-loup Gailly
3 * detect_data_type() function provided freely by Cosmin Truta, 2006 3 * detect_data_type() function provided freely by Cosmin Truta, 2006
4 * For conditions of distribution and use, see copyright notice in zlib.h 4 * For conditions of distribution and use, see copyright notice in zlib.h
5 */ 5 */
6 6
7/* 7/*
8 * ALGORITHM 8 * ALGORITHM
9 * 9 *
10 * The "deflation" process uses several Huffman trees. The more 10 * The "deflation" process uses several Huffman trees. The more
11 * common source values are represented by shorter bit sequences. 11 * common source values are represented by shorter bit sequences.
12 * 12 *
13 * Each code tree is stored in a compressed form which is itself 13 * Each code tree is stored in a compressed form which is itself
14 * a Huffman encoding of the lengths of all the code strings (in 14 * a Huffman encoding of the lengths of all the code strings (in
15 * ascending order by source values). The actual code strings are 15 * ascending order by source values). The actual code strings are
16 * reconstructed from the lengths in the inflate process, as described 16 * reconstructed from the lengths in the inflate process, as described
17 * in the deflate specification. 17 * in the deflate specification.
18 * 18 *
19 * REFERENCES 19 * REFERENCES
20 * 20 *
21 * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 21 * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
22 * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc 22 * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
23 * 23 *
24 * Storer, James A. 24 * Storer, James A.
25 * Data Compression: Methods and Theory, pp. 49-50. 25 * Data Compression: Methods and Theory, pp. 49-50.
26 * Computer Science Press, 1988. ISBN 0-7167-8156-5. 26 * Computer Science Press, 1988. ISBN 0-7167-8156-5.
27 * 27 *
28 * Sedgewick, R. 28 * Sedgewick, R.
29 * Algorithms, p290. 29 * Algorithms, p290.
30 * Addison-Wesley, 1983. ISBN 0-201-06672-6. 30 * Addison-Wesley, 1983. ISBN 0-201-06672-6.
31 */ 31 */
32 32
33/* @(#) $Id$ */ 33/* @(#) $Id$ */
34 34
35/* #define GEN_TREES_H */ 35/* #define GEN_TREES_H */
36 36
37#include "deflate.h" 37#include "deflate.h"
38 38
39#ifdef DEBUG 39#ifdef DEBUG
40# include <ctype.h> 40# include <ctype.h>
41#endif 41#endif
42 42
43/* =========================================================================== 43/* ===========================================================================
44 * Constants 44 * Constants
45 */ 45 */
46 46
47#define MAX_BL_BITS 7 47#define MAX_BL_BITS 7
48/* Bit length codes must not exceed MAX_BL_BITS bits */ 48/* Bit length codes must not exceed MAX_BL_BITS bits */
49 49
50#define END_BLOCK 256 50#define END_BLOCK 256
51/* end of block literal code */ 51/* end of block literal code */
52 52
53#define REP_3_6 16 53#define REP_3_6 16
54/* repeat previous bit length 3-6 times (2 bits of repeat count) */ 54/* repeat previous bit length 3-6 times (2 bits of repeat count) */
55 55
56#define REPZ_3_10 17 56#define REPZ_3_10 17
57/* repeat a zero length 3-10 times (3 bits of repeat count) */ 57/* repeat a zero length 3-10 times (3 bits of repeat count) */
58 58
59#define REPZ_11_138 18 59#define REPZ_11_138 18
60/* repeat a zero length 11-138 times (7 bits of repeat count) */ 60/* repeat a zero length 11-138 times (7 bits of repeat count) */
61 61
62local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ 62local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
63 = {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}; 63 = {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};
64 64
65local const int extra_dbits[D_CODES] /* extra bits for each distance code */ 65local const int extra_dbits[D_CODES] /* extra bits for each distance code */
66 = {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}; 66 = {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};
67 67
68local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ 68local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
69 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; 69 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
70 70
71local const uch bl_order[BL_CODES] 71local const uch bl_order[BL_CODES]
72 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; 72 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
73/* The lengths of the bit length codes are sent in order of decreasing 73/* The lengths of the bit length codes are sent in order of decreasing
74 * probability, to avoid transmitting the lengths for unused bit length codes. 74 * probability, to avoid transmitting the lengths for unused bit length codes.
75 */ 75 */
76 76
77/* =========================================================================== 77/* ===========================================================================
78 * Local data. These are initialized only once. 78 * Local data. These are initialized only once.
79 */ 79 */
80 80
81#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ 81#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
82 82
83#if defined(GEN_TREES_H) || !defined(STDC) 83#if defined(GEN_TREES_H) || !defined(STDC)
84/* non ANSI compilers may not accept trees.h */ 84/* non ANSI compilers may not accept trees.h */
85 85
86local ct_data static_ltree[L_CODES+2]; 86local ct_data static_ltree[L_CODES+2];
87/* The static literal tree. Since the bit lengths are imposed, there is no 87/* The static literal tree. Since the bit lengths are imposed, there is no
88 * need for the L_CODES extra codes used during heap construction. However 88 * need for the L_CODES extra codes used during heap construction. However
89 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init 89 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
90 * below). 90 * below).
91 */ 91 */
92 92
93local ct_data static_dtree[D_CODES]; 93local ct_data static_dtree[D_CODES];
94/* The static distance tree. (Actually a trivial tree since all codes use 94/* The static distance tree. (Actually a trivial tree since all codes use
95 * 5 bits.) 95 * 5 bits.)
96 */ 96 */
97 97
98uch _dist_code[DIST_CODE_LEN]; 98uch _dist_code[DIST_CODE_LEN];
99/* Distance codes. The first 256 values correspond to the distances 99/* Distance codes. The first 256 values correspond to the distances
100 * 3 .. 258, the last 256 values correspond to the top 8 bits of 100 * 3 .. 258, the last 256 values correspond to the top 8 bits of
101 * the 15 bit distances. 101 * the 15 bit distances.
102 */ 102 */
103 103
104uch _length_code[MAX_MATCH-MIN_MATCH+1]; 104uch _length_code[MAX_MATCH-MIN_MATCH+1];
105/* length code for each normalized match length (0 == MIN_MATCH) */ 105/* length code for each normalized match length (0 == MIN_MATCH) */
106 106
107local int base_length[LENGTH_CODES]; 107local int base_length[LENGTH_CODES];
108/* First normalized length for each code (0 = MIN_MATCH) */ 108/* First normalized length for each code (0 = MIN_MATCH) */
109 109
110local int base_dist[D_CODES]; 110local int base_dist[D_CODES];
111/* First normalized distance for each code (0 = distance of 1) */ 111/* First normalized distance for each code (0 = distance of 1) */
112 112
113#else 113#else
114# include "trees.h" 114# include "trees.h"
115#endif /* GEN_TREES_H */ 115#endif /* GEN_TREES_H */
116 116
117struct static_tree_desc_s { 117struct static_tree_desc_s {
118 const ct_data *static_tree; /* static tree or NULL */ 118 const ct_data *static_tree; /* static tree or NULL */
119 const intf *extra_bits; /* extra bits for each code or NULL */ 119 const intf *extra_bits; /* extra bits for each code or NULL */
120 int extra_base; /* base index for extra_bits */ 120 int extra_base; /* base index for extra_bits */
121 int elems; /* max number of elements in the tree */ 121 int elems; /* max number of elements in the tree */
122 int max_length; /* max bit length for the codes */ 122 int max_length; /* max bit length for the codes */
123}; 123};
124 124
125local static_tree_desc static_l_desc = 125local static_tree_desc static_l_desc =
126{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; 126{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
127 127
128local static_tree_desc static_d_desc = 128local static_tree_desc static_d_desc =
129{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; 129{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
130 130
131local static_tree_desc static_bl_desc = 131local static_tree_desc static_bl_desc =
132{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; 132{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
133 133
134/* =========================================================================== 134/* ===========================================================================
135 * Local (static) routines in this file. 135 * Local (static) routines in this file.
136 */ 136 */
137 137
138local void tr_static_init OF((void)); 138local void tr_static_init OF((void));
139local void init_block OF((deflate_state *s)); 139local void init_block OF((deflate_state *s));
140local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); 140local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
141local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); 141local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
142local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); 142local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
143local void build_tree OF((deflate_state *s, tree_desc *desc)); 143local void build_tree OF((deflate_state *s, tree_desc *desc));
144local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); 144local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
145local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); 145local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
146local int build_bl_tree OF((deflate_state *s)); 146local int build_bl_tree OF((deflate_state *s));
147local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, 147local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
148 int blcodes)); 148 int blcodes));
149local void compress_block OF((deflate_state *s, ct_data *ltree, 149local void compress_block OF((deflate_state *s, ct_data *ltree,
150 ct_data *dtree)); 150 ct_data *dtree));
151local int detect_data_type OF((deflate_state *s)); 151local int detect_data_type OF((deflate_state *s));
152local unsigned bi_reverse OF((unsigned value, int length)); 152local unsigned bi_reverse OF((unsigned value, int length));
153local void bi_windup OF((deflate_state *s)); 153local void bi_windup OF((deflate_state *s));
154local void bi_flush OF((deflate_state *s)); 154local void bi_flush OF((deflate_state *s));
155local void copy_block OF((deflate_state *s, charf *buf, unsigned len, 155local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
156 int header)); 156 int header));
157 157
158#ifdef GEN_TREES_H 158#ifdef GEN_TREES_H
159local void gen_trees_header OF((void)); 159local void gen_trees_header OF((void));
160#endif 160#endif
161 161
162#ifndef DEBUG 162#ifndef DEBUG
163# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) 163# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
164 /* Send a code of the given tree. c and tree must not have side effects */ 164 /* Send a code of the given tree. c and tree must not have side effects */
165 165
166#else /* DEBUG */ 166#else /* DEBUG */
167# define send_code(s, c, tree) \ 167# define send_code(s, c, tree) \
168 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ 168 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
169 send_bits(s, tree[c].Code, tree[c].Len); } 169 send_bits(s, tree[c].Code, tree[c].Len); }
170#endif 170#endif
171 171
172/* =========================================================================== 172/* ===========================================================================
173 * Output a short LSB first on the stream. 173 * Output a short LSB first on the stream.
174 * IN assertion: there is enough room in pendingBuf. 174 * IN assertion: there is enough room in pendingBuf.
175 */ 175 */
176#define put_short(s, w) { \ 176#define put_short(s, w) { \
177 put_byte(s, (uch)((w) & 0xff)); \ 177 put_byte(s, (uch)((w) & 0xff)); \
178 put_byte(s, (uch)((ush)(w) >> 8)); \ 178 put_byte(s, (uch)((ush)(w) >> 8)); \
179} 179}
180 180
181/* =========================================================================== 181/* ===========================================================================
182 * Send a value on a given number of bits. 182 * Send a value on a given number of bits.
183 * IN assertion: length <= 16 and value fits in length bits. 183 * IN assertion: length <= 16 and value fits in length bits.
184 */ 184 */
185#ifdef DEBUG 185#ifdef DEBUG
186local void send_bits OF((deflate_state *s, int value, int length)); 186local void send_bits OF((deflate_state *s, int value, int length));
187 187
188local void send_bits(s, value, length) 188local void send_bits(s, value, length)
189 deflate_state *s; 189 deflate_state *s;
190 int value; /* value to send */ 190 int value; /* value to send */
191 int length; /* number of bits */ 191 int length; /* number of bits */
192{ 192{
193 Tracevv((stderr," l %2d v %4x ", length, value)); 193 Tracevv((stderr," l %2d v %4x ", length, value));
194 Assert(length > 0 && length <= 15, "invalid length"); 194 Assert(length > 0 && length <= 15, "invalid length");
195 s->bits_sent += (ulg)length; 195 s->bits_sent += (ulg)length;
196 196
197 /* If not enough room in bi_buf, use (valid) bits from bi_buf and 197 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
198 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) 198 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
199 * unused bits in value. 199 * unused bits in value.
200 */ 200 */
201 if (s->bi_valid > (int)Buf_size - length) { 201 if (s->bi_valid > (int)Buf_size - length) {
202 s->bi_buf |= (ush)value << s->bi_valid; 202 s->bi_buf |= (ush)value << s->bi_valid;
203 put_short(s, s->bi_buf); 203 put_short(s, s->bi_buf);
204 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); 204 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
205 s->bi_valid += length - Buf_size; 205 s->bi_valid += length - Buf_size;
206 } else { 206 } else {
207 s->bi_buf |= (ush)value << s->bi_valid; 207 s->bi_buf |= (ush)value << s->bi_valid;
208 s->bi_valid += length; 208 s->bi_valid += length;
209 } 209 }
210} 210}
211#else /* !DEBUG */ 211#else /* !DEBUG */
212 212
213#define send_bits(s, value, length) \ 213#define send_bits(s, value, length) \
214{ int len = length;\ 214{ int len = length;\
215 if (s->bi_valid > (int)Buf_size - len) {\ 215 if (s->bi_valid > (int)Buf_size - len) {\
216 int val = value;\ 216 int val = value;\
217 s->bi_buf |= (ush)val << s->bi_valid;\ 217 s->bi_buf |= (ush)val << s->bi_valid;\
218 put_short(s, s->bi_buf);\ 218 put_short(s, s->bi_buf);\
219 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ 219 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
220 s->bi_valid += len - Buf_size;\ 220 s->bi_valid += len - Buf_size;\
221 } else {\ 221 } else {\
222 s->bi_buf |= (ush)(value) << s->bi_valid;\ 222 s->bi_buf |= (ush)(value) << s->bi_valid;\
223 s->bi_valid += len;\ 223 s->bi_valid += len;\
224 }\ 224 }\
225} 225}
226#endif /* DEBUG */ 226#endif /* DEBUG */
227 227
228 228
229/* the arguments must not have side effects */ 229/* the arguments must not have side effects */
230 230
231/* =========================================================================== 231/* ===========================================================================
232 * Initialize the various 'constant' tables. 232 * Initialize the various 'constant' tables.
233 */ 233 */
234local void tr_static_init() 234local void tr_static_init()
235{ 235{
236#if defined(GEN_TREES_H) || !defined(STDC) 236#if defined(GEN_TREES_H) || !defined(STDC)
237 static int static_init_done = 0; 237 static int static_init_done = 0;
238 int n; /* iterates over tree elements */ 238 int n; /* iterates over tree elements */
239 int bits; /* bit counter */ 239 int bits; /* bit counter */
240 int length; /* length value */ 240 int length; /* length value */
241 int code; /* code value */ 241 int code; /* code value */
242 int dist; /* distance index */ 242 int dist; /* distance index */
243 ush bl_count[MAX_BITS+1]; 243 ush bl_count[MAX_BITS+1];
244 /* number of codes at each bit length for an optimal tree */ 244 /* number of codes at each bit length for an optimal tree */
245 245
246 if (static_init_done) return; 246 if (static_init_done) return;
247 247
248 /* For some embedded targets, global variables are not initialized: */ 248 /* For some embedded targets, global variables are not initialized: */
249#ifdef NO_INIT_GLOBAL_POINTERS 249#ifdef NO_INIT_GLOBAL_POINTERS
250 static_l_desc.static_tree = static_ltree; 250 static_l_desc.static_tree = static_ltree;
251 static_l_desc.extra_bits = extra_lbits; 251 static_l_desc.extra_bits = extra_lbits;
252 static_d_desc.static_tree = static_dtree; 252 static_d_desc.static_tree = static_dtree;
253 static_d_desc.extra_bits = extra_dbits; 253 static_d_desc.extra_bits = extra_dbits;
254 static_bl_desc.extra_bits = extra_blbits; 254 static_bl_desc.extra_bits = extra_blbits;
255#endif 255#endif
256 256
257 /* Initialize the mapping length (0..255) -> length code (0..28) */ 257 /* Initialize the mapping length (0..255) -> length code (0..28) */
258 length = 0; 258 length = 0;
259 for (code = 0; code < LENGTH_CODES-1; code++) { 259 for (code = 0; code < LENGTH_CODES-1; code++) {
260 base_length[code] = length; 260 base_length[code] = length;
261 for (n = 0; n < (1<<extra_lbits[code]); n++) { 261 for (n = 0; n < (1<<extra_lbits[code]); n++) {
262 _length_code[length++] = (uch)code; 262 _length_code[length++] = (uch)code;
263 } 263 }
264 } 264 }
265 Assert (length == 256, "tr_static_init: length != 256"); 265 Assert (length == 256, "tr_static_init: length != 256");
266 /* Note that the length 255 (match length 258) can be represented 266 /* Note that the length 255 (match length 258) can be represented
267 * in two different ways: code 284 + 5 bits or code 285, so we 267 * in two different ways: code 284 + 5 bits or code 285, so we
268 * overwrite length_code[255] to use the best encoding: 268 * overwrite length_code[255] to use the best encoding:
269 */ 269 */
270 _length_code[length-1] = (uch)code; 270 _length_code[length-1] = (uch)code;
271 271
272 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ 272 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
273 dist = 0; 273 dist = 0;
274 for (code = 0 ; code < 16; code++) { 274 for (code = 0 ; code < 16; code++) {
275 base_dist[code] = dist; 275 base_dist[code] = dist;
276 for (n = 0; n < (1<<extra_dbits[code]); n++) { 276 for (n = 0; n < (1<<extra_dbits[code]); n++) {
277 _dist_code[dist++] = (uch)code; 277 _dist_code[dist++] = (uch)code;
278 } 278 }
279 } 279 }
280 Assert (dist == 256, "tr_static_init: dist != 256"); 280 Assert (dist == 256, "tr_static_init: dist != 256");
281 dist >>= 7; /* from now on, all distances are divided by 128 */ 281 dist >>= 7; /* from now on, all distances are divided by 128 */
282 for ( ; code < D_CODES; code++) { 282 for ( ; code < D_CODES; code++) {
283 base_dist[code] = dist << 7; 283 base_dist[code] = dist << 7;
284 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { 284 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
285 _dist_code[256 + dist++] = (uch)code; 285 _dist_code[256 + dist++] = (uch)code;
286 } 286 }
287 } 287 }
288 Assert (dist == 256, "tr_static_init: 256+dist != 512"); 288 Assert (dist == 256, "tr_static_init: 256+dist != 512");
289 289
290 /* Construct the codes of the static literal tree */ 290 /* Construct the codes of the static literal tree */
291 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; 291 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
292 n = 0; 292 n = 0;
293 while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; 293 while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
294 while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; 294 while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
295 while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; 295 while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
296 while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; 296 while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
297 /* Codes 286 and 287 do not exist, but we must include them in the 297 /* Codes 286 and 287 do not exist, but we must include them in the
298 * tree construction to get a canonical Huffman tree (longest code 298 * tree construction to get a canonical Huffman tree (longest code
299 * all ones) 299 * all ones)
300 */ 300 */
301 gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); 301 gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
302 302
303 /* The static distance tree is trivial: */ 303 /* The static distance tree is trivial: */
304 for (n = 0; n < D_CODES; n++) { 304 for (n = 0; n < D_CODES; n++) {
305 static_dtree[n].Len = 5; 305 static_dtree[n].Len = 5;
306 static_dtree[n].Code = bi_reverse((unsigned)n, 5); 306 static_dtree[n].Code = bi_reverse((unsigned)n, 5);
307 } 307 }
308 static_init_done = 1; 308 static_init_done = 1;
309 309
310# ifdef GEN_TREES_H 310# ifdef GEN_TREES_H
311 gen_trees_header(); 311 gen_trees_header();
312# endif 312# endif
313#endif /* defined(GEN_TREES_H) || !defined(STDC) */ 313#endif /* defined(GEN_TREES_H) || !defined(STDC) */
314} 314}
315 315
316/* =========================================================================== 316/* ===========================================================================
317 * Genererate the file trees.h describing the static trees. 317 * Genererate the file trees.h describing the static trees.
318 */ 318 */
319#ifdef GEN_TREES_H 319#ifdef GEN_TREES_H
320# ifndef DEBUG 320# ifndef DEBUG
321# include <stdio.h> 321# include <stdio.h>
322# endif 322# endif
323 323
324# define SEPARATOR(i, last, width) \ 324# define SEPARATOR(i, last, width) \
325 ((i) == (last)? "\n};\n\n" : \ 325 ((i) == (last)? "\n};\n\n" : \
326 ((i) % (width) == (width)-1 ? ",\n" : ", ")) 326 ((i) % (width) == (width)-1 ? ",\n" : ", "))
327 327
328void gen_trees_header() 328void gen_trees_header()
329{ 329{
330 FILE *header = fopen("trees.h", "w"); 330 FILE *header = fopen("trees.h", "w");
331 int i; 331 int i;
332 332
333 Assert (header != NULL, "Can't open trees.h"); 333 Assert (header != NULL, "Can't open trees.h");
334 fprintf(header, 334 fprintf(header,
335 "/* header created automatically with -DGEN_TREES_H */\n\n"); 335 "/* header created automatically with -DGEN_TREES_H */\n\n");
336 336
337 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); 337 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
338 for (i = 0; i < L_CODES+2; i++) { 338 for (i = 0; i < L_CODES+2; i++) {
339 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, 339 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
340 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); 340 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
341 } 341 }
342 342
343 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); 343 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
344 for (i = 0; i < D_CODES; i++) { 344 for (i = 0; i < D_CODES; i++) {
345 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, 345 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
346 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); 346 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
347 } 347 }
348 348
349 fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); 349 fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
350 for (i = 0; i < DIST_CODE_LEN; i++) { 350 for (i = 0; i < DIST_CODE_LEN; i++) {
351 fprintf(header, "%2u%s", _dist_code[i], 351 fprintf(header, "%2u%s", _dist_code[i],
352 SEPARATOR(i, DIST_CODE_LEN-1, 20)); 352 SEPARATOR(i, DIST_CODE_LEN-1, 20));
353 } 353 }
354 354
355 fprintf(header, 355 fprintf(header,
356 "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); 356 "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
357 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { 357 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
358 fprintf(header, "%2u%s", _length_code[i], 358 fprintf(header, "%2u%s", _length_code[i],
359 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); 359 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
360 } 360 }
361 361
362 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); 362 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
363 for (i = 0; i < LENGTH_CODES; i++) { 363 for (i = 0; i < LENGTH_CODES; i++) {
364 fprintf(header, "%1u%s", base_length[i], 364 fprintf(header, "%1u%s", base_length[i],
365 SEPARATOR(i, LENGTH_CODES-1, 20)); 365 SEPARATOR(i, LENGTH_CODES-1, 20));
366 } 366 }
367 367
368 fprintf(header, "local const int base_dist[D_CODES] = {\n"); 368 fprintf(header, "local const int base_dist[D_CODES] = {\n");
369 for (i = 0; i < D_CODES; i++) { 369 for (i = 0; i < D_CODES; i++) {
370 fprintf(header, "%5u%s", base_dist[i], 370 fprintf(header, "%5u%s", base_dist[i],
371 SEPARATOR(i, D_CODES-1, 10)); 371 SEPARATOR(i, D_CODES-1, 10));
372 } 372 }
373 373
374 fclose(header); 374 fclose(header);
375} 375}
376#endif /* GEN_TREES_H */ 376#endif /* GEN_TREES_H */
377 377
378/* =========================================================================== 378/* ===========================================================================
379 * Initialize the tree data structures for a new zlib stream. 379 * Initialize the tree data structures for a new zlib stream.
380 */ 380 */
381void ZLIB_INTERNAL _tr_init(s) 381void ZLIB_INTERNAL _tr_init(s)
382 deflate_state *s; 382 deflate_state *s;
383{ 383{
384 tr_static_init(); 384 tr_static_init();
385 385
386 s->l_desc.dyn_tree = s->dyn_ltree; 386 s->l_desc.dyn_tree = s->dyn_ltree;
387 s->l_desc.stat_desc = &static_l_desc; 387 s->l_desc.stat_desc = &static_l_desc;
388 388
389 s->d_desc.dyn_tree = s->dyn_dtree; 389 s->d_desc.dyn_tree = s->dyn_dtree;
390 s->d_desc.stat_desc = &static_d_desc; 390 s->d_desc.stat_desc = &static_d_desc;
391 391
392 s->bl_desc.dyn_tree = s->bl_tree; 392 s->bl_desc.dyn_tree = s->bl_tree;
393 s->bl_desc.stat_desc = &static_bl_desc; 393 s->bl_desc.stat_desc = &static_bl_desc;
394 394
395 s->bi_buf = 0; 395 s->bi_buf = 0;
396 s->bi_valid = 0; 396 s->bi_valid = 0;
397#ifdef DEBUG 397#ifdef DEBUG
398 s->compressed_len = 0L; 398 s->compressed_len = 0L;
399 s->bits_sent = 0L; 399 s->bits_sent = 0L;
400#endif 400#endif
401 401
402 /* Initialize the first block of the first file: */ 402 /* Initialize the first block of the first file: */
403 init_block(s); 403 init_block(s);
404} 404}
405 405
406/* =========================================================================== 406/* ===========================================================================
407 * Initialize a new block. 407 * Initialize a new block.
408 */ 408 */
409local void init_block(s) 409local void init_block(s)
410 deflate_state *s; 410 deflate_state *s;
411{ 411{
412 int n; /* iterates over tree elements */ 412 int n; /* iterates over tree elements */
413 413
414 /* Initialize the trees. */ 414 /* Initialize the trees. */
415 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; 415 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
416 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; 416 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
417 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; 417 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
418 418
419 s->dyn_ltree[END_BLOCK].Freq = 1; 419 s->dyn_ltree[END_BLOCK].Freq = 1;
420 s->opt_len = s->static_len = 0L; 420 s->opt_len = s->static_len = 0L;
421 s->last_lit = s->matches = 0; 421 s->last_lit = s->matches = 0;
422} 422}
423 423
424#define SMALLEST 1 424#define SMALLEST 1
425/* Index within the heap array of least frequent node in the Huffman tree */ 425/* Index within the heap array of least frequent node in the Huffman tree */
426 426
427 427
428/* =========================================================================== 428/* ===========================================================================
429 * Remove the smallest element from the heap and recreate the heap with 429 * Remove the smallest element from the heap and recreate the heap with
430 * one less element. Updates heap and heap_len. 430 * one less element. Updates heap and heap_len.
431 */ 431 */
432#define pqremove(s, tree, top) \ 432#define pqremove(s, tree, top) \
433{\ 433{\
434 top = s->heap[SMALLEST]; \ 434 top = s->heap[SMALLEST]; \
435 s->heap[SMALLEST] = s->heap[s->heap_len--]; \ 435 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
436 pqdownheap(s, tree, SMALLEST); \ 436 pqdownheap(s, tree, SMALLEST); \
437} 437}
438 438
439/* =========================================================================== 439/* ===========================================================================
440 * Compares to subtrees, using the tree depth as tie breaker when 440 * Compares to subtrees, using the tree depth as tie breaker when
441 * the subtrees have equal frequency. This minimizes the worst case length. 441 * the subtrees have equal frequency. This minimizes the worst case length.
442 */ 442 */
443#define smaller(tree, n, m, depth) \ 443#define smaller(tree, n, m, depth) \
444 (tree[n].Freq < tree[m].Freq || \ 444 (tree[n].Freq < tree[m].Freq || \
445 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) 445 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
446 446
447/* =========================================================================== 447/* ===========================================================================
448 * Restore the heap property by moving down the tree starting at node k, 448 * Restore the heap property by moving down the tree starting at node k,
449 * exchanging a node with the smallest of its two sons if necessary, stopping 449 * exchanging a node with the smallest of its two sons if necessary, stopping
450 * when the heap property is re-established (each father smaller than its 450 * when the heap property is re-established (each father smaller than its
451 * two sons). 451 * two sons).
452 */ 452 */
453local void pqdownheap(s, tree, k) 453local void pqdownheap(s, tree, k)
454 deflate_state *s; 454 deflate_state *s;
455 ct_data *tree; /* the tree to restore */ 455 ct_data *tree; /* the tree to restore */
456 int k; /* node to move down */ 456 int k; /* node to move down */
457{ 457{
458 int v = s->heap[k]; 458 int v = s->heap[k];
459 int j = k << 1; /* left son of k */ 459 int j = k << 1; /* left son of k */
460 while (j <= s->heap_len) { 460 while (j <= s->heap_len) {
461 /* Set j to the smallest of the two sons: */ 461 /* Set j to the smallest of the two sons: */
462 if (j < s->heap_len && 462 if (j < s->heap_len &&
463 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { 463 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
464 j++; 464 j++;
465 } 465 }
466 /* Exit if v is smaller than both sons */ 466 /* Exit if v is smaller than both sons */
467 if (smaller(tree, v, s->heap[j], s->depth)) break; 467 if (smaller(tree, v, s->heap[j], s->depth)) break;
468 468
469 /* Exchange v with the smallest son */ 469 /* Exchange v with the smallest son */
470 s->heap[k] = s->heap[j]; k = j; 470 s->heap[k] = s->heap[j]; k = j;
471 471
472 /* And continue down the tree, setting j to the left son of k */ 472 /* And continue down the tree, setting j to the left son of k */
473 j <<= 1; 473 j <<= 1;
474 } 474 }
475 s->heap[k] = v; 475 s->heap[k] = v;
476} 476}
477 477
478/* =========================================================================== 478/* ===========================================================================
479 * Compute the optimal bit lengths for a tree and update the total bit length 479 * Compute the optimal bit lengths for a tree and update the total bit length
480 * for the current block. 480 * for the current block.
481 * IN assertion: the fields freq and dad are set, heap[heap_max] and 481 * IN assertion: the fields freq and dad are set, heap[heap_max] and
482 * above are the tree nodes sorted by increasing frequency. 482 * above are the tree nodes sorted by increasing frequency.
483 * OUT assertions: the field len is set to the optimal bit length, the 483 * OUT assertions: the field len is set to the optimal bit length, the
484 * array bl_count contains the frequencies for each bit length. 484 * array bl_count contains the frequencies for each bit length.
485 * The length opt_len is updated; static_len is also updated if stree is 485 * The length opt_len is updated; static_len is also updated if stree is
486 * not null. 486 * not null.
487 */ 487 */
488local void gen_bitlen(s, desc) 488local void gen_bitlen(s, desc)
489 deflate_state *s; 489 deflate_state *s;
490 tree_desc *desc; /* the tree descriptor */ 490 tree_desc *desc; /* the tree descriptor */
491{ 491{
492 ct_data *tree = desc->dyn_tree; 492 ct_data *tree = desc->dyn_tree;
493 int max_code = desc->max_code; 493 int max_code = desc->max_code;
494 const ct_data *stree = desc->stat_desc->static_tree; 494 const ct_data *stree = desc->stat_desc->static_tree;
495 const intf *extra = desc->stat_desc->extra_bits; 495 const intf *extra = desc->stat_desc->extra_bits;
496 int base = desc->stat_desc->extra_base; 496 int base = desc->stat_desc->extra_base;
497 int max_length = desc->stat_desc->max_length; 497 int max_length = desc->stat_desc->max_length;
498 int h; /* heap index */ 498 int h; /* heap index */
499 int n, m; /* iterate over the tree elements */ 499 int n, m; /* iterate over the tree elements */
500 int bits; /* bit length */ 500 int bits; /* bit length */
501 int xbits; /* extra bits */ 501 int xbits; /* extra bits */
502 ush f; /* frequency */ 502 ush f; /* frequency */
503 int overflow = 0; /* number of elements with bit length too large */ 503 int overflow = 0; /* number of elements with bit length too large */
504 504
505 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; 505 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
506 506
507 /* In a first pass, compute the optimal bit lengths (which may 507 /* In a first pass, compute the optimal bit lengths (which may
508 * overflow in the case of the bit length tree). 508 * overflow in the case of the bit length tree).
509 */ 509 */
510 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ 510 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
511 511
512 for (h = s->heap_max+1; h < HEAP_SIZE; h++) { 512 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
513 n = s->heap[h]; 513 n = s->heap[h];
514 bits = tree[tree[n].Dad].Len + 1; 514 bits = tree[tree[n].Dad].Len + 1;
515 if (bits > max_length) bits = max_length, overflow++; 515 if (bits > max_length) bits = max_length, overflow++;
516 tree[n].Len = (ush)bits; 516 tree[n].Len = (ush)bits;
517 /* We overwrite tree[n].Dad which is no longer needed */ 517 /* We overwrite tree[n].Dad which is no longer needed */
518 518
519 if (n > max_code) continue; /* not a leaf node */ 519 if (n > max_code) continue; /* not a leaf node */
520 520
521 s->bl_count[bits]++; 521 s->bl_count[bits]++;
522 xbits = 0; 522 xbits = 0;
523 if (n >= base) xbits = extra[n-base]; 523 if (n >= base) xbits = extra[n-base];
524 f = tree[n].Freq; 524 f = tree[n].Freq;
525 s->opt_len += (ulg)f * (bits + xbits); 525 s->opt_len += (ulg)f * (bits + xbits);
526 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); 526 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
527 } 527 }
528 if (overflow == 0) return; 528 if (overflow == 0) return;
529 529
530 Trace((stderr,"\nbit length overflow\n")); 530 Trace((stderr,"\nbit length overflow\n"));
531 /* This happens for example on obj2 and pic of the Calgary corpus */ 531 /* This happens for example on obj2 and pic of the Calgary corpus */
532 532
533 /* Find the first bit length which could increase: */ 533 /* Find the first bit length which could increase: */
534 do { 534 do {
535 bits = max_length-1; 535 bits = max_length-1;
536 while (s->bl_count[bits] == 0) bits--; 536 while (s->bl_count[bits] == 0) bits--;
537 s->bl_count[bits]--; /* move one leaf down the tree */ 537 s->bl_count[bits]--; /* move one leaf down the tree */
538 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ 538 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
539 s->bl_count[max_length]--; 539 s->bl_count[max_length]--;
540 /* The brother of the overflow item also moves one step up, 540 /* The brother of the overflow item also moves one step up,
541 * but this does not affect bl_count[max_length] 541 * but this does not affect bl_count[max_length]
542 */ 542 */
543 overflow -= 2; 543 overflow -= 2;
544 } while (overflow > 0); 544 } while (overflow > 0);
545 545
546 /* Now recompute all bit lengths, scanning in increasing frequency. 546 /* Now recompute all bit lengths, scanning in increasing frequency.
547 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all 547 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
548 * lengths instead of fixing only the wrong ones. This idea is taken 548 * lengths instead of fixing only the wrong ones. This idea is taken
549 * from 'ar' written by Haruhiko Okumura.) 549 * from 'ar' written by Haruhiko Okumura.)
550 */ 550 */
551 for (bits = max_length; bits != 0; bits--) { 551 for (bits = max_length; bits != 0; bits--) {
552 n = s->bl_count[bits]; 552 n = s->bl_count[bits];
553 while (n != 0) { 553 while (n != 0) {
554 m = s->heap[--h]; 554 m = s->heap[--h];
555 if (m > max_code) continue; 555 if (m > max_code) continue;
556 if ((unsigned) tree[m].Len != (unsigned) bits) { 556 if ((unsigned) tree[m].Len != (unsigned) bits) {
557 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); 557 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
558 s->opt_len += ((long)bits - (long)tree[m].Len) 558 s->opt_len += ((long)bits - (long)tree[m].Len)
559 *(long)tree[m].Freq; 559 *(long)tree[m].Freq;
560 tree[m].Len = (ush)bits; 560 tree[m].Len = (ush)bits;
561 } 561 }
562 n--; 562 n--;
563 } 563 }
564 } 564 }
565} 565}
566 566
567/* =========================================================================== 567/* ===========================================================================
568 * Generate the codes for a given tree and bit counts (which need not be 568 * Generate the codes for a given tree and bit counts (which need not be
569 * optimal). 569 * optimal).
570 * IN assertion: the array bl_count contains the bit length statistics for 570 * IN assertion: the array bl_count contains the bit length statistics for
571 * the given tree and the field len is set for all tree elements. 571 * the given tree and the field len is set for all tree elements.
572 * OUT assertion: the field code is set for all tree elements of non 572 * OUT assertion: the field code is set for all tree elements of non
573 * zero code length. 573 * zero code length.
574 */ 574 */
575local void gen_codes (tree, max_code, bl_count) 575local void gen_codes (tree, max_code, bl_count)
576 ct_data *tree; /* the tree to decorate */ 576 ct_data *tree; /* the tree to decorate */
577 int max_code; /* largest code with non zero frequency */ 577 int max_code; /* largest code with non zero frequency */
578 ushf *bl_count; /* number of codes at each bit length */ 578 ushf *bl_count; /* number of codes at each bit length */
579{ 579{
580 ush next_code[MAX_BITS+1]; /* next code value for each bit length */ 580 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
581 ush code = 0; /* running code value */ 581 ush code = 0; /* running code value */
582 int bits; /* bit index */ 582 int bits; /* bit index */
583 int n; /* code index */ 583 int n; /* code index */
584 584
585 /* The distribution counts are first used to generate the code values 585 /* The distribution counts are first used to generate the code values
586 * without bit reversal. 586 * without bit reversal.
587 */ 587 */
588 for (bits = 1; bits <= MAX_BITS; bits++) { 588 for (bits = 1; bits <= MAX_BITS; bits++) {
589 next_code[bits] = code = (code + bl_count[bits-1]) << 1; 589 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
590 } 590 }
591 /* Check that the bit counts in bl_count are consistent. The last code 591 /* Check that the bit counts in bl_count are consistent. The last code
592 * must be all ones. 592 * must be all ones.
593 */ 593 */
594 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, 594 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
595 "inconsistent bit counts"); 595 "inconsistent bit counts");
596 Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); 596 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
597 597
598 for (n = 0; n <= max_code; n++) { 598 for (n = 0; n <= max_code; n++) {
599 int len = tree[n].Len; 599 int len = tree[n].Len;
600 if (len == 0) continue; 600 if (len == 0) continue;
601 /* Now reverse the bits */ 601 /* Now reverse the bits */
602 tree[n].Code = bi_reverse(next_code[len]++, len); 602 tree[n].Code = bi_reverse(next_code[len]++, len);
603 603
604 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", 604 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
605 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); 605 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
606 } 606 }
607} 607}
608 608
609/* =========================================================================== 609/* ===========================================================================
610 * Construct one Huffman tree and assigns the code bit strings and lengths. 610 * Construct one Huffman tree and assigns the code bit strings and lengths.
611 * Update the total bit length for the current block. 611 * Update the total bit length for the current block.
612 * IN assertion: the field freq is set for all tree elements. 612 * IN assertion: the field freq is set for all tree elements.
613 * OUT assertions: the fields len and code are set to the optimal bit length 613 * OUT assertions: the fields len and code are set to the optimal bit length
614 * and corresponding code. The length opt_len is updated; static_len is 614 * and corresponding code. The length opt_len is updated; static_len is
615 * also updated if stree is not null. The field max_code is set. 615 * also updated if stree is not null. The field max_code is set.
616 */ 616 */
617local void build_tree(s, desc) 617local void build_tree(s, desc)
618 deflate_state *s; 618 deflate_state *s;
619 tree_desc *desc; /* the tree descriptor */ 619 tree_desc *desc; /* the tree descriptor */
620{ 620{
621 ct_data *tree = desc->dyn_tree; 621 ct_data *tree = desc->dyn_tree;
622 const ct_data *stree = desc->stat_desc->static_tree; 622 const ct_data *stree = desc->stat_desc->static_tree;
623 int elems = desc->stat_desc->elems; 623 int elems = desc->stat_desc->elems;
624 int n, m; /* iterate over heap elements */ 624 int n, m; /* iterate over heap elements */
625 int max_code = -1; /* largest code with non zero frequency */ 625 int max_code = -1; /* largest code with non zero frequency */
626 int node; /* new node being created */ 626 int node; /* new node being created */
627 627
628 /* Construct the initial heap, with least frequent element in 628 /* Construct the initial heap, with least frequent element in
629 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. 629 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
630 * heap[0] is not used. 630 * heap[0] is not used.
631 */ 631 */
632 s->heap_len = 0, s->heap_max = HEAP_SIZE; 632 s->heap_len = 0, s->heap_max = HEAP_SIZE;
633 633
634 for (n = 0; n < elems; n++) { 634 for (n = 0; n < elems; n++) {
635 if (tree[n].Freq != 0) { 635 if (tree[n].Freq != 0) {
636 s->heap[++(s->heap_len)] = max_code = n; 636 s->heap[++(s->heap_len)] = max_code = n;
637 s->depth[n] = 0; 637 s->depth[n] = 0;
638 } else { 638 } else {
639 tree[n].Len = 0; 639 tree[n].Len = 0;
640 } 640 }
641 } 641 }
642 642
643 /* The pkzip format requires that at least one distance code exists, 643 /* The pkzip format requires that at least one distance code exists,
644 * and that at least one bit should be sent even if there is only one 644 * and that at least one bit should be sent even if there is only one
645 * possible code. So to avoid special checks later on we force at least 645 * possible code. So to avoid special checks later on we force at least
646 * two codes of non zero frequency. 646 * two codes of non zero frequency.
647 */ 647 */
648 while (s->heap_len < 2) { 648 while (s->heap_len < 2) {
649 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); 649 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
650 tree[node].Freq = 1; 650 tree[node].Freq = 1;
651 s->depth[node] = 0; 651 s->depth[node] = 0;
652 s->opt_len--; if (stree) s->static_len -= stree[node].Len; 652 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
653 /* node is 0 or 1 so it does not have extra bits */ 653 /* node is 0 or 1 so it does not have extra bits */
654 } 654 }
655 desc->max_code = max_code; 655 desc->max_code = max_code;
656 656
657 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, 657 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
658 * establish sub-heaps of increasing lengths: 658 * establish sub-heaps of increasing lengths:
659 */ 659 */
660 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); 660 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
661 661
662 /* Construct the Huffman tree by repeatedly combining the least two 662 /* Construct the Huffman tree by repeatedly combining the least two
663 * frequent nodes. 663 * frequent nodes.
664 */ 664 */
665 node = elems; /* next internal node of the tree */ 665 node = elems; /* next internal node of the tree */
666 do { 666 do {
667 pqremove(s, tree, n); /* n = node of least frequency */ 667 pqremove(s, tree, n); /* n = node of least frequency */
668 m = s->heap[SMALLEST]; /* m = node of next least frequency */ 668 m = s->heap[SMALLEST]; /* m = node of next least frequency */
669 669
670 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ 670 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
671 s->heap[--(s->heap_max)] = m; 671 s->heap[--(s->heap_max)] = m;
672 672
673 /* Create a new node father of n and m */ 673 /* Create a new node father of n and m */
674 tree[node].Freq = tree[n].Freq + tree[m].Freq; 674 tree[node].Freq = tree[n].Freq + tree[m].Freq;
675 s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? 675 s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
676 s->depth[n] : s->depth[m]) + 1); 676 s->depth[n] : s->depth[m]) + 1);
677 tree[n].Dad = tree[m].Dad = (ush)node; 677 tree[n].Dad = tree[m].Dad = (ush)node;
678#ifdef DUMP_BL_TREE 678#ifdef DUMP_BL_TREE
679 if (tree == s->bl_tree) { 679 if (tree == s->bl_tree) {
680 fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", 680 fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
681 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); 681 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
682 } 682 }
683#endif 683#endif
684 /* and insert the new node in the heap */ 684 /* and insert the new node in the heap */
685 s->heap[SMALLEST] = node++; 685 s->heap[SMALLEST] = node++;
686 pqdownheap(s, tree, SMALLEST); 686 pqdownheap(s, tree, SMALLEST);
687 687
688 } while (s->heap_len >= 2); 688 } while (s->heap_len >= 2);
689 689
690 s->heap[--(s->heap_max)] = s->heap[SMALLEST]; 690 s->heap[--(s->heap_max)] = s->heap[SMALLEST];
691 691
692 /* At this point, the fields freq and dad are set. We can now 692 /* At this point, the fields freq and dad are set. We can now
693 * generate the bit lengths. 693 * generate the bit lengths.
694 */ 694 */
695 gen_bitlen(s, (tree_desc *)desc); 695 gen_bitlen(s, (tree_desc *)desc);
696 696
697 /* The field len is now set, we can generate the bit codes */ 697 /* The field len is now set, we can generate the bit codes */
698 gen_codes ((ct_data *)tree, max_code, s->bl_count); 698 gen_codes ((ct_data *)tree, max_code, s->bl_count);
699} 699}
700 700
701/* =========================================================================== 701/* ===========================================================================
702 * Scan a literal or distance tree to determine the frequencies of the codes 702 * Scan a literal or distance tree to determine the frequencies of the codes
703 * in the bit length tree. 703 * in the bit length tree.
704 */ 704 */
705local void scan_tree (s, tree, max_code) 705local void scan_tree (s, tree, max_code)
706 deflate_state *s; 706 deflate_state *s;
707 ct_data *tree; /* the tree to be scanned */ 707 ct_data *tree; /* the tree to be scanned */
708 int max_code; /* and its largest code of non zero frequency */ 708 int max_code; /* and its largest code of non zero frequency */
709{ 709{
710 int n; /* iterates over all tree elements */ 710 int n; /* iterates over all tree elements */
711 int prevlen = -1; /* last emitted length */ 711 int prevlen = -1; /* last emitted length */
712 int curlen; /* length of current code */ 712 int curlen; /* length of current code */
713 int nextlen = tree[0].Len; /* length of next code */ 713 int nextlen = tree[0].Len; /* length of next code */
714 int count = 0; /* repeat count of the current code */ 714 int count = 0; /* repeat count of the current code */
715 int max_count = 7; /* max repeat count */ 715 int max_count = 7; /* max repeat count */
716 int min_count = 4; /* min repeat count */ 716 int min_count = 4; /* min repeat count */
717 717
718 if (nextlen == 0) max_count = 138, min_count = 3; 718 if (nextlen == 0) max_count = 138, min_count = 3;
719 tree[max_code+1].Len = (ush)0xffff; /* guard */ 719 tree[max_code+1].Len = (ush)0xffff; /* guard */
720 720
721 for (n = 0; n <= max_code; n++) { 721 for (n = 0; n <= max_code; n++) {
722 curlen = nextlen; nextlen = tree[n+1].Len; 722 curlen = nextlen; nextlen = tree[n+1].Len;
723 if (++count < max_count && curlen == nextlen) { 723 if (++count < max_count && curlen == nextlen) {
724 continue; 724 continue;
725 } else if (count < min_count) { 725 } else if (count < min_count) {
726 s->bl_tree[curlen].Freq += count; 726 s->bl_tree[curlen].Freq += count;
727 } else if (curlen != 0) { 727 } else if (curlen != 0) {
728 if (curlen != prevlen) s->bl_tree[curlen].Freq++; 728 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
729 s->bl_tree[REP_3_6].Freq++; 729 s->bl_tree[REP_3_6].Freq++;
730 } else if (count <= 10) { 730 } else if (count <= 10) {
731 s->bl_tree[REPZ_3_10].Freq++; 731 s->bl_tree[REPZ_3_10].Freq++;
732 } else { 732 } else {
733 s->bl_tree[REPZ_11_138].Freq++; 733 s->bl_tree[REPZ_11_138].Freq++;
734 } 734 }
735 count = 0; prevlen = curlen; 735 count = 0; prevlen = curlen;
736 if (nextlen == 0) { 736 if (nextlen == 0) {
737 max_count = 138, min_count = 3; 737 max_count = 138, min_count = 3;
738 } else if (curlen == nextlen) { 738 } else if (curlen == nextlen) {
739 max_count = 6, min_count = 3; 739 max_count = 6, min_count = 3;
740 } else { 740 } else {
741 max_count = 7, min_count = 4; 741 max_count = 7, min_count = 4;
742 } 742 }
743 } 743 }
744} 744}
745 745
746/* =========================================================================== 746/* ===========================================================================
747 * Send a literal or distance tree in compressed form, using the codes in 747 * Send a literal or distance tree in compressed form, using the codes in
748 * bl_tree. 748 * bl_tree.
749 */ 749 */
750local void send_tree (s, tree, max_code) 750local void send_tree (s, tree, max_code)
751 deflate_state *s; 751 deflate_state *s;
752 ct_data *tree; /* the tree to be scanned */ 752 ct_data *tree; /* the tree to be scanned */
753 int max_code; /* and its largest code of non zero frequency */ 753 int max_code; /* and its largest code of non zero frequency */
754{ 754{
755 int n; /* iterates over all tree elements */ 755 int n; /* iterates over all tree elements */
756 int prevlen = -1; /* last emitted length */ 756 int prevlen = -1; /* last emitted length */
757 int curlen; /* length of current code */ 757 int curlen; /* length of current code */
758 int nextlen = tree[0].Len; /* length of next code */ 758 int nextlen = tree[0].Len; /* length of next code */
759 int count = 0; /* repeat count of the current code */ 759 int count = 0; /* repeat count of the current code */
760 int max_count = 7; /* max repeat count */ 760 int max_count = 7; /* max repeat count */
761 int min_count = 4; /* min repeat count */ 761 int min_count = 4; /* min repeat count */
762 762
763 /* tree[max_code+1].Len = -1; */ /* guard already set */ 763 /* tree[max_code+1].Len = -1; */ /* guard already set */
764 if (nextlen == 0) max_count = 138, min_count = 3; 764 if (nextlen == 0) max_count = 138, min_count = 3;
765 765
766 for (n = 0; n <= max_code; n++) { 766 for (n = 0; n <= max_code; n++) {
767 curlen = nextlen; nextlen = tree[n+1].Len; 767 curlen = nextlen; nextlen = tree[n+1].Len;
768 if (++count < max_count && curlen == nextlen) { 768 if (++count < max_count && curlen == nextlen) {
769 continue; 769 continue;
770 } else if (count < min_count) { 770 } else if (count < min_count) {
771 do { send_code(s, curlen, s->bl_tree); } while (--count != 0); 771 do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
772 772
773 } else if (curlen != 0) { 773 } else if (curlen != 0) {
774 if (curlen != prevlen) { 774 if (curlen != prevlen) {
775 send_code(s, curlen, s->bl_tree); count--; 775 send_code(s, curlen, s->bl_tree); count--;
776 } 776 }
777 Assert(count >= 3 && count <= 6, " 3_6?"); 777 Assert(count >= 3 && count <= 6, " 3_6?");
778 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); 778 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
779 779
780 } else if (count <= 10) { 780 } else if (count <= 10) {
781 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); 781 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
782 782
783 } else { 783 } else {
784 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); 784 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
785 } 785 }
786 count = 0; prevlen = curlen; 786 count = 0; prevlen = curlen;
787 if (nextlen == 0) { 787 if (nextlen == 0) {
788 max_count = 138, min_count = 3; 788 max_count = 138, min_count = 3;
789 } else if (curlen == nextlen) { 789 } else if (curlen == nextlen) {
790 max_count = 6, min_count = 3; 790 max_count = 6, min_count = 3;
791 } else { 791 } else {
792 max_count = 7, min_count = 4; 792 max_count = 7, min_count = 4;
793 } 793 }
794 } 794 }
795} 795}
796 796
797/* =========================================================================== 797/* ===========================================================================
798 * Construct the Huffman tree for the bit lengths and return the index in 798 * Construct the Huffman tree for the bit lengths and return the index in
799 * bl_order of the last bit length code to send. 799 * bl_order of the last bit length code to send.
800 */ 800 */
801local int build_bl_tree(s) 801local int build_bl_tree(s)
802 deflate_state *s; 802 deflate_state *s;
803{ 803{
804 int max_blindex; /* index of last bit length code of non zero freq */ 804 int max_blindex; /* index of last bit length code of non zero freq */
805 805
806 /* Determine the bit length frequencies for literal and distance trees */ 806 /* Determine the bit length frequencies for literal and distance trees */
807 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); 807 scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
808 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); 808 scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
809 809
810 /* Build the bit length tree: */ 810 /* Build the bit length tree: */
811 build_tree(s, (tree_desc *)(&(s->bl_desc))); 811 build_tree(s, (tree_desc *)(&(s->bl_desc)));
812 /* opt_len now includes the length of the tree representations, except 812 /* opt_len now includes the length of the tree representations, except
813 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. 813 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
814 */ 814 */
815 815
816 /* Determine the number of bit length codes to send. The pkzip format 816 /* Determine the number of bit length codes to send. The pkzip format
817 * requires that at least 4 bit length codes be sent. (appnote.txt says 817 * requires that at least 4 bit length codes be sent. (appnote.txt says
818 * 3 but the actual value used is 4.) 818 * 3 but the actual value used is 4.)
819 */ 819 */
820 for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { 820 for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
821 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; 821 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
822 } 822 }
823 /* Update opt_len to include the bit length tree and counts */ 823 /* Update opt_len to include the bit length tree and counts */
824 s->opt_len += 3*(max_blindex+1) + 5+5+4; 824 s->opt_len += 3*(max_blindex+1) + 5+5+4;
825 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", 825 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
826 s->opt_len, s->static_len)); 826 s->opt_len, s->static_len));
827 827
828 return max_blindex; 828 return max_blindex;
829} 829}
830 830
831/* =========================================================================== 831/* ===========================================================================
832 * Send the header for a block using dynamic Huffman trees: the counts, the 832 * Send the header for a block using dynamic Huffman trees: the counts, the
833 * lengths of the bit length codes, the literal tree and the distance tree. 833 * lengths of the bit length codes, the literal tree and the distance tree.
834 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. 834 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
835 */ 835 */
836local void send_all_trees(s, lcodes, dcodes, blcodes) 836local void send_all_trees(s, lcodes, dcodes, blcodes)
837 deflate_state *s; 837 deflate_state *s;
838 int lcodes, dcodes, blcodes; /* number of codes for each tree */ 838 int lcodes, dcodes, blcodes; /* number of codes for each tree */
839{ 839{
840 int rank; /* index in bl_order */ 840 int rank; /* index in bl_order */
841 841
842 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); 842 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
843 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, 843 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
844 "too many codes"); 844 "too many codes");
845 Tracev((stderr, "\nbl counts: ")); 845 Tracev((stderr, "\nbl counts: "));
846 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ 846 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
847 send_bits(s, dcodes-1, 5); 847 send_bits(s, dcodes-1, 5);
848 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ 848 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
849 for (rank = 0; rank < blcodes; rank++) { 849 for (rank = 0; rank < blcodes; rank++) {
850 Tracev((stderr, "\nbl code %2d ", bl_order[rank])); 850 Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
851 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); 851 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
852 } 852 }
853 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); 853 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
854 854
855 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ 855 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
856 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); 856 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
857 857
858 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ 858 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
859 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); 859 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
860} 860}
861 861
862/* =========================================================================== 862/* ===========================================================================
863 * Send a stored block 863 * Send a stored block
864 */ 864 */
865void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) 865void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
866 deflate_state *s; 866 deflate_state *s;
867 charf *buf; /* input block */ 867 charf *buf; /* input block */
868 ulg stored_len; /* length of input block */ 868 ulg stored_len; /* length of input block */
869 int last; /* one if this is the last block for a file */ 869 int last; /* one if this is the last block for a file */
870{ 870{
871 send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ 871 send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
872#ifdef DEBUG 872#ifdef DEBUG
873 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; 873 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
874 s->compressed_len += (stored_len + 4) << 3; 874 s->compressed_len += (stored_len + 4) << 3;
875#endif 875#endif
876 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ 876 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
877} 877}
878 878
879/* =========================================================================== 879/* ===========================================================================
880 * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) 880 * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
881 */ 881 */
882void ZLIB_INTERNAL _tr_flush_bits(s) 882void ZLIB_INTERNAL _tr_flush_bits(s)
883 deflate_state *s; 883 deflate_state *s;
884{ 884{
885 bi_flush(s); 885 bi_flush(s);
886} 886}
887 887
888/* =========================================================================== 888/* ===========================================================================
889 * Send one empty static block to give enough lookahead for inflate. 889 * Send one empty static block to give enough lookahead for inflate.
890 * This takes 10 bits, of which 7 may remain in the bit buffer. 890 * This takes 10 bits, of which 7 may remain in the bit buffer.
891 */ 891 */
892void ZLIB_INTERNAL _tr_align(s) 892void ZLIB_INTERNAL _tr_align(s)
893 deflate_state *s; 893 deflate_state *s;
894{ 894{
895 send_bits(s, STATIC_TREES<<1, 3); 895 send_bits(s, STATIC_TREES<<1, 3);
896 send_code(s, END_BLOCK, static_ltree); 896 send_code(s, END_BLOCK, static_ltree);
897#ifdef DEBUG 897#ifdef DEBUG
898 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ 898 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
899#endif 899#endif
900 bi_flush(s); 900 bi_flush(s);
901} 901}
902 902
903/* =========================================================================== 903/* ===========================================================================
904 * Determine the best encoding for the current block: dynamic trees, static 904 * Determine the best encoding for the current block: dynamic trees, static
905 * trees or store, and output the encoded block to the zip file. 905 * trees or store, and output the encoded block to the zip file.
906 */ 906 */
907void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) 907void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
908 deflate_state *s; 908 deflate_state *s;
909 charf *buf; /* input block, or NULL if too old */ 909 charf *buf; /* input block, or NULL if too old */
910 ulg stored_len; /* length of input block */ 910 ulg stored_len; /* length of input block */
911 int last; /* one if this is the last block for a file */ 911 int last; /* one if this is the last block for a file */
912{ 912{
913 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ 913 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
914 int max_blindex = 0; /* index of last bit length code of non zero freq */ 914 int max_blindex = 0; /* index of last bit length code of non zero freq */
915 915
916 /* Build the Huffman trees unless a stored block is forced */ 916 /* Build the Huffman trees unless a stored block is forced */
917 if (s->level > 0) { 917 if (s->level > 0) {
918 918
919 /* Check if the file is binary or text */ 919 /* Check if the file is binary or text */
920 if (s->strm->data_type == Z_UNKNOWN) 920 if (s->strm->data_type == Z_UNKNOWN)
921 s->strm->data_type = detect_data_type(s); 921 s->strm->data_type = detect_data_type(s);
922 922
923 /* Construct the literal and distance trees */ 923 /* Construct the literal and distance trees */
924 build_tree(s, (tree_desc *)(&(s->l_desc))); 924 build_tree(s, (tree_desc *)(&(s->l_desc)));
925 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 925 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
926 s->static_len)); 926 s->static_len));
927 927
928 build_tree(s, (tree_desc *)(&(s->d_desc))); 928 build_tree(s, (tree_desc *)(&(s->d_desc)));
929 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, 929 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
930 s->static_len)); 930 s->static_len));
931 /* At this point, opt_len and static_len are the total bit lengths of 931 /* At this point, opt_len and static_len are the total bit lengths of
932 * the compressed block data, excluding the tree representations. 932 * the compressed block data, excluding the tree representations.
933 */ 933 */
934 934
935 /* Build the bit length tree for the above two trees, and get the index 935 /* Build the bit length tree for the above two trees, and get the index
936 * in bl_order of the last bit length code to send. 936 * in bl_order of the last bit length code to send.
937 */ 937 */
938 max_blindex = build_bl_tree(s); 938 max_blindex = build_bl_tree(s);
939 939
940 /* Determine the best encoding. Compute the block lengths in bytes. */ 940 /* Determine the best encoding. Compute the block lengths in bytes. */
941 opt_lenb = (s->opt_len+3+7)>>3; 941 opt_lenb = (s->opt_len+3+7)>>3;
942 static_lenb = (s->static_len+3+7)>>3; 942 static_lenb = (s->static_len+3+7)>>3;
943 943
944 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", 944 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
945 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, 945 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
946 s->last_lit)); 946 s->last_lit));
947 947
948 if (static_lenb <= opt_lenb) opt_lenb = static_lenb; 948 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
949 949
950 } else { 950 } else {
951 Assert(buf != (char*)0, "lost buf"); 951 Assert(buf != (char*)0, "lost buf");
952 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ 952 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
953 } 953 }
954 954
955#ifdef FORCE_STORED 955#ifdef FORCE_STORED
956 if (buf != (char*)0) { /* force stored block */ 956 if (buf != (char*)0) { /* force stored block */
957#else 957#else
958 if (stored_len+4 <= opt_lenb && buf != (char*)0) { 958 if (stored_len+4 <= opt_lenb && buf != (char*)0) {
959 /* 4: two words for the lengths */ 959 /* 4: two words for the lengths */
960#endif 960#endif
961 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. 961 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
962 * Otherwise we can't have processed more than WSIZE input bytes since 962 * Otherwise we can't have processed more than WSIZE input bytes since
963 * the last block flush, because compression would have been 963 * the last block flush, because compression would have been
964 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to 964 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
965 * transform a block into a stored block. 965 * transform a block into a stored block.
966 */ 966 */
967 _tr_stored_block(s, buf, stored_len, last); 967 _tr_stored_block(s, buf, stored_len, last);
968 968
969#ifdef FORCE_STATIC 969#ifdef FORCE_STATIC
970 } else if (static_lenb >= 0) { /* force static trees */ 970 } else if (static_lenb >= 0) { /* force static trees */
971#else 971#else
972 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { 972 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
973#endif 973#endif
974 send_bits(s, (STATIC_TREES<<1)+last, 3); 974 send_bits(s, (STATIC_TREES<<1)+last, 3);
975 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); 975 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
976#ifdef DEBUG 976#ifdef DEBUG
977 s->compressed_len += 3 + s->static_len; 977 s->compressed_len += 3 + s->static_len;
978#endif 978#endif
979 } else { 979 } else {
980 send_bits(s, (DYN_TREES<<1)+last, 3); 980 send_bits(s, (DYN_TREES<<1)+last, 3);
981 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, 981 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
982 max_blindex+1); 982 max_blindex+1);
983 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); 983 compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
984#ifdef DEBUG 984#ifdef DEBUG
985 s->compressed_len += 3 + s->opt_len; 985 s->compressed_len += 3 + s->opt_len;
986#endif 986#endif
987 } 987 }
988 Assert (s->compressed_len == s->bits_sent, "bad compressed size"); 988 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
989 /* The above check is made mod 2^32, for files larger than 512 MB 989 /* The above check is made mod 2^32, for files larger than 512 MB
990 * and uLong implemented on 32 bits. 990 * and uLong implemented on 32 bits.
991 */ 991 */
992 init_block(s); 992 init_block(s);
993 993
994 if (last) { 994 if (last) {
995 bi_windup(s); 995 bi_windup(s);
996#ifdef DEBUG 996#ifdef DEBUG
997 s->compressed_len += 7; /* align on byte boundary */ 997 s->compressed_len += 7; /* align on byte boundary */
998#endif 998#endif
999 } 999 }
1000 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, 1000 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1001 s->compressed_len-7*last)); 1001 s->compressed_len-7*last));
1002} 1002}
1003 1003
1004/* =========================================================================== 1004/* ===========================================================================
1005 * Save the match info and tally the frequency counts. Return true if 1005 * Save the match info and tally the frequency counts. Return true if
1006 * the current block must be flushed. 1006 * the current block must be flushed.
1007 */ 1007 */
1008int ZLIB_INTERNAL _tr_tally (s, dist, lc) 1008int ZLIB_INTERNAL _tr_tally (s, dist, lc)
1009 deflate_state *s; 1009 deflate_state *s;
1010 unsigned dist; /* distance of matched string */ 1010 unsigned dist; /* distance of matched string */
1011 unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ 1011 unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
1012{ 1012{
1013 s->d_buf[s->last_lit] = (ush)dist; 1013 s->d_buf[s->last_lit] = (ush)dist;
1014 s->l_buf[s->last_lit++] = (uch)lc; 1014 s->l_buf[s->last_lit++] = (uch)lc;
1015 if (dist == 0) { 1015 if (dist == 0) {
1016 /* lc is the unmatched char */ 1016 /* lc is the unmatched char */
1017 s->dyn_ltree[lc].Freq++; 1017 s->dyn_ltree[lc].Freq++;
1018 } else { 1018 } else {
1019 s->matches++; 1019 s->matches++;
1020 /* Here, lc is the match length - MIN_MATCH */ 1020 /* Here, lc is the match length - MIN_MATCH */
1021 dist--; /* dist = match distance - 1 */ 1021 dist--; /* dist = match distance - 1 */
1022 Assert((ush)dist < (ush)MAX_DIST(s) && 1022 Assert((ush)dist < (ush)MAX_DIST(s) &&
1023 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && 1023 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1024 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); 1024 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1025 1025
1026 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; 1026 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1027 s->dyn_dtree[d_code(dist)].Freq++; 1027 s->dyn_dtree[d_code(dist)].Freq++;
1028 } 1028 }
1029 1029
1030#ifdef TRUNCATE_BLOCK 1030#ifdef TRUNCATE_BLOCK
1031 /* Try to guess if it is profitable to stop the current block here */ 1031 /* Try to guess if it is profitable to stop the current block here */
1032 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { 1032 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1033 /* Compute an upper bound for the compressed length */ 1033 /* Compute an upper bound for the compressed length */
1034 ulg out_length = (ulg)s->last_lit*8L; 1034 ulg out_length = (ulg)s->last_lit*8L;
1035 ulg in_length = (ulg)((long)s->strstart - s->block_start); 1035 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1036 int dcode; 1036 int dcode;
1037 for (dcode = 0; dcode < D_CODES; dcode++) { 1037 for (dcode = 0; dcode < D_CODES; dcode++) {
1038 out_length += (ulg)s->dyn_dtree[dcode].Freq * 1038 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1039 (5L+extra_dbits[dcode]); 1039 (5L+extra_dbits[dcode]);
1040 } 1040 }
1041 out_length >>= 3; 1041 out_length >>= 3;
1042 Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", 1042 Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1043 s->last_lit, in_length, out_length, 1043 s->last_lit, in_length, out_length,
1044 100L - out_length*100L/in_length)); 1044 100L - out_length*100L/in_length));
1045 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; 1045 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1046 } 1046 }
1047#endif 1047#endif
1048 return (s->last_lit == s->lit_bufsize-1); 1048 return (s->last_lit == s->lit_bufsize-1);
1049 /* We avoid equality with lit_bufsize because of wraparound at 64K 1049 /* We avoid equality with lit_bufsize because of wraparound at 64K
1050 * on 16 bit machines and because stored blocks are restricted to 1050 * on 16 bit machines and because stored blocks are restricted to
1051 * 64K-1 bytes. 1051 * 64K-1 bytes.
1052 */ 1052 */
1053} 1053}
1054 1054
1055/* =========================================================================== 1055/* ===========================================================================
1056 * Send the block data compressed using the given Huffman trees 1056 * Send the block data compressed using the given Huffman trees
1057 */ 1057 */
1058local void compress_block(s, ltree, dtree) 1058local void compress_block(s, ltree, dtree)
1059 deflate_state *s; 1059 deflate_state *s;
1060 ct_data *ltree; /* literal tree */ 1060 ct_data *ltree; /* literal tree */
1061 ct_data *dtree; /* distance tree */ 1061 ct_data *dtree; /* distance tree */
1062{ 1062{
1063 unsigned dist; /* distance of matched string */ 1063 unsigned dist; /* distance of matched string */
1064 int lc; /* match length or unmatched char (if dist == 0) */ 1064 int lc; /* match length or unmatched char (if dist == 0) */
1065 unsigned lx = 0; /* running index in l_buf */ 1065 unsigned lx = 0; /* running index in l_buf */
1066 unsigned code; /* the code to send */ 1066 unsigned code; /* the code to send */
1067 int extra; /* number of extra bits to send */ 1067 int extra; /* number of extra bits to send */
1068 1068
1069 if (s->last_lit != 0) do { 1069 if (s->last_lit != 0) do {
1070 dist = s->d_buf[lx]; 1070 dist = s->d_buf[lx];
1071 lc = s->l_buf[lx++]; 1071 lc = s->l_buf[lx++];
1072 if (dist == 0) { 1072 if (dist == 0) {
1073 send_code(s, lc, ltree); /* send a literal byte */ 1073 send_code(s, lc, ltree); /* send a literal byte */
1074 Tracecv(isgraph(lc), (stderr," '%c' ", lc)); 1074 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1075 } else { 1075 } else {
1076 /* Here, lc is the match length - MIN_MATCH */ 1076 /* Here, lc is the match length - MIN_MATCH */
1077 code = _length_code[lc]; 1077 code = _length_code[lc];
1078 send_code(s, code+LITERALS+1, ltree); /* send the length code */ 1078 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1079 extra = extra_lbits[code]; 1079 extra = extra_lbits[code];
1080 if (extra != 0) { 1080 if (extra != 0) {
1081 lc -= base_length[code]; 1081 lc -= base_length[code];
1082 send_bits(s, lc, extra); /* send the extra length bits */ 1082 send_bits(s, lc, extra); /* send the extra length bits */
1083 } 1083 }
1084 dist--; /* dist is now the match distance - 1 */ 1084 dist--; /* dist is now the match distance - 1 */
1085 code = d_code(dist); 1085 code = d_code(dist);
1086 Assert (code < D_CODES, "bad d_code"); 1086 Assert (code < D_CODES, "bad d_code");
1087 1087
1088 send_code(s, code, dtree); /* send the distance code */ 1088 send_code(s, code, dtree); /* send the distance code */
1089 extra = extra_dbits[code]; 1089 extra = extra_dbits[code];
1090 if (extra != 0) { 1090 if (extra != 0) {
1091 dist -= base_dist[code]; 1091 dist -= base_dist[code];
1092 send_bits(s, dist, extra); /* send the extra distance bits */ 1092 send_bits(s, dist, extra); /* send the extra distance bits */
1093 } 1093 }
1094 } /* literal or match pair ? */ 1094 } /* literal or match pair ? */
1095 1095
1096 /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ 1096 /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
1097 Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, 1097 Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
1098 "pendingBuf overflow"); 1098 "pendingBuf overflow");
1099 1099
1100 } while (lx < s->last_lit); 1100 } while (lx < s->last_lit);
1101 1101
1102 send_code(s, END_BLOCK, ltree); 1102 send_code(s, END_BLOCK, ltree);
1103} 1103}
1104 1104
1105/* =========================================================================== 1105/* ===========================================================================
1106 * Check if the data type is TEXT or BINARY, using the following algorithm: 1106 * Check if the data type is TEXT or BINARY, using the following algorithm:
1107 * - TEXT if the two conditions below are satisfied: 1107 * - TEXT if the two conditions below are satisfied:
1108 * a) There are no non-portable control characters belonging to the 1108 * a) There are no non-portable control characters belonging to the
1109 * "black list" (0..6, 14..25, 28..31). 1109 * "black list" (0..6, 14..25, 28..31).
1110 * b) There is at least one printable character belonging to the 1110 * b) There is at least one printable character belonging to the
1111 * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). 1111 * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
1112 * - BINARY otherwise. 1112 * - BINARY otherwise.
1113 * - The following partially-portable control characters form a 1113 * - The following partially-portable control characters form a
1114 * "gray list" that is ignored in this detection algorithm: 1114 * "gray list" that is ignored in this detection algorithm:
1115 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). 1115 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
1116 * IN assertion: the fields Freq of dyn_ltree are set. 1116 * IN assertion: the fields Freq of dyn_ltree are set.
1117 */ 1117 */
1118local int detect_data_type(s) 1118local int detect_data_type(s)
1119 deflate_state *s; 1119 deflate_state *s;
1120{ 1120{
1121 /* black_mask is the bit mask of black-listed bytes 1121 /* black_mask is the bit mask of black-listed bytes
1122 * set bits 0..6, 14..25, and 28..31 1122 * set bits 0..6, 14..25, and 28..31
1123 * 0xf3ffc07f = binary 11110011111111111100000001111111 1123 * 0xf3ffc07f = binary 11110011111111111100000001111111
1124 */ 1124 */
1125 unsigned long black_mask = 0xf3ffc07fUL; 1125 unsigned long black_mask = 0xf3ffc07fUL;
1126 int n; 1126 int n;
1127 1127
1128 /* Check for non-textual ("black-listed") bytes. */ 1128 /* Check for non-textual ("black-listed") bytes. */
1129 for (n = 0; n <= 31; n++, black_mask >>= 1) 1129 for (n = 0; n <= 31; n++, black_mask >>= 1)
1130 if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) 1130 if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
1131 return Z_BINARY; 1131 return Z_BINARY;
1132 1132
1133 /* Check for textual ("white-listed") bytes. */ 1133 /* Check for textual ("white-listed") bytes. */
1134 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 1134 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
1135 || s->dyn_ltree[13].Freq != 0) 1135 || s->dyn_ltree[13].Freq != 0)
1136 return Z_TEXT; 1136 return Z_TEXT;
1137 for (n = 32; n < LITERALS; n++) 1137 for (n = 32; n < LITERALS; n++)
1138 if (s->dyn_ltree[n].Freq != 0) 1138 if (s->dyn_ltree[n].Freq != 0)
1139 return Z_TEXT; 1139 return Z_TEXT;
1140 1140
1141 /* There are no "black-listed" or "white-listed" bytes: 1141 /* There are no "black-listed" or "white-listed" bytes:
1142 * this stream either is empty or has tolerated ("gray-listed") bytes only. 1142 * this stream either is empty or has tolerated ("gray-listed") bytes only.
1143 */ 1143 */
1144 return Z_BINARY; 1144 return Z_BINARY;
1145} 1145}
1146 1146
1147/* =========================================================================== 1147/* ===========================================================================
1148 * Reverse the first len bits of a code, using straightforward code (a faster 1148 * Reverse the first len bits of a code, using straightforward code (a faster
1149 * method would use a table) 1149 * method would use a table)
1150 * IN assertion: 1 <= len <= 15 1150 * IN assertion: 1 <= len <= 15
1151 */ 1151 */
1152local unsigned bi_reverse(code, len) 1152local unsigned bi_reverse(code, len)
1153 unsigned code; /* the value to invert */ 1153 unsigned code; /* the value to invert */
1154 int len; /* its bit length */ 1154 int len; /* its bit length */
1155{ 1155{
1156 register unsigned res = 0; 1156 register unsigned res = 0;
1157 do { 1157 do {
1158 res |= code & 1; 1158 res |= code & 1;
1159 code >>= 1, res <<= 1; 1159 code >>= 1, res <<= 1;
1160 } while (--len > 0); 1160 } while (--len > 0);
1161 return res >> 1; 1161 return res >> 1;
1162} 1162}
1163 1163
1164/* =========================================================================== 1164/* ===========================================================================
1165 * Flush the bit buffer, keeping at most 7 bits in it. 1165 * Flush the bit buffer, keeping at most 7 bits in it.
1166 */ 1166 */
1167local void bi_flush(s) 1167local void bi_flush(s)
1168 deflate_state *s; 1168 deflate_state *s;
1169{ 1169{
1170 if (s->bi_valid == 16) { 1170 if (s->bi_valid == 16) {
1171 put_short(s, s->bi_buf); 1171 put_short(s, s->bi_buf);
1172 s->bi_buf = 0; 1172 s->bi_buf = 0;
1173 s->bi_valid = 0; 1173 s->bi_valid = 0;
1174 } else if (s->bi_valid >= 8) { 1174 } else if (s->bi_valid >= 8) {
1175 put_byte(s, (Byte)s->bi_buf); 1175 put_byte(s, (Byte)s->bi_buf);
1176 s->bi_buf >>= 8; 1176 s->bi_buf >>= 8;
1177 s->bi_valid -= 8; 1177 s->bi_valid -= 8;
1178 } 1178 }
1179} 1179}
1180 1180
1181/* =========================================================================== 1181/* ===========================================================================
1182 * Flush the bit buffer and align the output on a byte boundary 1182 * Flush the bit buffer and align the output on a byte boundary
1183 */ 1183 */
1184local void bi_windup(s) 1184local void bi_windup(s)
1185 deflate_state *s; 1185 deflate_state *s;
1186{ 1186{
1187 if (s->bi_valid > 8) { 1187 if (s->bi_valid > 8) {
1188 put_short(s, s->bi_buf); 1188 put_short(s, s->bi_buf);
1189 } else if (s->bi_valid > 0) { 1189 } else if (s->bi_valid > 0) {
1190 put_byte(s, (Byte)s->bi_buf); 1190 put_byte(s, (Byte)s->bi_buf);
1191 } 1191 }
1192 s->bi_buf = 0; 1192 s->bi_buf = 0;
1193 s->bi_valid = 0; 1193 s->bi_valid = 0;
1194#ifdef DEBUG 1194#ifdef DEBUG
1195 s->bits_sent = (s->bits_sent+7) & ~7; 1195 s->bits_sent = (s->bits_sent+7) & ~7;
1196#endif 1196#endif
1197} 1197}
1198 1198
1199/* =========================================================================== 1199/* ===========================================================================
1200 * Copy a stored block, storing first the length and its 1200 * Copy a stored block, storing first the length and its
1201 * one's complement if requested. 1201 * one's complement if requested.
1202 */ 1202 */
1203local void copy_block(s, buf, len, header) 1203local void copy_block(s, buf, len, header)
1204 deflate_state *s; 1204 deflate_state *s;
1205 charf *buf; /* the input data */ 1205 charf *buf; /* the input data */
1206 unsigned len; /* its length */ 1206 unsigned len; /* its length */
1207 int header; /* true if block header must be written */ 1207 int header; /* true if block header must be written */
1208{ 1208{
1209 bi_windup(s); /* align on byte boundary */ 1209 bi_windup(s); /* align on byte boundary */
1210 1210
1211 if (header) { 1211 if (header) {
1212 put_short(s, (ush)len); 1212 put_short(s, (ush)len);
1213 put_short(s, (ush)~len); 1213 put_short(s, (ush)~len);
1214#ifdef DEBUG 1214#ifdef DEBUG
1215 s->bits_sent += 2*16; 1215 s->bits_sent += 2*16;
1216#endif 1216#endif
1217 } 1217 }
1218#ifdef DEBUG 1218#ifdef DEBUG
1219 s->bits_sent += (ulg)len<<3; 1219 s->bits_sent += (ulg)len<<3;
1220#endif 1220#endif
1221 while (len--) { 1221 while (len--) {
1222 put_byte(s, *buf++); 1222 put_byte(s, *buf++);
1223 } 1223 }
1224} 1224}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.h
index ce8f620..d35639d 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/trees.h
@@ -1,128 +1,128 @@
1/* header created automatically with -DGEN_TREES_H */ 1/* header created automatically with -DGEN_TREES_H */
2 2
3local const ct_data static_ltree[L_CODES+2] = { 3local const ct_data static_ltree[L_CODES+2] = {
4{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 4{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
5{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 5{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
6{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 6{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
7{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 7{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
8{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 8{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
9{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 9{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
10{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 10{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
11{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 11{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
12{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 12{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
13{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 13{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
14{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 14{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
15{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 15{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
16{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 16{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
17{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 17{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
18{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 18{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
19{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 19{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
20{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 20{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
21{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 21{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
22{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 22{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
23{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 23{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
24{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 24{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
25{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 25{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
26{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 26{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
27{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 27{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
28{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 28{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
29{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 29{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
30{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 30{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
31{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 31{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
32{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 32{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
33{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 33{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
34{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 34{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
35{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 35{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
36{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 36{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
37{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 37{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
38{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 38{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
39{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 39{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
40{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 40{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
41{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 41{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
42{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 42{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
43{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 43{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
44{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 44{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
45{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 45{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
46{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 46{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
47{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 47{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
48{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 48{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
49{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 49{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
50{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 50{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
51{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 51{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
52{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 52{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
53{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 53{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
54{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 54{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
55{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 55{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
56{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 56{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
57{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 57{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
58{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 58{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
59{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 59{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
60{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 60{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
61{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 61{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
62}; 62};
63 63
64local const ct_data static_dtree[D_CODES] = { 64local const ct_data static_dtree[D_CODES] = {
65{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 65{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
66{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 66{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
67{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 67{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
68{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 68{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
69{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 69{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
70{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 70{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
71}; 71};
72 72
73const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 73const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
74 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 74 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
75 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 75 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
7610, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 7610, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
7711, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 7711, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
7812, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 7812, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
7913, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 7913, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
8013, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 8013, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8114, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 8114, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8214, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 8214, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
8314, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 8314, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
8415, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 8415, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
8515, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 8515, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
8615, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 8615, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
8718, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 8718, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
8823, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 8823, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
8924, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 8924, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
9026, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 9026, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
9126, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 9126, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
9227, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 9227, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
9327, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 9327, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9428, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 9428, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9528, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 9528, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
9628, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 9628, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9729, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 9729, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9829, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 9829, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
9929, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 9929, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
100}; 100};
101 101
102const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 102const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
103 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 103 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
10413, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 10413, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
10517, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 10517, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
10619, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 10619, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
10721, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 10721, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
10822, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 10822, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
10923, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 10923, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
11024, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 11024, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
11125, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 11125, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
11225, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 11225, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
11326, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 11326, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
11426, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 11426, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
11527, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 11527, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
116}; 116};
117 117
118local const int base_length[LENGTH_CODES] = { 118local const int base_length[LENGTH_CODES] = {
1190, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 1190, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
12064, 80, 96, 112, 128, 160, 192, 224, 0 12064, 80, 96, 112, 128, 160, 192, 224, 0
121}; 121};
122 122
123local const int base_dist[D_CODES] = { 123local const int base_dist[D_CODES] = {
124 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 124 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
125 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 125 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
126 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 126 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
127}; 127};
128 128
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/uncompr.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/uncompr.c
index f07773c..ad98be3 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/uncompr.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/uncompr.c
@@ -1,59 +1,59 @@
1/* uncompr.c -- decompress a memory buffer 1/* uncompr.c -- decompress a memory buffer
2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#define ZLIB_INTERNAL 8#define ZLIB_INTERNAL
9#include "zlib.h" 9#include "zlib.h"
10 10
11/* =========================================================================== 11/* ===========================================================================
12 Decompresses the source buffer into the destination buffer. sourceLen is 12 Decompresses the source buffer into the destination buffer. sourceLen is
13 the byte length of the source buffer. Upon entry, destLen is the total 13 the byte length of the source buffer. Upon entry, destLen is the total
14 size of the destination buffer, which must be large enough to hold the 14 size of the destination buffer, which must be large enough to hold the
15 entire uncompressed data. (The size of the uncompressed data must have 15 entire uncompressed data. (The size of the uncompressed data must have
16 been saved previously by the compressor and transmitted to the decompressor 16 been saved previously by the compressor and transmitted to the decompressor
17 by some mechanism outside the scope of this compression library.) 17 by some mechanism outside the scope of this compression library.)
18 Upon exit, destLen is the actual size of the compressed buffer. 18 Upon exit, destLen is the actual size of the compressed buffer.
19 19
20 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 20 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
21 enough memory, Z_BUF_ERROR if there was not enough room in the output 21 enough memory, Z_BUF_ERROR if there was not enough room in the output
22 buffer, or Z_DATA_ERROR if the input data was corrupted. 22 buffer, or Z_DATA_ERROR if the input data was corrupted.
23*/ 23*/
24int ZEXPORT uncompress (dest, destLen, source, sourceLen) 24int ZEXPORT uncompress (dest, destLen, source, sourceLen)
25 Bytef *dest; 25 Bytef *dest;
26 uLongf *destLen; 26 uLongf *destLen;
27 const Bytef *source; 27 const Bytef *source;
28 uLong sourceLen; 28 uLong sourceLen;
29{ 29{
30 z_stream stream; 30 z_stream stream;
31 int err; 31 int err;
32 32
33 stream.next_in = (Bytef*)source; 33 stream.next_in = (Bytef*)source;
34 stream.avail_in = (uInt)sourceLen; 34 stream.avail_in = (uInt)sourceLen;
35 /* Check for source > 64K on 16-bit machine: */ 35 /* Check for source > 64K on 16-bit machine: */
36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37 37
38 stream.next_out = dest; 38 stream.next_out = dest;
39 stream.avail_out = (uInt)*destLen; 39 stream.avail_out = (uInt)*destLen;
40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
41 41
42 stream.zalloc = (alloc_func)0; 42 stream.zalloc = (alloc_func)0;
43 stream.zfree = (free_func)0; 43 stream.zfree = (free_func)0;
44 44
45 err = inflateInit(&stream); 45 err = inflateInit(&stream);
46 if (err != Z_OK) return err; 46 if (err != Z_OK) return err;
47 47
48 err = inflate(&stream, Z_FINISH); 48 err = inflate(&stream, Z_FINISH);
49 if (err != Z_STREAM_END) { 49 if (err != Z_STREAM_END) {
50 inflateEnd(&stream); 50 inflateEnd(&stream);
51 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 51 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
52 return Z_DATA_ERROR; 52 return Z_DATA_ERROR;
53 return err; 53 return err;
54 } 54 }
55 *destLen = stream.total_out; 55 *destLen = stream.total_out;
56 56
57 err = inflateEnd(&stream); 57 err = inflateEnd(&stream);
58 return err; 58 return err;
59} 59}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zconf.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zconf.h
index a5f29f8..1477c89 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zconf.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zconf.h
@@ -1,506 +1,506 @@
1/* zconf.h -- configuration of the zlib compression library 1/* zconf.h -- configuration of the zlib compression library
2 * Copyright (C) 1995-2012 Jean-loup Gailly. 2 * Copyright (C) 1995-2012 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#ifndef ZCONF_H 8#ifndef ZCONF_H
9#define ZCONF_H 9#define ZCONF_H
10 10
11/* 11/*
12 * If you *really* need a unique prefix for all types and library functions, 12 * If you *really* need a unique prefix for all types and library functions,
13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 13 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14 * Even better than compiling with -DZ_PREFIX would be to use configure to set 14 * Even better than compiling with -DZ_PREFIX would be to use configure to set
15 * this permanently in zconf.h using "./configure --zprefix". 15 * this permanently in zconf.h using "./configure --zprefix".
16 */ 16 */
17#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ 17#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
18# define Z_PREFIX_SET 18# define Z_PREFIX_SET
19 19
20/* all linked symbols */ 20/* all linked symbols */
21# define _dist_code z__dist_code 21# define _dist_code z__dist_code
22# define _length_code z__length_code 22# define _length_code z__length_code
23# define _tr_align z__tr_align 23# define _tr_align z__tr_align
24# define _tr_flush_block z__tr_flush_block 24# define _tr_flush_block z__tr_flush_block
25# define _tr_init z__tr_init 25# define _tr_init z__tr_init
26# define _tr_stored_block z__tr_stored_block 26# define _tr_stored_block z__tr_stored_block
27# define _tr_tally z__tr_tally 27# define _tr_tally z__tr_tally
28# define adler32 z_adler32 28# define adler32 z_adler32
29# define adler32_combine z_adler32_combine 29# define adler32_combine z_adler32_combine
30# define adler32_combine64 z_adler32_combine64 30# define adler32_combine64 z_adler32_combine64
31# ifndef Z_SOLO 31# ifndef Z_SOLO
32# define compress z_compress 32# define compress z_compress
33# define compress2 z_compress2 33# define compress2 z_compress2
34# define compressBound z_compressBound 34# define compressBound z_compressBound
35# endif 35# endif
36# define crc32 z_crc32 36# define crc32 z_crc32
37# define crc32_combine z_crc32_combine 37# define crc32_combine z_crc32_combine
38# define crc32_combine64 z_crc32_combine64 38# define crc32_combine64 z_crc32_combine64
39# define deflate z_deflate 39# define deflate z_deflate
40# define deflateBound z_deflateBound 40# define deflateBound z_deflateBound
41# define deflateCopy z_deflateCopy 41# define deflateCopy z_deflateCopy
42# define deflateEnd z_deflateEnd 42# define deflateEnd z_deflateEnd
43# define deflateInit2_ z_deflateInit2_ 43# define deflateInit2_ z_deflateInit2_
44# define deflateInit_ z_deflateInit_ 44# define deflateInit_ z_deflateInit_
45# define deflateParams z_deflateParams 45# define deflateParams z_deflateParams
46# define deflatePending z_deflatePending 46# define deflatePending z_deflatePending
47# define deflatePrime z_deflatePrime 47# define deflatePrime z_deflatePrime
48# define deflateReset z_deflateReset 48# define deflateReset z_deflateReset
49# define deflateResetKeep z_deflateResetKeep 49# define deflateResetKeep z_deflateResetKeep
50# define deflateSetDictionary z_deflateSetDictionary 50# define deflateSetDictionary z_deflateSetDictionary
51# define deflateSetHeader z_deflateSetHeader 51# define deflateSetHeader z_deflateSetHeader
52# define deflateTune z_deflateTune 52# define deflateTune z_deflateTune
53# define deflate_copyright z_deflate_copyright 53# define deflate_copyright z_deflate_copyright
54# define get_crc_table z_get_crc_table 54# define get_crc_table z_get_crc_table
55# ifndef Z_SOLO 55# ifndef Z_SOLO
56# define gz_error z_gz_error 56# define gz_error z_gz_error
57# define gz_intmax z_gz_intmax 57# define gz_intmax z_gz_intmax
58# define gz_strwinerror z_gz_strwinerror 58# define gz_strwinerror z_gz_strwinerror
59# define gzbuffer z_gzbuffer 59# define gzbuffer z_gzbuffer
60# define gzclearerr z_gzclearerr 60# define gzclearerr z_gzclearerr
61# define gzclose z_gzclose 61# define gzclose z_gzclose
62# define gzclose_r z_gzclose_r 62# define gzclose_r z_gzclose_r
63# define gzclose_w z_gzclose_w 63# define gzclose_w z_gzclose_w
64# define gzdirect z_gzdirect 64# define gzdirect z_gzdirect
65# define gzdopen z_gzdopen 65# define gzdopen z_gzdopen
66# define gzeof z_gzeof 66# define gzeof z_gzeof
67# define gzerror z_gzerror 67# define gzerror z_gzerror
68# define gzflush z_gzflush 68# define gzflush z_gzflush
69# define gzgetc z_gzgetc 69# define gzgetc z_gzgetc
70# define gzgetc_ z_gzgetc_ 70# define gzgetc_ z_gzgetc_
71# define gzgets z_gzgets 71# define gzgets z_gzgets
72# define gzoffset z_gzoffset 72# define gzoffset z_gzoffset
73# define gzoffset64 z_gzoffset64 73# define gzoffset64 z_gzoffset64
74# define gzopen z_gzopen 74# define gzopen z_gzopen
75# define gzopen64 z_gzopen64 75# define gzopen64 z_gzopen64
76# ifdef _WIN32 76# ifdef _WIN32
77# define gzopen_w z_gzopen_w 77# define gzopen_w z_gzopen_w
78# endif 78# endif
79# define gzprintf z_gzprintf 79# define gzprintf z_gzprintf
80# define gzputc z_gzputc 80# define gzputc z_gzputc
81# define gzputs z_gzputs 81# define gzputs z_gzputs
82# define gzread z_gzread 82# define gzread z_gzread
83# define gzrewind z_gzrewind 83# define gzrewind z_gzrewind
84# define gzseek z_gzseek 84# define gzseek z_gzseek
85# define gzseek64 z_gzseek64 85# define gzseek64 z_gzseek64
86# define gzsetparams z_gzsetparams 86# define gzsetparams z_gzsetparams
87# define gztell z_gztell 87# define gztell z_gztell
88# define gztell64 z_gztell64 88# define gztell64 z_gztell64
89# define gzungetc z_gzungetc 89# define gzungetc z_gzungetc
90# define gzwrite z_gzwrite 90# define gzwrite z_gzwrite
91# endif 91# endif
92# define inflate z_inflate 92# define inflate z_inflate
93# define inflateBack z_inflateBack 93# define inflateBack z_inflateBack
94# define inflateBackEnd z_inflateBackEnd 94# define inflateBackEnd z_inflateBackEnd
95# define inflateBackInit_ z_inflateBackInit_ 95# define inflateBackInit_ z_inflateBackInit_
96# define inflateCopy z_inflateCopy 96# define inflateCopy z_inflateCopy
97# define inflateEnd z_inflateEnd 97# define inflateEnd z_inflateEnd
98# define inflateGetHeader z_inflateGetHeader 98# define inflateGetHeader z_inflateGetHeader
99# define inflateInit2_ z_inflateInit2_ 99# define inflateInit2_ z_inflateInit2_
100# define inflateInit_ z_inflateInit_ 100# define inflateInit_ z_inflateInit_
101# define inflateMark z_inflateMark 101# define inflateMark z_inflateMark
102# define inflatePrime z_inflatePrime 102# define inflatePrime z_inflatePrime
103# define inflateReset z_inflateReset 103# define inflateReset z_inflateReset
104# define inflateReset2 z_inflateReset2 104# define inflateReset2 z_inflateReset2
105# define inflateSetDictionary z_inflateSetDictionary 105# define inflateSetDictionary z_inflateSetDictionary
106# define inflateSync z_inflateSync 106# define inflateSync z_inflateSync
107# define inflateSyncPoint z_inflateSyncPoint 107# define inflateSyncPoint z_inflateSyncPoint
108# define inflateUndermine z_inflateUndermine 108# define inflateUndermine z_inflateUndermine
109# define inflateResetKeep z_inflateResetKeep 109# define inflateResetKeep z_inflateResetKeep
110# define inflate_copyright z_inflate_copyright 110# define inflate_copyright z_inflate_copyright
111# define inflate_fast z_inflate_fast 111# define inflate_fast z_inflate_fast
112# define inflate_table z_inflate_table 112# define inflate_table z_inflate_table
113# ifndef Z_SOLO 113# ifndef Z_SOLO
114# define uncompress z_uncompress 114# define uncompress z_uncompress
115# endif 115# endif
116# define zError z_zError 116# define zError z_zError
117# ifndef Z_SOLO 117# ifndef Z_SOLO
118# define zcalloc z_zcalloc 118# define zcalloc z_zcalloc
119# define zcfree z_zcfree 119# define zcfree z_zcfree
120# endif 120# endif
121# define zlibCompileFlags z_zlibCompileFlags 121# define zlibCompileFlags z_zlibCompileFlags
122# define zlibVersion z_zlibVersion 122# define zlibVersion z_zlibVersion
123 123
124/* all zlib typedefs in zlib.h and zconf.h */ 124/* all zlib typedefs in zlib.h and zconf.h */
125# define Byte z_Byte 125# define Byte z_Byte
126# define Bytef z_Bytef 126# define Bytef z_Bytef
127# define alloc_func z_alloc_func 127# define alloc_func z_alloc_func
128# define charf z_charf 128# define charf z_charf
129# define free_func z_free_func 129# define free_func z_free_func
130# ifndef Z_SOLO 130# ifndef Z_SOLO
131# define gzFile z_gzFile 131# define gzFile z_gzFile
132# endif 132# endif
133# define gz_header z_gz_header 133# define gz_header z_gz_header
134# define gz_headerp z_gz_headerp 134# define gz_headerp z_gz_headerp
135# define in_func z_in_func 135# define in_func z_in_func
136# define intf z_intf 136# define intf z_intf
137# define out_func z_out_func 137# define out_func z_out_func
138# define uInt z_uInt 138# define uInt z_uInt
139# define uIntf z_uIntf 139# define uIntf z_uIntf
140# define uLong z_uLong 140# define uLong z_uLong
141# define uLongf z_uLongf 141# define uLongf z_uLongf
142# define voidp z_voidp 142# define voidp z_voidp
143# define voidpc z_voidpc 143# define voidpc z_voidpc
144# define voidpf z_voidpf 144# define voidpf z_voidpf
145 145
146/* all zlib structs in zlib.h and zconf.h */ 146/* all zlib structs in zlib.h and zconf.h */
147# define gz_header_s z_gz_header_s 147# define gz_header_s z_gz_header_s
148# define internal_state z_internal_state 148# define internal_state z_internal_state
149 149
150#endif 150#endif
151 151
152#if defined(__MSDOS__) && !defined(MSDOS) 152#if defined(__MSDOS__) && !defined(MSDOS)
153# define MSDOS 153# define MSDOS
154#endif 154#endif
155#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 155#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
156# define OS2 156# define OS2
157#endif 157#endif
158#if defined(_WINDOWS) && !defined(WINDOWS) 158#if defined(_WINDOWS) && !defined(WINDOWS)
159# define WINDOWS 159# define WINDOWS
160#endif 160#endif
161#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 161#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
162# ifndef WIN32 162# ifndef WIN32
163# define WIN32 163# define WIN32
164# endif 164# endif
165#endif 165#endif
166#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 166#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
167# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 167# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
168# ifndef SYS16BIT 168# ifndef SYS16BIT
169# define SYS16BIT 169# define SYS16BIT
170# endif 170# endif
171# endif 171# endif
172#endif 172#endif
173 173
174/* 174/*
175 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 175 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
176 * than 64k bytes at a time (needed on systems with 16-bit int). 176 * than 64k bytes at a time (needed on systems with 16-bit int).
177 */ 177 */
178#ifdef SYS16BIT 178#ifdef SYS16BIT
179# define MAXSEG_64K 179# define MAXSEG_64K
180#endif 180#endif
181#ifdef MSDOS 181#ifdef MSDOS
182# define UNALIGNED_OK 182# define UNALIGNED_OK
183#endif 183#endif
184 184
185#ifdef __STDC_VERSION__ 185#ifdef __STDC_VERSION__
186# ifndef STDC 186# ifndef STDC
187# define STDC 187# define STDC
188# endif 188# endif
189# if __STDC_VERSION__ >= 199901L 189# if __STDC_VERSION__ >= 199901L
190# ifndef STDC99 190# ifndef STDC99
191# define STDC99 191# define STDC99
192# endif 192# endif
193# endif 193# endif
194#endif 194#endif
195#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 195#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
196# define STDC 196# define STDC
197#endif 197#endif
198#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 198#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
199# define STDC 199# define STDC
200#endif 200#endif
201#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 201#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
202# define STDC 202# define STDC
203#endif 203#endif
204#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 204#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
205# define STDC 205# define STDC
206#endif 206#endif
207 207
208#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 208#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
209# define STDC 209# define STDC
210#endif 210#endif
211 211
212#ifndef STDC 212#ifndef STDC
213# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 213# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
214# define const /* note: need a more gentle solution here */ 214# define const /* note: need a more gentle solution here */
215# endif 215# endif
216#endif 216#endif
217 217
218#if defined(ZLIB_CONST) && !defined(z_const) 218#if defined(ZLIB_CONST) && !defined(z_const)
219# define z_const const 219# define z_const const
220#else 220#else
221# define z_const 221# define z_const
222#endif 222#endif
223 223
224/* Some Mac compilers merge all .h files incorrectly: */ 224/* Some Mac compilers merge all .h files incorrectly: */
225#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 225#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
226# define NO_DUMMY_DECL 226# define NO_DUMMY_DECL
227#endif 227#endif
228 228
229/* Maximum value for memLevel in deflateInit2 */ 229/* Maximum value for memLevel in deflateInit2 */
230#ifndef MAX_MEM_LEVEL 230#ifndef MAX_MEM_LEVEL
231# ifdef MAXSEG_64K 231# ifdef MAXSEG_64K
232# define MAX_MEM_LEVEL 8 232# define MAX_MEM_LEVEL 8
233# else 233# else
234# define MAX_MEM_LEVEL 9 234# define MAX_MEM_LEVEL 9
235# endif 235# endif
236#endif 236#endif
237 237
238/* Maximum value for windowBits in deflateInit2 and inflateInit2. 238/* Maximum value for windowBits in deflateInit2 and inflateInit2.
239 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 239 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
240 * created by gzip. (Files created by minigzip can still be extracted by 240 * created by gzip. (Files created by minigzip can still be extracted by
241 * gzip.) 241 * gzip.)
242 */ 242 */
243#ifndef MAX_WBITS 243#ifndef MAX_WBITS
244# define MAX_WBITS 15 /* 32K LZ77 window */ 244# define MAX_WBITS 15 /* 32K LZ77 window */
245#endif 245#endif
246 246
247/* The memory requirements for deflate are (in bytes): 247/* The memory requirements for deflate are (in bytes):
248 (1 << (windowBits+2)) + (1 << (memLevel+9)) 248 (1 << (windowBits+2)) + (1 << (memLevel+9))
249 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 249 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
250 plus a few kilobytes for small objects. For example, if you want to reduce 250 plus a few kilobytes for small objects. For example, if you want to reduce
251 the default memory requirements from 256K to 128K, compile with 251 the default memory requirements from 256K to 128K, compile with
252 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 252 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
253 Of course this will generally degrade compression (there's no free lunch). 253 Of course this will generally degrade compression (there's no free lunch).
254 254
255 The memory requirements for inflate are (in bytes) 1 << windowBits 255 The memory requirements for inflate are (in bytes) 1 << windowBits
256 that is, 32K for windowBits=15 (default value) plus a few kilobytes 256 that is, 32K for windowBits=15 (default value) plus a few kilobytes
257 for small objects. 257 for small objects.
258*/ 258*/
259 259
260 /* Type declarations */ 260 /* Type declarations */
261 261
262#ifndef OF /* function prototypes */ 262#ifndef OF /* function prototypes */
263# ifdef STDC 263# ifdef STDC
264# define OF(args) args 264# define OF(args) args
265# else 265# else
266# define OF(args) () 266# define OF(args) ()
267# endif 267# endif
268#endif 268#endif
269 269
270#ifndef Z_ARG /* function prototypes for stdarg */ 270#ifndef Z_ARG /* function prototypes for stdarg */
271# if defined(STDC) || defined(Z_HAVE_STDARG_H) 271# if defined(STDC) || defined(Z_HAVE_STDARG_H)
272# define Z_ARG(args) args 272# define Z_ARG(args) args
273# else 273# else
274# define Z_ARG(args) () 274# define Z_ARG(args) ()
275# endif 275# endif
276#endif 276#endif
277 277
278/* The following definitions for FAR are needed only for MSDOS mixed 278/* The following definitions for FAR are needed only for MSDOS mixed
279 * model programming (small or medium model with some far allocations). 279 * model programming (small or medium model with some far allocations).
280 * This was tested only with MSC; for other MSDOS compilers you may have 280 * This was tested only with MSC; for other MSDOS compilers you may have
281 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 281 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
282 * just define FAR to be empty. 282 * just define FAR to be empty.
283 */ 283 */
284#ifdef SYS16BIT 284#ifdef SYS16BIT
285# if defined(M_I86SM) || defined(M_I86MM) 285# if defined(M_I86SM) || defined(M_I86MM)
286 /* MSC small or medium model */ 286 /* MSC small or medium model */
287# define SMALL_MEDIUM 287# define SMALL_MEDIUM
288# ifdef _MSC_VER 288# ifdef _MSC_VER
289# define FAR _far 289# define FAR _far
290# else 290# else
291# define FAR far 291# define FAR far
292# endif 292# endif
293# endif 293# endif
294# if (defined(__SMALL__) || defined(__MEDIUM__)) 294# if (defined(__SMALL__) || defined(__MEDIUM__))
295 /* Turbo C small or medium model */ 295 /* Turbo C small or medium model */
296# define SMALL_MEDIUM 296# define SMALL_MEDIUM
297# ifdef __BORLANDC__ 297# ifdef __BORLANDC__
298# define FAR _far 298# define FAR _far
299# else 299# else
300# define FAR far 300# define FAR far
301# endif 301# endif
302# endif 302# endif
303#endif 303#endif
304 304
305#if defined(WINDOWS) || defined(WIN32) 305#if defined(WINDOWS) || defined(WIN32)
306 /* If building or using zlib as a DLL, define ZLIB_DLL. 306 /* If building or using zlib as a DLL, define ZLIB_DLL.
307 * This is not mandatory, but it offers a little performance increase. 307 * This is not mandatory, but it offers a little performance increase.
308 */ 308 */
309# ifdef ZLIB_DLL 309# ifdef ZLIB_DLL
310# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 310# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
311# ifdef ZLIB_INTERNAL 311# ifdef ZLIB_INTERNAL
312# define ZEXTERN extern __declspec(dllexport) 312# define ZEXTERN extern __declspec(dllexport)
313# else 313# else
314# define ZEXTERN extern __declspec(dllimport) 314# define ZEXTERN extern __declspec(dllimport)
315# endif 315# endif
316# endif 316# endif
317# endif /* ZLIB_DLL */ 317# endif /* ZLIB_DLL */
318 /* If building or using zlib with the WINAPI/WINAPIV calling convention, 318 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
319 * define ZLIB_WINAPI. 319 * define ZLIB_WINAPI.
320 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 320 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
321 */ 321 */
322# ifdef ZLIB_WINAPI 322# ifdef ZLIB_WINAPI
323# ifdef FAR 323# ifdef FAR
324# undef FAR 324# undef FAR
325# endif 325# endif
326# include <windows.h> 326# include <windows.h>
327 /* No need for _export, use ZLIB.DEF instead. */ 327 /* No need for _export, use ZLIB.DEF instead. */
328 /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 328 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
329# define ZEXPORT WINAPI 329# define ZEXPORT WINAPI
330# ifdef WIN32 330# ifdef WIN32
331# define ZEXPORTVA WINAPIV 331# define ZEXPORTVA WINAPIV
332# else 332# else
333# define ZEXPORTVA FAR CDECL 333# define ZEXPORTVA FAR CDECL
334# endif 334# endif
335# endif 335# endif
336#endif 336#endif
337 337
338#if defined (__BEOS__) 338#if defined (__BEOS__)
339# ifdef ZLIB_DLL 339# ifdef ZLIB_DLL
340# ifdef ZLIB_INTERNAL 340# ifdef ZLIB_INTERNAL
341# define ZEXPORT __declspec(dllexport) 341# define ZEXPORT __declspec(dllexport)
342# define ZEXPORTVA __declspec(dllexport) 342# define ZEXPORTVA __declspec(dllexport)
343# else 343# else
344# define ZEXPORT __declspec(dllimport) 344# define ZEXPORT __declspec(dllimport)
345# define ZEXPORTVA __declspec(dllimport) 345# define ZEXPORTVA __declspec(dllimport)
346# endif 346# endif
347# endif 347# endif
348#endif 348#endif
349 349
350#ifndef ZEXTERN 350#ifndef ZEXTERN
351# define ZEXTERN extern 351# define ZEXTERN extern
352#endif 352#endif
353#ifndef ZEXPORT 353#ifndef ZEXPORT
354# define ZEXPORT 354# define ZEXPORT
355#endif 355#endif
356#ifndef ZEXPORTVA 356#ifndef ZEXPORTVA
357# define ZEXPORTVA 357# define ZEXPORTVA
358#endif 358#endif
359 359
360#ifndef FAR 360#ifndef FAR
361# define FAR 361# define FAR
362#endif 362#endif
363 363
364#if !defined(__MACTYPES__) 364#if !defined(__MACTYPES__)
365typedef unsigned char Byte; /* 8 bits */ 365typedef unsigned char Byte; /* 8 bits */
366#endif 366#endif
367typedef unsigned int uInt; /* 16 bits or more */ 367typedef unsigned int uInt; /* 16 bits or more */
368typedef unsigned long uLong; /* 32 bits or more */ 368typedef unsigned long uLong; /* 32 bits or more */
369 369
370#ifdef SMALL_MEDIUM 370#ifdef SMALL_MEDIUM
371 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 371 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
372# define Bytef Byte FAR 372# define Bytef Byte FAR
373#else 373#else
374 typedef Byte FAR Bytef; 374 typedef Byte FAR Bytef;
375#endif 375#endif
376typedef char FAR charf; 376typedef char FAR charf;
377typedef int FAR intf; 377typedef int FAR intf;
378typedef uInt FAR uIntf; 378typedef uInt FAR uIntf;
379typedef uLong FAR uLongf; 379typedef uLong FAR uLongf;
380 380
381#ifdef STDC 381#ifdef STDC
382 typedef void const *voidpc; 382 typedef void const *voidpc;
383 typedef void FAR *voidpf; 383 typedef void FAR *voidpf;
384 typedef void *voidp; 384 typedef void *voidp;
385#else 385#else
386 typedef Byte const *voidpc; 386 typedef Byte const *voidpc;
387 typedef Byte FAR *voidpf; 387 typedef Byte FAR *voidpf;
388 typedef Byte *voidp; 388 typedef Byte *voidp;
389#endif 389#endif
390 390
391/* ./configure may #define Z_U4 here */ 391/* ./configure may #define Z_U4 here */
392 392
393#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) 393#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
394# include <limits.h> 394# include <limits.h>
395# if (UINT_MAX == 0xffffffffUL) 395# if (UINT_MAX == 0xffffffffUL)
396# define Z_U4 unsigned 396# define Z_U4 unsigned
397# else 397# else
398# if (ULONG_MAX == 0xffffffffUL) 398# if (ULONG_MAX == 0xffffffffUL)
399# define Z_U4 unsigned long 399# define Z_U4 unsigned long
400# else 400# else
401# if (USHRT_MAX == 0xffffffffUL) 401# if (USHRT_MAX == 0xffffffffUL)
402# define Z_U4 unsigned short 402# define Z_U4 unsigned short
403# endif 403# endif
404# endif 404# endif
405# endif 405# endif
406#endif 406#endif
407 407
408#ifdef Z_U4 408#ifdef Z_U4
409 typedef Z_U4 z_crc_t; 409 typedef Z_U4 z_crc_t;
410#else 410#else
411 typedef unsigned long z_crc_t; 411 typedef unsigned long z_crc_t;
412#endif 412#endif
413 413
414#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ 414#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
415# define Z_HAVE_UNISTD_H 415# define Z_HAVE_UNISTD_H
416#endif 416#endif
417 417
418#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ 418#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
419# define Z_HAVE_STDARG_H 419# define Z_HAVE_STDARG_H
420#endif 420#endif
421 421
422#ifdef STDC 422#ifdef STDC
423# ifndef Z_SOLO 423# ifndef Z_SOLO
424# include <sys/types.h> /* for off_t */ 424# include <sys/types.h> /* for off_t */
425# endif 425# endif
426#endif 426#endif
427 427
428#ifdef _WIN32 428#ifdef _WIN32
429# include <stddef.h> /* for wchar_t */ 429# include <stddef.h> /* for wchar_t */
430#endif 430#endif
431 431
432/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and 432/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
433 * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even 433 * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
434 * though the former does not conform to the LFS document), but considering 434 * though the former does not conform to the LFS document), but considering
435 * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as 435 * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
436 * equivalently requesting no 64-bit operations 436 * equivalently requesting no 64-bit operations
437 */ 437 */
438#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 438#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
439# undef _LARGEFILE64_SOURCE 439# undef _LARGEFILE64_SOURCE
440#endif 440#endif
441 441
442#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) 442#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
443# define Z_HAVE_UNISTD_H 443# define Z_HAVE_UNISTD_H
444#endif 444#endif
445#ifndef Z_SOLO 445#ifndef Z_SOLO
446# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE) 446# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
447# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ 447# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
448# ifdef VMS 448# ifdef VMS
449# include <unixio.h> /* for off_t */ 449# include <unixio.h> /* for off_t */
450# endif 450# endif
451# ifndef z_off_t 451# ifndef z_off_t
452# define z_off_t off_t 452# define z_off_t off_t
453# endif 453# endif
454# endif 454# endif
455#endif 455#endif
456 456
457#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 457#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
458# define Z_LFS64 458# define Z_LFS64
459#endif 459#endif
460 460
461#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) 461#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
462# define Z_LARGE64 462# define Z_LARGE64
463#endif 463#endif
464 464
465#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) 465#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
466# define Z_WANT64 466# define Z_WANT64
467#endif 467#endif
468 468
469#if !defined(SEEK_SET) && !defined(Z_SOLO) 469#if !defined(SEEK_SET) && !defined(Z_SOLO)
470# define SEEK_SET 0 /* Seek from beginning of file. */ 470# define SEEK_SET 0 /* Seek from beginning of file. */
471# define SEEK_CUR 1 /* Seek from current position. */ 471# define SEEK_CUR 1 /* Seek from current position. */
472# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 472# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
473#endif 473#endif
474 474
475#ifndef z_off_t 475#ifndef z_off_t
476# define z_off_t long 476# define z_off_t long
477#endif 477#endif
478 478
479#if !defined(_WIN32) && defined(Z_LARGE64) 479#if !defined(_WIN32) && defined(Z_LARGE64)
480# define z_off64_t off64_t 480# define z_off64_t off64_t
481#else 481#else
482# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) 482# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
483# define z_off64_t __int64 483# define z_off64_t __int64
484# else 484# else
485# define z_off64_t z_off_t 485# define z_off64_t z_off_t
486# endif 486# endif
487#endif 487#endif
488 488
489/* MVS linker does not support external names larger than 8 bytes */ 489/* MVS linker does not support external names larger than 8 bytes */
490#if defined(__MVS__) 490#if defined(__MVS__)
491 #pragma map(deflateInit_,"DEIN") 491 #pragma map(deflateInit_,"DEIN")
492 #pragma map(deflateInit2_,"DEIN2") 492 #pragma map(deflateInit2_,"DEIN2")
493 #pragma map(deflateEnd,"DEEND") 493 #pragma map(deflateEnd,"DEEND")
494 #pragma map(deflateBound,"DEBND") 494 #pragma map(deflateBound,"DEBND")
495 #pragma map(inflateInit_,"ININ") 495 #pragma map(inflateInit_,"ININ")
496 #pragma map(inflateInit2_,"ININ2") 496 #pragma map(inflateInit2_,"ININ2")
497 #pragma map(inflateEnd,"INEND") 497 #pragma map(inflateEnd,"INEND")
498 #pragma map(inflateSync,"INSY") 498 #pragma map(inflateSync,"INSY")
499 #pragma map(inflateSetDictionary,"INSEDI") 499 #pragma map(inflateSetDictionary,"INSEDI")
500 #pragma map(compressBound,"CMBND") 500 #pragma map(compressBound,"CMBND")
501 #pragma map(inflate_table,"INTABL") 501 #pragma map(inflate_table,"INTABL")
502 #pragma map(inflate_fast,"INFA") 502 #pragma map(inflate_fast,"INFA")
503 #pragma map(inflate_copyright,"INCOPY") 503 #pragma map(inflate_copyright,"INCOPY")
504#endif 504#endif
505 505
506#endif /* ZCONF_H */ 506#endif /* ZCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zlib.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zlib.h
index 4112d91..be12096 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zlib.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zlib.h
@@ -1,1744 +1,1744 @@
1/* zlib.h -- interface of the 'zlib' general purpose compression library 1/* zlib.h -- interface of the 'zlib' general purpose compression library
2 version 1.2.7, May 2nd, 2012 2 version 1.2.7, May 2nd, 2012
3 3
4 Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler 4 Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
5 5
6 This software is provided 'as-is', without any express or implied 6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages 7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software. 8 arising from the use of this software.
9 9
10 Permission is granted to anyone to use this software for any purpose, 10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it 11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions: 12 freely, subject to the following restrictions:
13 13
14 1. The origin of this software must not be misrepresented; you must not 14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software 15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be 16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required. 17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be 18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software. 19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution. 20 3. This notice may not be removed or altered from any source distribution.
21 21
22 Jean-loup Gailly Mark Adler 22 Jean-loup Gailly Mark Adler
23 jloup@gzip.org madler@alumni.caltech.edu 23 jloup@gzip.org madler@alumni.caltech.edu
24 24
25 25
26 The data format used by the zlib library is described by RFCs (Request for 26 The data format used by the zlib library is described by RFCs (Request for
27 Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 27 Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
28 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). 28 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
29*/ 29*/
30 30
31#ifndef ZLIB_H 31#ifndef ZLIB_H
32#define ZLIB_H 32#define ZLIB_H
33 33
34#include "zconf.h" 34#include "zconf.h"
35 35
36#ifdef __cplusplus 36#ifdef __cplusplus
37extern "C" { 37extern "C" {
38#endif 38#endif
39 39
40#define ZLIB_VERSION "1.2.7" 40#define ZLIB_VERSION "1.2.7"
41#define ZLIB_VERNUM 0x1270 41#define ZLIB_VERNUM 0x1270
42#define ZLIB_VER_MAJOR 1 42#define ZLIB_VER_MAJOR 1
43#define ZLIB_VER_MINOR 2 43#define ZLIB_VER_MINOR 2
44#define ZLIB_VER_REVISION 7 44#define ZLIB_VER_REVISION 7
45#define ZLIB_VER_SUBREVISION 0 45#define ZLIB_VER_SUBREVISION 0
46 46
47/* 47/*
48 The 'zlib' compression library provides in-memory compression and 48 The 'zlib' compression library provides in-memory compression and
49 decompression functions, including integrity checks of the uncompressed data. 49 decompression functions, including integrity checks of the uncompressed data.
50 This version of the library supports only one compression method (deflation) 50 This version of the library supports only one compression method (deflation)
51 but other algorithms will be added later and will have the same stream 51 but other algorithms will be added later and will have the same stream
52 interface. 52 interface.
53 53
54 Compression can be done in a single step if the buffers are large enough, 54 Compression can be done in a single step if the buffers are large enough,
55 or can be done by repeated calls of the compression function. In the latter 55 or can be done by repeated calls of the compression function. In the latter
56 case, the application must provide more input and/or consume the output 56 case, the application must provide more input and/or consume the output
57 (providing more output space) before each call. 57 (providing more output space) before each call.
58 58
59 The compressed data format used by default by the in-memory functions is 59 The compressed data format used by default by the in-memory functions is
60 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped 60 the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61 around a deflate stream, which is itself documented in RFC 1951. 61 around a deflate stream, which is itself documented in RFC 1951.
62 62
63 The library also supports reading and writing files in gzip (.gz) format 63 The library also supports reading and writing files in gzip (.gz) format
64 with an interface similar to that of stdio using the functions that start 64 with an interface similar to that of stdio using the functions that start
65 with "gz". The gzip format is different from the zlib format. gzip is a 65 with "gz". The gzip format is different from the zlib format. gzip is a
66 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. 66 gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67 67
68 This library can optionally read and write gzip streams in memory as well. 68 This library can optionally read and write gzip streams in memory as well.
69 69
70 The zlib format was designed to be compact and fast for use in memory 70 The zlib format was designed to be compact and fast for use in memory
71 and on communications channels. The gzip format was designed for single- 71 and on communications channels. The gzip format was designed for single-
72 file compression on file systems, has a larger header than zlib to maintain 72 file compression on file systems, has a larger header than zlib to maintain
73 directory information, and uses a different, slower check method than zlib. 73 directory information, and uses a different, slower check method than zlib.
74 74
75 The library does not install any signal handler. The decoder checks 75 The library does not install any signal handler. The decoder checks
76 the consistency of the compressed data, so the library should never crash 76 the consistency of the compressed data, so the library should never crash
77 even in case of corrupted input. 77 even in case of corrupted input.
78*/ 78*/
79 79
80typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); 80typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
81typedef void (*free_func) OF((voidpf opaque, voidpf address)); 81typedef void (*free_func) OF((voidpf opaque, voidpf address));
82 82
83struct internal_state; 83struct internal_state;
84 84
85typedef struct z_stream_s { 85typedef struct z_stream_s {
86 z_const Bytef *next_in; /* next input byte */ 86 z_const Bytef *next_in; /* next input byte */
87 uInt avail_in; /* number of bytes available at next_in */ 87 uInt avail_in; /* number of bytes available at next_in */
88 uLong total_in; /* total number of input bytes read so far */ 88 uLong total_in; /* total number of input bytes read so far */
89 89
90 Bytef *next_out; /* next output byte should be put there */ 90 Bytef *next_out; /* next output byte should be put there */
91 uInt avail_out; /* remaining free space at next_out */ 91 uInt avail_out; /* remaining free space at next_out */
92 uLong total_out; /* total number of bytes output so far */ 92 uLong total_out; /* total number of bytes output so far */
93 93
94 z_const char *msg; /* last error message, NULL if no error */ 94 z_const char *msg; /* last error message, NULL if no error */
95 struct internal_state FAR *state; /* not visible by applications */ 95 struct internal_state FAR *state; /* not visible by applications */
96 96
97 alloc_func zalloc; /* used to allocate the internal state */ 97 alloc_func zalloc; /* used to allocate the internal state */
98 free_func zfree; /* used to free the internal state */ 98 free_func zfree; /* used to free the internal state */
99 voidpf opaque; /* private data object passed to zalloc and zfree */ 99 voidpf opaque; /* private data object passed to zalloc and zfree */
100 100
101 int data_type; /* best guess about the data type: binary or text */ 101 int data_type; /* best guess about the data type: binary or text */
102 uLong adler; /* adler32 value of the uncompressed data */ 102 uLong adler; /* adler32 value of the uncompressed data */
103 uLong reserved; /* reserved for future use */ 103 uLong reserved; /* reserved for future use */
104} z_stream; 104} z_stream;
105 105
106typedef z_stream FAR *z_streamp; 106typedef z_stream FAR *z_streamp;
107 107
108/* 108/*
109 gzip header information passed to and from zlib routines. See RFC 1952 109 gzip header information passed to and from zlib routines. See RFC 1952
110 for more details on the meanings of these fields. 110 for more details on the meanings of these fields.
111*/ 111*/
112typedef struct gz_header_s { 112typedef struct gz_header_s {
113 int text; /* true if compressed data believed to be text */ 113 int text; /* true if compressed data believed to be text */
114 uLong time; /* modification time */ 114 uLong time; /* modification time */
115 int xflags; /* extra flags (not used when writing a gzip file) */ 115 int xflags; /* extra flags (not used when writing a gzip file) */
116 int os; /* operating system */ 116 int os; /* operating system */
117 Bytef *extra; /* pointer to extra field or Z_NULL if none */ 117 Bytef *extra; /* pointer to extra field or Z_NULL if none */
118 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ 118 uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
119 uInt extra_max; /* space at extra (only when reading header) */ 119 uInt extra_max; /* space at extra (only when reading header) */
120 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ 120 Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
121 uInt name_max; /* space at name (only when reading header) */ 121 uInt name_max; /* space at name (only when reading header) */
122 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ 122 Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
123 uInt comm_max; /* space at comment (only when reading header) */ 123 uInt comm_max; /* space at comment (only when reading header) */
124 int hcrc; /* true if there was or will be a header crc */ 124 int hcrc; /* true if there was or will be a header crc */
125 int done; /* true when done reading gzip header (not used 125 int done; /* true when done reading gzip header (not used
126 when writing a gzip file) */ 126 when writing a gzip file) */
127} gz_header; 127} gz_header;
128 128
129typedef gz_header FAR *gz_headerp; 129typedef gz_header FAR *gz_headerp;
130 130
131/* 131/*
132 The application must update next_in and avail_in when avail_in has dropped 132 The application must update next_in and avail_in when avail_in has dropped
133 to zero. It must update next_out and avail_out when avail_out has dropped 133 to zero. It must update next_out and avail_out when avail_out has dropped
134 to zero. The application must initialize zalloc, zfree and opaque before 134 to zero. The application must initialize zalloc, zfree and opaque before
135 calling the init function. All other fields are set by the compression 135 calling the init function. All other fields are set by the compression
136 library and must not be updated by the application. 136 library and must not be updated by the application.
137 137
138 The opaque value provided by the application will be passed as the first 138 The opaque value provided by the application will be passed as the first
139 parameter for calls of zalloc and zfree. This can be useful for custom 139 parameter for calls of zalloc and zfree. This can be useful for custom
140 memory management. The compression library attaches no meaning to the 140 memory management. The compression library attaches no meaning to the
141 opaque value. 141 opaque value.
142 142
143 zalloc must return Z_NULL if there is not enough memory for the object. 143 zalloc must return Z_NULL if there is not enough memory for the object.
144 If zlib is used in a multi-threaded application, zalloc and zfree must be 144 If zlib is used in a multi-threaded application, zalloc and zfree must be
145 thread safe. 145 thread safe.
146 146
147 On 16-bit systems, the functions zalloc and zfree must be able to allocate 147 On 16-bit systems, the functions zalloc and zfree must be able to allocate
148 exactly 65536 bytes, but will not be required to allocate more than this if 148 exactly 65536 bytes, but will not be required to allocate more than this if
149 the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers 149 the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
150 returned by zalloc for objects of exactly 65536 bytes *must* have their 150 returned by zalloc for objects of exactly 65536 bytes *must* have their
151 offset normalized to zero. The default allocation function provided by this 151 offset normalized to zero. The default allocation function provided by this
152 library ensures this (see zutil.c). To reduce memory requirements and avoid 152 library ensures this (see zutil.c). To reduce memory requirements and avoid
153 any allocation of 64K objects, at the expense of compression ratio, compile 153 any allocation of 64K objects, at the expense of compression ratio, compile
154 the library with -DMAX_WBITS=14 (see zconf.h). 154 the library with -DMAX_WBITS=14 (see zconf.h).
155 155
156 The fields total_in and total_out can be used for statistics or progress 156 The fields total_in and total_out can be used for statistics or progress
157 reports. After compression, total_in holds the total size of the 157 reports. After compression, total_in holds the total size of the
158 uncompressed data and may be saved for use in the decompressor (particularly 158 uncompressed data and may be saved for use in the decompressor (particularly
159 if the decompressor wants to decompress everything in a single step). 159 if the decompressor wants to decompress everything in a single step).
160*/ 160*/
161 161
162 /* constants */ 162 /* constants */
163 163
164#define Z_NO_FLUSH 0 164#define Z_NO_FLUSH 0
165#define Z_PARTIAL_FLUSH 1 165#define Z_PARTIAL_FLUSH 1
166#define Z_SYNC_FLUSH 2 166#define Z_SYNC_FLUSH 2
167#define Z_FULL_FLUSH 3 167#define Z_FULL_FLUSH 3
168#define Z_FINISH 4 168#define Z_FINISH 4
169#define Z_BLOCK 5 169#define Z_BLOCK 5
170#define Z_TREES 6 170#define Z_TREES 6
171/* Allowed flush values; see deflate() and inflate() below for details */ 171/* Allowed flush values; see deflate() and inflate() below for details */
172 172
173#define Z_OK 0 173#define Z_OK 0
174#define Z_STREAM_END 1 174#define Z_STREAM_END 1
175#define Z_NEED_DICT 2 175#define Z_NEED_DICT 2
176#define Z_ERRNO (-1) 176#define Z_ERRNO (-1)
177#define Z_STREAM_ERROR (-2) 177#define Z_STREAM_ERROR (-2)
178#define Z_DATA_ERROR (-3) 178#define Z_DATA_ERROR (-3)
179#define Z_MEM_ERROR (-4) 179#define Z_MEM_ERROR (-4)
180#define Z_BUF_ERROR (-5) 180#define Z_BUF_ERROR (-5)
181#define Z_VERSION_ERROR (-6) 181#define Z_VERSION_ERROR (-6)
182/* Return codes for the compression/decompression functions. Negative values 182/* Return codes for the compression/decompression functions. Negative values
183 * are errors, positive values are used for special but normal events. 183 * are errors, positive values are used for special but normal events.
184 */ 184 */
185 185
186#define Z_NO_COMPRESSION 0 186#define Z_NO_COMPRESSION 0
187#define Z_BEST_SPEED 1 187#define Z_BEST_SPEED 1
188#define Z_BEST_COMPRESSION 9 188#define Z_BEST_COMPRESSION 9
189#define Z_DEFAULT_COMPRESSION (-1) 189#define Z_DEFAULT_COMPRESSION (-1)
190/* compression levels */ 190/* compression levels */
191 191
192#define Z_FILTERED 1 192#define Z_FILTERED 1
193#define Z_HUFFMAN_ONLY 2 193#define Z_HUFFMAN_ONLY 2
194#define Z_RLE 3 194#define Z_RLE 3
195#define Z_FIXED 4 195#define Z_FIXED 4
196#define Z_DEFAULT_STRATEGY 0 196#define Z_DEFAULT_STRATEGY 0
197/* compression strategy; see deflateInit2() below for details */ 197/* compression strategy; see deflateInit2() below for details */
198 198
199#define Z_BINARY 0 199#define Z_BINARY 0
200#define Z_TEXT 1 200#define Z_TEXT 1
201#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ 201#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
202#define Z_UNKNOWN 2 202#define Z_UNKNOWN 2
203/* Possible values of the data_type field (though see inflate()) */ 203/* Possible values of the data_type field (though see inflate()) */
204 204
205#define Z_DEFLATED 8 205#define Z_DEFLATED 8
206/* The deflate compression method (the only one supported in this version) */ 206/* The deflate compression method (the only one supported in this version) */
207 207
208#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ 208#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
209 209
210#define zlib_version zlibVersion() 210#define zlib_version zlibVersion()
211/* for compatibility with versions < 1.0.2 */ 211/* for compatibility with versions < 1.0.2 */
212 212
213 213
214 /* basic functions */ 214 /* basic functions */
215 215
216ZEXTERN const char * ZEXPORT zlibVersion OF((void)); 216ZEXTERN const char * ZEXPORT zlibVersion OF((void));
217/* The application can compare zlibVersion and ZLIB_VERSION for consistency. 217/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
218 If the first character differs, the library code actually used is not 218 If the first character differs, the library code actually used is not
219 compatible with the zlib.h header file used by the application. This check 219 compatible with the zlib.h header file used by the application. This check
220 is automatically made by deflateInit and inflateInit. 220 is automatically made by deflateInit and inflateInit.
221 */ 221 */
222 222
223/* 223/*
224ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); 224ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
225 225
226 Initializes the internal stream state for compression. The fields 226 Initializes the internal stream state for compression. The fields
227 zalloc, zfree and opaque must be initialized before by the caller. If 227 zalloc, zfree and opaque must be initialized before by the caller. If
228 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default 228 zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
229 allocation functions. 229 allocation functions.
230 230
231 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 231 The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
232 1 gives best speed, 9 gives best compression, 0 gives no compression at all 232 1 gives best speed, 9 gives best compression, 0 gives no compression at all
233 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION 233 (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
234 requests a default compromise between speed and compression (currently 234 requests a default compromise between speed and compression (currently
235 equivalent to level 6). 235 equivalent to level 6).
236 236
237 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 237 deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
238 memory, Z_STREAM_ERROR if level is not a valid compression level, or 238 memory, Z_STREAM_ERROR if level is not a valid compression level, or
239 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible 239 Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
240 with the version assumed by the caller (ZLIB_VERSION). msg is set to null 240 with the version assumed by the caller (ZLIB_VERSION). msg is set to null
241 if there is no error message. deflateInit does not perform any compression: 241 if there is no error message. deflateInit does not perform any compression:
242 this will be done by deflate(). 242 this will be done by deflate().
243*/ 243*/
244 244
245 245
246ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); 246ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
247/* 247/*
248 deflate compresses as much data as possible, and stops when the input 248 deflate compresses as much data as possible, and stops when the input
249 buffer becomes empty or the output buffer becomes full. It may introduce 249 buffer becomes empty or the output buffer becomes full. It may introduce
250 some output latency (reading input without producing any output) except when 250 some output latency (reading input without producing any output) except when
251 forced to flush. 251 forced to flush.
252 252
253 The detailed semantics are as follows. deflate performs one or both of the 253 The detailed semantics are as follows. deflate performs one or both of the
254 following actions: 254 following actions:
255 255
256 - Compress more input starting at next_in and update next_in and avail_in 256 - Compress more input starting at next_in and update next_in and avail_in
257 accordingly. If not all input can be processed (because there is not 257 accordingly. If not all input can be processed (because there is not
258 enough room in the output buffer), next_in and avail_in are updated and 258 enough room in the output buffer), next_in and avail_in are updated and
259 processing will resume at this point for the next call of deflate(). 259 processing will resume at this point for the next call of deflate().
260 260
261 - Provide more output starting at next_out and update next_out and avail_out 261 - Provide more output starting at next_out and update next_out and avail_out
262 accordingly. This action is forced if the parameter flush is non zero. 262 accordingly. This action is forced if the parameter flush is non zero.
263 Forcing flush frequently degrades the compression ratio, so this parameter 263 Forcing flush frequently degrades the compression ratio, so this parameter
264 should be set only when necessary (in interactive applications). Some 264 should be set only when necessary (in interactive applications). Some
265 output may be provided even if flush is not set. 265 output may be provided even if flush is not set.
266 266
267 Before the call of deflate(), the application should ensure that at least 267 Before the call of deflate(), the application should ensure that at least
268 one of the actions is possible, by providing more input and/or consuming more 268 one of the actions is possible, by providing more input and/or consuming more
269 output, and updating avail_in or avail_out accordingly; avail_out should 269 output, and updating avail_in or avail_out accordingly; avail_out should
270 never be zero before the call. The application can consume the compressed 270 never be zero before the call. The application can consume the compressed
271 output when it wants, for example when the output buffer is full (avail_out 271 output when it wants, for example when the output buffer is full (avail_out
272 == 0), or after each call of deflate(). If deflate returns Z_OK and with 272 == 0), or after each call of deflate(). If deflate returns Z_OK and with
273 zero avail_out, it must be called again after making room in the output 273 zero avail_out, it must be called again after making room in the output
274 buffer because there might be more output pending. 274 buffer because there might be more output pending.
275 275
276 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to 276 Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
277 decide how much data to accumulate before producing output, in order to 277 decide how much data to accumulate before producing output, in order to
278 maximize compression. 278 maximize compression.
279 279
280 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is 280 If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
281 flushed to the output buffer and the output is aligned on a byte boundary, so 281 flushed to the output buffer and the output is aligned on a byte boundary, so
282 that the decompressor can get all input data available so far. (In 282 that the decompressor can get all input data available so far. (In
283 particular avail_in is zero after the call if enough output space has been 283 particular avail_in is zero after the call if enough output space has been
284 provided before the call.) Flushing may degrade compression for some 284 provided before the call.) Flushing may degrade compression for some
285 compression algorithms and so it should be used only when necessary. This 285 compression algorithms and so it should be used only when necessary. This
286 completes the current deflate block and follows it with an empty stored block 286 completes the current deflate block and follows it with an empty stored block
287 that is three bits plus filler bits to the next byte, followed by four bytes 287 that is three bits plus filler bits to the next byte, followed by four bytes
288 (00 00 ff ff). 288 (00 00 ff ff).
289 289
290 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the 290 If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
291 output buffer, but the output is not aligned to a byte boundary. All of the 291 output buffer, but the output is not aligned to a byte boundary. All of the
292 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. 292 input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
293 This completes the current deflate block and follows it with an empty fixed 293 This completes the current deflate block and follows it with an empty fixed
294 codes block that is 10 bits long. This assures that enough bytes are output 294 codes block that is 10 bits long. This assures that enough bytes are output
295 in order for the decompressor to finish the block before the empty fixed code 295 in order for the decompressor to finish the block before the empty fixed code
296 block. 296 block.
297 297
298 If flush is set to Z_BLOCK, a deflate block is completed and emitted, as 298 If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
299 for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to 299 for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
300 seven bits of the current block are held to be written as the next byte after 300 seven bits of the current block are held to be written as the next byte after
301 the next deflate block is completed. In this case, the decompressor may not 301 the next deflate block is completed. In this case, the decompressor may not
302 be provided enough bits at this point in order to complete decompression of 302 be provided enough bits at this point in order to complete decompression of
303 the data provided so far to the compressor. It may need to wait for the next 303 the data provided so far to the compressor. It may need to wait for the next
304 block to be emitted. This is for advanced applications that need to control 304 block to be emitted. This is for advanced applications that need to control
305 the emission of deflate blocks. 305 the emission of deflate blocks.
306 306
307 If flush is set to Z_FULL_FLUSH, all output is flushed as with 307 If flush is set to Z_FULL_FLUSH, all output is flushed as with
308 Z_SYNC_FLUSH, and the compression state is reset so that decompression can 308 Z_SYNC_FLUSH, and the compression state is reset so that decompression can
309 restart from this point if previous compressed data has been damaged or if 309 restart from this point if previous compressed data has been damaged or if
310 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade 310 random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
311 compression. 311 compression.
312 312
313 If deflate returns with avail_out == 0, this function must be called again 313 If deflate returns with avail_out == 0, this function must be called again
314 with the same value of the flush parameter and more output space (updated 314 with the same value of the flush parameter and more output space (updated
315 avail_out), until the flush is complete (deflate returns with non-zero 315 avail_out), until the flush is complete (deflate returns with non-zero
316 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that 316 avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
317 avail_out is greater than six to avoid repeated flush markers due to 317 avail_out is greater than six to avoid repeated flush markers due to
318 avail_out == 0 on return. 318 avail_out == 0 on return.
319 319
320 If the parameter flush is set to Z_FINISH, pending input is processed, 320 If the parameter flush is set to Z_FINISH, pending input is processed,
321 pending output is flushed and deflate returns with Z_STREAM_END if there was 321 pending output is flushed and deflate returns with Z_STREAM_END if there was
322 enough output space; if deflate returns with Z_OK, this function must be 322 enough output space; if deflate returns with Z_OK, this function must be
323 called again with Z_FINISH and more output space (updated avail_out) but no 323 called again with Z_FINISH and more output space (updated avail_out) but no
324 more input data, until it returns with Z_STREAM_END or an error. After 324 more input data, until it returns with Z_STREAM_END or an error. After
325 deflate has returned Z_STREAM_END, the only possible operations on the stream 325 deflate has returned Z_STREAM_END, the only possible operations on the stream
326 are deflateReset or deflateEnd. 326 are deflateReset or deflateEnd.
327 327
328 Z_FINISH can be used immediately after deflateInit if all the compression 328 Z_FINISH can be used immediately after deflateInit if all the compression
329 is to be done in a single step. In this case, avail_out must be at least the 329 is to be done in a single step. In this case, avail_out must be at least the
330 value returned by deflateBound (see below). Then deflate is guaranteed to 330 value returned by deflateBound (see below). Then deflate is guaranteed to
331 return Z_STREAM_END. If not enough output space is provided, deflate will 331 return Z_STREAM_END. If not enough output space is provided, deflate will
332 not return Z_STREAM_END, and it must be called again as described above. 332 not return Z_STREAM_END, and it must be called again as described above.
333 333
334 deflate() sets strm->adler to the adler32 checksum of all input read 334 deflate() sets strm->adler to the adler32 checksum of all input read
335 so far (that is, total_in bytes). 335 so far (that is, total_in bytes).
336 336
337 deflate() may update strm->data_type if it can make a good guess about 337 deflate() may update strm->data_type if it can make a good guess about
338 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered 338 the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
339 binary. This field is only for information purposes and does not affect the 339 binary. This field is only for information purposes and does not affect the
340 compression algorithm in any manner. 340 compression algorithm in any manner.
341 341
342 deflate() returns Z_OK if some progress has been made (more input 342 deflate() returns Z_OK if some progress has been made (more input
343 processed or more output produced), Z_STREAM_END if all input has been 343 processed or more output produced), Z_STREAM_END if all input has been
344 consumed and all output has been produced (only when flush is set to 344 consumed and all output has been produced (only when flush is set to
345 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example 345 Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
346 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible 346 if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
347 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not 347 (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
348 fatal, and deflate() can be called again with more input and more output 348 fatal, and deflate() can be called again with more input and more output
349 space to continue compressing. 349 space to continue compressing.
350*/ 350*/
351 351
352 352
353ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); 353ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
354/* 354/*
355 All dynamically allocated data structures for this stream are freed. 355 All dynamically allocated data structures for this stream are freed.
356 This function discards any unprocessed input and does not flush any pending 356 This function discards any unprocessed input and does not flush any pending
357 output. 357 output.
358 358
359 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the 359 deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
360 stream state was inconsistent, Z_DATA_ERROR if the stream was freed 360 stream state was inconsistent, Z_DATA_ERROR if the stream was freed
361 prematurely (some input or output was discarded). In the error case, msg 361 prematurely (some input or output was discarded). In the error case, msg
362 may be set but then points to a static string (which must not be 362 may be set but then points to a static string (which must not be
363 deallocated). 363 deallocated).
364*/ 364*/
365 365
366 366
367/* 367/*
368ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); 368ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
369 369
370 Initializes the internal stream state for decompression. The fields 370 Initializes the internal stream state for decompression. The fields
371 next_in, avail_in, zalloc, zfree and opaque must be initialized before by 371 next_in, avail_in, zalloc, zfree and opaque must be initialized before by
372 the caller. If next_in is not Z_NULL and avail_in is large enough (the 372 the caller. If next_in is not Z_NULL and avail_in is large enough (the
373 exact value depends on the compression method), inflateInit determines the 373 exact value depends on the compression method), inflateInit determines the
374 compression method from the zlib header and allocates all data structures 374 compression method from the zlib header and allocates all data structures
375 accordingly; otherwise the allocation will be deferred to the first call of 375 accordingly; otherwise the allocation will be deferred to the first call of
376 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to 376 inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
377 use default allocation functions. 377 use default allocation functions.
378 378
379 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough 379 inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
380 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 380 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
381 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 381 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
382 invalid, such as a null pointer to the structure. msg is set to null if 382 invalid, such as a null pointer to the structure. msg is set to null if
383 there is no error message. inflateInit does not perform any decompression 383 there is no error message. inflateInit does not perform any decompression
384 apart from possibly reading the zlib header if present: actual decompression 384 apart from possibly reading the zlib header if present: actual decompression
385 will be done by inflate(). (So next_in and avail_in may be modified, but 385 will be done by inflate(). (So next_in and avail_in may be modified, but
386 next_out and avail_out are unused and unchanged.) The current implementation 386 next_out and avail_out are unused and unchanged.) The current implementation
387 of inflateInit() does not process any header information -- that is deferred 387 of inflateInit() does not process any header information -- that is deferred
388 until inflate() is called. 388 until inflate() is called.
389*/ 389*/
390 390
391 391
392ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); 392ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
393/* 393/*
394 inflate decompresses as much data as possible, and stops when the input 394 inflate decompresses as much data as possible, and stops when the input
395 buffer becomes empty or the output buffer becomes full. It may introduce 395 buffer becomes empty or the output buffer becomes full. It may introduce
396 some output latency (reading input without producing any output) except when 396 some output latency (reading input without producing any output) except when
397 forced to flush. 397 forced to flush.
398 398
399 The detailed semantics are as follows. inflate performs one or both of the 399 The detailed semantics are as follows. inflate performs one or both of the
400 following actions: 400 following actions:
401 401
402 - Decompress more input starting at next_in and update next_in and avail_in 402 - Decompress more input starting at next_in and update next_in and avail_in
403 accordingly. If not all input can be processed (because there is not 403 accordingly. If not all input can be processed (because there is not
404 enough room in the output buffer), next_in is updated and processing will 404 enough room in the output buffer), next_in is updated and processing will
405 resume at this point for the next call of inflate(). 405 resume at this point for the next call of inflate().
406 406
407 - Provide more output starting at next_out and update next_out and avail_out 407 - Provide more output starting at next_out and update next_out and avail_out
408 accordingly. inflate() provides as much output as possible, until there is 408 accordingly. inflate() provides as much output as possible, until there is
409 no more input data or no more space in the output buffer (see below about 409 no more input data or no more space in the output buffer (see below about
410 the flush parameter). 410 the flush parameter).
411 411
412 Before the call of inflate(), the application should ensure that at least 412 Before the call of inflate(), the application should ensure that at least
413 one of the actions is possible, by providing more input and/or consuming more 413 one of the actions is possible, by providing more input and/or consuming more
414 output, and updating the next_* and avail_* values accordingly. The 414 output, and updating the next_* and avail_* values accordingly. The
415 application can consume the uncompressed output when it wants, for example 415 application can consume the uncompressed output when it wants, for example
416 when the output buffer is full (avail_out == 0), or after each call of 416 when the output buffer is full (avail_out == 0), or after each call of
417 inflate(). If inflate returns Z_OK and with zero avail_out, it must be 417 inflate(). If inflate returns Z_OK and with zero avail_out, it must be
418 called again after making room in the output buffer because there might be 418 called again after making room in the output buffer because there might be
419 more output pending. 419 more output pending.
420 420
421 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, 421 The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
422 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much 422 Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
423 output as possible to the output buffer. Z_BLOCK requests that inflate() 423 output as possible to the output buffer. Z_BLOCK requests that inflate()
424 stop if and when it gets to the next deflate block boundary. When decoding 424 stop if and when it gets to the next deflate block boundary. When decoding
425 the zlib or gzip format, this will cause inflate() to return immediately 425 the zlib or gzip format, this will cause inflate() to return immediately
426 after the header and before the first block. When doing a raw inflate, 426 after the header and before the first block. When doing a raw inflate,
427 inflate() will go ahead and process the first block, and will return when it 427 inflate() will go ahead and process the first block, and will return when it
428 gets to the end of that block, or when it runs out of data. 428 gets to the end of that block, or when it runs out of data.
429 429
430 The Z_BLOCK option assists in appending to or combining deflate streams. 430 The Z_BLOCK option assists in appending to or combining deflate streams.
431 Also to assist in this, on return inflate() will set strm->data_type to the 431 Also to assist in this, on return inflate() will set strm->data_type to the
432 number of unused bits in the last byte taken from strm->next_in, plus 64 if 432 number of unused bits in the last byte taken from strm->next_in, plus 64 if
433 inflate() is currently decoding the last block in the deflate stream, plus 433 inflate() is currently decoding the last block in the deflate stream, plus
434 128 if inflate() returned immediately after decoding an end-of-block code or 434 128 if inflate() returned immediately after decoding an end-of-block code or
435 decoding the complete header up to just before the first byte of the deflate 435 decoding the complete header up to just before the first byte of the deflate
436 stream. The end-of-block will not be indicated until all of the uncompressed 436 stream. The end-of-block will not be indicated until all of the uncompressed
437 data from that block has been written to strm->next_out. The number of 437 data from that block has been written to strm->next_out. The number of
438 unused bits may in general be greater than seven, except when bit 7 of 438 unused bits may in general be greater than seven, except when bit 7 of
439 data_type is set, in which case the number of unused bits will be less than 439 data_type is set, in which case the number of unused bits will be less than
440 eight. data_type is set as noted here every time inflate() returns for all 440 eight. data_type is set as noted here every time inflate() returns for all
441 flush options, and so can be used to determine the amount of currently 441 flush options, and so can be used to determine the amount of currently
442 consumed input in bits. 442 consumed input in bits.
443 443
444 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the 444 The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
445 end of each deflate block header is reached, before any actual data in that 445 end of each deflate block header is reached, before any actual data in that
446 block is decoded. This allows the caller to determine the length of the 446 block is decoded. This allows the caller to determine the length of the
447 deflate block header for later use in random access within a deflate block. 447 deflate block header for later use in random access within a deflate block.
448 256 is added to the value of strm->data_type when inflate() returns 448 256 is added to the value of strm->data_type when inflate() returns
449 immediately after reaching the end of the deflate block header. 449 immediately after reaching the end of the deflate block header.
450 450
451 inflate() should normally be called until it returns Z_STREAM_END or an 451 inflate() should normally be called until it returns Z_STREAM_END or an
452 error. However if all decompression is to be performed in a single step (a 452 error. However if all decompression is to be performed in a single step (a
453 single call of inflate), the parameter flush should be set to Z_FINISH. In 453 single call of inflate), the parameter flush should be set to Z_FINISH. In
454 this case all pending input is processed and all pending output is flushed; 454 this case all pending input is processed and all pending output is flushed;
455 avail_out must be large enough to hold all of the uncompressed data for the 455 avail_out must be large enough to hold all of the uncompressed data for the
456 operation to complete. (The size of the uncompressed data may have been 456 operation to complete. (The size of the uncompressed data may have been
457 saved by the compressor for this purpose.) The use of Z_FINISH is not 457 saved by the compressor for this purpose.) The use of Z_FINISH is not
458 required to perform an inflation in one step. However it may be used to 458 required to perform an inflation in one step. However it may be used to
459 inform inflate that a faster approach can be used for the single inflate() 459 inform inflate that a faster approach can be used for the single inflate()
460 call. Z_FINISH also informs inflate to not maintain a sliding window if the 460 call. Z_FINISH also informs inflate to not maintain a sliding window if the
461 stream completes, which reduces inflate's memory footprint. If the stream 461 stream completes, which reduces inflate's memory footprint. If the stream
462 does not complete, either because not all of the stream is provided or not 462 does not complete, either because not all of the stream is provided or not
463 enough output space is provided, then a sliding window will be allocated and 463 enough output space is provided, then a sliding window will be allocated and
464 inflate() can be called again to continue the operation as if Z_NO_FLUSH had 464 inflate() can be called again to continue the operation as if Z_NO_FLUSH had
465 been used. 465 been used.
466 466
467 In this implementation, inflate() always flushes as much output as 467 In this implementation, inflate() always flushes as much output as
468 possible to the output buffer, and always uses the faster approach on the 468 possible to the output buffer, and always uses the faster approach on the
469 first call. So the effects of the flush parameter in this implementation are 469 first call. So the effects of the flush parameter in this implementation are
470 on the return value of inflate() as noted below, when inflate() returns early 470 on the return value of inflate() as noted below, when inflate() returns early
471 when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of 471 when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
472 memory for a sliding window when Z_FINISH is used. 472 memory for a sliding window when Z_FINISH is used.
473 473
474 If a preset dictionary is needed after this call (see inflateSetDictionary 474 If a preset dictionary is needed after this call (see inflateSetDictionary
475 below), inflate sets strm->adler to the Adler-32 checksum of the dictionary 475 below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
476 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets 476 chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
477 strm->adler to the Adler-32 checksum of all output produced so far (that is, 477 strm->adler to the Adler-32 checksum of all output produced so far (that is,
478 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described 478 total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
479 below. At the end of the stream, inflate() checks that its computed adler32 479 below. At the end of the stream, inflate() checks that its computed adler32
480 checksum is equal to that saved by the compressor and returns Z_STREAM_END 480 checksum is equal to that saved by the compressor and returns Z_STREAM_END
481 only if the checksum is correct. 481 only if the checksum is correct.
482 482
483 inflate() can decompress and check either zlib-wrapped or gzip-wrapped 483 inflate() can decompress and check either zlib-wrapped or gzip-wrapped
484 deflate data. The header type is detected automatically, if requested when 484 deflate data. The header type is detected automatically, if requested when
485 initializing with inflateInit2(). Any information contained in the gzip 485 initializing with inflateInit2(). Any information contained in the gzip
486 header is not retained, so applications that need that information should 486 header is not retained, so applications that need that information should
487 instead use raw inflate, see inflateInit2() below, or inflateBack() and 487 instead use raw inflate, see inflateInit2() below, or inflateBack() and
488 perform their own processing of the gzip header and trailer. When processing 488 perform their own processing of the gzip header and trailer. When processing
489 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output 489 gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
490 producted so far. The CRC-32 is checked against the gzip trailer. 490 producted so far. The CRC-32 is checked against the gzip trailer.
491 491
492 inflate() returns Z_OK if some progress has been made (more input processed 492 inflate() returns Z_OK if some progress has been made (more input processed
493 or more output produced), Z_STREAM_END if the end of the compressed data has 493 or more output produced), Z_STREAM_END if the end of the compressed data has
494 been reached and all uncompressed output has been produced, Z_NEED_DICT if a 494 been reached and all uncompressed output has been produced, Z_NEED_DICT if a
495 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was 495 preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
496 corrupted (input stream not conforming to the zlib format or incorrect check 496 corrupted (input stream not conforming to the zlib format or incorrect check
497 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example 497 value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
498 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, 498 next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
499 Z_BUF_ERROR if no progress is possible or if there was not enough room in the 499 Z_BUF_ERROR if no progress is possible or if there was not enough room in the
500 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and 500 output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
501 inflate() can be called again with more input and more output space to 501 inflate() can be called again with more input and more output space to
502 continue decompressing. If Z_DATA_ERROR is returned, the application may 502 continue decompressing. If Z_DATA_ERROR is returned, the application may
503 then call inflateSync() to look for a good compression block if a partial 503 then call inflateSync() to look for a good compression block if a partial
504 recovery of the data is desired. 504 recovery of the data is desired.
505*/ 505*/
506 506
507 507
508ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); 508ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
509/* 509/*
510 All dynamically allocated data structures for this stream are freed. 510 All dynamically allocated data structures for this stream are freed.
511 This function discards any unprocessed input and does not flush any pending 511 This function discards any unprocessed input and does not flush any pending
512 output. 512 output.
513 513
514 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state 514 inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
515 was inconsistent. In the error case, msg may be set but then points to a 515 was inconsistent. In the error case, msg may be set but then points to a
516 static string (which must not be deallocated). 516 static string (which must not be deallocated).
517*/ 517*/
518 518
519 519
520 /* Advanced functions */ 520 /* Advanced functions */
521 521
522/* 522/*
523 The following functions are needed only in some special applications. 523 The following functions are needed only in some special applications.
524*/ 524*/
525 525
526/* 526/*
527ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, 527ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
528 int level, 528 int level,
529 int method, 529 int method,
530 int windowBits, 530 int windowBits,
531 int memLevel, 531 int memLevel,
532 int strategy)); 532 int strategy));
533 533
534 This is another version of deflateInit with more compression options. The 534 This is another version of deflateInit with more compression options. The
535 fields next_in, zalloc, zfree and opaque must be initialized before by the 535 fields next_in, zalloc, zfree and opaque must be initialized before by the
536 caller. 536 caller.
537 537
538 The method parameter is the compression method. It must be Z_DEFLATED in 538 The method parameter is the compression method. It must be Z_DEFLATED in
539 this version of the library. 539 this version of the library.
540 540
541 The windowBits parameter is the base two logarithm of the window size 541 The windowBits parameter is the base two logarithm of the window size
542 (the size of the history buffer). It should be in the range 8..15 for this 542 (the size of the history buffer). It should be in the range 8..15 for this
543 version of the library. Larger values of this parameter result in better 543 version of the library. Larger values of this parameter result in better
544 compression at the expense of memory usage. The default value is 15 if 544 compression at the expense of memory usage. The default value is 15 if
545 deflateInit is used instead. 545 deflateInit is used instead.
546 546
547 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits 547 windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
548 determines the window size. deflate() will then generate raw deflate data 548 determines the window size. deflate() will then generate raw deflate data
549 with no zlib header or trailer, and will not compute an adler32 check value. 549 with no zlib header or trailer, and will not compute an adler32 check value.
550 550
551 windowBits can also be greater than 15 for optional gzip encoding. Add 551 windowBits can also be greater than 15 for optional gzip encoding. Add
552 16 to windowBits to write a simple gzip header and trailer around the 552 16 to windowBits to write a simple gzip header and trailer around the
553 compressed data instead of a zlib wrapper. The gzip header will have no 553 compressed data instead of a zlib wrapper. The gzip header will have no
554 file name, no extra data, no comment, no modification time (set to zero), no 554 file name, no extra data, no comment, no modification time (set to zero), no
555 header crc, and the operating system will be set to 255 (unknown). If a 555 header crc, and the operating system will be set to 255 (unknown). If a
556 gzip stream is being written, strm->adler is a crc32 instead of an adler32. 556 gzip stream is being written, strm->adler is a crc32 instead of an adler32.
557 557
558 The memLevel parameter specifies how much memory should be allocated 558 The memLevel parameter specifies how much memory should be allocated
559 for the internal compression state. memLevel=1 uses minimum memory but is 559 for the internal compression state. memLevel=1 uses minimum memory but is
560 slow and reduces compression ratio; memLevel=9 uses maximum memory for 560 slow and reduces compression ratio; memLevel=9 uses maximum memory for
561 optimal speed. The default value is 8. See zconf.h for total memory usage 561 optimal speed. The default value is 8. See zconf.h for total memory usage
562 as a function of windowBits and memLevel. 562 as a function of windowBits and memLevel.
563 563
564 The strategy parameter is used to tune the compression algorithm. Use the 564 The strategy parameter is used to tune the compression algorithm. Use the
565 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a 565 value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
566 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no 566 filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
567 string match), or Z_RLE to limit match distances to one (run-length 567 string match), or Z_RLE to limit match distances to one (run-length
568 encoding). Filtered data consists mostly of small values with a somewhat 568 encoding). Filtered data consists mostly of small values with a somewhat
569 random distribution. In this case, the compression algorithm is tuned to 569 random distribution. In this case, the compression algorithm is tuned to
570 compress them better. The effect of Z_FILTERED is to force more Huffman 570 compress them better. The effect of Z_FILTERED is to force more Huffman
571 coding and less string matching; it is somewhat intermediate between 571 coding and less string matching; it is somewhat intermediate between
572 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as 572 Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
573 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The 573 fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
574 strategy parameter only affects the compression ratio but not the 574 strategy parameter only affects the compression ratio but not the
575 correctness of the compressed output even if it is not set appropriately. 575 correctness of the compressed output even if it is not set appropriately.
576 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler 576 Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
577 decoder for special applications. 577 decoder for special applications.
578 578
579 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 579 deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
580 memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid 580 memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
581 method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is 581 method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
582 incompatible with the version assumed by the caller (ZLIB_VERSION). msg is 582 incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
583 set to null if there is no error message. deflateInit2 does not perform any 583 set to null if there is no error message. deflateInit2 does not perform any
584 compression: this will be done by deflate(). 584 compression: this will be done by deflate().
585*/ 585*/
586 586
587ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, 587ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
588 const Bytef *dictionary, 588 const Bytef *dictionary,
589 uInt dictLength)); 589 uInt dictLength));
590/* 590/*
591 Initializes the compression dictionary from the given byte sequence 591 Initializes the compression dictionary from the given byte sequence
592 without producing any compressed output. When using the zlib format, this 592 without producing any compressed output. When using the zlib format, this
593 function must be called immediately after deflateInit, deflateInit2 or 593 function must be called immediately after deflateInit, deflateInit2 or
594 deflateReset, and before any call of deflate. When doing raw deflate, this 594 deflateReset, and before any call of deflate. When doing raw deflate, this
595 function must be called either before any call of deflate, or immediately 595 function must be called either before any call of deflate, or immediately
596 after the completion of a deflate block, i.e. after all input has been 596 after the completion of a deflate block, i.e. after all input has been
597 consumed and all output has been delivered when using any of the flush 597 consumed and all output has been delivered when using any of the flush
598 options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The 598 options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
599 compressor and decompressor must use exactly the same dictionary (see 599 compressor and decompressor must use exactly the same dictionary (see
600 inflateSetDictionary). 600 inflateSetDictionary).
601 601
602 The dictionary should consist of strings (byte sequences) that are likely 602 The dictionary should consist of strings (byte sequences) that are likely
603 to be encountered later in the data to be compressed, with the most commonly 603 to be encountered later in the data to be compressed, with the most commonly
604 used strings preferably put towards the end of the dictionary. Using a 604 used strings preferably put towards the end of the dictionary. Using a
605 dictionary is most useful when the data to be compressed is short and can be 605 dictionary is most useful when the data to be compressed is short and can be
606 predicted with good accuracy; the data can then be compressed better than 606 predicted with good accuracy; the data can then be compressed better than
607 with the default empty dictionary. 607 with the default empty dictionary.
608 608
609 Depending on the size of the compression data structures selected by 609 Depending on the size of the compression data structures selected by
610 deflateInit or deflateInit2, a part of the dictionary may in effect be 610 deflateInit or deflateInit2, a part of the dictionary may in effect be
611 discarded, for example if the dictionary is larger than the window size 611 discarded, for example if the dictionary is larger than the window size
612 provided in deflateInit or deflateInit2. Thus the strings most likely to be 612 provided in deflateInit or deflateInit2. Thus the strings most likely to be
613 useful should be put at the end of the dictionary, not at the front. In 613 useful should be put at the end of the dictionary, not at the front. In
614 addition, the current implementation of deflate will use at most the window 614 addition, the current implementation of deflate will use at most the window
615 size minus 262 bytes of the provided dictionary. 615 size minus 262 bytes of the provided dictionary.
616 616
617 Upon return of this function, strm->adler is set to the adler32 value 617 Upon return of this function, strm->adler is set to the adler32 value
618 of the dictionary; the decompressor may later use this value to determine 618 of the dictionary; the decompressor may later use this value to determine
619 which dictionary has been used by the compressor. (The adler32 value 619 which dictionary has been used by the compressor. (The adler32 value
620 applies to the whole dictionary even if only a subset of the dictionary is 620 applies to the whole dictionary even if only a subset of the dictionary is
621 actually used by the compressor.) If a raw deflate was requested, then the 621 actually used by the compressor.) If a raw deflate was requested, then the
622 adler32 value is not computed and strm->adler is not set. 622 adler32 value is not computed and strm->adler is not set.
623 623
624 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a 624 deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
625 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 625 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
626 inconsistent (for example if deflate has already been called for this stream 626 inconsistent (for example if deflate has already been called for this stream
627 or if not at a block boundary for raw deflate). deflateSetDictionary does 627 or if not at a block boundary for raw deflate). deflateSetDictionary does
628 not perform any compression: this will be done by deflate(). 628 not perform any compression: this will be done by deflate().
629*/ 629*/
630 630
631ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, 631ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
632 z_streamp source)); 632 z_streamp source));
633/* 633/*
634 Sets the destination stream as a complete copy of the source stream. 634 Sets the destination stream as a complete copy of the source stream.
635 635
636 This function can be useful when several compression strategies will be 636 This function can be useful when several compression strategies will be
637 tried, for example when there are several ways of pre-processing the input 637 tried, for example when there are several ways of pre-processing the input
638 data with a filter. The streams that will be discarded should then be freed 638 data with a filter. The streams that will be discarded should then be freed
639 by calling deflateEnd. Note that deflateCopy duplicates the internal 639 by calling deflateEnd. Note that deflateCopy duplicates the internal
640 compression state which can be quite large, so this strategy is slow and can 640 compression state which can be quite large, so this strategy is slow and can
641 consume lots of memory. 641 consume lots of memory.
642 642
643 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 643 deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
644 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 644 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
645 (such as zalloc being Z_NULL). msg is left unchanged in both source and 645 (such as zalloc being Z_NULL). msg is left unchanged in both source and
646 destination. 646 destination.
647*/ 647*/
648 648
649ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); 649ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
650/* 650/*
651 This function is equivalent to deflateEnd followed by deflateInit, 651 This function is equivalent to deflateEnd followed by deflateInit,
652 but does not free and reallocate all the internal compression state. The 652 but does not free and reallocate all the internal compression state. The
653 stream will keep the same compression level and any other attributes that 653 stream will keep the same compression level and any other attributes that
654 may have been set by deflateInit2. 654 may have been set by deflateInit2.
655 655
656 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 656 deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
657 stream state was inconsistent (such as zalloc or state being Z_NULL). 657 stream state was inconsistent (such as zalloc or state being Z_NULL).
658*/ 658*/
659 659
660ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, 660ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
661 int level, 661 int level,
662 int strategy)); 662 int strategy));
663/* 663/*
664 Dynamically update the compression level and compression strategy. The 664 Dynamically update the compression level and compression strategy. The
665 interpretation of level and strategy is as in deflateInit2. This can be 665 interpretation of level and strategy is as in deflateInit2. This can be
666 used to switch between compression and straight copy of the input data, or 666 used to switch between compression and straight copy of the input data, or
667 to switch to a different kind of input data requiring a different strategy. 667 to switch to a different kind of input data requiring a different strategy.
668 If the compression level is changed, the input available so far is 668 If the compression level is changed, the input available so far is
669 compressed with the old level (and may be flushed); the new level will take 669 compressed with the old level (and may be flushed); the new level will take
670 effect only at the next call of deflate(). 670 effect only at the next call of deflate().
671 671
672 Before the call of deflateParams, the stream state must be set as for 672 Before the call of deflateParams, the stream state must be set as for
673 a call of deflate(), since the currently available input may have to be 673 a call of deflate(), since the currently available input may have to be
674 compressed and flushed. In particular, strm->avail_out must be non-zero. 674 compressed and flushed. In particular, strm->avail_out must be non-zero.
675 675
676 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source 676 deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
677 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if 677 stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
678 strm->avail_out was zero. 678 strm->avail_out was zero.
679*/ 679*/
680 680
681ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, 681ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
682 int good_length, 682 int good_length,
683 int max_lazy, 683 int max_lazy,
684 int nice_length, 684 int nice_length,
685 int max_chain)); 685 int max_chain));
686/* 686/*
687 Fine tune deflate's internal compression parameters. This should only be 687 Fine tune deflate's internal compression parameters. This should only be
688 used by someone who understands the algorithm used by zlib's deflate for 688 used by someone who understands the algorithm used by zlib's deflate for
689 searching for the best matching string, and even then only by the most 689 searching for the best matching string, and even then only by the most
690 fanatic optimizer trying to squeeze out the last compressed bit for their 690 fanatic optimizer trying to squeeze out the last compressed bit for their
691 specific input data. Read the deflate.c source code for the meaning of the 691 specific input data. Read the deflate.c source code for the meaning of the
692 max_lazy, good_length, nice_length, and max_chain parameters. 692 max_lazy, good_length, nice_length, and max_chain parameters.
693 693
694 deflateTune() can be called after deflateInit() or deflateInit2(), and 694 deflateTune() can be called after deflateInit() or deflateInit2(), and
695 returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. 695 returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
696 */ 696 */
697 697
698ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, 698ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
699 uLong sourceLen)); 699 uLong sourceLen));
700/* 700/*
701 deflateBound() returns an upper bound on the compressed size after 701 deflateBound() returns an upper bound on the compressed size after
702 deflation of sourceLen bytes. It must be called after deflateInit() or 702 deflation of sourceLen bytes. It must be called after deflateInit() or
703 deflateInit2(), and after deflateSetHeader(), if used. This would be used 703 deflateInit2(), and after deflateSetHeader(), if used. This would be used
704 to allocate an output buffer for deflation in a single pass, and so would be 704 to allocate an output buffer for deflation in a single pass, and so would be
705 called before deflate(). If that first deflate() call is provided the 705 called before deflate(). If that first deflate() call is provided the
706 sourceLen input bytes, an output buffer allocated to the size returned by 706 sourceLen input bytes, an output buffer allocated to the size returned by
707 deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed 707 deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
708 to return Z_STREAM_END. Note that it is possible for the compressed size to 708 to return Z_STREAM_END. Note that it is possible for the compressed size to
709 be larger than the value returned by deflateBound() if flush options other 709 be larger than the value returned by deflateBound() if flush options other
710 than Z_FINISH or Z_NO_FLUSH are used. 710 than Z_FINISH or Z_NO_FLUSH are used.
711*/ 711*/
712 712
713ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, 713ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
714 unsigned *pending, 714 unsigned *pending,
715 int *bits)); 715 int *bits));
716/* 716/*
717 deflatePending() returns the number of bytes and bits of output that have 717 deflatePending() returns the number of bytes and bits of output that have
718 been generated, but not yet provided in the available output. The bytes not 718 been generated, but not yet provided in the available output. The bytes not
719 provided would be due to the available output space having being consumed. 719 provided would be due to the available output space having being consumed.
720 The number of bits of output not provided are between 0 and 7, where they 720 The number of bits of output not provided are between 0 and 7, where they
721 await more bits to join them in order to fill out a full byte. If pending 721 await more bits to join them in order to fill out a full byte. If pending
722 or bits are Z_NULL, then those values are not set. 722 or bits are Z_NULL, then those values are not set.
723 723
724 deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source 724 deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
725 stream state was inconsistent. 725 stream state was inconsistent.
726 */ 726 */
727 727
728ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, 728ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
729 int bits, 729 int bits,
730 int value)); 730 int value));
731/* 731/*
732 deflatePrime() inserts bits in the deflate output stream. The intent 732 deflatePrime() inserts bits in the deflate output stream. The intent
733 is that this function is used to start off the deflate output with the bits 733 is that this function is used to start off the deflate output with the bits
734 leftover from a previous deflate stream when appending to it. As such, this 734 leftover from a previous deflate stream when appending to it. As such, this
735 function can only be used for raw deflate, and must be used before the first 735 function can only be used for raw deflate, and must be used before the first
736 deflate() call after a deflateInit2() or deflateReset(). bits must be less 736 deflate() call after a deflateInit2() or deflateReset(). bits must be less
737 than or equal to 16, and that many of the least significant bits of value 737 than or equal to 16, and that many of the least significant bits of value
738 will be inserted in the output. 738 will be inserted in the output.
739 739
740 deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough 740 deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
741 room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the 741 room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
742 source stream state was inconsistent. 742 source stream state was inconsistent.
743*/ 743*/
744 744
745ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, 745ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
746 gz_headerp head)); 746 gz_headerp head));
747/* 747/*
748 deflateSetHeader() provides gzip header information for when a gzip 748 deflateSetHeader() provides gzip header information for when a gzip
749 stream is requested by deflateInit2(). deflateSetHeader() may be called 749 stream is requested by deflateInit2(). deflateSetHeader() may be called
750 after deflateInit2() or deflateReset() and before the first call of 750 after deflateInit2() or deflateReset() and before the first call of
751 deflate(). The text, time, os, extra field, name, and comment information 751 deflate(). The text, time, os, extra field, name, and comment information
752 in the provided gz_header structure are written to the gzip header (xflag is 752 in the provided gz_header structure are written to the gzip header (xflag is
753 ignored -- the extra flags are set according to the compression level). The 753 ignored -- the extra flags are set according to the compression level). The
754 caller must assure that, if not Z_NULL, name and comment are terminated with 754 caller must assure that, if not Z_NULL, name and comment are terminated with
755 a zero byte, and that if extra is not Z_NULL, that extra_len bytes are 755 a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
756 available there. If hcrc is true, a gzip header crc is included. Note that 756 available there. If hcrc is true, a gzip header crc is included. Note that
757 the current versions of the command-line version of gzip (up through version 757 the current versions of the command-line version of gzip (up through version
758 1.3.x) do not support header crc's, and will report that it is a "multi-part 758 1.3.x) do not support header crc's, and will report that it is a "multi-part
759 gzip file" and give up. 759 gzip file" and give up.
760 760
761 If deflateSetHeader is not used, the default gzip header has text false, 761 If deflateSetHeader is not used, the default gzip header has text false,
762 the time set to zero, and os set to 255, with no extra, name, or comment 762 the time set to zero, and os set to 255, with no extra, name, or comment
763 fields. The gzip header is returned to the default state by deflateReset(). 763 fields. The gzip header is returned to the default state by deflateReset().
764 764
765 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 765 deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
766 stream state was inconsistent. 766 stream state was inconsistent.
767*/ 767*/
768 768
769/* 769/*
770ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, 770ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
771 int windowBits)); 771 int windowBits));
772 772
773 This is another version of inflateInit with an extra parameter. The 773 This is another version of inflateInit with an extra parameter. The
774 fields next_in, avail_in, zalloc, zfree and opaque must be initialized 774 fields next_in, avail_in, zalloc, zfree and opaque must be initialized
775 before by the caller. 775 before by the caller.
776 776
777 The windowBits parameter is the base two logarithm of the maximum window 777 The windowBits parameter is the base two logarithm of the maximum window
778 size (the size of the history buffer). It should be in the range 8..15 for 778 size (the size of the history buffer). It should be in the range 8..15 for
779 this version of the library. The default value is 15 if inflateInit is used 779 this version of the library. The default value is 15 if inflateInit is used
780 instead. windowBits must be greater than or equal to the windowBits value 780 instead. windowBits must be greater than or equal to the windowBits value
781 provided to deflateInit2() while compressing, or it must be equal to 15 if 781 provided to deflateInit2() while compressing, or it must be equal to 15 if
782 deflateInit2() was not used. If a compressed stream with a larger window 782 deflateInit2() was not used. If a compressed stream with a larger window
783 size is given as input, inflate() will return with the error code 783 size is given as input, inflate() will return with the error code
784 Z_DATA_ERROR instead of trying to allocate a larger window. 784 Z_DATA_ERROR instead of trying to allocate a larger window.
785 785
786 windowBits can also be zero to request that inflate use the window size in 786 windowBits can also be zero to request that inflate use the window size in
787 the zlib header of the compressed stream. 787 the zlib header of the compressed stream.
788 788
789 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits 789 windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
790 determines the window size. inflate() will then process raw deflate data, 790 determines the window size. inflate() will then process raw deflate data,
791 not looking for a zlib or gzip header, not generating a check value, and not 791 not looking for a zlib or gzip header, not generating a check value, and not
792 looking for any check values for comparison at the end of the stream. This 792 looking for any check values for comparison at the end of the stream. This
793 is for use with other formats that use the deflate compressed data format 793 is for use with other formats that use the deflate compressed data format
794 such as zip. Those formats provide their own check values. If a custom 794 such as zip. Those formats provide their own check values. If a custom
795 format is developed using the raw deflate format for compressed data, it is 795 format is developed using the raw deflate format for compressed data, it is
796 recommended that a check value such as an adler32 or a crc32 be applied to 796 recommended that a check value such as an adler32 or a crc32 be applied to
797 the uncompressed data as is done in the zlib, gzip, and zip formats. For 797 the uncompressed data as is done in the zlib, gzip, and zip formats. For
798 most applications, the zlib format should be used as is. Note that comments 798 most applications, the zlib format should be used as is. Note that comments
799 above on the use in deflateInit2() applies to the magnitude of windowBits. 799 above on the use in deflateInit2() applies to the magnitude of windowBits.
800 800
801 windowBits can also be greater than 15 for optional gzip decoding. Add 801 windowBits can also be greater than 15 for optional gzip decoding. Add
802 32 to windowBits to enable zlib and gzip decoding with automatic header 802 32 to windowBits to enable zlib and gzip decoding with automatic header
803 detection, or add 16 to decode only the gzip format (the zlib format will 803 detection, or add 16 to decode only the gzip format (the zlib format will
804 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a 804 return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
805 crc32 instead of an adler32. 805 crc32 instead of an adler32.
806 806
807 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 807 inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
808 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the 808 memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
809 version assumed by the caller, or Z_STREAM_ERROR if the parameters are 809 version assumed by the caller, or Z_STREAM_ERROR if the parameters are
810 invalid, such as a null pointer to the structure. msg is set to null if 810 invalid, such as a null pointer to the structure. msg is set to null if
811 there is no error message. inflateInit2 does not perform any decompression 811 there is no error message. inflateInit2 does not perform any decompression
812 apart from possibly reading the zlib header if present: actual decompression 812 apart from possibly reading the zlib header if present: actual decompression
813 will be done by inflate(). (So next_in and avail_in may be modified, but 813 will be done by inflate(). (So next_in and avail_in may be modified, but
814 next_out and avail_out are unused and unchanged.) The current implementation 814 next_out and avail_out are unused and unchanged.) The current implementation
815 of inflateInit2() does not process any header information -- that is 815 of inflateInit2() does not process any header information -- that is
816 deferred until inflate() is called. 816 deferred until inflate() is called.
817*/ 817*/
818 818
819ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, 819ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
820 const Bytef *dictionary, 820 const Bytef *dictionary,
821 uInt dictLength)); 821 uInt dictLength));
822/* 822/*
823 Initializes the decompression dictionary from the given uncompressed byte 823 Initializes the decompression dictionary from the given uncompressed byte
824 sequence. This function must be called immediately after a call of inflate, 824 sequence. This function must be called immediately after a call of inflate,
825 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor 825 if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
826 can be determined from the adler32 value returned by that call of inflate. 826 can be determined from the adler32 value returned by that call of inflate.
827 The compressor and decompressor must use exactly the same dictionary (see 827 The compressor and decompressor must use exactly the same dictionary (see
828 deflateSetDictionary). For raw inflate, this function can be called at any 828 deflateSetDictionary). For raw inflate, this function can be called at any
829 time to set the dictionary. If the provided dictionary is smaller than the 829 time to set the dictionary. If the provided dictionary is smaller than the
830 window and there is already data in the window, then the provided dictionary 830 window and there is already data in the window, then the provided dictionary
831 will amend what's there. The application must insure that the dictionary 831 will amend what's there. The application must insure that the dictionary
832 that was used for compression is provided. 832 that was used for compression is provided.
833 833
834 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a 834 inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
835 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is 835 parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
836 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the 836 inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
837 expected one (incorrect adler32 value). inflateSetDictionary does not 837 expected one (incorrect adler32 value). inflateSetDictionary does not
838 perform any decompression: this will be done by subsequent calls of 838 perform any decompression: this will be done by subsequent calls of
839 inflate(). 839 inflate().
840*/ 840*/
841 841
842ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); 842ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
843/* 843/*
844 Skips invalid compressed data until a possible full flush point (see above 844 Skips invalid compressed data until a possible full flush point (see above
845 for the description of deflate with Z_FULL_FLUSH) can be found, or until all 845 for the description of deflate with Z_FULL_FLUSH) can be found, or until all
846 available input is skipped. No output is provided. 846 available input is skipped. No output is provided.
847 847
848 inflateSync searches for a 00 00 FF FF pattern in the compressed data. 848 inflateSync searches for a 00 00 FF FF pattern in the compressed data.
849 All full flush points have this pattern, but not all occurences of this 849 All full flush points have this pattern, but not all occurences of this
850 pattern are full flush points. 850 pattern are full flush points.
851 851
852 inflateSync returns Z_OK if a possible full flush point has been found, 852 inflateSync returns Z_OK if a possible full flush point has been found,
853 Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point 853 Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
854 has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. 854 has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
855 In the success case, the application may save the current current value of 855 In the success case, the application may save the current current value of
856 total_in which indicates where valid compressed data was found. In the 856 total_in which indicates where valid compressed data was found. In the
857 error case, the application may repeatedly call inflateSync, providing more 857 error case, the application may repeatedly call inflateSync, providing more
858 input each time, until success or end of the input data. 858 input each time, until success or end of the input data.
859*/ 859*/
860 860
861ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, 861ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
862 z_streamp source)); 862 z_streamp source));
863/* 863/*
864 Sets the destination stream as a complete copy of the source stream. 864 Sets the destination stream as a complete copy of the source stream.
865 865
866 This function can be useful when randomly accessing a large stream. The 866 This function can be useful when randomly accessing a large stream. The
867 first pass through the stream can periodically record the inflate state, 867 first pass through the stream can periodically record the inflate state,
868 allowing restarting inflate at those points when randomly accessing the 868 allowing restarting inflate at those points when randomly accessing the
869 stream. 869 stream.
870 870
871 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not 871 inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
872 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent 872 enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
873 (such as zalloc being Z_NULL). msg is left unchanged in both source and 873 (such as zalloc being Z_NULL). msg is left unchanged in both source and
874 destination. 874 destination.
875*/ 875*/
876 876
877ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); 877ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
878/* 878/*
879 This function is equivalent to inflateEnd followed by inflateInit, 879 This function is equivalent to inflateEnd followed by inflateInit,
880 but does not free and reallocate all the internal decompression state. The 880 but does not free and reallocate all the internal decompression state. The
881 stream will keep attributes that may have been set by inflateInit2. 881 stream will keep attributes that may have been set by inflateInit2.
882 882
883 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source 883 inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
884 stream state was inconsistent (such as zalloc or state being Z_NULL). 884 stream state was inconsistent (such as zalloc or state being Z_NULL).
885*/ 885*/
886 886
887ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, 887ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
888 int windowBits)); 888 int windowBits));
889/* 889/*
890 This function is the same as inflateReset, but it also permits changing 890 This function is the same as inflateReset, but it also permits changing
891 the wrap and window size requests. The windowBits parameter is interpreted 891 the wrap and window size requests. The windowBits parameter is interpreted
892 the same as it is for inflateInit2. 892 the same as it is for inflateInit2.
893 893
894 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source 894 inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
895 stream state was inconsistent (such as zalloc or state being Z_NULL), or if 895 stream state was inconsistent (such as zalloc or state being Z_NULL), or if
896 the windowBits parameter is invalid. 896 the windowBits parameter is invalid.
897*/ 897*/
898 898
899ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, 899ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
900 int bits, 900 int bits,
901 int value)); 901 int value));
902/* 902/*
903 This function inserts bits in the inflate input stream. The intent is 903 This function inserts bits in the inflate input stream. The intent is
904 that this function is used to start inflating at a bit position in the 904 that this function is used to start inflating at a bit position in the
905 middle of a byte. The provided bits will be used before any bytes are used 905 middle of a byte. The provided bits will be used before any bytes are used
906 from next_in. This function should only be used with raw inflate, and 906 from next_in. This function should only be used with raw inflate, and
907 should be used before the first inflate() call after inflateInit2() or 907 should be used before the first inflate() call after inflateInit2() or
908 inflateReset(). bits must be less than or equal to 16, and that many of the 908 inflateReset(). bits must be less than or equal to 16, and that many of the
909 least significant bits of value will be inserted in the input. 909 least significant bits of value will be inserted in the input.
910 910
911 If bits is negative, then the input stream bit buffer is emptied. Then 911 If bits is negative, then the input stream bit buffer is emptied. Then
912 inflatePrime() can be called again to put bits in the buffer. This is used 912 inflatePrime() can be called again to put bits in the buffer. This is used
913 to clear out bits leftover after feeding inflate a block description prior 913 to clear out bits leftover after feeding inflate a block description prior
914 to feeding inflate codes. 914 to feeding inflate codes.
915 915
916 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source 916 inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
917 stream state was inconsistent. 917 stream state was inconsistent.
918*/ 918*/
919 919
920ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); 920ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
921/* 921/*
922 This function returns two values, one in the lower 16 bits of the return 922 This function returns two values, one in the lower 16 bits of the return
923 value, and the other in the remaining upper bits, obtained by shifting the 923 value, and the other in the remaining upper bits, obtained by shifting the
924 return value down 16 bits. If the upper value is -1 and the lower value is 924 return value down 16 bits. If the upper value is -1 and the lower value is
925 zero, then inflate() is currently decoding information outside of a block. 925 zero, then inflate() is currently decoding information outside of a block.
926 If the upper value is -1 and the lower value is non-zero, then inflate is in 926 If the upper value is -1 and the lower value is non-zero, then inflate is in
927 the middle of a stored block, with the lower value equaling the number of 927 the middle of a stored block, with the lower value equaling the number of
928 bytes from the input remaining to copy. If the upper value is not -1, then 928 bytes from the input remaining to copy. If the upper value is not -1, then
929 it is the number of bits back from the current bit position in the input of 929 it is the number of bits back from the current bit position in the input of
930 the code (literal or length/distance pair) currently being processed. In 930 the code (literal or length/distance pair) currently being processed. In
931 that case the lower value is the number of bytes already emitted for that 931 that case the lower value is the number of bytes already emitted for that
932 code. 932 code.
933 933
934 A code is being processed if inflate is waiting for more input to complete 934 A code is being processed if inflate is waiting for more input to complete
935 decoding of the code, or if it has completed decoding but is waiting for 935 decoding of the code, or if it has completed decoding but is waiting for
936 more output space to write the literal or match data. 936 more output space to write the literal or match data.
937 937
938 inflateMark() is used to mark locations in the input data for random 938 inflateMark() is used to mark locations in the input data for random
939 access, which may be at bit positions, and to note those cases where the 939 access, which may be at bit positions, and to note those cases where the
940 output of a code may span boundaries of random access blocks. The current 940 output of a code may span boundaries of random access blocks. The current
941 location in the input stream can be determined from avail_in and data_type 941 location in the input stream can be determined from avail_in and data_type
942 as noted in the description for the Z_BLOCK flush parameter for inflate. 942 as noted in the description for the Z_BLOCK flush parameter for inflate.
943 943
944 inflateMark returns the value noted above or -1 << 16 if the provided 944 inflateMark returns the value noted above or -1 << 16 if the provided
945 source stream state was inconsistent. 945 source stream state was inconsistent.
946*/ 946*/
947 947
948ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, 948ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
949 gz_headerp head)); 949 gz_headerp head));
950/* 950/*
951 inflateGetHeader() requests that gzip header information be stored in the 951 inflateGetHeader() requests that gzip header information be stored in the
952 provided gz_header structure. inflateGetHeader() may be called after 952 provided gz_header structure. inflateGetHeader() may be called after
953 inflateInit2() or inflateReset(), and before the first call of inflate(). 953 inflateInit2() or inflateReset(), and before the first call of inflate().
954 As inflate() processes the gzip stream, head->done is zero until the header 954 As inflate() processes the gzip stream, head->done is zero until the header
955 is completed, at which time head->done is set to one. If a zlib stream is 955 is completed, at which time head->done is set to one. If a zlib stream is
956 being decoded, then head->done is set to -1 to indicate that there will be 956 being decoded, then head->done is set to -1 to indicate that there will be
957 no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be 957 no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
958 used to force inflate() to return immediately after header processing is 958 used to force inflate() to return immediately after header processing is
959 complete and before any actual data is decompressed. 959 complete and before any actual data is decompressed.
960 960
961 The text, time, xflags, and os fields are filled in with the gzip header 961 The text, time, xflags, and os fields are filled in with the gzip header
962 contents. hcrc is set to true if there is a header CRC. (The header CRC 962 contents. hcrc is set to true if there is a header CRC. (The header CRC
963 was valid if done is set to one.) If extra is not Z_NULL, then extra_max 963 was valid if done is set to one.) If extra is not Z_NULL, then extra_max
964 contains the maximum number of bytes to write to extra. Once done is true, 964 contains the maximum number of bytes to write to extra. Once done is true,
965 extra_len contains the actual extra field length, and extra contains the 965 extra_len contains the actual extra field length, and extra contains the
966 extra field, or that field truncated if extra_max is less than extra_len. 966 extra field, or that field truncated if extra_max is less than extra_len.
967 If name is not Z_NULL, then up to name_max characters are written there, 967 If name is not Z_NULL, then up to name_max characters are written there,
968 terminated with a zero unless the length is greater than name_max. If 968 terminated with a zero unless the length is greater than name_max. If
969 comment is not Z_NULL, then up to comm_max characters are written there, 969 comment is not Z_NULL, then up to comm_max characters are written there,
970 terminated with a zero unless the length is greater than comm_max. When any 970 terminated with a zero unless the length is greater than comm_max. When any
971 of extra, name, or comment are not Z_NULL and the respective field is not 971 of extra, name, or comment are not Z_NULL and the respective field is not
972 present in the header, then that field is set to Z_NULL to signal its 972 present in the header, then that field is set to Z_NULL to signal its
973 absence. This allows the use of deflateSetHeader() with the returned 973 absence. This allows the use of deflateSetHeader() with the returned
974 structure to duplicate the header. However if those fields are set to 974 structure to duplicate the header. However if those fields are set to
975 allocated memory, then the application will need to save those pointers 975 allocated memory, then the application will need to save those pointers
976 elsewhere so that they can be eventually freed. 976 elsewhere so that they can be eventually freed.
977 977
978 If inflateGetHeader is not used, then the header information is simply 978 If inflateGetHeader is not used, then the header information is simply
979 discarded. The header is always checked for validity, including the header 979 discarded. The header is always checked for validity, including the header
980 CRC if present. inflateReset() will reset the process to discard the header 980 CRC if present. inflateReset() will reset the process to discard the header
981 information. The application would need to call inflateGetHeader() again to 981 information. The application would need to call inflateGetHeader() again to
982 retrieve the header from the next gzip stream. 982 retrieve the header from the next gzip stream.
983 983
984 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source 984 inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
985 stream state was inconsistent. 985 stream state was inconsistent.
986*/ 986*/
987 987
988/* 988/*
989ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, 989ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
990 unsigned char FAR *window)); 990 unsigned char FAR *window));
991 991
992 Initialize the internal stream state for decompression using inflateBack() 992 Initialize the internal stream state for decompression using inflateBack()
993 calls. The fields zalloc, zfree and opaque in strm must be initialized 993 calls. The fields zalloc, zfree and opaque in strm must be initialized
994 before the call. If zalloc and zfree are Z_NULL, then the default library- 994 before the call. If zalloc and zfree are Z_NULL, then the default library-
995 derived memory allocation routines are used. windowBits is the base two 995 derived memory allocation routines are used. windowBits is the base two
996 logarithm of the window size, in the range 8..15. window is a caller 996 logarithm of the window size, in the range 8..15. window is a caller
997 supplied buffer of that size. Except for special applications where it is 997 supplied buffer of that size. Except for special applications where it is
998 assured that deflate was used with small window sizes, windowBits must be 15 998 assured that deflate was used with small window sizes, windowBits must be 15
999 and a 32K byte window must be supplied to be able to decompress general 999 and a 32K byte window must be supplied to be able to decompress general
1000 deflate streams. 1000 deflate streams.
1001 1001
1002 See inflateBack() for the usage of these routines. 1002 See inflateBack() for the usage of these routines.
1003 1003
1004 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of 1004 inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
1005 the parameters are invalid, Z_MEM_ERROR if the internal state could not be 1005 the parameters are invalid, Z_MEM_ERROR if the internal state could not be
1006 allocated, or Z_VERSION_ERROR if the version of the library does not match 1006 allocated, or Z_VERSION_ERROR if the version of the library does not match
1007 the version of the header file. 1007 the version of the header file.
1008*/ 1008*/
1009 1009
1010typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); 1010typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
1011typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); 1011typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1012 1012
1013ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, 1013ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1014 in_func in, void FAR *in_desc, 1014 in_func in, void FAR *in_desc,
1015 out_func out, void FAR *out_desc)); 1015 out_func out, void FAR *out_desc));
1016/* 1016/*
1017 inflateBack() does a raw inflate with a single call using a call-back 1017 inflateBack() does a raw inflate with a single call using a call-back
1018 interface for input and output. This is more efficient than inflate() for 1018 interface for input and output. This is more efficient than inflate() for
1019 file i/o applications in that it avoids copying between the output and the 1019 file i/o applications in that it avoids copying between the output and the
1020 sliding window by simply making the window itself the output buffer. This 1020 sliding window by simply making the window itself the output buffer. This
1021 function trusts the application to not change the output buffer passed by 1021 function trusts the application to not change the output buffer passed by
1022 the output function, at least until inflateBack() returns. 1022 the output function, at least until inflateBack() returns.
1023 1023
1024 inflateBackInit() must be called first to allocate the internal state 1024 inflateBackInit() must be called first to allocate the internal state
1025 and to initialize the state with the user-provided window buffer. 1025 and to initialize the state with the user-provided window buffer.
1026 inflateBack() may then be used multiple times to inflate a complete, raw 1026 inflateBack() may then be used multiple times to inflate a complete, raw
1027 deflate stream with each call. inflateBackEnd() is then called to free the 1027 deflate stream with each call. inflateBackEnd() is then called to free the
1028 allocated state. 1028 allocated state.
1029 1029
1030 A raw deflate stream is one with no zlib or gzip header or trailer. 1030 A raw deflate stream is one with no zlib or gzip header or trailer.
1031 This routine would normally be used in a utility that reads zip or gzip 1031 This routine would normally be used in a utility that reads zip or gzip
1032 files and writes out uncompressed files. The utility would decode the 1032 files and writes out uncompressed files. The utility would decode the
1033 header and process the trailer on its own, hence this routine expects only 1033 header and process the trailer on its own, hence this routine expects only
1034 the raw deflate stream to decompress. This is different from the normal 1034 the raw deflate stream to decompress. This is different from the normal
1035 behavior of inflate(), which expects either a zlib or gzip header and 1035 behavior of inflate(), which expects either a zlib or gzip header and
1036 trailer around the deflate stream. 1036 trailer around the deflate stream.
1037 1037
1038 inflateBack() uses two subroutines supplied by the caller that are then 1038 inflateBack() uses two subroutines supplied by the caller that are then
1039 called by inflateBack() for input and output. inflateBack() calls those 1039 called by inflateBack() for input and output. inflateBack() calls those
1040 routines until it reads a complete deflate stream and writes out all of the 1040 routines until it reads a complete deflate stream and writes out all of the
1041 uncompressed data, or until it encounters an error. The function's 1041 uncompressed data, or until it encounters an error. The function's
1042 parameters and return types are defined above in the in_func and out_func 1042 parameters and return types are defined above in the in_func and out_func
1043 typedefs. inflateBack() will call in(in_desc, &buf) which should return the 1043 typedefs. inflateBack() will call in(in_desc, &buf) which should return the
1044 number of bytes of provided input, and a pointer to that input in buf. If 1044 number of bytes of provided input, and a pointer to that input in buf. If
1045 there is no input available, in() must return zero--buf is ignored in that 1045 there is no input available, in() must return zero--buf is ignored in that
1046 case--and inflateBack() will return a buffer error. inflateBack() will call 1046 case--and inflateBack() will return a buffer error. inflateBack() will call
1047 out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() 1047 out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
1048 should return zero on success, or non-zero on failure. If out() returns 1048 should return zero on success, or non-zero on failure. If out() returns
1049 non-zero, inflateBack() will return with an error. Neither in() nor out() 1049 non-zero, inflateBack() will return with an error. Neither in() nor out()
1050 are permitted to change the contents of the window provided to 1050 are permitted to change the contents of the window provided to
1051 inflateBackInit(), which is also the buffer that out() uses to write from. 1051 inflateBackInit(), which is also the buffer that out() uses to write from.
1052 The length written by out() will be at most the window size. Any non-zero 1052 The length written by out() will be at most the window size. Any non-zero
1053 amount of input may be provided by in(). 1053 amount of input may be provided by in().
1054 1054
1055 For convenience, inflateBack() can be provided input on the first call by 1055 For convenience, inflateBack() can be provided input on the first call by
1056 setting strm->next_in and strm->avail_in. If that input is exhausted, then 1056 setting strm->next_in and strm->avail_in. If that input is exhausted, then
1057 in() will be called. Therefore strm->next_in must be initialized before 1057 in() will be called. Therefore strm->next_in must be initialized before
1058 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called 1058 calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1059 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in 1059 immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1060 must also be initialized, and then if strm->avail_in is not zero, input will 1060 must also be initialized, and then if strm->avail_in is not zero, input will
1061 initially be taken from strm->next_in[0 .. strm->avail_in - 1]. 1061 initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1062 1062
1063 The in_desc and out_desc parameters of inflateBack() is passed as the 1063 The in_desc and out_desc parameters of inflateBack() is passed as the
1064 first parameter of in() and out() respectively when they are called. These 1064 first parameter of in() and out() respectively when they are called. These
1065 descriptors can be optionally used to pass any information that the caller- 1065 descriptors can be optionally used to pass any information that the caller-
1066 supplied in() and out() functions need to do their job. 1066 supplied in() and out() functions need to do their job.
1067 1067
1068 On return, inflateBack() will set strm->next_in and strm->avail_in to 1068 On return, inflateBack() will set strm->next_in and strm->avail_in to
1069 pass back any unused input that was provided by the last in() call. The 1069 pass back any unused input that was provided by the last in() call. The
1070 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR 1070 return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
1071 if in() or out() returned an error, Z_DATA_ERROR if there was a format error 1071 if in() or out() returned an error, Z_DATA_ERROR if there was a format error
1072 in the deflate stream (in which case strm->msg is set to indicate the nature 1072 in the deflate stream (in which case strm->msg is set to indicate the nature
1073 of the error), or Z_STREAM_ERROR if the stream was not properly initialized. 1073 of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
1074 In the case of Z_BUF_ERROR, an input or output error can be distinguished 1074 In the case of Z_BUF_ERROR, an input or output error can be distinguished
1075 using strm->next_in which will be Z_NULL only if in() returned an error. If 1075 using strm->next_in which will be Z_NULL only if in() returned an error. If
1076 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning 1076 strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1077 non-zero. (in() will always be called before out(), so strm->next_in is 1077 non-zero. (in() will always be called before out(), so strm->next_in is
1078 assured to be defined if out() returns non-zero.) Note that inflateBack() 1078 assured to be defined if out() returns non-zero.) Note that inflateBack()
1079 cannot return Z_OK. 1079 cannot return Z_OK.
1080*/ 1080*/
1081 1081
1082ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); 1082ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
1083/* 1083/*
1084 All memory allocated by inflateBackInit() is freed. 1084 All memory allocated by inflateBackInit() is freed.
1085 1085
1086 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream 1086 inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
1087 state was inconsistent. 1087 state was inconsistent.
1088*/ 1088*/
1089 1089
1090ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); 1090ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1091/* Return flags indicating compile-time options. 1091/* Return flags indicating compile-time options.
1092 1092
1093 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: 1093 Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1094 1.0: size of uInt 1094 1.0: size of uInt
1095 3.2: size of uLong 1095 3.2: size of uLong
1096 5.4: size of voidpf (pointer) 1096 5.4: size of voidpf (pointer)
1097 7.6: size of z_off_t 1097 7.6: size of z_off_t
1098 1098
1099 Compiler, assembler, and debug options: 1099 Compiler, assembler, and debug options:
1100 8: DEBUG 1100 8: DEBUG
1101 9: ASMV or ASMINF -- use ASM code 1101 9: ASMV or ASMINF -- use ASM code
1102 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention 1102 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
1103 11: 0 (reserved) 1103 11: 0 (reserved)
1104 1104
1105 One-time table building (smaller code, but not thread-safe if true): 1105 One-time table building (smaller code, but not thread-safe if true):
1106 12: BUILDFIXED -- build static block decoding tables when needed 1106 12: BUILDFIXED -- build static block decoding tables when needed
1107 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed 1107 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
1108 14,15: 0 (reserved) 1108 14,15: 0 (reserved)
1109 1109
1110 Library content (indicates missing functionality): 1110 Library content (indicates missing functionality):
1111 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking 1111 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
1112 deflate code when not needed) 1112 deflate code when not needed)
1113 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect 1113 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
1114 and decode gzip streams (to avoid linking crc code) 1114 and decode gzip streams (to avoid linking crc code)
1115 18-19: 0 (reserved) 1115 18-19: 0 (reserved)
1116 1116
1117 Operation variations (changes in library functionality): 1117 Operation variations (changes in library functionality):
1118 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate 1118 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
1119 21: FASTEST -- deflate algorithm with only one, lowest compression level 1119 21: FASTEST -- deflate algorithm with only one, lowest compression level
1120 22,23: 0 (reserved) 1120 22,23: 0 (reserved)
1121 1121
1122 The sprintf variant used by gzprintf (zero is best): 1122 The sprintf variant used by gzprintf (zero is best):
1123 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format 1123 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
1124 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! 1124 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
1125 26: 0 = returns value, 1 = void -- 1 means inferred string length returned 1125 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
1126 1126
1127 Remainder: 1127 Remainder:
1128 27-31: 0 (reserved) 1128 27-31: 0 (reserved)
1129 */ 1129 */
1130 1130
1131#ifndef Z_SOLO 1131#ifndef Z_SOLO
1132 1132
1133 /* utility functions */ 1133 /* utility functions */
1134 1134
1135/* 1135/*
1136 The following utility functions are implemented on top of the basic 1136 The following utility functions are implemented on top of the basic
1137 stream-oriented functions. To simplify the interface, some default options 1137 stream-oriented functions. To simplify the interface, some default options
1138 are assumed (compression level and memory usage, standard memory allocation 1138 are assumed (compression level and memory usage, standard memory allocation
1139 functions). The source code of these utility functions can be modified if 1139 functions). The source code of these utility functions can be modified if
1140 you need special options. 1140 you need special options.
1141*/ 1141*/
1142 1142
1143ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, 1143ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1144 const Bytef *source, uLong sourceLen)); 1144 const Bytef *source, uLong sourceLen));
1145/* 1145/*
1146 Compresses the source buffer into the destination buffer. sourceLen is 1146 Compresses the source buffer into the destination buffer. sourceLen is
1147 the byte length of the source buffer. Upon entry, destLen is the total size 1147 the byte length of the source buffer. Upon entry, destLen is the total size
1148 of the destination buffer, which must be at least the value returned by 1148 of the destination buffer, which must be at least the value returned by
1149 compressBound(sourceLen). Upon exit, destLen is the actual size of the 1149 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1150 compressed buffer. 1150 compressed buffer.
1151 1151
1152 compress returns Z_OK if success, Z_MEM_ERROR if there was not 1152 compress returns Z_OK if success, Z_MEM_ERROR if there was not
1153 enough memory, Z_BUF_ERROR if there was not enough room in the output 1153 enough memory, Z_BUF_ERROR if there was not enough room in the output
1154 buffer. 1154 buffer.
1155*/ 1155*/
1156 1156
1157ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, 1157ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1158 const Bytef *source, uLong sourceLen, 1158 const Bytef *source, uLong sourceLen,
1159 int level)); 1159 int level));
1160/* 1160/*
1161 Compresses the source buffer into the destination buffer. The level 1161 Compresses the source buffer into the destination buffer. The level
1162 parameter has the same meaning as in deflateInit. sourceLen is the byte 1162 parameter has the same meaning as in deflateInit. sourceLen is the byte
1163 length of the source buffer. Upon entry, destLen is the total size of the 1163 length of the source buffer. Upon entry, destLen is the total size of the
1164 destination buffer, which must be at least the value returned by 1164 destination buffer, which must be at least the value returned by
1165 compressBound(sourceLen). Upon exit, destLen is the actual size of the 1165 compressBound(sourceLen). Upon exit, destLen is the actual size of the
1166 compressed buffer. 1166 compressed buffer.
1167 1167
1168 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 1168 compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1169 memory, Z_BUF_ERROR if there was not enough room in the output buffer, 1169 memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1170 Z_STREAM_ERROR if the level parameter is invalid. 1170 Z_STREAM_ERROR if the level parameter is invalid.
1171*/ 1171*/
1172 1172
1173ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); 1173ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1174/* 1174/*
1175 compressBound() returns an upper bound on the compressed size after 1175 compressBound() returns an upper bound on the compressed size after
1176 compress() or compress2() on sourceLen bytes. It would be used before a 1176 compress() or compress2() on sourceLen bytes. It would be used before a
1177 compress() or compress2() call to allocate the destination buffer. 1177 compress() or compress2() call to allocate the destination buffer.
1178*/ 1178*/
1179 1179
1180ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, 1180ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1181 const Bytef *source, uLong sourceLen)); 1181 const Bytef *source, uLong sourceLen));
1182/* 1182/*
1183 Decompresses the source buffer into the destination buffer. sourceLen is 1183 Decompresses the source buffer into the destination buffer. sourceLen is
1184 the byte length of the source buffer. Upon entry, destLen is the total size 1184 the byte length of the source buffer. Upon entry, destLen is the total size
1185 of the destination buffer, which must be large enough to hold the entire 1185 of the destination buffer, which must be large enough to hold the entire
1186 uncompressed data. (The size of the uncompressed data must have been saved 1186 uncompressed data. (The size of the uncompressed data must have been saved
1187 previously by the compressor and transmitted to the decompressor by some 1187 previously by the compressor and transmitted to the decompressor by some
1188 mechanism outside the scope of this compression library.) Upon exit, destLen 1188 mechanism outside the scope of this compression library.) Upon exit, destLen
1189 is the actual size of the uncompressed buffer. 1189 is the actual size of the uncompressed buffer.
1190 1190
1191 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1191 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1192 enough memory, Z_BUF_ERROR if there was not enough room in the output 1192 enough memory, Z_BUF_ERROR if there was not enough room in the output
1193 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In 1193 buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1194 the case where there is not enough room, uncompress() will fill the output 1194 the case where there is not enough room, uncompress() will fill the output
1195 buffer with the uncompressed data up to that point. 1195 buffer with the uncompressed data up to that point.
1196*/ 1196*/
1197 1197
1198 /* gzip file access functions */ 1198 /* gzip file access functions */
1199 1199
1200/* 1200/*
1201 This library supports reading and writing files in gzip (.gz) format with 1201 This library supports reading and writing files in gzip (.gz) format with
1202 an interface similar to that of stdio, using the functions that start with 1202 an interface similar to that of stdio, using the functions that start with
1203 "gz". The gzip format is different from the zlib format. gzip is a gzip 1203 "gz". The gzip format is different from the zlib format. gzip is a gzip
1204 wrapper, documented in RFC 1952, wrapped around a deflate stream. 1204 wrapper, documented in RFC 1952, wrapped around a deflate stream.
1205*/ 1205*/
1206 1206
1207typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ 1207typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1208 1208
1209/* 1209/*
1210ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); 1210ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1211 1211
1212 Opens a gzip (.gz) file for reading or writing. The mode parameter is as 1212 Opens a gzip (.gz) file for reading or writing. The mode parameter is as
1213 in fopen ("rb" or "wb") but can also include a compression level ("wb9") or 1213 in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
1214 a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only 1214 a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
1215 compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' 1215 compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
1216 for fixed code compression as in "wb9F". (See the description of 1216 for fixed code compression as in "wb9F". (See the description of
1217 deflateInit2 for more information about the strategy parameter.) 'T' will 1217 deflateInit2 for more information about the strategy parameter.) 'T' will
1218 request transparent writing or appending with no compression and not using 1218 request transparent writing or appending with no compression and not using
1219 the gzip format. 1219 the gzip format.
1220 1220
1221 "a" can be used instead of "w" to request that the gzip stream that will 1221 "a" can be used instead of "w" to request that the gzip stream that will
1222 be written be appended to the file. "+" will result in an error, since 1222 be written be appended to the file. "+" will result in an error, since
1223 reading and writing to the same gzip file is not supported. The addition of 1223 reading and writing to the same gzip file is not supported. The addition of
1224 "x" when writing will create the file exclusively, which fails if the file 1224 "x" when writing will create the file exclusively, which fails if the file
1225 already exists. On systems that support it, the addition of "e" when 1225 already exists. On systems that support it, the addition of "e" when
1226 reading or writing will set the flag to close the file on an execve() call. 1226 reading or writing will set the flag to close the file on an execve() call.
1227 1227
1228 These functions, as well as gzip, will read and decode a sequence of gzip 1228 These functions, as well as gzip, will read and decode a sequence of gzip
1229 streams in a file. The append function of gzopen() can be used to create 1229 streams in a file. The append function of gzopen() can be used to create
1230 such a file. (Also see gzflush() for another way to do this.) When 1230 such a file. (Also see gzflush() for another way to do this.) When
1231 appending, gzopen does not test whether the file begins with a gzip stream, 1231 appending, gzopen does not test whether the file begins with a gzip stream,
1232 nor does it look for the end of the gzip streams to begin appending. gzopen 1232 nor does it look for the end of the gzip streams to begin appending. gzopen
1233 will simply append a gzip stream to the existing file. 1233 will simply append a gzip stream to the existing file.
1234 1234
1235 gzopen can be used to read a file which is not in gzip format; in this 1235 gzopen can be used to read a file which is not in gzip format; in this
1236 case gzread will directly read from the file without decompression. When 1236 case gzread will directly read from the file without decompression. When
1237 reading, this will be detected automatically by looking for the magic two- 1237 reading, this will be detected automatically by looking for the magic two-
1238 byte gzip header. 1238 byte gzip header.
1239 1239
1240 gzopen returns NULL if the file could not be opened, if there was 1240 gzopen returns NULL if the file could not be opened, if there was
1241 insufficient memory to allocate the gzFile state, or if an invalid mode was 1241 insufficient memory to allocate the gzFile state, or if an invalid mode was
1242 specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). 1242 specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
1243 errno can be checked to determine if the reason gzopen failed was that the 1243 errno can be checked to determine if the reason gzopen failed was that the
1244 file could not be opened. 1244 file could not be opened.
1245*/ 1245*/
1246 1246
1247ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); 1247ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1248/* 1248/*
1249 gzdopen associates a gzFile with the file descriptor fd. File descriptors 1249 gzdopen associates a gzFile with the file descriptor fd. File descriptors
1250 are obtained from calls like open, dup, creat, pipe or fileno (if the file 1250 are obtained from calls like open, dup, creat, pipe or fileno (if the file
1251 has been previously opened with fopen). The mode parameter is as in gzopen. 1251 has been previously opened with fopen). The mode parameter is as in gzopen.
1252 1252
1253 The next call of gzclose on the returned gzFile will also close the file 1253 The next call of gzclose on the returned gzFile will also close the file
1254 descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor 1254 descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
1255 fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, 1255 fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
1256 mode);. The duplicated descriptor should be saved to avoid a leak, since 1256 mode);. The duplicated descriptor should be saved to avoid a leak, since
1257 gzdopen does not close fd if it fails. If you are using fileno() to get the 1257 gzdopen does not close fd if it fails. If you are using fileno() to get the
1258 file descriptor from a FILE *, then you will have to use dup() to avoid 1258 file descriptor from a FILE *, then you will have to use dup() to avoid
1259 double-close()ing the file descriptor. Both gzclose() and fclose() will 1259 double-close()ing the file descriptor. Both gzclose() and fclose() will
1260 close the associated file descriptor, so they need to have different file 1260 close the associated file descriptor, so they need to have different file
1261 descriptors. 1261 descriptors.
1262 1262
1263 gzdopen returns NULL if there was insufficient memory to allocate the 1263 gzdopen returns NULL if there was insufficient memory to allocate the
1264 gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not 1264 gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
1265 provided, or '+' was provided), or if fd is -1. The file descriptor is not 1265 provided, or '+' was provided), or if fd is -1. The file descriptor is not
1266 used until the next gz* read, write, seek, or close operation, so gzdopen 1266 used until the next gz* read, write, seek, or close operation, so gzdopen
1267 will not detect if fd is invalid (unless fd is -1). 1267 will not detect if fd is invalid (unless fd is -1).
1268*/ 1268*/
1269 1269
1270ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); 1270ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1271/* 1271/*
1272 Set the internal buffer size used by this library's functions. The 1272 Set the internal buffer size used by this library's functions. The
1273 default buffer size is 8192 bytes. This function must be called after 1273 default buffer size is 8192 bytes. This function must be called after
1274 gzopen() or gzdopen(), and before any other calls that read or write the 1274 gzopen() or gzdopen(), and before any other calls that read or write the
1275 file. The buffer memory allocation is always deferred to the first read or 1275 file. The buffer memory allocation is always deferred to the first read or
1276 write. Two buffers are allocated, either both of the specified size when 1276 write. Two buffers are allocated, either both of the specified size when
1277 writing, or one of the specified size and the other twice that size when 1277 writing, or one of the specified size and the other twice that size when
1278 reading. A larger buffer size of, for example, 64K or 128K bytes will 1278 reading. A larger buffer size of, for example, 64K or 128K bytes will
1279 noticeably increase the speed of decompression (reading). 1279 noticeably increase the speed of decompression (reading).
1280 1280
1281 The new buffer size also affects the maximum length for gzprintf(). 1281 The new buffer size also affects the maximum length for gzprintf().
1282 1282
1283 gzbuffer() returns 0 on success, or -1 on failure, such as being called 1283 gzbuffer() returns 0 on success, or -1 on failure, such as being called
1284 too late. 1284 too late.
1285*/ 1285*/
1286 1286
1287ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); 1287ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1288/* 1288/*
1289 Dynamically update the compression level or strategy. See the description 1289 Dynamically update the compression level or strategy. See the description
1290 of deflateInit2 for the meaning of these parameters. 1290 of deflateInit2 for the meaning of these parameters.
1291 1291
1292 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not 1292 gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1293 opened for writing. 1293 opened for writing.
1294*/ 1294*/
1295 1295
1296ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); 1296ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1297/* 1297/*
1298 Reads the given number of uncompressed bytes from the compressed file. If 1298 Reads the given number of uncompressed bytes from the compressed file. If
1299 the input file is not in gzip format, gzread copies the given number of 1299 the input file is not in gzip format, gzread copies the given number of
1300 bytes into the buffer directly from the file. 1300 bytes into the buffer directly from the file.
1301 1301
1302 After reaching the end of a gzip stream in the input, gzread will continue 1302 After reaching the end of a gzip stream in the input, gzread will continue
1303 to read, looking for another gzip stream. Any number of gzip streams may be 1303 to read, looking for another gzip stream. Any number of gzip streams may be
1304 concatenated in the input file, and will all be decompressed by gzread(). 1304 concatenated in the input file, and will all be decompressed by gzread().
1305 If something other than a gzip stream is encountered after a gzip stream, 1305 If something other than a gzip stream is encountered after a gzip stream,
1306 that remaining trailing garbage is ignored (and no error is returned). 1306 that remaining trailing garbage is ignored (and no error is returned).
1307 1307
1308 gzread can be used to read a gzip file that is being concurrently written. 1308 gzread can be used to read a gzip file that is being concurrently written.
1309 Upon reaching the end of the input, gzread will return with the available 1309 Upon reaching the end of the input, gzread will return with the available
1310 data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then 1310 data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
1311 gzclearerr can be used to clear the end of file indicator in order to permit 1311 gzclearerr can be used to clear the end of file indicator in order to permit
1312 gzread to be tried again. Z_OK indicates that a gzip stream was completed 1312 gzread to be tried again. Z_OK indicates that a gzip stream was completed
1313 on the last gzread. Z_BUF_ERROR indicates that the input file ended in the 1313 on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
1314 middle of a gzip stream. Note that gzread does not return -1 in the event 1314 middle of a gzip stream. Note that gzread does not return -1 in the event
1315 of an incomplete gzip stream. This error is deferred until gzclose(), which 1315 of an incomplete gzip stream. This error is deferred until gzclose(), which
1316 will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip 1316 will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
1317 stream. Alternatively, gzerror can be used before gzclose to detect this 1317 stream. Alternatively, gzerror can be used before gzclose to detect this
1318 case. 1318 case.
1319 1319
1320 gzread returns the number of uncompressed bytes actually read, less than 1320 gzread returns the number of uncompressed bytes actually read, less than
1321 len for end of file, or -1 for error. 1321 len for end of file, or -1 for error.
1322*/ 1322*/
1323 1323
1324ZEXTERN int ZEXPORT gzwrite OF((gzFile file, 1324ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1325 voidpc buf, unsigned len)); 1325 voidpc buf, unsigned len));
1326/* 1326/*
1327 Writes the given number of uncompressed bytes into the compressed file. 1327 Writes the given number of uncompressed bytes into the compressed file.
1328 gzwrite returns the number of uncompressed bytes written or 0 in case of 1328 gzwrite returns the number of uncompressed bytes written or 0 in case of
1329 error. 1329 error.
1330*/ 1330*/
1331 1331
1332ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); 1332ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
1333/* 1333/*
1334 Converts, formats, and writes the arguments to the compressed file under 1334 Converts, formats, and writes the arguments to the compressed file under
1335 control of the format string, as in fprintf. gzprintf returns the number of 1335 control of the format string, as in fprintf. gzprintf returns the number of
1336 uncompressed bytes actually written, or 0 in case of error. The number of 1336 uncompressed bytes actually written, or 0 in case of error. The number of
1337 uncompressed bytes written is limited to 8191, or one less than the buffer 1337 uncompressed bytes written is limited to 8191, or one less than the buffer
1338 size given to gzbuffer(). The caller should assure that this limit is not 1338 size given to gzbuffer(). The caller should assure that this limit is not
1339 exceeded. If it is exceeded, then gzprintf() will return an error (0) with 1339 exceeded. If it is exceeded, then gzprintf() will return an error (0) with
1340 nothing written. In this case, there may also be a buffer overflow with 1340 nothing written. In this case, there may also be a buffer overflow with
1341 unpredictable consequences, which is possible only if zlib was compiled with 1341 unpredictable consequences, which is possible only if zlib was compiled with
1342 the insecure functions sprintf() or vsprintf() because the secure snprintf() 1342 the insecure functions sprintf() or vsprintf() because the secure snprintf()
1343 or vsnprintf() functions were not available. This can be determined using 1343 or vsnprintf() functions were not available. This can be determined using
1344 zlibCompileFlags(). 1344 zlibCompileFlags().
1345*/ 1345*/
1346 1346
1347ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); 1347ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1348/* 1348/*
1349 Writes the given null-terminated string to the compressed file, excluding 1349 Writes the given null-terminated string to the compressed file, excluding
1350 the terminating null character. 1350 the terminating null character.
1351 1351
1352 gzputs returns the number of characters written, or -1 in case of error. 1352 gzputs returns the number of characters written, or -1 in case of error.
1353*/ 1353*/
1354 1354
1355ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); 1355ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1356/* 1356/*
1357 Reads bytes from the compressed file until len-1 characters are read, or a 1357 Reads bytes from the compressed file until len-1 characters are read, or a
1358 newline character is read and transferred to buf, or an end-of-file 1358 newline character is read and transferred to buf, or an end-of-file
1359 condition is encountered. If any characters are read or if len == 1, the 1359 condition is encountered. If any characters are read or if len == 1, the
1360 string is terminated with a null character. If no characters are read due 1360 string is terminated with a null character. If no characters are read due
1361 to an end-of-file or len < 1, then the buffer is left untouched. 1361 to an end-of-file or len < 1, then the buffer is left untouched.
1362 1362
1363 gzgets returns buf which is a null-terminated string, or it returns NULL 1363 gzgets returns buf which is a null-terminated string, or it returns NULL
1364 for end-of-file or in case of error. If there was an error, the contents at 1364 for end-of-file or in case of error. If there was an error, the contents at
1365 buf are indeterminate. 1365 buf are indeterminate.
1366*/ 1366*/
1367 1367
1368ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); 1368ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1369/* 1369/*
1370 Writes c, converted to an unsigned char, into the compressed file. gzputc 1370 Writes c, converted to an unsigned char, into the compressed file. gzputc
1371 returns the value that was written, or -1 in case of error. 1371 returns the value that was written, or -1 in case of error.
1372*/ 1372*/
1373 1373
1374ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); 1374ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1375/* 1375/*
1376 Reads one byte from the compressed file. gzgetc returns this byte or -1 1376 Reads one byte from the compressed file. gzgetc returns this byte or -1
1377 in case of end of file or error. This is implemented as a macro for speed. 1377 in case of end of file or error. This is implemented as a macro for speed.
1378 As such, it does not do all of the checking the other functions do. I.e. 1378 As such, it does not do all of the checking the other functions do. I.e.
1379 it does not check to see if file is NULL, nor whether the structure file 1379 it does not check to see if file is NULL, nor whether the structure file
1380 points to has been clobbered or not. 1380 points to has been clobbered or not.
1381*/ 1381*/
1382 1382
1383ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); 1383ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1384/* 1384/*
1385 Push one character back onto the stream to be read as the first character 1385 Push one character back onto the stream to be read as the first character
1386 on the next read. At least one character of push-back is allowed. 1386 on the next read. At least one character of push-back is allowed.
1387 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will 1387 gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1388 fail if c is -1, and may fail if a character has been pushed but not read 1388 fail if c is -1, and may fail if a character has been pushed but not read
1389 yet. If gzungetc is used immediately after gzopen or gzdopen, at least the 1389 yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
1390 output buffer size of pushed characters is allowed. (See gzbuffer above.) 1390 output buffer size of pushed characters is allowed. (See gzbuffer above.)
1391 The pushed character will be discarded if the stream is repositioned with 1391 The pushed character will be discarded if the stream is repositioned with
1392 gzseek() or gzrewind(). 1392 gzseek() or gzrewind().
1393*/ 1393*/
1394 1394
1395ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); 1395ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1396/* 1396/*
1397 Flushes all pending output into the compressed file. The parameter flush 1397 Flushes all pending output into the compressed file. The parameter flush
1398 is as in the deflate() function. The return value is the zlib error number 1398 is as in the deflate() function. The return value is the zlib error number
1399 (see function gzerror below). gzflush is only permitted when writing. 1399 (see function gzerror below). gzflush is only permitted when writing.
1400 1400
1401 If the flush parameter is Z_FINISH, the remaining data is written and the 1401 If the flush parameter is Z_FINISH, the remaining data is written and the
1402 gzip stream is completed in the output. If gzwrite() is called again, a new 1402 gzip stream is completed in the output. If gzwrite() is called again, a new
1403 gzip stream will be started in the output. gzread() is able to read such 1403 gzip stream will be started in the output. gzread() is able to read such
1404 concatented gzip streams. 1404 concatented gzip streams.
1405 1405
1406 gzflush should be called only when strictly necessary because it will 1406 gzflush should be called only when strictly necessary because it will
1407 degrade compression if called too often. 1407 degrade compression if called too often.
1408*/ 1408*/
1409 1409
1410/* 1410/*
1411ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, 1411ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1412 z_off_t offset, int whence)); 1412 z_off_t offset, int whence));
1413 1413
1414 Sets the starting position for the next gzread or gzwrite on the given 1414 Sets the starting position for the next gzread or gzwrite on the given
1415 compressed file. The offset represents a number of bytes in the 1415 compressed file. The offset represents a number of bytes in the
1416 uncompressed data stream. The whence parameter is defined as in lseek(2); 1416 uncompressed data stream. The whence parameter is defined as in lseek(2);
1417 the value SEEK_END is not supported. 1417 the value SEEK_END is not supported.
1418 1418
1419 If the file is opened for reading, this function is emulated but can be 1419 If the file is opened for reading, this function is emulated but can be
1420 extremely slow. If the file is opened for writing, only forward seeks are 1420 extremely slow. If the file is opened for writing, only forward seeks are
1421 supported; gzseek then compresses a sequence of zeroes up to the new 1421 supported; gzseek then compresses a sequence of zeroes up to the new
1422 starting position. 1422 starting position.
1423 1423
1424 gzseek returns the resulting offset location as measured in bytes from 1424 gzseek returns the resulting offset location as measured in bytes from
1425 the beginning of the uncompressed stream, or -1 in case of error, in 1425 the beginning of the uncompressed stream, or -1 in case of error, in
1426 particular if the file is opened for writing and the new starting position 1426 particular if the file is opened for writing and the new starting position
1427 would be before the current position. 1427 would be before the current position.
1428*/ 1428*/
1429 1429
1430ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); 1430ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1431/* 1431/*
1432 Rewinds the given file. This function is supported only for reading. 1432 Rewinds the given file. This function is supported only for reading.
1433 1433
1434 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) 1434 gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1435*/ 1435*/
1436 1436
1437/* 1437/*
1438ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); 1438ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1439 1439
1440 Returns the starting position for the next gzread or gzwrite on the given 1440 Returns the starting position for the next gzread or gzwrite on the given
1441 compressed file. This position represents a number of bytes in the 1441 compressed file. This position represents a number of bytes in the
1442 uncompressed data stream, and is zero when starting, even if appending or 1442 uncompressed data stream, and is zero when starting, even if appending or
1443 reading a gzip stream from the middle of a file using gzdopen(). 1443 reading a gzip stream from the middle of a file using gzdopen().
1444 1444
1445 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) 1445 gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1446*/ 1446*/
1447 1447
1448/* 1448/*
1449ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); 1449ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1450 1450
1451 Returns the current offset in the file being read or written. This offset 1451 Returns the current offset in the file being read or written. This offset
1452 includes the count of bytes that precede the gzip stream, for example when 1452 includes the count of bytes that precede the gzip stream, for example when
1453 appending or when using gzdopen() for reading. When reading, the offset 1453 appending or when using gzdopen() for reading. When reading, the offset
1454 does not include as yet unused buffered input. This information can be used 1454 does not include as yet unused buffered input. This information can be used
1455 for a progress indicator. On error, gzoffset() returns -1. 1455 for a progress indicator. On error, gzoffset() returns -1.
1456*/ 1456*/
1457 1457
1458ZEXTERN int ZEXPORT gzeof OF((gzFile file)); 1458ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1459/* 1459/*
1460 Returns true (1) if the end-of-file indicator has been set while reading, 1460 Returns true (1) if the end-of-file indicator has been set while reading,
1461 false (0) otherwise. Note that the end-of-file indicator is set only if the 1461 false (0) otherwise. Note that the end-of-file indicator is set only if the
1462 read tried to go past the end of the input, but came up short. Therefore, 1462 read tried to go past the end of the input, but came up short. Therefore,
1463 just like feof(), gzeof() may return false even if there is no more data to 1463 just like feof(), gzeof() may return false even if there is no more data to
1464 read, in the event that the last read request was for the exact number of 1464 read, in the event that the last read request was for the exact number of
1465 bytes remaining in the input file. This will happen if the input file size 1465 bytes remaining in the input file. This will happen if the input file size
1466 is an exact multiple of the buffer size. 1466 is an exact multiple of the buffer size.
1467 1467
1468 If gzeof() returns true, then the read functions will return no more data, 1468 If gzeof() returns true, then the read functions will return no more data,
1469 unless the end-of-file indicator is reset by gzclearerr() and the input file 1469 unless the end-of-file indicator is reset by gzclearerr() and the input file
1470 has grown since the previous end of file was detected. 1470 has grown since the previous end of file was detected.
1471*/ 1471*/
1472 1472
1473ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); 1473ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1474/* 1474/*
1475 Returns true (1) if file is being copied directly while reading, or false 1475 Returns true (1) if file is being copied directly while reading, or false
1476 (0) if file is a gzip stream being decompressed. 1476 (0) if file is a gzip stream being decompressed.
1477 1477
1478 If the input file is empty, gzdirect() will return true, since the input 1478 If the input file is empty, gzdirect() will return true, since the input
1479 does not contain a gzip stream. 1479 does not contain a gzip stream.
1480 1480
1481 If gzdirect() is used immediately after gzopen() or gzdopen() it will 1481 If gzdirect() is used immediately after gzopen() or gzdopen() it will
1482 cause buffers to be allocated to allow reading the file to determine if it 1482 cause buffers to be allocated to allow reading the file to determine if it
1483 is a gzip file. Therefore if gzbuffer() is used, it should be called before 1483 is a gzip file. Therefore if gzbuffer() is used, it should be called before
1484 gzdirect(). 1484 gzdirect().
1485 1485
1486 When writing, gzdirect() returns true (1) if transparent writing was 1486 When writing, gzdirect() returns true (1) if transparent writing was
1487 requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: 1487 requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
1488 gzdirect() is not needed when writing. Transparent writing must be 1488 gzdirect() is not needed when writing. Transparent writing must be
1489 explicitly requested, so the application already knows the answer. When 1489 explicitly requested, so the application already knows the answer. When
1490 linking statically, using gzdirect() will include all of the zlib code for 1490 linking statically, using gzdirect() will include all of the zlib code for
1491 gzip file reading and decompression, which may not be desired.) 1491 gzip file reading and decompression, which may not be desired.)
1492*/ 1492*/
1493 1493
1494ZEXTERN int ZEXPORT gzclose OF((gzFile file)); 1494ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1495/* 1495/*
1496 Flushes all pending output if necessary, closes the compressed file and 1496 Flushes all pending output if necessary, closes the compressed file and
1497 deallocates the (de)compression state. Note that once file is closed, you 1497 deallocates the (de)compression state. Note that once file is closed, you
1498 cannot call gzerror with file, since its structures have been deallocated. 1498 cannot call gzerror with file, since its structures have been deallocated.
1499 gzclose must not be called more than once on the same file, just as free 1499 gzclose must not be called more than once on the same file, just as free
1500 must not be called more than once on the same allocation. 1500 must not be called more than once on the same allocation.
1501 1501
1502 gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a 1502 gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
1503 file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the 1503 file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
1504 last read ended in the middle of a gzip stream, or Z_OK on success. 1504 last read ended in the middle of a gzip stream, or Z_OK on success.
1505*/ 1505*/
1506 1506
1507ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); 1507ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1508ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); 1508ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1509/* 1509/*
1510 Same as gzclose(), but gzclose_r() is only for use when reading, and 1510 Same as gzclose(), but gzclose_r() is only for use when reading, and
1511 gzclose_w() is only for use when writing or appending. The advantage to 1511 gzclose_w() is only for use when writing or appending. The advantage to
1512 using these instead of gzclose() is that they avoid linking in zlib 1512 using these instead of gzclose() is that they avoid linking in zlib
1513 compression or decompression code that is not used when only reading or only 1513 compression or decompression code that is not used when only reading or only
1514 writing respectively. If gzclose() is used, then both compression and 1514 writing respectively. If gzclose() is used, then both compression and
1515 decompression code will be included the application when linking to a static 1515 decompression code will be included the application when linking to a static
1516 zlib library. 1516 zlib library.
1517*/ 1517*/
1518 1518
1519ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); 1519ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1520/* 1520/*
1521 Returns the error message for the last error which occurred on the given 1521 Returns the error message for the last error which occurred on the given
1522 compressed file. errnum is set to zlib error number. If an error occurred 1522 compressed file. errnum is set to zlib error number. If an error occurred
1523 in the file system and not in the compression library, errnum is set to 1523 in the file system and not in the compression library, errnum is set to
1524 Z_ERRNO and the application may consult errno to get the exact error code. 1524 Z_ERRNO and the application may consult errno to get the exact error code.
1525 1525
1526 The application must not modify the returned string. Future calls to 1526 The application must not modify the returned string. Future calls to
1527 this function may invalidate the previously returned string. If file is 1527 this function may invalidate the previously returned string. If file is
1528 closed, then the string previously returned by gzerror will no longer be 1528 closed, then the string previously returned by gzerror will no longer be
1529 available. 1529 available.
1530 1530
1531 gzerror() should be used to distinguish errors from end-of-file for those 1531 gzerror() should be used to distinguish errors from end-of-file for those
1532 functions above that do not distinguish those cases in their return values. 1532 functions above that do not distinguish those cases in their return values.
1533*/ 1533*/
1534 1534
1535ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); 1535ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1536/* 1536/*
1537 Clears the error and end-of-file flags for file. This is analogous to the 1537 Clears the error and end-of-file flags for file. This is analogous to the
1538 clearerr() function in stdio. This is useful for continuing to read a gzip 1538 clearerr() function in stdio. This is useful for continuing to read a gzip
1539 file that is being written concurrently. 1539 file that is being written concurrently.
1540*/ 1540*/
1541 1541
1542#endif /* !Z_SOLO */ 1542#endif /* !Z_SOLO */
1543 1543
1544 /* checksum functions */ 1544 /* checksum functions */
1545 1545
1546/* 1546/*
1547 These functions are not related to compression but are exported 1547 These functions are not related to compression but are exported
1548 anyway because they might be useful in applications using the compression 1548 anyway because they might be useful in applications using the compression
1549 library. 1549 library.
1550*/ 1550*/
1551 1551
1552ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); 1552ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1553/* 1553/*
1554 Update a running Adler-32 checksum with the bytes buf[0..len-1] and 1554 Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1555 return the updated checksum. If buf is Z_NULL, this function returns the 1555 return the updated checksum. If buf is Z_NULL, this function returns the
1556 required initial value for the checksum. 1556 required initial value for the checksum.
1557 1557
1558 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 1558 An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1559 much faster. 1559 much faster.
1560 1560
1561 Usage example: 1561 Usage example:
1562 1562
1563 uLong adler = adler32(0L, Z_NULL, 0); 1563 uLong adler = adler32(0L, Z_NULL, 0);
1564 1564
1565 while (read_buffer(buffer, length) != EOF) { 1565 while (read_buffer(buffer, length) != EOF) {
1566 adler = adler32(adler, buffer, length); 1566 adler = adler32(adler, buffer, length);
1567 } 1567 }
1568 if (adler != original_adler) error(); 1568 if (adler != original_adler) error();
1569*/ 1569*/
1570 1570
1571/* 1571/*
1572ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, 1572ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1573 z_off_t len2)); 1573 z_off_t len2));
1574 1574
1575 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 1575 Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1576 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for 1576 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1577 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of 1577 each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1578 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note 1578 seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1579 that the z_off_t type (like off_t) is a signed integer. If len2 is 1579 that the z_off_t type (like off_t) is a signed integer. If len2 is
1580 negative, the result has no meaning or utility. 1580 negative, the result has no meaning or utility.
1581*/ 1581*/
1582 1582
1583ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); 1583ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1584/* 1584/*
1585 Update a running CRC-32 with the bytes buf[0..len-1] and return the 1585 Update a running CRC-32 with the bytes buf[0..len-1] and return the
1586 updated CRC-32. If buf is Z_NULL, this function returns the required 1586 updated CRC-32. If buf is Z_NULL, this function returns the required
1587 initial value for the crc. Pre- and post-conditioning (one's complement) is 1587 initial value for the crc. Pre- and post-conditioning (one's complement) is
1588 performed within this function so it shouldn't be done by the application. 1588 performed within this function so it shouldn't be done by the application.
1589 1589
1590 Usage example: 1590 Usage example:
1591 1591
1592 uLong crc = crc32(0L, Z_NULL, 0); 1592 uLong crc = crc32(0L, Z_NULL, 0);
1593 1593
1594 while (read_buffer(buffer, length) != EOF) { 1594 while (read_buffer(buffer, length) != EOF) {
1595 crc = crc32(crc, buffer, length); 1595 crc = crc32(crc, buffer, length);
1596 } 1596 }
1597 if (crc != original_crc) error(); 1597 if (crc != original_crc) error();
1598*/ 1598*/
1599 1599
1600/* 1600/*
1601ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); 1601ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1602 1602
1603 Combine two CRC-32 check values into one. For two sequences of bytes, 1603 Combine two CRC-32 check values into one. For two sequences of bytes,
1604 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were 1604 seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1605 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 1605 calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1606 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and 1606 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1607 len2. 1607 len2.
1608*/ 1608*/
1609 1609
1610 1610
1611 /* various hacks, don't look :) */ 1611 /* various hacks, don't look :) */
1612 1612
1613/* deflateInit and inflateInit are macros to allow checking the zlib version 1613/* deflateInit and inflateInit are macros to allow checking the zlib version
1614 * and the compiler's view of z_stream: 1614 * and the compiler's view of z_stream:
1615 */ 1615 */
1616ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, 1616ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1617 const char *version, int stream_size)); 1617 const char *version, int stream_size));
1618ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, 1618ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1619 const char *version, int stream_size)); 1619 const char *version, int stream_size));
1620ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, 1620ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1621 int windowBits, int memLevel, 1621 int windowBits, int memLevel,
1622 int strategy, const char *version, 1622 int strategy, const char *version,
1623 int stream_size)); 1623 int stream_size));
1624ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, 1624ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1625 const char *version, int stream_size)); 1625 const char *version, int stream_size));
1626ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, 1626ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1627 unsigned char FAR *window, 1627 unsigned char FAR *window,
1628 const char *version, 1628 const char *version,
1629 int stream_size)); 1629 int stream_size));
1630#define deflateInit(strm, level) \ 1630#define deflateInit(strm, level) \
1631 deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) 1631 deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
1632#define inflateInit(strm) \ 1632#define inflateInit(strm) \
1633 inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) 1633 inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
1634#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ 1634#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1635 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ 1635 deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1636 (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) 1636 (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
1637#define inflateInit2(strm, windowBits) \ 1637#define inflateInit2(strm, windowBits) \
1638 inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ 1638 inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
1639 (int)sizeof(z_stream)) 1639 (int)sizeof(z_stream))
1640#define inflateBackInit(strm, windowBits, window) \ 1640#define inflateBackInit(strm, windowBits, window) \
1641 inflateBackInit_((strm), (windowBits), (window), \ 1641 inflateBackInit_((strm), (windowBits), (window), \
1642 ZLIB_VERSION, (int)sizeof(z_stream)) 1642 ZLIB_VERSION, (int)sizeof(z_stream))
1643 1643
1644#ifndef Z_SOLO 1644#ifndef Z_SOLO
1645 1645
1646/* gzgetc() macro and its supporting function and exposed data structure. Note 1646/* gzgetc() macro and its supporting function and exposed data structure. Note
1647 * that the real internal state is much larger than the exposed structure. 1647 * that the real internal state is much larger than the exposed structure.
1648 * This abbreviated structure exposes just enough for the gzgetc() macro. The 1648 * This abbreviated structure exposes just enough for the gzgetc() macro. The
1649 * user should not mess with these exposed elements, since their names or 1649 * user should not mess with these exposed elements, since their names or
1650 * behavior could change in the future, perhaps even capriciously. They can 1650 * behavior could change in the future, perhaps even capriciously. They can
1651 * only be used by the gzgetc() macro. You have been warned. 1651 * only be used by the gzgetc() macro. You have been warned.
1652 */ 1652 */
1653struct gzFile_s { 1653struct gzFile_s {
1654 unsigned have; 1654 unsigned have;
1655 unsigned char *next; 1655 unsigned char *next;
1656 z_off64_t pos; 1656 z_off64_t pos;
1657}; 1657};
1658ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ 1658ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
1659#ifdef Z_PREFIX_SET 1659#ifdef Z_PREFIX_SET
1660# undef z_gzgetc 1660# undef z_gzgetc
1661# define z_gzgetc(g) \ 1661# define z_gzgetc(g) \
1662 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) 1662 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1663#else 1663#else
1664# define gzgetc(g) \ 1664# define gzgetc(g) \
1665 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) 1665 ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1666#endif 1666#endif
1667 1667
1668/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or 1668/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
1669 * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if 1669 * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
1670 * both are true, the application gets the *64 functions, and the regular 1670 * both are true, the application gets the *64 functions, and the regular
1671 * functions are changed to 64 bits) -- in case these are set on systems 1671 * functions are changed to 64 bits) -- in case these are set on systems
1672 * without large file support, _LFS64_LARGEFILE must also be true 1672 * without large file support, _LFS64_LARGEFILE must also be true
1673 */ 1673 */
1674#ifdef Z_LARGE64 1674#ifdef Z_LARGE64
1675 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1675 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1676 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 1676 ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
1677 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 1677 ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
1678 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 1678 ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
1679 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); 1679 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
1680 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); 1680 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
1681#endif 1681#endif
1682 1682
1683#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) 1683#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
1684# ifdef Z_PREFIX_SET 1684# ifdef Z_PREFIX_SET
1685# define z_gzopen z_gzopen64 1685# define z_gzopen z_gzopen64
1686# define z_gzseek z_gzseek64 1686# define z_gzseek z_gzseek64
1687# define z_gztell z_gztell64 1687# define z_gztell z_gztell64
1688# define z_gzoffset z_gzoffset64 1688# define z_gzoffset z_gzoffset64
1689# define z_adler32_combine z_adler32_combine64 1689# define z_adler32_combine z_adler32_combine64
1690# define z_crc32_combine z_crc32_combine64 1690# define z_crc32_combine z_crc32_combine64
1691# else 1691# else
1692# define gzopen gzopen64 1692# define gzopen gzopen64
1693# define gzseek gzseek64 1693# define gzseek gzseek64
1694# define gztell gztell64 1694# define gztell gztell64
1695# define gzoffset gzoffset64 1695# define gzoffset gzoffset64
1696# define adler32_combine adler32_combine64 1696# define adler32_combine adler32_combine64
1697# define crc32_combine crc32_combine64 1697# define crc32_combine crc32_combine64
1698# endif 1698# endif
1699# ifndef Z_LARGE64 1699# ifndef Z_LARGE64
1700 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 1700 ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1701 ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); 1701 ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
1702 ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); 1702 ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
1703 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); 1703 ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
1704 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 1704 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
1705 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 1705 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
1706# endif 1706# endif
1707#else 1707#else
1708 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); 1708 ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
1709 ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); 1709 ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
1710 ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); 1710 ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
1711 ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); 1711 ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
1712 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1712 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1713 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1713 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1714#endif 1714#endif
1715 1715
1716#else /* Z_SOLO */ 1716#else /* Z_SOLO */
1717 1717
1718 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); 1718 ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1719 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); 1719 ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1720 1720
1721#endif /* !Z_SOLO */ 1721#endif /* !Z_SOLO */
1722 1722
1723/* hack for buggy compilers */ 1723/* hack for buggy compilers */
1724#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) 1724#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1725 struct internal_state {int dummy;}; 1725 struct internal_state {int dummy;};
1726#endif 1726#endif
1727 1727
1728/* undocumented functions */ 1728/* undocumented functions */
1729ZEXTERN const char * ZEXPORT zError OF((int)); 1729ZEXTERN const char * ZEXPORT zError OF((int));
1730ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); 1730ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1731ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); 1731ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
1732ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); 1732ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1733ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); 1733ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
1734ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); 1734ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1735#if defined(_WIN32) && !defined(Z_SOLO) 1735#if defined(_WIN32) && !defined(Z_SOLO)
1736ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, 1736ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
1737 const char *mode)); 1737 const char *mode));
1738#endif 1738#endif
1739 1739
1740#ifdef __cplusplus 1740#ifdef __cplusplus
1741} 1741}
1742#endif 1742#endif
1743 1743
1744#endif /* ZLIB_H */ 1744#endif /* ZLIB_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.c b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.c
index 09f129c..fba73b7 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.c
@@ -1,324 +1,324 @@
1/* zutil.c -- target dependent utility functions for the compression library 1/* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. 2 * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* @(#) $Id$ */ 6/* @(#) $Id$ */
7 7
8#include "zutil.h" 8#include "zutil.h"
9#ifndef Z_SOLO 9#ifndef Z_SOLO
10# include "gzguts.h" 10# include "gzguts.h"
11#endif 11#endif
12 12
13#ifndef NO_DUMMY_DECL 13#ifndef NO_DUMMY_DECL
14struct internal_state {int dummy;}; /* for buggy compilers */ 14struct internal_state {int dummy;}; /* for buggy compilers */
15#endif 15#endif
16 16
17const char * const z_errmsg[10] = { 17const char * const z_errmsg[10] = {
18"need dictionary", /* Z_NEED_DICT 2 */ 18"need dictionary", /* Z_NEED_DICT 2 */
19"stream end", /* Z_STREAM_END 1 */ 19"stream end", /* Z_STREAM_END 1 */
20"", /* Z_OK 0 */ 20"", /* Z_OK 0 */
21"file error", /* Z_ERRNO (-1) */ 21"file error", /* Z_ERRNO (-1) */
22"stream error", /* Z_STREAM_ERROR (-2) */ 22"stream error", /* Z_STREAM_ERROR (-2) */
23"data error", /* Z_DATA_ERROR (-3) */ 23"data error", /* Z_DATA_ERROR (-3) */
24"insufficient memory", /* Z_MEM_ERROR (-4) */ 24"insufficient memory", /* Z_MEM_ERROR (-4) */
25"buffer error", /* Z_BUF_ERROR (-5) */ 25"buffer error", /* Z_BUF_ERROR (-5) */
26"incompatible version",/* Z_VERSION_ERROR (-6) */ 26"incompatible version",/* Z_VERSION_ERROR (-6) */
27""}; 27""};
28 28
29 29
30const char * ZEXPORT zlibVersion() 30const char * ZEXPORT zlibVersion()
31{ 31{
32 return ZLIB_VERSION; 32 return ZLIB_VERSION;
33} 33}
34 34
35uLong ZEXPORT zlibCompileFlags() 35uLong ZEXPORT zlibCompileFlags()
36{ 36{
37 uLong flags; 37 uLong flags;
38 38
39 flags = 0; 39 flags = 0;
40 switch ((int)(sizeof(uInt))) { 40 switch ((int)(sizeof(uInt))) {
41 case 2: break; 41 case 2: break;
42 case 4: flags += 1; break; 42 case 4: flags += 1; break;
43 case 8: flags += 2; break; 43 case 8: flags += 2; break;
44 default: flags += 3; 44 default: flags += 3;
45 } 45 }
46 switch ((int)(sizeof(uLong))) { 46 switch ((int)(sizeof(uLong))) {
47 case 2: break; 47 case 2: break;
48 case 4: flags += 1 << 2; break; 48 case 4: flags += 1 << 2; break;
49 case 8: flags += 2 << 2; break; 49 case 8: flags += 2 << 2; break;
50 default: flags += 3 << 2; 50 default: flags += 3 << 2;
51 } 51 }
52 switch ((int)(sizeof(voidpf))) { 52 switch ((int)(sizeof(voidpf))) {
53 case 2: break; 53 case 2: break;
54 case 4: flags += 1 << 4; break; 54 case 4: flags += 1 << 4; break;
55 case 8: flags += 2 << 4; break; 55 case 8: flags += 2 << 4; break;
56 default: flags += 3 << 4; 56 default: flags += 3 << 4;
57 } 57 }
58 switch ((int)(sizeof(z_off_t))) { 58 switch ((int)(sizeof(z_off_t))) {
59 case 2: break; 59 case 2: break;
60 case 4: flags += 1 << 6; break; 60 case 4: flags += 1 << 6; break;
61 case 8: flags += 2 << 6; break; 61 case 8: flags += 2 << 6; break;
62 default: flags += 3 << 6; 62 default: flags += 3 << 6;
63 } 63 }
64#ifdef DEBUG 64#ifdef DEBUG
65 flags += 1 << 8; 65 flags += 1 << 8;
66#endif 66#endif
67#if defined(ASMV) || defined(ASMINF) 67#if defined(ASMV) || defined(ASMINF)
68 flags += 1 << 9; 68 flags += 1 << 9;
69#endif 69#endif
70#ifdef ZLIB_WINAPI 70#ifdef ZLIB_WINAPI
71 flags += 1 << 10; 71 flags += 1 << 10;
72#endif 72#endif
73#ifdef BUILDFIXED 73#ifdef BUILDFIXED
74 flags += 1 << 12; 74 flags += 1 << 12;
75#endif 75#endif
76#ifdef DYNAMIC_CRC_TABLE 76#ifdef DYNAMIC_CRC_TABLE
77 flags += 1 << 13; 77 flags += 1 << 13;
78#endif 78#endif
79#ifdef NO_GZCOMPRESS 79#ifdef NO_GZCOMPRESS
80 flags += 1L << 16; 80 flags += 1L << 16;
81#endif 81#endif
82#ifdef NO_GZIP 82#ifdef NO_GZIP
83 flags += 1L << 17; 83 flags += 1L << 17;
84#endif 84#endif
85#ifdef PKZIP_BUG_WORKAROUND 85#ifdef PKZIP_BUG_WORKAROUND
86 flags += 1L << 20; 86 flags += 1L << 20;
87#endif 87#endif
88#ifdef FASTEST 88#ifdef FASTEST
89 flags += 1L << 21; 89 flags += 1L << 21;
90#endif 90#endif
91#if defined(STDC) || defined(Z_HAVE_STDARG_H) 91#if defined(STDC) || defined(Z_HAVE_STDARG_H)
92# ifdef NO_vsnprintf 92# ifdef NO_vsnprintf
93 flags += 1L << 25; 93 flags += 1L << 25;
94# ifdef HAS_vsprintf_void 94# ifdef HAS_vsprintf_void
95 flags += 1L << 26; 95 flags += 1L << 26;
96# endif 96# endif
97# else 97# else
98# ifdef HAS_vsnprintf_void 98# ifdef HAS_vsnprintf_void
99 flags += 1L << 26; 99 flags += 1L << 26;
100# endif 100# endif
101# endif 101# endif
102#else 102#else
103 flags += 1L << 24; 103 flags += 1L << 24;
104# ifdef NO_snprintf 104# ifdef NO_snprintf
105 flags += 1L << 25; 105 flags += 1L << 25;
106# ifdef HAS_sprintf_void 106# ifdef HAS_sprintf_void
107 flags += 1L << 26; 107 flags += 1L << 26;
108# endif 108# endif
109# else 109# else
110# ifdef HAS_snprintf_void 110# ifdef HAS_snprintf_void
111 flags += 1L << 26; 111 flags += 1L << 26;
112# endif 112# endif
113# endif 113# endif
114#endif 114#endif
115 return flags; 115 return flags;
116} 116}
117 117
118#ifdef DEBUG 118#ifdef DEBUG
119 119
120# ifndef verbose 120# ifndef verbose
121# define verbose 0 121# define verbose 0
122# endif 122# endif
123int ZLIB_INTERNAL z_verbose = verbose; 123int ZLIB_INTERNAL z_verbose = verbose;
124 124
125void ZLIB_INTERNAL z_error (m) 125void ZLIB_INTERNAL z_error (m)
126 char *m; 126 char *m;
127{ 127{
128 fprintf(stderr, "%s\n", m); 128 fprintf(stderr, "%s\n", m);
129 exit(1); 129 exit(1);
130} 130}
131#endif 131#endif
132 132
133/* exported to allow conversion of error code to string for compress() and 133/* exported to allow conversion of error code to string for compress() and
134 * uncompress() 134 * uncompress()
135 */ 135 */
136const char * ZEXPORT zError(err) 136const char * ZEXPORT zError(err)
137 int err; 137 int err;
138{ 138{
139 return ERR_MSG(err); 139 return ERR_MSG(err);
140} 140}
141 141
142#if defined(_WIN32_WCE) 142#if defined(_WIN32_WCE)
143 /* The Microsoft C Run-Time Library for Windows CE doesn't have 143 /* The Microsoft C Run-Time Library for Windows CE doesn't have
144 * errno. We define it as a global variable to simplify porting. 144 * errno. We define it as a global variable to simplify porting.
145 * Its value is always 0 and should not be used. 145 * Its value is always 0 and should not be used.
146 */ 146 */
147 int errno = 0; 147 int errno = 0;
148#endif 148#endif
149 149
150#ifndef HAVE_MEMCPY 150#ifndef HAVE_MEMCPY
151 151
152void ZLIB_INTERNAL zmemcpy(dest, source, len) 152void ZLIB_INTERNAL zmemcpy(dest, source, len)
153 Bytef* dest; 153 Bytef* dest;
154 const Bytef* source; 154 const Bytef* source;
155 uInt len; 155 uInt len;
156{ 156{
157 if (len == 0) return; 157 if (len == 0) return;
158 do { 158 do {
159 *dest++ = *source++; /* ??? to be unrolled */ 159 *dest++ = *source++; /* ??? to be unrolled */
160 } while (--len != 0); 160 } while (--len != 0);
161} 161}
162 162
163int ZLIB_INTERNAL zmemcmp(s1, s2, len) 163int ZLIB_INTERNAL zmemcmp(s1, s2, len)
164 const Bytef* s1; 164 const Bytef* s1;
165 const Bytef* s2; 165 const Bytef* s2;
166 uInt len; 166 uInt len;
167{ 167{
168 uInt j; 168 uInt j;
169 169
170 for (j = 0; j < len; j++) { 170 for (j = 0; j < len; j++) {
171 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 171 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
172 } 172 }
173 return 0; 173 return 0;
174} 174}
175 175
176void ZLIB_INTERNAL zmemzero(dest, len) 176void ZLIB_INTERNAL zmemzero(dest, len)
177 Bytef* dest; 177 Bytef* dest;
178 uInt len; 178 uInt len;
179{ 179{
180 if (len == 0) return; 180 if (len == 0) return;
181 do { 181 do {
182 *dest++ = 0; /* ??? to be unrolled */ 182 *dest++ = 0; /* ??? to be unrolled */
183 } while (--len != 0); 183 } while (--len != 0);
184} 184}
185#endif 185#endif
186 186
187#ifndef Z_SOLO 187#ifndef Z_SOLO
188 188
189#ifdef SYS16BIT 189#ifdef SYS16BIT
190 190
191#ifdef __TURBOC__ 191#ifdef __TURBOC__
192/* Turbo C in 16-bit mode */ 192/* Turbo C in 16-bit mode */
193 193
194# define MY_ZCALLOC 194# define MY_ZCALLOC
195 195
196/* Turbo C malloc() does not allow dynamic allocation of 64K bytes 196/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
197 * and farmalloc(64K) returns a pointer with an offset of 8, so we 197 * and farmalloc(64K) returns a pointer with an offset of 8, so we
198 * must fix the pointer. Warning: the pointer must be put back to its 198 * must fix the pointer. Warning: the pointer must be put back to its
199 * original form in order to free it, use zcfree(). 199 * original form in order to free it, use zcfree().
200 */ 200 */
201 201
202#define MAX_PTR 10 202#define MAX_PTR 10
203/* 10*64K = 640K */ 203/* 10*64K = 640K */
204 204
205local int next_ptr = 0; 205local int next_ptr = 0;
206 206
207typedef struct ptr_table_s { 207typedef struct ptr_table_s {
208 voidpf org_ptr; 208 voidpf org_ptr;
209 voidpf new_ptr; 209 voidpf new_ptr;
210} ptr_table; 210} ptr_table;
211 211
212local ptr_table table[MAX_PTR]; 212local ptr_table table[MAX_PTR];
213/* This table is used to remember the original form of pointers 213/* This table is used to remember the original form of pointers
214 * to large buffers (64K). Such pointers are normalized with a zero offset. 214 * to large buffers (64K). Such pointers are normalized with a zero offset.
215 * Since MSDOS is not a preemptive multitasking OS, this table is not 215 * Since MSDOS is not a preemptive multitasking OS, this table is not
216 * protected from concurrent access. This hack doesn't work anyway on 216 * protected from concurrent access. This hack doesn't work anyway on
217 * a protected system like OS/2. Use Microsoft C instead. 217 * a protected system like OS/2. Use Microsoft C instead.
218 */ 218 */
219 219
220voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 220voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
221{ 221{
222 voidpf buf = opaque; /* just to make some compilers happy */ 222 voidpf buf = opaque; /* just to make some compilers happy */
223 ulg bsize = (ulg)items*size; 223 ulg bsize = (ulg)items*size;
224 224
225 /* If we allocate less than 65520 bytes, we assume that farmalloc 225 /* If we allocate less than 65520 bytes, we assume that farmalloc
226 * will return a usable pointer which doesn't have to be normalized. 226 * will return a usable pointer which doesn't have to be normalized.
227 */ 227 */
228 if (bsize < 65520L) { 228 if (bsize < 65520L) {
229 buf = farmalloc(bsize); 229 buf = farmalloc(bsize);
230 if (*(ush*)&buf != 0) return buf; 230 if (*(ush*)&buf != 0) return buf;
231 } else { 231 } else {
232 buf = farmalloc(bsize + 16L); 232 buf = farmalloc(bsize + 16L);
233 } 233 }
234 if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 234 if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
235 table[next_ptr].org_ptr = buf; 235 table[next_ptr].org_ptr = buf;
236 236
237 /* Normalize the pointer to seg:0 */ 237 /* Normalize the pointer to seg:0 */
238 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 238 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
239 *(ush*)&buf = 0; 239 *(ush*)&buf = 0;
240 table[next_ptr++].new_ptr = buf; 240 table[next_ptr++].new_ptr = buf;
241 return buf; 241 return buf;
242} 242}
243 243
244void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 244void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
245{ 245{
246 int n; 246 int n;
247 if (*(ush*)&ptr != 0) { /* object < 64K */ 247 if (*(ush*)&ptr != 0) { /* object < 64K */
248 farfree(ptr); 248 farfree(ptr);
249 return; 249 return;
250 } 250 }
251 /* Find the original pointer */ 251 /* Find the original pointer */
252 for (n = 0; n < next_ptr; n++) { 252 for (n = 0; n < next_ptr; n++) {
253 if (ptr != table[n].new_ptr) continue; 253 if (ptr != table[n].new_ptr) continue;
254 254
255 farfree(table[n].org_ptr); 255 farfree(table[n].org_ptr);
256 while (++n < next_ptr) { 256 while (++n < next_ptr) {
257 table[n-1] = table[n]; 257 table[n-1] = table[n];
258 } 258 }
259 next_ptr--; 259 next_ptr--;
260 return; 260 return;
261 } 261 }
262 ptr = opaque; /* just to make some compilers happy */ 262 ptr = opaque; /* just to make some compilers happy */
263 Assert(0, "zcfree: ptr not found"); 263 Assert(0, "zcfree: ptr not found");
264} 264}
265 265
266#endif /* __TURBOC__ */ 266#endif /* __TURBOC__ */
267 267
268 268
269#ifdef M_I86 269#ifdef M_I86
270/* Microsoft C in 16-bit mode */ 270/* Microsoft C in 16-bit mode */
271 271
272# define MY_ZCALLOC 272# define MY_ZCALLOC
273 273
274#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 274#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
275# define _halloc halloc 275# define _halloc halloc
276# define _hfree hfree 276# define _hfree hfree
277#endif 277#endif
278 278
279voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 279voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
280{ 280{
281 if (opaque) opaque = 0; /* to make compiler happy */ 281 if (opaque) opaque = 0; /* to make compiler happy */
282 return _halloc((long)items, size); 282 return _halloc((long)items, size);
283} 283}
284 284
285void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 285void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
286{ 286{
287 if (opaque) opaque = 0; /* to make compiler happy */ 287 if (opaque) opaque = 0; /* to make compiler happy */
288 _hfree(ptr); 288 _hfree(ptr);
289} 289}
290 290
291#endif /* M_I86 */ 291#endif /* M_I86 */
292 292
293#endif /* SYS16BIT */ 293#endif /* SYS16BIT */
294 294
295 295
296#ifndef MY_ZCALLOC /* Any system without a special alloc function */ 296#ifndef MY_ZCALLOC /* Any system without a special alloc function */
297 297
298#ifndef STDC 298#ifndef STDC
299extern voidp malloc OF((uInt size)); 299extern voidp malloc OF((uInt size));
300extern voidp calloc OF((uInt items, uInt size)); 300extern voidp calloc OF((uInt items, uInt size));
301extern void free OF((voidpf ptr)); 301extern void free OF((voidpf ptr));
302#endif 302#endif
303 303
304voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 304voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
305 voidpf opaque; 305 voidpf opaque;
306 unsigned items; 306 unsigned items;
307 unsigned size; 307 unsigned size;
308{ 308{
309 if (opaque) items += size - size; /* make compiler happy */ 309 if (opaque) items += size - size; /* make compiler happy */
310 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 310 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
311 (voidpf)calloc(items, size); 311 (voidpf)calloc(items, size);
312} 312}
313 313
314void ZLIB_INTERNAL zcfree (opaque, ptr) 314void ZLIB_INTERNAL zcfree (opaque, ptr)
315 voidpf opaque; 315 voidpf opaque;
316 voidpf ptr; 316 voidpf ptr;
317{ 317{
318 free(ptr); 318 free(ptr);
319 if (opaque) return; /* make compiler happy */ 319 if (opaque) return; /* make compiler happy */
320} 320}
321 321
322#endif /* MY_ZCALLOC */ 322#endif /* MY_ZCALLOC */
323 323
324#endif /* !Z_SOLO */ 324#endif /* !Z_SOLO */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.h b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.h
index 2b98c1a..a133a91 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/zlib/zutil.h
@@ -1,252 +1,252 @@
1/* zutil.h -- internal interface and configuration of the compression library 1/* zutil.h -- internal interface and configuration of the compression library
2 * Copyright (C) 1995-2012 Jean-loup Gailly. 2 * Copyright (C) 1995-2012 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* WARNING: this file should *not* be used by applications. It is 6/* WARNING: this file should *not* be used by applications. It is
7 part of the implementation of the compression library and is 7 part of the implementation of the compression library and is
8 subject to change. Applications should only use zlib.h. 8 subject to change. Applications should only use zlib.h.
9 */ 9 */
10 10
11/* @(#) $Id$ */ 11/* @(#) $Id$ */
12 12
13#ifndef ZUTIL_H 13#ifndef ZUTIL_H
14#define ZUTIL_H 14#define ZUTIL_H
15 15
16#ifdef HAVE_HIDDEN 16#ifdef HAVE_HIDDEN
17# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
18#else 18#else
19# define ZLIB_INTERNAL 19# define ZLIB_INTERNAL
20#endif 20#endif
21 21
22#include "zlib.h" 22#include "zlib.h"
23 23
24#if defined(STDC) && !defined(Z_SOLO) 24#if defined(STDC) && !defined(Z_SOLO)
25# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 25# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26# include <stddef.h> 26# include <stddef.h>
27# endif 27# endif
28# include <string.h> 28# include <string.h>
29# include <stdlib.h> 29# include <stdlib.h>
30#endif 30#endif
31 31
32#ifdef Z_SOLO 32#ifdef Z_SOLO
33 typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 33 typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
34#endif 34#endif
35 35
36#ifndef local 36#ifndef local
37# define local static 37# define local static
38#endif 38#endif
39/* compile with -Dlocal if your debugger can't find static symbols */ 39/* compile with -Dlocal if your debugger can't find static symbols */
40 40
41typedef unsigned char uch; 41typedef unsigned char uch;
42typedef uch FAR uchf; 42typedef uch FAR uchf;
43typedef unsigned short ush; 43typedef unsigned short ush;
44typedef ush FAR ushf; 44typedef ush FAR ushf;
45typedef unsigned long ulg; 45typedef unsigned long ulg;
46 46
47extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 47extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
48/* (size given to avoid silly warnings with Visual C++) */ 48/* (size given to avoid silly warnings with Visual C++) */
49 49
50#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 50#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
51 51
52#define ERR_RETURN(strm,err) \ 52#define ERR_RETURN(strm,err) \
53 return (strm->msg = (char*)ERR_MSG(err), (err)) 53 return (strm->msg = (char*)ERR_MSG(err), (err))
54/* To be used only when the state is known to be valid */ 54/* To be used only when the state is known to be valid */
55 55
56 /* common constants */ 56 /* common constants */
57 57
58#ifndef DEF_WBITS 58#ifndef DEF_WBITS
59# define DEF_WBITS MAX_WBITS 59# define DEF_WBITS MAX_WBITS
60#endif 60#endif
61/* default windowBits for decompression. MAX_WBITS is for compression only */ 61/* default windowBits for decompression. MAX_WBITS is for compression only */
62 62
63#if MAX_MEM_LEVEL >= 8 63#if MAX_MEM_LEVEL >= 8
64# define DEF_MEM_LEVEL 8 64# define DEF_MEM_LEVEL 8
65#else 65#else
66# define DEF_MEM_LEVEL MAX_MEM_LEVEL 66# define DEF_MEM_LEVEL MAX_MEM_LEVEL
67#endif 67#endif
68/* default memLevel */ 68/* default memLevel */
69 69
70#define STORED_BLOCK 0 70#define STORED_BLOCK 0
71#define STATIC_TREES 1 71#define STATIC_TREES 1
72#define DYN_TREES 2 72#define DYN_TREES 2
73/* The three kinds of block type */ 73/* The three kinds of block type */
74 74
75#define MIN_MATCH 3 75#define MIN_MATCH 3
76#define MAX_MATCH 258 76#define MAX_MATCH 258
77/* The minimum and maximum match lengths */ 77/* The minimum and maximum match lengths */
78 78
79#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 79#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
80 80
81 /* target dependencies */ 81 /* target dependencies */
82 82
83#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 83#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
84# define OS_CODE 0x00 84# define OS_CODE 0x00
85# ifndef Z_SOLO 85# ifndef Z_SOLO
86# if defined(__TURBOC__) || defined(__BORLANDC__) 86# if defined(__TURBOC__) || defined(__BORLANDC__)
87# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 87# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
88 /* Allow compilation with ANSI keywords only enabled */ 88 /* Allow compilation with ANSI keywords only enabled */
89 void _Cdecl farfree( void *block ); 89 void _Cdecl farfree( void *block );
90 void *_Cdecl farmalloc( unsigned long nbytes ); 90 void *_Cdecl farmalloc( unsigned long nbytes );
91# else 91# else
92# include <alloc.h> 92# include <alloc.h>
93# endif 93# endif
94# else /* MSC or DJGPP */ 94# else /* MSC or DJGPP */
95# include <malloc.h> 95# include <malloc.h>
96# endif 96# endif
97# endif 97# endif
98#endif 98#endif
99 99
100#ifdef AMIGA 100#ifdef AMIGA
101# define OS_CODE 0x01 101# define OS_CODE 0x01
102#endif 102#endif
103 103
104#if defined(VAXC) || defined(VMS) 104#if defined(VAXC) || defined(VMS)
105# define OS_CODE 0x02 105# define OS_CODE 0x02
106# define F_OPEN(name, mode) \ 106# define F_OPEN(name, mode) \
107 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 107 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
108#endif 108#endif
109 109
110#if defined(ATARI) || defined(atarist) 110#if defined(ATARI) || defined(atarist)
111# define OS_CODE 0x05 111# define OS_CODE 0x05
112#endif 112#endif
113 113
114#ifdef OS2 114#ifdef OS2
115# define OS_CODE 0x06 115# define OS_CODE 0x06
116# if defined(M_I86) && !defined(Z_SOLO) 116# if defined(M_I86) && !defined(Z_SOLO)
117# include <malloc.h> 117# include <malloc.h>
118# endif 118# endif
119#endif 119#endif
120 120
121#if defined(MACOS) || defined(TARGET_OS_MAC) 121#if defined(MACOS) || defined(TARGET_OS_MAC)
122# define OS_CODE 0x07 122# define OS_CODE 0x07
123# ifndef Z_SOLO 123# ifndef Z_SOLO
124# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 124# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
125# include <unix.h> /* for fdopen */ 125# include <unix.h> /* for fdopen */
126# else 126# else
127# ifndef fdopen 127# ifndef fdopen
128# define fdopen(fd,mode) NULL /* No fdopen() */ 128# define fdopen(fd,mode) NULL /* No fdopen() */
129# endif 129# endif
130# endif 130# endif
131# endif 131# endif
132#endif 132#endif
133 133
134#ifdef TOPS20 134#ifdef TOPS20
135# define OS_CODE 0x0a 135# define OS_CODE 0x0a
136#endif 136#endif
137 137
138#ifdef WIN32 138#ifdef WIN32
139# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 139# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
140# define OS_CODE 0x0b 140# define OS_CODE 0x0b
141# endif 141# endif
142#endif 142#endif
143 143
144#ifdef __50SERIES /* Prime/PRIMOS */ 144#ifdef __50SERIES /* Prime/PRIMOS */
145# define OS_CODE 0x0f 145# define OS_CODE 0x0f
146#endif 146#endif
147 147
148#if defined(_BEOS_) || defined(RISCOS) 148#if defined(_BEOS_) || defined(RISCOS)
149# define fdopen(fd,mode) NULL /* No fdopen() */ 149# define fdopen(fd,mode) NULL /* No fdopen() */
150#endif 150#endif
151 151
152#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 152#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
153# if defined(_WIN32_WCE) 153# if defined(_WIN32_WCE)
154# define fdopen(fd,mode) NULL /* No fdopen() */ 154# define fdopen(fd,mode) NULL /* No fdopen() */
155# ifndef _PTRDIFF_T_DEFINED 155# ifndef _PTRDIFF_T_DEFINED
156 typedef int ptrdiff_t; 156 typedef int ptrdiff_t;
157# define _PTRDIFF_T_DEFINED 157# define _PTRDIFF_T_DEFINED
158# endif 158# endif
159# else 159# else
160# define fdopen(fd,type) _fdopen(fd,type) 160# define fdopen(fd,type) _fdopen(fd,type)
161# endif 161# endif
162#endif 162#endif
163 163
164#if defined(__BORLANDC__) && !defined(MSDOS) 164#if defined(__BORLANDC__) && !defined(MSDOS)
165 #pragma warn -8004 165 #pragma warn -8004
166 #pragma warn -8008 166 #pragma warn -8008
167 #pragma warn -8066 167 #pragma warn -8066
168#endif 168#endif
169 169
170/* provide prototypes for these when building zlib without LFS */ 170/* provide prototypes for these when building zlib without LFS */
171#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 171#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
172 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 172 ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
173 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 173 ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
174#endif 174#endif
175 175
176 /* common defaults */ 176 /* common defaults */
177 177
178#ifndef OS_CODE 178#ifndef OS_CODE
179# define OS_CODE 0x03 /* assume Unix */ 179# define OS_CODE 0x03 /* assume Unix */
180#endif 180#endif
181 181
182#ifndef F_OPEN 182#ifndef F_OPEN
183# define F_OPEN(name, mode) fopen((name), (mode)) 183# define F_OPEN(name, mode) fopen((name), (mode))
184#endif 184#endif
185 185
186 /* functions */ 186 /* functions */
187 187
188#if defined(pyr) || defined(Z_SOLO) 188#if defined(pyr) || defined(Z_SOLO)
189# define NO_MEMCPY 189# define NO_MEMCPY
190#endif 190#endif
191#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 191#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
192 /* Use our own functions for small and medium model with MSC <= 5.0. 192 /* Use our own functions for small and medium model with MSC <= 5.0.
193 * You may have to use the same strategy for Borland C (untested). 193 * You may have to use the same strategy for Borland C (untested).
194 * The __SC__ check is for Symantec. 194 * The __SC__ check is for Symantec.
195 */ 195 */
196# define NO_MEMCPY 196# define NO_MEMCPY
197#endif 197#endif
198#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 198#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
199# define HAVE_MEMCPY 199# define HAVE_MEMCPY
200#endif 200#endif
201#ifdef HAVE_MEMCPY 201#ifdef HAVE_MEMCPY
202# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 202# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
203# define zmemcpy _fmemcpy 203# define zmemcpy _fmemcpy
204# define zmemcmp _fmemcmp 204# define zmemcmp _fmemcmp
205# define zmemzero(dest, len) _fmemset(dest, 0, len) 205# define zmemzero(dest, len) _fmemset(dest, 0, len)
206# else 206# else
207# define zmemcpy memcpy 207# define zmemcpy memcpy
208# define zmemcmp memcmp 208# define zmemcmp memcmp
209# define zmemzero(dest, len) memset(dest, 0, len) 209# define zmemzero(dest, len) memset(dest, 0, len)
210# endif 210# endif
211#else 211#else
212 void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 212 void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
213 int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 213 int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
214 void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 214 void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
215#endif 215#endif
216 216
217/* Diagnostic functions */ 217/* Diagnostic functions */
218#ifdef DEBUG 218#ifdef DEBUG
219# include <stdio.h> 219# include <stdio.h>
220 extern int ZLIB_INTERNAL z_verbose; 220 extern int ZLIB_INTERNAL z_verbose;
221 extern void ZLIB_INTERNAL z_error OF((char *m)); 221 extern void ZLIB_INTERNAL z_error OF((char *m));
222# define Assert(cond,msg) {if(!(cond)) z_error(msg);} 222# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
223# define Trace(x) {if (z_verbose>=0) fprintf x ;} 223# define Trace(x) {if (z_verbose>=0) fprintf x ;}
224# define Tracev(x) {if (z_verbose>0) fprintf x ;} 224# define Tracev(x) {if (z_verbose>0) fprintf x ;}
225# define Tracevv(x) {if (z_verbose>1) fprintf x ;} 225# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
226# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 226# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
227# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 227# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
228#else 228#else
229# define Assert(cond,msg) 229# define Assert(cond,msg)
230# define Trace(x) 230# define Trace(x)
231# define Tracev(x) 231# define Tracev(x)
232# define Tracevv(x) 232# define Tracevv(x)
233# define Tracec(c,x) 233# define Tracec(c,x)
234# define Tracecv(c,x) 234# define Tracecv(c,x)
235#endif 235#endif
236 236
237#ifndef Z_SOLO 237#ifndef Z_SOLO
238 voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 238 voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
239 unsigned size)); 239 unsigned size));
240 void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 240 void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
241#endif 241#endif
242 242
243#define ZALLOC(strm, items, size) \ 243#define ZALLOC(strm, items, size) \
244 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 244 (*((strm)->zalloc))((strm)->opaque, (items), (size))
245#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 245#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
246#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 246#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
247 247
248/* Reverse the bytes in a 32-bit value */ 248/* Reverse the bytes in a 32-bit value */
249#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 249#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
250 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 250 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
251 251
252#endif /* ZUTIL_H */ 252#endif /* ZUTIL_H */