mirror of
https://github.com/ZDoom/zdbsp.git
synced 2024-11-21 19:32:31 +00:00
- Updated ZDBSP to zlib 1.2.7.
SVN r3984 (trunk)
This commit is contained in:
parent
8e785ba3b1
commit
b53fe459f9
13 changed files with 1779 additions and 946 deletions
|
@ -13,6 +13,7 @@ add_library( z
|
||||||
zutil.c
|
zutil.c
|
||||||
crc32.h
|
crc32.h
|
||||||
deflate.h
|
deflate.h
|
||||||
|
gzguts.h
|
||||||
trees.h
|
trees.h
|
||||||
zconf.h
|
zconf.h
|
||||||
zlib.h
|
zlib.h
|
||||||
|
|
102
zlib/adler32.c
102
zlib/adler32.c
|
@ -1,14 +1,17 @@
|
||||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||||
* Copyright (C) 1995-2004 Mark Adler
|
* Copyright (C) 1995-2011 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#define ZLIB_INTERNAL
|
#include "zutil.h"
|
||||||
#include "zlib.h"
|
|
||||||
|
|
||||||
#define BASE 65521UL /* largest prime smaller than 65536 */
|
#define local static
|
||||||
|
|
||||||
|
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
|
||||||
|
|
||||||
|
#define BASE 65521 /* largest prime smaller than 65536 */
|
||||||
#define NMAX 5552
|
#define NMAX 5552
|
||||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||||
|
|
||||||
|
@ -18,39 +21,44 @@
|
||||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||||
|
|
||||||
/* use NO_DIVIDE if your processor does not do division in hardware */
|
/* use NO_DIVIDE if your processor does not do division in hardware --
|
||||||
|
try it both ways to see which is faster */
|
||||||
#ifdef NO_DIVIDE
|
#ifdef NO_DIVIDE
|
||||||
# define MOD(a) \
|
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
|
||||||
|
(thank you to John Reiser for pointing this out) */
|
||||||
|
# define CHOP(a) \
|
||||||
do { \
|
do { \
|
||||||
if (a >= (BASE << 16)) a -= (BASE << 16); \
|
unsigned long tmp = a >> 16; \
|
||||||
if (a >= (BASE << 15)) a -= (BASE << 15); \
|
a &= 0xffffUL; \
|
||||||
if (a >= (BASE << 14)) a -= (BASE << 14); \
|
a += (tmp << 4) - tmp; \
|
||||||
if (a >= (BASE << 13)) a -= (BASE << 13); \
|
} while (0)
|
||||||
if (a >= (BASE << 12)) a -= (BASE << 12); \
|
# define MOD28(a) \
|
||||||
if (a >= (BASE << 11)) a -= (BASE << 11); \
|
do { \
|
||||||
if (a >= (BASE << 10)) a -= (BASE << 10); \
|
CHOP(a); \
|
||||||
if (a >= (BASE << 9)) a -= (BASE << 9); \
|
|
||||||
if (a >= (BASE << 8)) a -= (BASE << 8); \
|
|
||||||
if (a >= (BASE << 7)) a -= (BASE << 7); \
|
|
||||||
if (a >= (BASE << 6)) a -= (BASE << 6); \
|
|
||||||
if (a >= (BASE << 5)) a -= (BASE << 5); \
|
|
||||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
|
||||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
|
||||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
|
||||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
|
||||||
if (a >= BASE) a -= BASE; \
|
if (a >= BASE) a -= BASE; \
|
||||||
} while (0)
|
} while (0)
|
||||||
# define MOD4(a) \
|
# define MOD(a) \
|
||||||
do { \
|
do { \
|
||||||
if (a >= (BASE << 4)) a -= (BASE << 4); \
|
CHOP(a); \
|
||||||
if (a >= (BASE << 3)) a -= (BASE << 3); \
|
MOD28(a); \
|
||||||
if (a >= (BASE << 2)) a -= (BASE << 2); \
|
} while (0)
|
||||||
if (a >= (BASE << 1)) a -= (BASE << 1); \
|
# define MOD63(a) \
|
||||||
|
do { /* this assumes a is not negative */ \
|
||||||
|
z_off64_t tmp = a >> 32; \
|
||||||
|
a &= 0xffffffffL; \
|
||||||
|
a += (tmp << 8) - (tmp << 5) + tmp; \
|
||||||
|
tmp = a >> 16; \
|
||||||
|
a &= 0xffffL; \
|
||||||
|
a += (tmp << 4) - tmp; \
|
||||||
|
tmp = a >> 16; \
|
||||||
|
a &= 0xffffL; \
|
||||||
|
a += (tmp << 4) - tmp; \
|
||||||
if (a >= BASE) a -= BASE; \
|
if (a >= BASE) a -= BASE; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
# define MOD(a) a %= BASE
|
# define MOD(a) a %= BASE
|
||||||
# define MOD4(a) a %= BASE
|
# define MOD28(a) a %= BASE
|
||||||
|
# define MOD63(a) a %= BASE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
@ -89,7 +97,7 @@ uLong ZEXPORT adler32(adler, buf, len)
|
||||||
}
|
}
|
||||||
if (adler >= BASE)
|
if (adler >= BASE)
|
||||||
adler -= BASE;
|
adler -= BASE;
|
||||||
MOD4(sum2); /* only added so many BASE's */
|
MOD28(sum2); /* only added so many BASE's */
|
||||||
return adler | (sum2 << 16);
|
return adler | (sum2 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,25 +133,47 @@ uLong ZEXPORT adler32(adler, buf, len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
local uLong adler32_combine_(adler1, adler2, len2)
|
||||||
uLong adler1;
|
uLong adler1;
|
||||||
uLong adler2;
|
uLong adler2;
|
||||||
z_off_t len2;
|
z_off64_t len2;
|
||||||
{
|
{
|
||||||
unsigned long sum1;
|
unsigned long sum1;
|
||||||
unsigned long sum2;
|
unsigned long sum2;
|
||||||
unsigned rem;
|
unsigned rem;
|
||||||
|
|
||||||
|
/* for negative len, return invalid adler32 as a clue for debugging */
|
||||||
|
if (len2 < 0)
|
||||||
|
return 0xffffffffUL;
|
||||||
|
|
||||||
/* the derivation of this formula is left as an exercise for the reader */
|
/* the derivation of this formula is left as an exercise for the reader */
|
||||||
rem = (unsigned)(len2 % BASE);
|
MOD63(len2); /* assumes len2 >= 0 */
|
||||||
|
rem = (unsigned)len2;
|
||||||
sum1 = adler1 & 0xffff;
|
sum1 = adler1 & 0xffff;
|
||||||
sum2 = rem * sum1;
|
sum2 = rem * sum1;
|
||||||
MOD(sum2);
|
MOD(sum2);
|
||||||
sum1 += (adler2 & 0xffff) + BASE - 1;
|
sum1 += (adler2 & 0xffff) + BASE - 1;
|
||||||
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
|
||||||
if (sum1 > BASE) sum1 -= BASE;
|
if (sum1 >= BASE) sum1 -= BASE;
|
||||||
if (sum1 > BASE) sum1 -= BASE;
|
if (sum1 >= BASE) sum1 -= BASE;
|
||||||
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
|
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
|
||||||
if (sum2 > BASE) sum2 -= BASE;
|
if (sum2 >= BASE) sum2 -= BASE;
|
||||||
return sum1 | (sum2 << 16);
|
return sum1 | (sum2 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
|
||||||
|
uLong adler1;
|
||||||
|
uLong adler2;
|
||||||
|
z_off_t len2;
|
||||||
|
{
|
||||||
|
return adler32_combine_(adler1, adler2, len2);
|
||||||
|
}
|
||||||
|
|
||||||
|
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
|
||||||
|
uLong adler1;
|
||||||
|
uLong adler2;
|
||||||
|
z_off64_t len2;
|
||||||
|
{
|
||||||
|
return adler32_combine_(adler1, adler2, len2);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* compress.c -- compress a memory buffer
|
/* compress.c -- compress a memory buffer
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -75,5 +75,6 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
|
||||||
uLong ZEXPORT compressBound (sourceLen)
|
uLong ZEXPORT compressBound (sourceLen)
|
||||||
uLong sourceLen;
|
uLong sourceLen;
|
||||||
{
|
{
|
||||||
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
|
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||||
|
(sourceLen >> 25) + 13;
|
||||||
}
|
}
|
||||||
|
|
112
zlib/crc32.c
112
zlib/crc32.c
|
@ -1,5 +1,5 @@
|
||||||
/* crc32.c -- compute the CRC-32 of a data stream
|
/* crc32.c -- compute the CRC-32 of a data stream
|
||||||
* Copyright (C) 1995-2005 Mark Adler
|
* Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*
|
*
|
||||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||||
|
@ -17,6 +17,8 @@
|
||||||
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||||
first call get_crc_table() to initialize the tables before allowing more than
|
first call get_crc_table() to initialize the tables before allowing more than
|
||||||
one thread to use crc32().
|
one thread to use crc32().
|
||||||
|
|
||||||
|
DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
|
@ -30,31 +32,11 @@
|
||||||
|
|
||||||
#define local static
|
#define local static
|
||||||
|
|
||||||
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
|
||||||
#ifndef NOBYFOUR
|
|
||||||
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
|
||||||
# include <limits.h>
|
|
||||||
# define BYFOUR
|
|
||||||
# if (UINT_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned int u4;
|
|
||||||
# else
|
|
||||||
# if (ULONG_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned long u4;
|
|
||||||
# else
|
|
||||||
# if (USHRT_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned short u4;
|
|
||||||
# else
|
|
||||||
# undef BYFOUR /* can't find a four-byte integer type! */
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# endif /* STDC */
|
|
||||||
#endif /* !NOBYFOUR */
|
|
||||||
|
|
||||||
/* Definitions for doing the crc four data bytes at a time. */
|
/* Definitions for doing the crc four data bytes at a time. */
|
||||||
|
#if !defined(NOBYFOUR) && defined(Z_U4)
|
||||||
|
# define BYFOUR
|
||||||
|
#endif
|
||||||
#ifdef BYFOUR
|
#ifdef BYFOUR
|
||||||
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
|
|
||||||
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
|
||||||
local unsigned long crc32_little OF((unsigned long,
|
local unsigned long crc32_little OF((unsigned long,
|
||||||
const unsigned char FAR *, unsigned));
|
const unsigned char FAR *, unsigned));
|
||||||
local unsigned long crc32_big OF((unsigned long,
|
local unsigned long crc32_big OF((unsigned long,
|
||||||
|
@ -68,14 +50,16 @@
|
||||||
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
local unsigned long gf2_matrix_times OF((unsigned long *mat,
|
||||||
unsigned long vec));
|
unsigned long vec));
|
||||||
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
|
||||||
|
local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
|
||||||
|
|
||||||
|
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
|
||||||
local volatile int crc_table_empty = 1;
|
local volatile int crc_table_empty = 1;
|
||||||
local unsigned long FAR crc_table[TBLS][256];
|
local z_crc_t FAR crc_table[TBLS][256];
|
||||||
local void make_crc_table OF((void));
|
local void make_crc_table OF((void));
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
local void write_table OF((FILE *, const unsigned long FAR *));
|
local void write_table OF((FILE *, const z_crc_t FAR *));
|
||||||
#endif /* MAKECRCH */
|
#endif /* MAKECRCH */
|
||||||
/*
|
/*
|
||||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||||
|
@ -105,9 +89,9 @@ local void make_crc_table OF((void));
|
||||||
*/
|
*/
|
||||||
local void make_crc_table()
|
local void make_crc_table()
|
||||||
{
|
{
|
||||||
unsigned long c;
|
z_crc_t c;
|
||||||
int n, k;
|
int n, k;
|
||||||
unsigned long poly; /* polynomial exclusive-or pattern */
|
z_crc_t poly; /* polynomial exclusive-or pattern */
|
||||||
/* terms of polynomial defining this crc (except x^32): */
|
/* terms of polynomial defining this crc (except x^32): */
|
||||||
static volatile int first = 1; /* flag to limit concurrent making */
|
static volatile int first = 1; /* flag to limit concurrent making */
|
||||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||||
|
@ -119,13 +103,13 @@ local void make_crc_table()
|
||||||
first = 0;
|
first = 0;
|
||||||
|
|
||||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||||
poly = 0UL;
|
poly = 0;
|
||||||
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
|
||||||
poly |= 1UL << (31 - p[n]);
|
poly |= (z_crc_t)1 << (31 - p[n]);
|
||||||
|
|
||||||
/* generate a crc for every 8-bit value */
|
/* generate a crc for every 8-bit value */
|
||||||
for (n = 0; n < 256; n++) {
|
for (n = 0; n < 256; n++) {
|
||||||
c = (unsigned long)n;
|
c = (z_crc_t)n;
|
||||||
for (k = 0; k < 8; k++)
|
for (k = 0; k < 8; k++)
|
||||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||||
crc_table[0][n] = c;
|
crc_table[0][n] = c;
|
||||||
|
@ -136,11 +120,11 @@ local void make_crc_table()
|
||||||
and then the byte reversal of those as well as the first table */
|
and then the byte reversal of those as well as the first table */
|
||||||
for (n = 0; n < 256; n++) {
|
for (n = 0; n < 256; n++) {
|
||||||
c = crc_table[0][n];
|
c = crc_table[0][n];
|
||||||
crc_table[4][n] = REV(c);
|
crc_table[4][n] = ZSWAP32(c);
|
||||||
for (k = 1; k < 4; k++) {
|
for (k = 1; k < 4; k++) {
|
||||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||||
crc_table[k][n] = c;
|
crc_table[k][n] = c;
|
||||||
crc_table[k + 4][n] = REV(c);
|
crc_table[k + 4][n] = ZSWAP32(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* BYFOUR */
|
#endif /* BYFOUR */
|
||||||
|
@ -162,7 +146,7 @@ local void make_crc_table()
|
||||||
if (out == NULL) return;
|
if (out == NULL) return;
|
||||||
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
||||||
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
||||||
fprintf(out, "local const unsigned long FAR ");
|
fprintf(out, "local const z_crc_t FAR ");
|
||||||
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
||||||
write_table(out, crc_table[0]);
|
write_table(out, crc_table[0]);
|
||||||
# ifdef BYFOUR
|
# ifdef BYFOUR
|
||||||
|
@ -182,12 +166,13 @@ local void make_crc_table()
|
||||||
#ifdef MAKECRCH
|
#ifdef MAKECRCH
|
||||||
local void write_table(out, table)
|
local void write_table(out, table)
|
||||||
FILE *out;
|
FILE *out;
|
||||||
const unsigned long FAR *table;
|
const z_crc_t FAR *table;
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
for (n = 0; n < 256; n++)
|
for (n = 0; n < 256; n++)
|
||||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
|
||||||
|
(unsigned long)(table[n]),
|
||||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||||
}
|
}
|
||||||
#endif /* MAKECRCH */
|
#endif /* MAKECRCH */
|
||||||
|
@ -202,13 +187,13 @@ local void write_table(out, table)
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
* This function can be used by asm versions of crc32()
|
* This function can be used by asm versions of crc32()
|
||||||
*/
|
*/
|
||||||
const unsigned long FAR * ZEXPORT get_crc_table()
|
const z_crc_t FAR * ZEXPORT get_crc_table()
|
||||||
{
|
{
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
if (crc_table_empty)
|
if (crc_table_empty)
|
||||||
make_crc_table();
|
make_crc_table();
|
||||||
#endif /* DYNAMIC_CRC_TABLE */
|
#endif /* DYNAMIC_CRC_TABLE */
|
||||||
return (const unsigned long FAR *)crc_table;
|
return (const z_crc_t FAR *)crc_table;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
@ -219,7 +204,7 @@ const unsigned long FAR * ZEXPORT get_crc_table()
|
||||||
unsigned long ZEXPORT crc32(crc, buf, len)
|
unsigned long ZEXPORT crc32(crc, buf, len)
|
||||||
unsigned long crc;
|
unsigned long crc;
|
||||||
const unsigned char FAR *buf;
|
const unsigned char FAR *buf;
|
||||||
unsigned len;
|
uInt len;
|
||||||
{
|
{
|
||||||
if (buf == Z_NULL) return 0UL;
|
if (buf == Z_NULL) return 0UL;
|
||||||
|
|
||||||
|
@ -230,7 +215,7 @@ unsigned long ZEXPORT crc32(crc, buf, len)
|
||||||
|
|
||||||
#ifdef BYFOUR
|
#ifdef BYFOUR
|
||||||
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
||||||
u4 endian;
|
z_crc_t endian;
|
||||||
|
|
||||||
endian = 1;
|
endian = 1;
|
||||||
if (*((unsigned char *)(&endian)))
|
if (*((unsigned char *)(&endian)))
|
||||||
|
@ -264,17 +249,17 @@ local unsigned long crc32_little(crc, buf, len)
|
||||||
const unsigned char FAR *buf;
|
const unsigned char FAR *buf;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
{
|
{
|
||||||
register u4 c;
|
register z_crc_t c;
|
||||||
register const u4 FAR *buf4;
|
register const z_crc_t FAR *buf4;
|
||||||
|
|
||||||
c = (u4)crc;
|
c = (z_crc_t)crc;
|
||||||
c = ~c;
|
c = ~c;
|
||||||
while (len && ((ptrdiff_t)buf & 3)) {
|
while (len && ((ptrdiff_t)buf & 3)) {
|
||||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||||
while (len >= 32) {
|
while (len >= 32) {
|
||||||
DOLIT32;
|
DOLIT32;
|
||||||
len -= 32;
|
len -= 32;
|
||||||
|
@ -304,17 +289,17 @@ local unsigned long crc32_big(crc, buf, len)
|
||||||
const unsigned char FAR *buf;
|
const unsigned char FAR *buf;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
{
|
{
|
||||||
register u4 c;
|
register z_crc_t c;
|
||||||
register const u4 FAR *buf4;
|
register const z_crc_t FAR *buf4;
|
||||||
|
|
||||||
c = REV((u4)crc);
|
c = ZSWAP32((z_crc_t)crc);
|
||||||
c = ~c;
|
c = ~c;
|
||||||
while (len && ((ptrdiff_t)buf & 3)) {
|
while (len && ((ptrdiff_t)buf & 3)) {
|
||||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)(const void FAR *)buf;
|
buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
|
||||||
buf4--;
|
buf4--;
|
||||||
while (len >= 32) {
|
while (len >= 32) {
|
||||||
DOBIG32;
|
DOBIG32;
|
||||||
|
@ -331,7 +316,7 @@ local unsigned long crc32_big(crc, buf, len)
|
||||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||||
} while (--len);
|
} while (--len);
|
||||||
c = ~c;
|
c = ~c;
|
||||||
return (unsigned long)(REV(c));
|
return (unsigned long)(ZSWAP32(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* BYFOUR */
|
#endif /* BYFOUR */
|
||||||
|
@ -367,22 +352,22 @@ local void gf2_matrix_square(square, mat)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
local uLong crc32_combine_(crc1, crc2, len2)
|
||||||
uLong crc1;
|
uLong crc1;
|
||||||
uLong crc2;
|
uLong crc2;
|
||||||
z_off_t len2;
|
z_off64_t len2;
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
unsigned long row;
|
unsigned long row;
|
||||||
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
|
||||||
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
|
||||||
|
|
||||||
/* degenerate case */
|
/* degenerate case (also disallow negative lengths) */
|
||||||
if (len2 == 0)
|
if (len2 <= 0)
|
||||||
return crc1;
|
return crc1;
|
||||||
|
|
||||||
/* put operator for one zero bit in odd */
|
/* put operator for one zero bit in odd */
|
||||||
odd[0] = 0xedb88320L; /* CRC-32 polynomial */
|
odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
|
||||||
row = 1;
|
row = 1;
|
||||||
for (n = 1; n < GF2_DIM; n++) {
|
for (n = 1; n < GF2_DIM; n++) {
|
||||||
odd[n] = row;
|
odd[n] = row;
|
||||||
|
@ -421,3 +406,20 @@ uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||||
crc1 ^= crc2;
|
crc1 ^= crc2;
|
||||||
return crc1;
|
return crc1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
uLong ZEXPORT crc32_combine(crc1, crc2, len2)
|
||||||
|
uLong crc1;
|
||||||
|
uLong crc2;
|
||||||
|
z_off_t len2;
|
||||||
|
{
|
||||||
|
return crc32_combine_(crc1, crc2, len2);
|
||||||
|
}
|
||||||
|
|
||||||
|
uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
|
||||||
|
uLong crc1;
|
||||||
|
uLong crc2;
|
||||||
|
z_off64_t len2;
|
||||||
|
{
|
||||||
|
return crc32_combine_(crc1, crc2, len2);
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Generated automatically by crc32.c
|
* Generated automatically by crc32.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
local const unsigned long FAR crc_table[TBLS][256] =
|
local const z_crc_t FAR crc_table[TBLS][256] =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
|
0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
|
||||||
|
|
513
zlib/deflate.c
513
zlib/deflate.c
|
@ -1,5 +1,5 @@
|
||||||
/* deflate.c -- compress data using the deflation algorithm
|
/* deflate.c -- compress data using the deflation algorithm
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
* Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
* REFERENCES
|
* REFERENCES
|
||||||
*
|
*
|
||||||
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
|
* Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
|
||||||
* Available in http://www.ietf.org/rfc/rfc1951.txt
|
* Available in http://tools.ietf.org/html/rfc1951
|
||||||
*
|
*
|
||||||
* A description of the Rabin and Karp algorithm is given in the book
|
* A description of the Rabin and Karp algorithm is given in the book
|
||||||
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
|
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
#include "deflate.h"
|
#include "deflate.h"
|
||||||
|
|
||||||
const char deflate_copyright[] =
|
const char deflate_copyright[] =
|
||||||
" deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
|
" deflate 1.2.7 Copyright 1995-2012 Jean-loup Gailly and Mark Adler ";
|
||||||
/*
|
/*
|
||||||
If you use the zlib library in a product, an acknowledgment is welcome
|
If you use the zlib library in a product, an acknowledgment is welcome
|
||||||
in the documentation of your product. If for some reason you cannot
|
in the documentation of your product. If for some reason you cannot
|
||||||
|
@ -79,19 +79,18 @@ local block_state deflate_fast OF((deflate_state *s, int flush));
|
||||||
#ifndef FASTEST
|
#ifndef FASTEST
|
||||||
local block_state deflate_slow OF((deflate_state *s, int flush));
|
local block_state deflate_slow OF((deflate_state *s, int flush));
|
||||||
#endif
|
#endif
|
||||||
|
local block_state deflate_rle OF((deflate_state *s, int flush));
|
||||||
|
local block_state deflate_huff OF((deflate_state *s, int flush));
|
||||||
local void lm_init OF((deflate_state *s));
|
local void lm_init OF((deflate_state *s));
|
||||||
local void putShortMSB OF((deflate_state *s, uInt b));
|
local void putShortMSB OF((deflate_state *s, uInt b));
|
||||||
local void flush_pending OF((z_streamp strm));
|
local void flush_pending OF((z_streamp strm));
|
||||||
local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
|
local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
|
||||||
#ifndef FASTEST
|
|
||||||
#ifdef ASMV
|
#ifdef ASMV
|
||||||
void match_init OF((void)); /* asm code initialization */
|
void match_init OF((void)); /* asm code initialization */
|
||||||
uInt longest_match OF((deflate_state *s, IPos cur_match));
|
uInt longest_match OF((deflate_state *s, IPos cur_match));
|
||||||
#else
|
#else
|
||||||
local uInt longest_match OF((deflate_state *s, IPos cur_match));
|
local uInt longest_match OF((deflate_state *s, IPos cur_match));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
local void check_match OF((deflate_state *s, IPos start, IPos match,
|
local void check_match OF((deflate_state *s, IPos start, IPos match,
|
||||||
|
@ -110,11 +109,6 @@ local void check_match OF((deflate_state *s, IPos start, IPos match,
|
||||||
#endif
|
#endif
|
||||||
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
|
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
|
||||||
|
|
||||||
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
|
||||||
/* Minimum amount of lookahead, except at the end of the input file.
|
|
||||||
* See deflate.c for comments about the MIN_MATCH+1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Values for max_lazy_match, good_match and max_chain_length, depending on
|
/* Values for max_lazy_match, good_match and max_chain_length, depending on
|
||||||
* the desired pack level (0..9). The values given below have been tuned to
|
* the desired pack level (0..9). The values given below have been tuned to
|
||||||
* exclude worst case performance for pathological files. Better values may be
|
* exclude worst case performance for pathological files. Better values may be
|
||||||
|
@ -161,6 +155,9 @@ local const config configuration_table[10] = {
|
||||||
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
|
struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */
|
||||||
|
#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Update a hash value with the given input byte
|
* Update a hash value with the given input byte
|
||||||
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
|
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
|
||||||
|
@ -241,10 +238,19 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||||
|
|
||||||
strm->msg = Z_NULL;
|
strm->msg = Z_NULL;
|
||||||
if (strm->zalloc == (alloc_func)0) {
|
if (strm->zalloc == (alloc_func)0) {
|
||||||
|
#ifdef Z_SOLO
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
#else
|
||||||
strm->zalloc = zcalloc;
|
strm->zalloc = zcalloc;
|
||||||
strm->opaque = (voidpf)0;
|
strm->opaque = (voidpf)0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (strm->zfree == (free_func)0) strm->zfree = zcfree;
|
if (strm->zfree == (free_func)0)
|
||||||
|
#ifdef Z_SOLO
|
||||||
|
return Z_STREAM_ERROR;
|
||||||
|
#else
|
||||||
|
strm->zfree = zcfree;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef FASTEST
|
#ifdef FASTEST
|
||||||
if (level != 0) level = 1;
|
if (level != 0) level = 1;
|
||||||
|
@ -288,6 +294,8 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
|
||||||
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
|
s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
|
||||||
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
|
s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
|
||||||
|
|
||||||
|
s->high_water = 0; /* nothing written to s->window yet */
|
||||||
|
|
||||||
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
||||||
|
|
||||||
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
|
overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
|
||||||
|
@ -318,43 +326,70 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
|
||||||
uInt dictLength;
|
uInt dictLength;
|
||||||
{
|
{
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
uInt length = dictLength;
|
uInt str, n;
|
||||||
uInt n;
|
int wrap;
|
||||||
IPos hash_head = 0;
|
unsigned avail;
|
||||||
|
unsigned char *next;
|
||||||
|
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
|
if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL)
|
||||||
strm->state->wrap == 2 ||
|
return Z_STREAM_ERROR;
|
||||||
(strm->state->wrap == 1 && strm->state->status != INIT_STATE))
|
s = strm->state;
|
||||||
|
wrap = s->wrap;
|
||||||
|
if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
|
||||||
s = strm->state;
|
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
|
||||||
if (s->wrap)
|
if (wrap == 1)
|
||||||
strm->adler = adler32(strm->adler, dictionary, dictLength);
|
strm->adler = adler32(strm->adler, dictionary, dictLength);
|
||||||
|
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
|
||||||
|
|
||||||
if (length < MIN_MATCH) return Z_OK;
|
/* if dictionary would fill window, just replace the history */
|
||||||
if (length > MAX_DIST(s)) {
|
if (dictLength >= s->w_size) {
|
||||||
length = MAX_DIST(s);
|
if (wrap == 0) { /* already empty otherwise */
|
||||||
dictionary += dictLength - length; /* use the tail of the dictionary */
|
CLEAR_HASH(s);
|
||||||
|
s->strstart = 0;
|
||||||
|
s->block_start = 0L;
|
||||||
|
s->insert = 0;
|
||||||
|
}
|
||||||
|
dictionary += dictLength - s->w_size; /* use the tail */
|
||||||
|
dictLength = s->w_size;
|
||||||
}
|
}
|
||||||
zmemcpy(s->window, dictionary, length);
|
|
||||||
s->strstart = length;
|
|
||||||
s->block_start = (long)length;
|
|
||||||
|
|
||||||
/* Insert all strings in the hash table (except for the last two bytes).
|
/* insert dictionary into window and hash */
|
||||||
* s->lookahead stays null, so s->ins_h will be recomputed at the next
|
avail = strm->avail_in;
|
||||||
* call of fill_window.
|
next = strm->next_in;
|
||||||
*/
|
strm->avail_in = dictLength;
|
||||||
s->ins_h = s->window[0];
|
strm->next_in = (Bytef *)dictionary;
|
||||||
UPDATE_HASH(s, s->ins_h, s->window[1]);
|
fill_window(s);
|
||||||
for (n = 0; n <= length - MIN_MATCH; n++) {
|
while (s->lookahead >= MIN_MATCH) {
|
||||||
INSERT_STRING(s, n, hash_head);
|
str = s->strstart;
|
||||||
|
n = s->lookahead - (MIN_MATCH-1);
|
||||||
|
do {
|
||||||
|
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
||||||
|
#ifndef FASTEST
|
||||||
|
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
||||||
|
#endif
|
||||||
|
s->head[s->ins_h] = (Pos)str;
|
||||||
|
str++;
|
||||||
|
} while (--n);
|
||||||
|
s->strstart = str;
|
||||||
|
s->lookahead = MIN_MATCH-1;
|
||||||
|
fill_window(s);
|
||||||
}
|
}
|
||||||
if (hash_head) hash_head = 0; /* to make compiler happy */
|
s->strstart += s->lookahead;
|
||||||
|
s->block_start = (long)s->strstart;
|
||||||
|
s->insert = s->lookahead;
|
||||||
|
s->lookahead = 0;
|
||||||
|
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||||
|
s->match_available = 0;
|
||||||
|
strm->next_in = next;
|
||||||
|
strm->avail_in = avail;
|
||||||
|
s->wrap = wrap;
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
int ZEXPORT deflateReset (strm)
|
int ZEXPORT deflateResetKeep (strm)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
{
|
{
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
|
@ -384,11 +419,22 @@ int ZEXPORT deflateReset (strm)
|
||||||
s->last_flush = Z_NO_FLUSH;
|
s->last_flush = Z_NO_FLUSH;
|
||||||
|
|
||||||
_tr_init(s);
|
_tr_init(s);
|
||||||
lm_init(s);
|
|
||||||
|
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
int ZEXPORT deflateReset (strm)
|
||||||
|
z_streamp strm;
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = deflateResetKeep(strm);
|
||||||
|
if (ret == Z_OK)
|
||||||
|
lm_init(strm->state);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
int ZEXPORT deflateSetHeader (strm, head)
|
int ZEXPORT deflateSetHeader (strm, head)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
|
@ -400,15 +446,43 @@ int ZEXPORT deflateSetHeader (strm, head)
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================================================================= */
|
||||||
|
int ZEXPORT deflatePending (strm, pending, bits)
|
||||||
|
unsigned *pending;
|
||||||
|
int *bits;
|
||||||
|
z_streamp strm;
|
||||||
|
{
|
||||||
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
|
if (pending != Z_NULL)
|
||||||
|
*pending = strm->state->pending;
|
||||||
|
if (bits != Z_NULL)
|
||||||
|
*bits = strm->state->bi_valid;
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
int ZEXPORT deflatePrime (strm, bits, value)
|
int ZEXPORT deflatePrime (strm, bits, value)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
int bits;
|
int bits;
|
||||||
int value;
|
int value;
|
||||||
{
|
{
|
||||||
|
deflate_state *s;
|
||||||
|
int put;
|
||||||
|
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
|
||||||
strm->state->bi_valid = bits;
|
s = strm->state;
|
||||||
strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
|
if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3))
|
||||||
|
return Z_BUF_ERROR;
|
||||||
|
do {
|
||||||
|
put = Buf_size - s->bi_valid;
|
||||||
|
if (put > bits)
|
||||||
|
put = bits;
|
||||||
|
s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
|
||||||
|
s->bi_valid += put;
|
||||||
|
_tr_flush_bits(s);
|
||||||
|
value >>= put;
|
||||||
|
bits -= put;
|
||||||
|
} while (bits);
|
||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,9 +509,10 @@ int ZEXPORT deflateParams(strm, level, strategy)
|
||||||
}
|
}
|
||||||
func = configuration_table[s->level].func;
|
func = configuration_table[s->level].func;
|
||||||
|
|
||||||
if (func != configuration_table[level].func && strm->total_in != 0) {
|
if ((strategy != s->strategy || func != configuration_table[level].func) &&
|
||||||
|
strm->total_in != 0) {
|
||||||
/* Flush the last buffer: */
|
/* Flush the last buffer: */
|
||||||
err = deflate(strm, Z_PARTIAL_FLUSH);
|
err = deflate(strm, Z_BLOCK);
|
||||||
}
|
}
|
||||||
if (s->level != level) {
|
if (s->level != level) {
|
||||||
s->level = level;
|
s->level = level;
|
||||||
|
@ -481,33 +556,66 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
|
||||||
* resulting from using fixed blocks instead of stored blocks, which deflate
|
* resulting from using fixed blocks instead of stored blocks, which deflate
|
||||||
* can emit on compressed data for some combinations of the parameters.
|
* can emit on compressed data for some combinations of the parameters.
|
||||||
*
|
*
|
||||||
* This function could be more sophisticated to provide closer upper bounds
|
* This function could be more sophisticated to provide closer upper bounds for
|
||||||
* for every combination of windowBits and memLevel, as well as wrap.
|
* every combination of windowBits and memLevel. But even the conservative
|
||||||
* But even the conservative upper bound of about 14% expansion does not
|
* upper bound of about 14% expansion does not seem onerous for output buffer
|
||||||
* seem onerous for output buffer allocation.
|
* allocation.
|
||||||
*/
|
*/
|
||||||
uLong ZEXPORT deflateBound(strm, sourceLen)
|
uLong ZEXPORT deflateBound(strm, sourceLen)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
uLong sourceLen;
|
uLong sourceLen;
|
||||||
{
|
{
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
uLong destLen;
|
uLong complen, wraplen;
|
||||||
|
Bytef *str;
|
||||||
|
|
||||||
/* conservative upper bound */
|
/* conservative upper bound for compressed data */
|
||||||
destLen = sourceLen +
|
complen = sourceLen +
|
||||||
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
|
((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
|
||||||
|
|
||||||
/* if can't get parameters, return conservative bound */
|
/* if can't get parameters, return conservative bound plus zlib wrapper */
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL)
|
if (strm == Z_NULL || strm->state == Z_NULL)
|
||||||
return destLen;
|
return complen + 6;
|
||||||
|
|
||||||
|
/* compute wrapper length */
|
||||||
|
s = strm->state;
|
||||||
|
switch (s->wrap) {
|
||||||
|
case 0: /* raw deflate */
|
||||||
|
wraplen = 0;
|
||||||
|
break;
|
||||||
|
case 1: /* zlib wrapper */
|
||||||
|
wraplen = 6 + (s->strstart ? 4 : 0);
|
||||||
|
break;
|
||||||
|
case 2: /* gzip wrapper */
|
||||||
|
wraplen = 18;
|
||||||
|
if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
|
||||||
|
if (s->gzhead->extra != Z_NULL)
|
||||||
|
wraplen += 2 + s->gzhead->extra_len;
|
||||||
|
str = s->gzhead->name;
|
||||||
|
if (str != Z_NULL)
|
||||||
|
do {
|
||||||
|
wraplen++;
|
||||||
|
} while (*str++);
|
||||||
|
str = s->gzhead->comment;
|
||||||
|
if (str != Z_NULL)
|
||||||
|
do {
|
||||||
|
wraplen++;
|
||||||
|
} while (*str++);
|
||||||
|
if (s->gzhead->hcrc)
|
||||||
|
wraplen += 2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: /* for compiler happiness */
|
||||||
|
wraplen = 6;
|
||||||
|
}
|
||||||
|
|
||||||
/* if not default parameters, return conservative bound */
|
/* if not default parameters, return conservative bound */
|
||||||
s = strm->state;
|
|
||||||
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
|
if (s->w_bits != 15 || s->hash_bits != 8 + 7)
|
||||||
return destLen;
|
return complen + wraplen;
|
||||||
|
|
||||||
/* default settings: return tight bound for that case */
|
/* default settings: return tight bound for that case */
|
||||||
return compressBound(sourceLen);
|
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
|
||||||
|
(sourceLen >> 25) + 13 - 6 + wraplen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
|
@ -532,19 +640,22 @@ local void putShortMSB (s, b)
|
||||||
local void flush_pending(strm)
|
local void flush_pending(strm)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
{
|
{
|
||||||
unsigned len = strm->state->pending;
|
unsigned len;
|
||||||
|
deflate_state *s = strm->state;
|
||||||
|
|
||||||
|
_tr_flush_bits(s);
|
||||||
|
len = s->pending;
|
||||||
if (len > strm->avail_out) len = strm->avail_out;
|
if (len > strm->avail_out) len = strm->avail_out;
|
||||||
if (len == 0) return;
|
if (len == 0) return;
|
||||||
|
|
||||||
zmemcpy(strm->next_out, strm->state->pending_out, len);
|
zmemcpy(strm->next_out, s->pending_out, len);
|
||||||
strm->next_out += len;
|
strm->next_out += len;
|
||||||
strm->state->pending_out += len;
|
s->pending_out += len;
|
||||||
strm->total_out += len;
|
strm->total_out += len;
|
||||||
strm->avail_out -= len;
|
strm->avail_out -= len;
|
||||||
strm->state->pending -= len;
|
s->pending -= len;
|
||||||
if (strm->state->pending == 0) {
|
if (s->pending == 0) {
|
||||||
strm->state->pending_out = strm->state->pending_buf;
|
s->pending_out = s->pending_buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,7 +668,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
|
|
||||||
if (strm == Z_NULL || strm->state == Z_NULL ||
|
if (strm == Z_NULL || strm->state == Z_NULL ||
|
||||||
flush > Z_FINISH || flush < 0) {
|
flush > Z_BLOCK || flush < 0) {
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
s = strm->state;
|
s = strm->state;
|
||||||
|
@ -581,7 +692,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
put_byte(s, 31);
|
put_byte(s, 31);
|
||||||
put_byte(s, 139);
|
put_byte(s, 139);
|
||||||
put_byte(s, 8);
|
put_byte(s, 8);
|
||||||
if (s->gzhead == NULL) {
|
if (s->gzhead == Z_NULL) {
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
put_byte(s, 0);
|
put_byte(s, 0);
|
||||||
|
@ -608,7 +719,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
(s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
|
||||||
4 : 0));
|
4 : 0));
|
||||||
put_byte(s, s->gzhead->os & 0xff);
|
put_byte(s, s->gzhead->os & 0xff);
|
||||||
if (s->gzhead->extra != NULL) {
|
if (s->gzhead->extra != Z_NULL) {
|
||||||
put_byte(s, s->gzhead->extra_len & 0xff);
|
put_byte(s, s->gzhead->extra_len & 0xff);
|
||||||
put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
|
put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
|
||||||
}
|
}
|
||||||
|
@ -650,7 +761,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
}
|
}
|
||||||
#ifdef GZIP
|
#ifdef GZIP
|
||||||
if (s->status == EXTRA_STATE) {
|
if (s->status == EXTRA_STATE) {
|
||||||
if (s->gzhead->extra != NULL) {
|
if (s->gzhead->extra != Z_NULL) {
|
||||||
uInt beg = s->pending; /* start of bytes to update crc */
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
|
|
||||||
while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
|
while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
|
||||||
|
@ -678,7 +789,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
s->status = NAME_STATE;
|
s->status = NAME_STATE;
|
||||||
}
|
}
|
||||||
if (s->status == NAME_STATE) {
|
if (s->status == NAME_STATE) {
|
||||||
if (s->gzhead->name != NULL) {
|
if (s->gzhead->name != Z_NULL) {
|
||||||
uInt beg = s->pending; /* start of bytes to update crc */
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
|
@ -709,7 +820,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
s->status = COMMENT_STATE;
|
s->status = COMMENT_STATE;
|
||||||
}
|
}
|
||||||
if (s->status == COMMENT_STATE) {
|
if (s->status == COMMENT_STATE) {
|
||||||
if (s->gzhead->comment != NULL) {
|
if (s->gzhead->comment != Z_NULL) {
|
||||||
uInt beg = s->pending; /* start of bytes to update crc */
|
uInt beg = s->pending; /* start of bytes to update crc */
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
|
@ -771,7 +882,7 @@ int ZEXPORT deflate (strm, flush)
|
||||||
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
||||||
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
||||||
*/
|
*/
|
||||||
} else if (strm->avail_in == 0 && flush <= old_flush &&
|
} else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
|
||||||
flush != Z_FINISH) {
|
flush != Z_FINISH) {
|
||||||
ERR_RETURN(strm, Z_BUF_ERROR);
|
ERR_RETURN(strm, Z_BUF_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -787,7 +898,9 @@ int ZEXPORT deflate (strm, flush)
|
||||||
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
|
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
|
||||||
block_state bstate;
|
block_state bstate;
|
||||||
|
|
||||||
bstate = (*(configuration_table[s->level].func))(s, flush);
|
bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
|
||||||
|
(s->strategy == Z_RLE ? deflate_rle(s, flush) :
|
||||||
|
(*(configuration_table[s->level].func))(s, flush));
|
||||||
|
|
||||||
if (bstate == finish_started || bstate == finish_done) {
|
if (bstate == finish_started || bstate == finish_done) {
|
||||||
s->status = FINISH_STATE;
|
s->status = FINISH_STATE;
|
||||||
|
@ -808,13 +921,18 @@ int ZEXPORT deflate (strm, flush)
|
||||||
if (bstate == block_done) {
|
if (bstate == block_done) {
|
||||||
if (flush == Z_PARTIAL_FLUSH) {
|
if (flush == Z_PARTIAL_FLUSH) {
|
||||||
_tr_align(s);
|
_tr_align(s);
|
||||||
} else { /* FULL_FLUSH or SYNC_FLUSH */
|
} else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
|
||||||
_tr_stored_block(s, (char*)0, 0L, 0);
|
_tr_stored_block(s, (char*)0, 0L, 0);
|
||||||
/* For a full flush, this empty block will be recognized
|
/* For a full flush, this empty block will be recognized
|
||||||
* as a special marker by inflate_sync().
|
* as a special marker by inflate_sync().
|
||||||
*/
|
*/
|
||||||
if (flush == Z_FULL_FLUSH) {
|
if (flush == Z_FULL_FLUSH) {
|
||||||
CLEAR_HASH(s); /* forget history */
|
CLEAR_HASH(s); /* forget history */
|
||||||
|
if (s->lookahead == 0) {
|
||||||
|
s->strstart = 0;
|
||||||
|
s->block_start = 0L;
|
||||||
|
s->insert = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flush_pending(strm);
|
flush_pending(strm);
|
||||||
|
@ -909,12 +1027,12 @@ int ZEXPORT deflateCopy (dest, source)
|
||||||
|
|
||||||
ss = source->state;
|
ss = source->state;
|
||||||
|
|
||||||
zmemcpy(dest, source, sizeof(z_stream));
|
zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream));
|
||||||
|
|
||||||
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
|
||||||
if (ds == Z_NULL) return Z_MEM_ERROR;
|
if (ds == Z_NULL) return Z_MEM_ERROR;
|
||||||
dest->state = (struct internal_state FAR *) ds;
|
dest->state = (struct internal_state FAR *) ds;
|
||||||
zmemcpy(ds, ss, sizeof(deflate_state));
|
zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state));
|
||||||
ds->strm = dest;
|
ds->strm = dest;
|
||||||
|
|
||||||
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
|
||||||
|
@ -930,8 +1048,8 @@ int ZEXPORT deflateCopy (dest, source)
|
||||||
}
|
}
|
||||||
/* following zmemcpy do not work for 16-bit MSDOS */
|
/* following zmemcpy do not work for 16-bit MSDOS */
|
||||||
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
|
||||||
zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
|
zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
|
||||||
zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
|
zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
|
||||||
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
|
||||||
|
|
||||||
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
|
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
|
||||||
|
@ -965,15 +1083,15 @@ local int read_buf(strm, buf, size)
|
||||||
|
|
||||||
strm->avail_in -= len;
|
strm->avail_in -= len;
|
||||||
|
|
||||||
|
zmemcpy(buf, strm->next_in, len);
|
||||||
if (strm->state->wrap == 1) {
|
if (strm->state->wrap == 1) {
|
||||||
strm->adler = adler32(strm->adler, strm->next_in, len);
|
strm->adler = adler32(strm->adler, buf, len);
|
||||||
}
|
}
|
||||||
#ifdef GZIP
|
#ifdef GZIP
|
||||||
else if (strm->state->wrap == 2) {
|
else if (strm->state->wrap == 2) {
|
||||||
strm->adler = crc32(strm->adler, strm->next_in, len);
|
strm->adler = crc32(strm->adler, buf, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
zmemcpy(buf, strm->next_in, len);
|
|
||||||
strm->next_in += len;
|
strm->next_in += len;
|
||||||
strm->total_in += len;
|
strm->total_in += len;
|
||||||
|
|
||||||
|
@ -1000,6 +1118,7 @@ local void lm_init (s)
|
||||||
s->strstart = 0;
|
s->strstart = 0;
|
||||||
s->block_start = 0L;
|
s->block_start = 0L;
|
||||||
s->lookahead = 0;
|
s->lookahead = 0;
|
||||||
|
s->insert = 0;
|
||||||
s->match_length = s->prev_length = MIN_MATCH-1;
|
s->match_length = s->prev_length = MIN_MATCH-1;
|
||||||
s->match_available = 0;
|
s->match_available = 0;
|
||||||
s->ins_h = 0;
|
s->ins_h = 0;
|
||||||
|
@ -1167,12 +1286,13 @@ local uInt longest_match(s, cur_match)
|
||||||
return s->lookahead;
|
return s->lookahead;
|
||||||
}
|
}
|
||||||
#endif /* ASMV */
|
#endif /* ASMV */
|
||||||
#endif /* FASTEST */
|
|
||||||
|
#else /* FASTEST */
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------
|
/* ---------------------------------------------------------------------------
|
||||||
* Optimized version for level == 1 or strategy == Z_RLE only
|
* Optimized version for FASTEST only
|
||||||
*/
|
*/
|
||||||
local uInt longest_match_fast(s, cur_match)
|
local uInt longest_match(s, cur_match)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
IPos cur_match; /* current match */
|
IPos cur_match; /* current match */
|
||||||
{
|
{
|
||||||
|
@ -1225,6 +1345,8 @@ local uInt longest_match_fast(s, cur_match)
|
||||||
return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
|
return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* FASTEST */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Check that the match at match_start is indeed a match.
|
* Check that the match at match_start is indeed a match.
|
||||||
|
@ -1271,6 +1393,8 @@ local void fill_window(s)
|
||||||
unsigned more; /* Amount of free space at the end of the window. */
|
unsigned more; /* Amount of free space at the end of the window. */
|
||||||
uInt wsize = s->w_size;
|
uInt wsize = s->w_size;
|
||||||
|
|
||||||
|
Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
|
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
|
||||||
|
|
||||||
|
@ -1303,7 +1427,6 @@ local void fill_window(s)
|
||||||
later. (Using level 0 permanently is not an optimal usage of
|
later. (Using level 0 permanently is not an optimal usage of
|
||||||
zlib, so we don't care about this pathological case.)
|
zlib, so we don't care about this pathological case.)
|
||||||
*/
|
*/
|
||||||
/* %%% avoid this when Z_RLE */
|
|
||||||
n = s->hash_size;
|
n = s->hash_size;
|
||||||
p = &s->head[n];
|
p = &s->head[n];
|
||||||
do {
|
do {
|
||||||
|
@ -1324,7 +1447,7 @@ local void fill_window(s)
|
||||||
#endif
|
#endif
|
||||||
more += wsize;
|
more += wsize;
|
||||||
}
|
}
|
||||||
if (s->strm->avail_in == 0) return;
|
if (s->strm->avail_in == 0) break;
|
||||||
|
|
||||||
/* If there was no sliding:
|
/* If there was no sliding:
|
||||||
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
|
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
|
||||||
|
@ -1343,39 +1466,88 @@ local void fill_window(s)
|
||||||
s->lookahead += n;
|
s->lookahead += n;
|
||||||
|
|
||||||
/* Initialize the hash value now that we have some input: */
|
/* Initialize the hash value now that we have some input: */
|
||||||
if (s->lookahead >= MIN_MATCH) {
|
if (s->lookahead + s->insert >= MIN_MATCH) {
|
||||||
s->ins_h = s->window[s->strstart];
|
uInt str = s->strstart - s->insert;
|
||||||
UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
|
s->ins_h = s->window[str];
|
||||||
|
UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
|
||||||
#if MIN_MATCH != 3
|
#if MIN_MATCH != 3
|
||||||
Call UPDATE_HASH() MIN_MATCH-3 more times
|
Call UPDATE_HASH() MIN_MATCH-3 more times
|
||||||
#endif
|
#endif
|
||||||
|
while (s->insert) {
|
||||||
|
UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
|
||||||
|
#ifndef FASTEST
|
||||||
|
s->prev[str & s->w_mask] = s->head[s->ins_h];
|
||||||
|
#endif
|
||||||
|
s->head[s->ins_h] = (Pos)str;
|
||||||
|
str++;
|
||||||
|
s->insert--;
|
||||||
|
if (s->lookahead + s->insert < MIN_MATCH)
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
||||||
* but this is not important since only literal bytes will be emitted.
|
* but this is not important since only literal bytes will be emitted.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
|
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
|
||||||
|
|
||||||
|
/* If the WIN_INIT bytes after the end of the current data have never been
|
||||||
|
* written, then zero those bytes in order to avoid memory check reports of
|
||||||
|
* the use of uninitialized (or uninitialised as Julian writes) bytes by
|
||||||
|
* the longest match routines. Update the high water mark for the next
|
||||||
|
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
|
||||||
|
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
|
||||||
|
*/
|
||||||
|
if (s->high_water < s->window_size) {
|
||||||
|
ulg curr = s->strstart + (ulg)(s->lookahead);
|
||||||
|
ulg init;
|
||||||
|
|
||||||
|
if (s->high_water < curr) {
|
||||||
|
/* Previous high water mark below current data -- zero WIN_INIT
|
||||||
|
* bytes or up to end of window, whichever is less.
|
||||||
|
*/
|
||||||
|
init = s->window_size - curr;
|
||||||
|
if (init > WIN_INIT)
|
||||||
|
init = WIN_INIT;
|
||||||
|
zmemzero(s->window + curr, (unsigned)init);
|
||||||
|
s->high_water = curr + init;
|
||||||
|
}
|
||||||
|
else if (s->high_water < (ulg)curr + WIN_INIT) {
|
||||||
|
/* High water mark at or above current data, but below current data
|
||||||
|
* plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
|
||||||
|
* to end of window, whichever is less.
|
||||||
|
*/
|
||||||
|
init = (ulg)curr + WIN_INIT - s->high_water;
|
||||||
|
if (init > s->window_size - s->high_water)
|
||||||
|
init = s->window_size - s->high_water;
|
||||||
|
zmemzero(s->window + s->high_water, (unsigned)init);
|
||||||
|
s->high_water += init;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
|
||||||
|
"not enough room for search");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Flush the current block, with given end-of-file flag.
|
* Flush the current block, with given end-of-file flag.
|
||||||
* IN assertion: strstart is set to the end of the current match.
|
* IN assertion: strstart is set to the end of the current match.
|
||||||
*/
|
*/
|
||||||
#define FLUSH_BLOCK_ONLY(s, eof) { \
|
#define FLUSH_BLOCK_ONLY(s, last) { \
|
||||||
_tr_flush_block(s, (s->block_start >= 0L ? \
|
_tr_flush_block(s, (s->block_start >= 0L ? \
|
||||||
(charf *)&s->window[(unsigned)s->block_start] : \
|
(charf *)&s->window[(unsigned)s->block_start] : \
|
||||||
(charf *)Z_NULL), \
|
(charf *)Z_NULL), \
|
||||||
(ulg)((long)s->strstart - s->block_start), \
|
(ulg)((long)s->strstart - s->block_start), \
|
||||||
(eof)); \
|
(last)); \
|
||||||
s->block_start = s->strstart; \
|
s->block_start = s->strstart; \
|
||||||
flush_pending(s->strm); \
|
flush_pending(s->strm); \
|
||||||
Tracev((stderr,"[FLUSH]")); \
|
Tracev((stderr,"[FLUSH]")); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Same but force premature exit if necessary. */
|
/* Same but force premature exit if necessary. */
|
||||||
#define FLUSH_BLOCK(s, eof) { \
|
#define FLUSH_BLOCK(s, last) { \
|
||||||
FLUSH_BLOCK_ONLY(s, eof); \
|
FLUSH_BLOCK_ONLY(s, last); \
|
||||||
if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
|
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
|
@ -1434,8 +1606,14 @@ local block_state deflate_stored(s, flush)
|
||||||
FLUSH_BLOCK(s, 0);
|
FLUSH_BLOCK(s, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
s->insert = 0;
|
||||||
return flush == Z_FINISH ? finish_done : block_done;
|
if (flush == Z_FINISH) {
|
||||||
|
FLUSH_BLOCK(s, 1);
|
||||||
|
return finish_done;
|
||||||
|
}
|
||||||
|
if ((long)s->strstart > s->block_start)
|
||||||
|
FLUSH_BLOCK(s, 0);
|
||||||
|
return block_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
|
@ -1449,7 +1627,7 @@ local block_state deflate_fast(s, flush)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
int flush;
|
int flush;
|
||||||
{
|
{
|
||||||
IPos hash_head = NIL; /* head of the hash chain */
|
IPos hash_head; /* head of the hash chain */
|
||||||
int bflush; /* set if current block must be flushed */
|
int bflush; /* set if current block must be flushed */
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -1469,6 +1647,7 @@ local block_state deflate_fast(s, flush)
|
||||||
/* Insert the string window[strstart .. strstart+2] in the
|
/* Insert the string window[strstart .. strstart+2] in the
|
||||||
* dictionary, and set hash_head to the head of the hash chain:
|
* dictionary, and set hash_head to the head of the hash chain:
|
||||||
*/
|
*/
|
||||||
|
hash_head = NIL;
|
||||||
if (s->lookahead >= MIN_MATCH) {
|
if (s->lookahead >= MIN_MATCH) {
|
||||||
INSERT_STRING(s, s->strstart, hash_head);
|
INSERT_STRING(s, s->strstart, hash_head);
|
||||||
}
|
}
|
||||||
|
@ -1481,19 +1660,8 @@ local block_state deflate_fast(s, flush)
|
||||||
* of window index 0 (in particular we have to avoid a match
|
* of window index 0 (in particular we have to avoid a match
|
||||||
* of the string with itself at the start of the input file).
|
* of the string with itself at the start of the input file).
|
||||||
*/
|
*/
|
||||||
#ifdef FASTEST
|
s->match_length = longest_match (s, hash_head);
|
||||||
if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
|
/* longest_match() sets match_start */
|
||||||
(s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
|
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
|
||||||
s->match_length = longest_match (s, hash_head);
|
|
||||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/* longest_match() or longest_match_fast() sets match_start */
|
|
||||||
}
|
}
|
||||||
if (s->match_length >= MIN_MATCH) {
|
if (s->match_length >= MIN_MATCH) {
|
||||||
check_match(s, s->strstart, s->match_start, s->match_length);
|
check_match(s, s->strstart, s->match_start, s->match_length);
|
||||||
|
@ -1541,8 +1709,14 @@ local block_state deflate_fast(s, flush)
|
||||||
}
|
}
|
||||||
if (bflush) FLUSH_BLOCK(s, 0);
|
if (bflush) FLUSH_BLOCK(s, 0);
|
||||||
}
|
}
|
||||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
||||||
return flush == Z_FINISH ? finish_done : block_done;
|
if (flush == Z_FINISH) {
|
||||||
|
FLUSH_BLOCK(s, 1);
|
||||||
|
return finish_done;
|
||||||
|
}
|
||||||
|
if (s->last_lit)
|
||||||
|
FLUSH_BLOCK(s, 0);
|
||||||
|
return block_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FASTEST
|
#ifndef FASTEST
|
||||||
|
@ -1555,7 +1729,7 @@ local block_state deflate_slow(s, flush)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
int flush;
|
int flush;
|
||||||
{
|
{
|
||||||
IPos hash_head = NIL; /* head of hash chain */
|
IPos hash_head; /* head of hash chain */
|
||||||
int bflush; /* set if current block must be flushed */
|
int bflush; /* set if current block must be flushed */
|
||||||
|
|
||||||
/* Process the input block. */
|
/* Process the input block. */
|
||||||
|
@ -1576,6 +1750,7 @@ local block_state deflate_slow(s, flush)
|
||||||
/* Insert the string window[strstart .. strstart+2] in the
|
/* Insert the string window[strstart .. strstart+2] in the
|
||||||
* dictionary, and set hash_head to the head of the hash chain:
|
* dictionary, and set hash_head to the head of the hash chain:
|
||||||
*/
|
*/
|
||||||
|
hash_head = NIL;
|
||||||
if (s->lookahead >= MIN_MATCH) {
|
if (s->lookahead >= MIN_MATCH) {
|
||||||
INSERT_STRING(s, s->strstart, hash_head);
|
INSERT_STRING(s, s->strstart, hash_head);
|
||||||
}
|
}
|
||||||
|
@ -1591,12 +1766,8 @@ local block_state deflate_slow(s, flush)
|
||||||
* of window index 0 (in particular we have to avoid a match
|
* of window index 0 (in particular we have to avoid a match
|
||||||
* of the string with itself at the start of the input file).
|
* of the string with itself at the start of the input file).
|
||||||
*/
|
*/
|
||||||
if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
|
s->match_length = longest_match (s, hash_head);
|
||||||
s->match_length = longest_match (s, hash_head);
|
/* longest_match() sets match_start */
|
||||||
} else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
|
|
||||||
s->match_length = longest_match_fast (s, hash_head);
|
|
||||||
}
|
|
||||||
/* longest_match() or longest_match_fast() sets match_start */
|
|
||||||
|
|
||||||
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
|
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
|
||||||
#if TOO_FAR <= 32767
|
#if TOO_FAR <= 32767
|
||||||
|
@ -1669,12 +1840,17 @@ local block_state deflate_slow(s, flush)
|
||||||
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
_tr_tally_lit(s, s->window[s->strstart-1], bflush);
|
||||||
s->match_available = 0;
|
s->match_available = 0;
|
||||||
}
|
}
|
||||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
|
||||||
return flush == Z_FINISH ? finish_done : block_done;
|
if (flush == Z_FINISH) {
|
||||||
|
FLUSH_BLOCK(s, 1);
|
||||||
|
return finish_done;
|
||||||
|
}
|
||||||
|
if (s->last_lit)
|
||||||
|
FLUSH_BLOCK(s, 0);
|
||||||
|
return block_done;
|
||||||
}
|
}
|
||||||
#endif /* FASTEST */
|
#endif /* FASTEST */
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
||||||
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
||||||
|
@ -1684,43 +1860,52 @@ local block_state deflate_rle(s, flush)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
int flush;
|
int flush;
|
||||||
{
|
{
|
||||||
int bflush; /* set if current block must be flushed */
|
int bflush; /* set if current block must be flushed */
|
||||||
uInt run; /* length of run */
|
uInt prev; /* byte at distance one to match */
|
||||||
uInt max; /* maximum length of run */
|
Bytef *scan, *strend; /* scan goes up to strend for length of run */
|
||||||
uInt prev; /* byte at distance one to match */
|
|
||||||
Bytef *scan; /* scan for end of run */
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Make sure that we always have enough lookahead, except
|
/* Make sure that we always have enough lookahead, except
|
||||||
* at the end of the input file. We need MAX_MATCH bytes
|
* at the end of the input file. We need MAX_MATCH bytes
|
||||||
* for the longest encodable run.
|
* for the longest run, plus one for the unrolled loop.
|
||||||
*/
|
*/
|
||||||
if (s->lookahead < MAX_MATCH) {
|
if (s->lookahead <= MAX_MATCH) {
|
||||||
fill_window(s);
|
fill_window(s);
|
||||||
if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
|
if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
|
||||||
return need_more;
|
return need_more;
|
||||||
}
|
}
|
||||||
if (s->lookahead == 0) break; /* flush the current block */
|
if (s->lookahead == 0) break; /* flush the current block */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See how many times the previous byte repeats */
|
/* See how many times the previous byte repeats */
|
||||||
run = 0;
|
s->match_length = 0;
|
||||||
if (s->strstart > 0) { /* if there is a previous byte, that is */
|
if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
|
||||||
max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
|
|
||||||
scan = s->window + s->strstart - 1;
|
scan = s->window + s->strstart - 1;
|
||||||
prev = *scan++;
|
prev = *scan;
|
||||||
do {
|
if (prev == *++scan && prev == *++scan && prev == *++scan) {
|
||||||
if (*scan++ != prev)
|
strend = s->window + s->strstart + MAX_MATCH;
|
||||||
break;
|
do {
|
||||||
} while (++run < max);
|
} while (prev == *++scan && prev == *++scan &&
|
||||||
|
prev == *++scan && prev == *++scan &&
|
||||||
|
prev == *++scan && prev == *++scan &&
|
||||||
|
prev == *++scan && prev == *++scan &&
|
||||||
|
scan < strend);
|
||||||
|
s->match_length = MAX_MATCH - (int)(strend - scan);
|
||||||
|
if (s->match_length > s->lookahead)
|
||||||
|
s->match_length = s->lookahead;
|
||||||
|
}
|
||||||
|
Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
/* Emit match if have run of MIN_MATCH or longer, else emit literal */
|
||||||
if (run >= MIN_MATCH) {
|
if (s->match_length >= MIN_MATCH) {
|
||||||
check_match(s, s->strstart, s->strstart - 1, run);
|
check_match(s, s->strstart, s->strstart - 1, s->match_length);
|
||||||
_tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
|
|
||||||
s->lookahead -= run;
|
_tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
|
||||||
s->strstart += run;
|
|
||||||
|
s->lookahead -= s->match_length;
|
||||||
|
s->strstart += s->match_length;
|
||||||
|
s->match_length = 0;
|
||||||
} else {
|
} else {
|
||||||
/* No match, output a literal byte */
|
/* No match, output a literal byte */
|
||||||
Tracevv((stderr,"%c", s->window[s->strstart]));
|
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||||
|
@ -1730,7 +1915,51 @@ local block_state deflate_rle(s, flush)
|
||||||
}
|
}
|
||||||
if (bflush) FLUSH_BLOCK(s, 0);
|
if (bflush) FLUSH_BLOCK(s, 0);
|
||||||
}
|
}
|
||||||
FLUSH_BLOCK(s, flush == Z_FINISH);
|
s->insert = 0;
|
||||||
return flush == Z_FINISH ? finish_done : block_done;
|
if (flush == Z_FINISH) {
|
||||||
|
FLUSH_BLOCK(s, 1);
|
||||||
|
return finish_done;
|
||||||
|
}
|
||||||
|
if (s->last_lit)
|
||||||
|
FLUSH_BLOCK(s, 0);
|
||||||
|
return block_done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
|
* For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
|
||||||
|
* (It will be regenerated if this run of deflate switches away from Huffman.)
|
||||||
|
*/
|
||||||
|
local block_state deflate_huff(s, flush)
|
||||||
|
deflate_state *s;
|
||||||
|
int flush;
|
||||||
|
{
|
||||||
|
int bflush; /* set if current block must be flushed */
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
/* Make sure that we have a literal to write. */
|
||||||
|
if (s->lookahead == 0) {
|
||||||
|
fill_window(s);
|
||||||
|
if (s->lookahead == 0) {
|
||||||
|
if (flush == Z_NO_FLUSH)
|
||||||
|
return need_more;
|
||||||
|
break; /* flush the current block */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Output a literal byte */
|
||||||
|
s->match_length = 0;
|
||||||
|
Tracevv((stderr,"%c", s->window[s->strstart]));
|
||||||
|
_tr_tally_lit (s, s->window[s->strstart], bflush);
|
||||||
|
s->lookahead--;
|
||||||
|
s->strstart++;
|
||||||
|
if (bflush) FLUSH_BLOCK(s, 0);
|
||||||
|
}
|
||||||
|
s->insert = 0;
|
||||||
|
if (flush == Z_FINISH) {
|
||||||
|
FLUSH_BLOCK(s, 1);
|
||||||
|
return finish_done;
|
||||||
|
}
|
||||||
|
if (s->last_lit)
|
||||||
|
FLUSH_BLOCK(s, 0);
|
||||||
|
return block_done;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* deflate.h -- internal compression state
|
/* deflate.h -- internal compression state
|
||||||
* Copyright (C) 1995-2004 Jean-loup Gailly
|
* Copyright (C) 1995-2012 Jean-loup Gailly
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@
|
||||||
#define MAX_BITS 15
|
#define MAX_BITS 15
|
||||||
/* All codes must not exceed MAX_BITS bits */
|
/* All codes must not exceed MAX_BITS bits */
|
||||||
|
|
||||||
|
#define Buf_size 16
|
||||||
|
/* size of bit buffer in bi_buf */
|
||||||
|
|
||||||
#define INIT_STATE 42
|
#define INIT_STATE 42
|
||||||
#define EXTRA_STATE 69
|
#define EXTRA_STATE 69
|
||||||
#define NAME_STATE 73
|
#define NAME_STATE 73
|
||||||
|
@ -188,7 +191,7 @@ typedef struct internal_state {
|
||||||
int nice_match; /* Stop searching when current match exceeds this */
|
int nice_match; /* Stop searching when current match exceeds this */
|
||||||
|
|
||||||
/* used by trees.c: */
|
/* used by trees.c: */
|
||||||
/* Didn't use ct_data typedef below to supress compiler warning */
|
/* Didn't use ct_data typedef below to suppress compiler warning */
|
||||||
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
||||||
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
||||||
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
||||||
|
@ -244,7 +247,7 @@ typedef struct internal_state {
|
||||||
ulg opt_len; /* bit length of current block with optimal trees */
|
ulg opt_len; /* bit length of current block with optimal trees */
|
||||||
ulg static_len; /* bit length of current block with static trees */
|
ulg static_len; /* bit length of current block with static trees */
|
||||||
uInt matches; /* number of string matches in current block */
|
uInt matches; /* number of string matches in current block */
|
||||||
int last_eob_len; /* bit length of EOB code for last block */
|
uInt insert; /* bytes at end of window left to insert */
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
||||||
|
@ -260,6 +263,13 @@ typedef struct internal_state {
|
||||||
* are always zero.
|
* are always zero.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ulg high_water;
|
||||||
|
/* High water mark offset in window for initialized bytes -- bytes above
|
||||||
|
* this are set to zero in order to avoid memory check warnings when
|
||||||
|
* longest match routines access bytes past the input. This is then
|
||||||
|
* updated to the new high water mark.
|
||||||
|
*/
|
||||||
|
|
||||||
} FAR deflate_state;
|
} FAR deflate_state;
|
||||||
|
|
||||||
/* Output a byte on the stream.
|
/* Output a byte on the stream.
|
||||||
|
@ -278,14 +288,19 @@ typedef struct internal_state {
|
||||||
* distances are limited to MAX_DIST instead of WSIZE.
|
* distances are limited to MAX_DIST instead of WSIZE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define WIN_INIT MAX_MATCH
|
||||||
|
/* Number of bytes after end of data in window to initialize in order to avoid
|
||||||
|
memory checker errors from longest match routines */
|
||||||
|
|
||||||
/* in trees.c */
|
/* in trees.c */
|
||||||
void _tr_init OF((deflate_state *s));
|
void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
|
||||||
int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
||||||
void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
|
||||||
int eof));
|
ulg stored_len, int last));
|
||||||
void _tr_align OF((deflate_state *s));
|
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
|
||||||
void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
|
||||||
int eof));
|
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
||||||
|
ulg stored_len, int last));
|
||||||
|
|
||||||
#define d_code(dist) \
|
#define d_code(dist) \
|
||||||
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
||||||
|
@ -298,11 +313,11 @@ void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
|
||||||
/* Inline versions of _tr_tally for speed: */
|
/* Inline versions of _tr_tally for speed: */
|
||||||
|
|
||||||
#if defined(GEN_TREES_H) || !defined(STDC)
|
#if defined(GEN_TREES_H) || !defined(STDC)
|
||||||
extern uch _length_code[];
|
extern uch ZLIB_INTERNAL _length_code[];
|
||||||
extern uch _dist_code[];
|
extern uch ZLIB_INTERNAL _dist_code[];
|
||||||
#else
|
#else
|
||||||
extern const uch _length_code[];
|
extern const uch ZLIB_INTERNAL _length_code[];
|
||||||
extern const uch _dist_code[];
|
extern const uch ZLIB_INTERNAL _dist_code[];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# define _tr_tally_lit(s, c, flush) \
|
# define _tr_tally_lit(s, c, flush) \
|
||||||
|
|
131
zlib/trees.c
131
zlib/trees.c
|
@ -1,5 +1,6 @@
|
||||||
/* trees.c -- output deflated data using Huffman coding
|
/* trees.c -- output deflated data using Huffman coding
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly
|
* Copyright (C) 1995-2012 Jean-loup Gailly
|
||||||
|
* detect_data_type() function provided freely by Cosmin Truta, 2006
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -73,11 +74,6 @@ local const uch bl_order[BL_CODES]
|
||||||
* probability, to avoid transmitting the lengths for unused bit length codes.
|
* probability, to avoid transmitting the lengths for unused bit length codes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Buf_size (8 * 2*sizeof(char))
|
|
||||||
/* Number of bits used within bi_buf. (bi_buf might be implemented on
|
|
||||||
* more than 16 bits on some systems.)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Local data. These are initialized only once.
|
* Local data. These are initialized only once.
|
||||||
*/
|
*/
|
||||||
|
@ -152,7 +148,7 @@ local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
|
||||||
int blcodes));
|
int blcodes));
|
||||||
local void compress_block OF((deflate_state *s, ct_data *ltree,
|
local void compress_block OF((deflate_state *s, ct_data *ltree,
|
||||||
ct_data *dtree));
|
ct_data *dtree));
|
||||||
local void set_data_type OF((deflate_state *s));
|
local int detect_data_type OF((deflate_state *s));
|
||||||
local unsigned bi_reverse OF((unsigned value, int length));
|
local unsigned bi_reverse OF((unsigned value, int length));
|
||||||
local void bi_windup OF((deflate_state *s));
|
local void bi_windup OF((deflate_state *s));
|
||||||
local void bi_flush OF((deflate_state *s));
|
local void bi_flush OF((deflate_state *s));
|
||||||
|
@ -203,12 +199,12 @@ local void send_bits(s, value, length)
|
||||||
* unused bits in value.
|
* unused bits in value.
|
||||||
*/
|
*/
|
||||||
if (s->bi_valid > (int)Buf_size - length) {
|
if (s->bi_valid > (int)Buf_size - length) {
|
||||||
s->bi_buf |= (value << s->bi_valid);
|
s->bi_buf |= (ush)value << s->bi_valid;
|
||||||
put_short(s, s->bi_buf);
|
put_short(s, s->bi_buf);
|
||||||
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
|
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
|
||||||
s->bi_valid += length - Buf_size;
|
s->bi_valid += length - Buf_size;
|
||||||
} else {
|
} else {
|
||||||
s->bi_buf |= value << s->bi_valid;
|
s->bi_buf |= (ush)value << s->bi_valid;
|
||||||
s->bi_valid += length;
|
s->bi_valid += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,12 +214,12 @@ local void send_bits(s, value, length)
|
||||||
{ int len = length;\
|
{ int len = length;\
|
||||||
if (s->bi_valid > (int)Buf_size - len) {\
|
if (s->bi_valid > (int)Buf_size - len) {\
|
||||||
int val = value;\
|
int val = value;\
|
||||||
s->bi_buf |= (val << s->bi_valid);\
|
s->bi_buf |= (ush)val << s->bi_valid;\
|
||||||
put_short(s, s->bi_buf);\
|
put_short(s, s->bi_buf);\
|
||||||
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
|
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
|
||||||
s->bi_valid += len - Buf_size;\
|
s->bi_valid += len - Buf_size;\
|
||||||
} else {\
|
} else {\
|
||||||
s->bi_buf |= (value) << s->bi_valid;\
|
s->bi_buf |= (ush)(value) << s->bi_valid;\
|
||||||
s->bi_valid += len;\
|
s->bi_valid += len;\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
@ -250,11 +246,13 @@ local void tr_static_init()
|
||||||
if (static_init_done) return;
|
if (static_init_done) return;
|
||||||
|
|
||||||
/* For some embedded targets, global variables are not initialized: */
|
/* For some embedded targets, global variables are not initialized: */
|
||||||
|
#ifdef NO_INIT_GLOBAL_POINTERS
|
||||||
static_l_desc.static_tree = static_ltree;
|
static_l_desc.static_tree = static_ltree;
|
||||||
static_l_desc.extra_bits = extra_lbits;
|
static_l_desc.extra_bits = extra_lbits;
|
||||||
static_d_desc.static_tree = static_dtree;
|
static_d_desc.static_tree = static_dtree;
|
||||||
static_d_desc.extra_bits = extra_dbits;
|
static_d_desc.extra_bits = extra_dbits;
|
||||||
static_bl_desc.extra_bits = extra_blbits;
|
static_bl_desc.extra_bits = extra_blbits;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize the mapping length (0..255) -> length code (0..28) */
|
/* Initialize the mapping length (0..255) -> length code (0..28) */
|
||||||
length = 0;
|
length = 0;
|
||||||
|
@ -348,13 +346,14 @@ void gen_trees_header()
|
||||||
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
|
static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
|
fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
|
||||||
for (i = 0; i < DIST_CODE_LEN; i++) {
|
for (i = 0; i < DIST_CODE_LEN; i++) {
|
||||||
fprintf(header, "%2u%s", _dist_code[i],
|
fprintf(header, "%2u%s", _dist_code[i],
|
||||||
SEPARATOR(i, DIST_CODE_LEN-1, 20));
|
SEPARATOR(i, DIST_CODE_LEN-1, 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
|
fprintf(header,
|
||||||
|
"const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
|
||||||
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
|
for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
|
||||||
fprintf(header, "%2u%s", _length_code[i],
|
fprintf(header, "%2u%s", _length_code[i],
|
||||||
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
|
SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
|
||||||
|
@ -379,7 +378,7 @@ void gen_trees_header()
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Initialize the tree data structures for a new zlib stream.
|
* Initialize the tree data structures for a new zlib stream.
|
||||||
*/
|
*/
|
||||||
void _tr_init(s)
|
void ZLIB_INTERNAL _tr_init(s)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
{
|
{
|
||||||
tr_static_init();
|
tr_static_init();
|
||||||
|
@ -395,7 +394,6 @@ void _tr_init(s)
|
||||||
|
|
||||||
s->bi_buf = 0;
|
s->bi_buf = 0;
|
||||||
s->bi_valid = 0;
|
s->bi_valid = 0;
|
||||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
s->compressed_len = 0L;
|
s->compressed_len = 0L;
|
||||||
s->bits_sent = 0L;
|
s->bits_sent = 0L;
|
||||||
|
@ -864,13 +862,13 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Send a stored block
|
* Send a stored block
|
||||||
*/
|
*/
|
||||||
void _tr_stored_block(s, buf, stored_len, eof)
|
void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
charf *buf; /* input block */
|
charf *buf; /* input block */
|
||||||
ulg stored_len; /* length of input block */
|
ulg stored_len; /* length of input block */
|
||||||
int eof; /* true if this is the last block for a file */
|
int last; /* one if this is the last block for a file */
|
||||||
{
|
{
|
||||||
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
|
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
|
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
|
||||||
s->compressed_len += (stored_len + 4) << 3;
|
s->compressed_len += (stored_len + 4) << 3;
|
||||||
|
@ -878,18 +876,20 @@ void _tr_stored_block(s, buf, stored_len, eof)
|
||||||
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
|
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
|
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
|
||||||
|
*/
|
||||||
|
void ZLIB_INTERNAL _tr_flush_bits(s)
|
||||||
|
deflate_state *s;
|
||||||
|
{
|
||||||
|
bi_flush(s);
|
||||||
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Send one empty static block to give enough lookahead for inflate.
|
* Send one empty static block to give enough lookahead for inflate.
|
||||||
* This takes 10 bits, of which 7 may remain in the bit buffer.
|
* This takes 10 bits, of which 7 may remain in the bit buffer.
|
||||||
* The current inflate code requires 9 bits of lookahead. If the
|
|
||||||
* last two codes for the previous block (real code plus EOB) were coded
|
|
||||||
* on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
|
|
||||||
* the last real code. In this case we send two empty static blocks instead
|
|
||||||
* of one. (There are no problems if the previous block is stored or fixed.)
|
|
||||||
* To simplify the code, we assume the worst case of last real code encoded
|
|
||||||
* on one bit only.
|
|
||||||
*/
|
*/
|
||||||
void _tr_align(s)
|
void ZLIB_INTERNAL _tr_align(s)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
{
|
{
|
||||||
send_bits(s, STATIC_TREES<<1, 3);
|
send_bits(s, STATIC_TREES<<1, 3);
|
||||||
|
@ -898,31 +898,17 @@ void _tr_align(s)
|
||||||
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
|
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
|
||||||
#endif
|
#endif
|
||||||
bi_flush(s);
|
bi_flush(s);
|
||||||
/* Of the 10 bits for the empty block, we have already sent
|
|
||||||
* (10 - bi_valid) bits. The lookahead for the last real code (before
|
|
||||||
* the EOB of the previous block) was thus at least one plus the length
|
|
||||||
* of the EOB plus what we have just sent of the empty static block.
|
|
||||||
*/
|
|
||||||
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
|
|
||||||
send_bits(s, STATIC_TREES<<1, 3);
|
|
||||||
send_code(s, END_BLOCK, static_ltree);
|
|
||||||
#ifdef DEBUG
|
|
||||||
s->compressed_len += 10L;
|
|
||||||
#endif
|
|
||||||
bi_flush(s);
|
|
||||||
}
|
|
||||||
s->last_eob_len = 7;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Determine the best encoding for the current block: dynamic trees, static
|
* Determine the best encoding for the current block: dynamic trees, static
|
||||||
* trees or store, and output the encoded block to the zip file.
|
* trees or store, and output the encoded block to the zip file.
|
||||||
*/
|
*/
|
||||||
void _tr_flush_block(s, buf, stored_len, eof)
|
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
charf *buf; /* input block, or NULL if too old */
|
charf *buf; /* input block, or NULL if too old */
|
||||||
ulg stored_len; /* length of input block */
|
ulg stored_len; /* length of input block */
|
||||||
int eof; /* true if this is the last block for a file */
|
int last; /* one if this is the last block for a file */
|
||||||
{
|
{
|
||||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||||
int max_blindex = 0; /* index of last bit length code of non zero freq */
|
int max_blindex = 0; /* index of last bit length code of non zero freq */
|
||||||
|
@ -931,8 +917,8 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||||
if (s->level > 0) {
|
if (s->level > 0) {
|
||||||
|
|
||||||
/* Check if the file is binary or text */
|
/* Check if the file is binary or text */
|
||||||
if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
|
if (s->strm->data_type == Z_UNKNOWN)
|
||||||
set_data_type(s);
|
s->strm->data_type = detect_data_type(s);
|
||||||
|
|
||||||
/* Construct the literal and distance trees */
|
/* Construct the literal and distance trees */
|
||||||
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
build_tree(s, (tree_desc *)(&(s->l_desc)));
|
||||||
|
@ -978,20 +964,20 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||||
* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
|
* successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
|
||||||
* transform a block into a stored block.
|
* transform a block into a stored block.
|
||||||
*/
|
*/
|
||||||
_tr_stored_block(s, buf, stored_len, eof);
|
_tr_stored_block(s, buf, stored_len, last);
|
||||||
|
|
||||||
#ifdef FORCE_STATIC
|
#ifdef FORCE_STATIC
|
||||||
} else if (static_lenb >= 0) { /* force static trees */
|
} else if (static_lenb >= 0) { /* force static trees */
|
||||||
#else
|
#else
|
||||||
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
|
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
|
||||||
#endif
|
#endif
|
||||||
send_bits(s, (STATIC_TREES<<1)+eof, 3);
|
send_bits(s, (STATIC_TREES<<1)+last, 3);
|
||||||
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
s->compressed_len += 3 + s->static_len;
|
s->compressed_len += 3 + s->static_len;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
send_bits(s, (DYN_TREES<<1)+eof, 3);
|
send_bits(s, (DYN_TREES<<1)+last, 3);
|
||||||
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
|
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
|
||||||
max_blindex+1);
|
max_blindex+1);
|
||||||
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
|
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
|
||||||
|
@ -1005,21 +991,21 @@ void _tr_flush_block(s, buf, stored_len, eof)
|
||||||
*/
|
*/
|
||||||
init_block(s);
|
init_block(s);
|
||||||
|
|
||||||
if (eof) {
|
if (last) {
|
||||||
bi_windup(s);
|
bi_windup(s);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
s->compressed_len += 7; /* align on byte boundary */
|
s->compressed_len += 7; /* align on byte boundary */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
|
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
|
||||||
s->compressed_len-7*eof));
|
s->compressed_len-7*last));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Save the match info and tally the frequency counts. Return true if
|
* Save the match info and tally the frequency counts. Return true if
|
||||||
* the current block must be flushed.
|
* the current block must be flushed.
|
||||||
*/
|
*/
|
||||||
int _tr_tally (s, dist, lc)
|
int ZLIB_INTERNAL _tr_tally (s, dist, lc)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
unsigned dist; /* distance of matched string */
|
unsigned dist; /* distance of matched string */
|
||||||
unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
|
unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
|
||||||
|
@ -1114,28 +1100,48 @@ local void compress_block(s, ltree, dtree)
|
||||||
} while (lx < s->last_lit);
|
} while (lx < s->last_lit);
|
||||||
|
|
||||||
send_code(s, END_BLOCK, ltree);
|
send_code(s, END_BLOCK, ltree);
|
||||||
s->last_eob_len = ltree[END_BLOCK].Len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Set the data type to BINARY or TEXT, using a crude approximation:
|
* Check if the data type is TEXT or BINARY, using the following algorithm:
|
||||||
* set it to Z_TEXT if all symbols are either printable characters (33 to 255)
|
* - TEXT if the two conditions below are satisfied:
|
||||||
* or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
|
* a) There are no non-portable control characters belonging to the
|
||||||
|
* "black list" (0..6, 14..25, 28..31).
|
||||||
|
* b) There is at least one printable character belonging to the
|
||||||
|
* "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
|
||||||
|
* - BINARY otherwise.
|
||||||
|
* - The following partially-portable control characters form a
|
||||||
|
* "gray list" that is ignored in this detection algorithm:
|
||||||
|
* (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
|
||||||
* IN assertion: the fields Freq of dyn_ltree are set.
|
* IN assertion: the fields Freq of dyn_ltree are set.
|
||||||
*/
|
*/
|
||||||
local void set_data_type(s)
|
local int detect_data_type(s)
|
||||||
deflate_state *s;
|
deflate_state *s;
|
||||||
{
|
{
|
||||||
|
/* black_mask is the bit mask of black-listed bytes
|
||||||
|
* set bits 0..6, 14..25, and 28..31
|
||||||
|
* 0xf3ffc07f = binary 11110011111111111100000001111111
|
||||||
|
*/
|
||||||
|
unsigned long black_mask = 0xf3ffc07fUL;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
for (n = 0; n < 9; n++)
|
/* Check for non-textual ("black-listed") bytes. */
|
||||||
|
for (n = 0; n <= 31; n++, black_mask >>= 1)
|
||||||
|
if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
|
||||||
|
return Z_BINARY;
|
||||||
|
|
||||||
|
/* Check for textual ("white-listed") bytes. */
|
||||||
|
if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
|
||||||
|
|| s->dyn_ltree[13].Freq != 0)
|
||||||
|
return Z_TEXT;
|
||||||
|
for (n = 32; n < LITERALS; n++)
|
||||||
if (s->dyn_ltree[n].Freq != 0)
|
if (s->dyn_ltree[n].Freq != 0)
|
||||||
break;
|
return Z_TEXT;
|
||||||
if (n == 9)
|
|
||||||
for (n = 14; n < 32; n++)
|
/* There are no "black-listed" or "white-listed" bytes:
|
||||||
if (s->dyn_ltree[n].Freq != 0)
|
* this stream either is empty or has tolerated ("gray-listed") bytes only.
|
||||||
break;
|
*/
|
||||||
s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
|
return Z_BINARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
|
@ -1201,7 +1207,6 @@ local void copy_block(s, buf, len, header)
|
||||||
int header; /* true if block header must be written */
|
int header; /* true if block header must be written */
|
||||||
{
|
{
|
||||||
bi_windup(s); /* align on byte boundary */
|
bi_windup(s); /* align on byte boundary */
|
||||||
s->last_eob_len = 8; /* enough lookahead for inflate */
|
|
||||||
|
|
||||||
if (header) {
|
if (header) {
|
||||||
put_short(s, (ush)len);
|
put_short(s, (ush)len);
|
||||||
|
|
|
@ -70,7 +70,7 @@ local const ct_data static_dtree[D_CODES] = {
|
||||||
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
|
||||||
};
|
};
|
||||||
|
|
||||||
const uch _dist_code[DIST_CODE_LEN] = {
|
const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
|
||||||
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
|
||||||
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
|
||||||
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||||
|
@ -99,7 +99,7 @@ const uch _dist_code[DIST_CODE_LEN] = {
|
||||||
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
|
||||||
};
|
};
|
||||||
|
|
||||||
const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||||
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
|
||||||
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
|
||||||
|
|
290
zlib/zconf.h
290
zlib/zconf.h
|
@ -1,5 +1,5 @@
|
||||||
/* zconf.h -- configuration of the zlib compression library
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
* Copyright (C) 1995-2012 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11,52 +11,142 @@
|
||||||
/*
|
/*
|
||||||
* If you *really* need a unique prefix for all types and library functions,
|
* If you *really* need a unique prefix for all types and library functions,
|
||||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||||
|
* Even better than compiling with -DZ_PREFIX would be to use configure to set
|
||||||
|
* this permanently in zconf.h using "./configure --zprefix".
|
||||||
*/
|
*/
|
||||||
#ifdef Z_PREFIX
|
#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
|
||||||
# define deflateInit_ z_deflateInit_
|
# define Z_PREFIX_SET
|
||||||
|
|
||||||
|
/* all linked symbols */
|
||||||
|
# define _dist_code z__dist_code
|
||||||
|
# define _length_code z__length_code
|
||||||
|
# define _tr_align z__tr_align
|
||||||
|
# define _tr_flush_block z__tr_flush_block
|
||||||
|
# define _tr_init z__tr_init
|
||||||
|
# define _tr_stored_block z__tr_stored_block
|
||||||
|
# define _tr_tally z__tr_tally
|
||||||
|
# define adler32 z_adler32
|
||||||
|
# define adler32_combine z_adler32_combine
|
||||||
|
# define adler32_combine64 z_adler32_combine64
|
||||||
|
# ifndef Z_SOLO
|
||||||
|
# define compress z_compress
|
||||||
|
# define compress2 z_compress2
|
||||||
|
# define compressBound z_compressBound
|
||||||
|
# endif
|
||||||
|
# define crc32 z_crc32
|
||||||
|
# define crc32_combine z_crc32_combine
|
||||||
|
# define crc32_combine64 z_crc32_combine64
|
||||||
# define deflate z_deflate
|
# define deflate z_deflate
|
||||||
# define deflateEnd z_deflateEnd
|
|
||||||
# define inflateInit_ z_inflateInit_
|
|
||||||
# define inflate z_inflate
|
|
||||||
# define inflateEnd z_inflateEnd
|
|
||||||
# define deflateInit2_ z_deflateInit2_
|
|
||||||
# define deflateSetDictionary z_deflateSetDictionary
|
|
||||||
# define deflateCopy z_deflateCopy
|
|
||||||
# define deflateReset z_deflateReset
|
|
||||||
# define deflateParams z_deflateParams
|
|
||||||
# define deflateBound z_deflateBound
|
# define deflateBound z_deflateBound
|
||||||
|
# define deflateCopy z_deflateCopy
|
||||||
|
# define deflateEnd z_deflateEnd
|
||||||
|
# define deflateInit2_ z_deflateInit2_
|
||||||
|
# define deflateInit_ z_deflateInit_
|
||||||
|
# define deflateParams z_deflateParams
|
||||||
|
# define deflatePending z_deflatePending
|
||||||
# define deflatePrime z_deflatePrime
|
# define deflatePrime z_deflatePrime
|
||||||
|
# define deflateReset z_deflateReset
|
||||||
|
# define deflateResetKeep z_deflateResetKeep
|
||||||
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
|
# define deflateSetHeader z_deflateSetHeader
|
||||||
|
# define deflateTune z_deflateTune
|
||||||
|
# define deflate_copyright z_deflate_copyright
|
||||||
|
# define get_crc_table z_get_crc_table
|
||||||
|
# ifndef Z_SOLO
|
||||||
|
# define gz_error z_gz_error
|
||||||
|
# define gz_intmax z_gz_intmax
|
||||||
|
# define gz_strwinerror z_gz_strwinerror
|
||||||
|
# define gzbuffer z_gzbuffer
|
||||||
|
# define gzclearerr z_gzclearerr
|
||||||
|
# define gzclose z_gzclose
|
||||||
|
# define gzclose_r z_gzclose_r
|
||||||
|
# define gzclose_w z_gzclose_w
|
||||||
|
# define gzdirect z_gzdirect
|
||||||
|
# define gzdopen z_gzdopen
|
||||||
|
# define gzeof z_gzeof
|
||||||
|
# define gzerror z_gzerror
|
||||||
|
# define gzflush z_gzflush
|
||||||
|
# define gzgetc z_gzgetc
|
||||||
|
# define gzgetc_ z_gzgetc_
|
||||||
|
# define gzgets z_gzgets
|
||||||
|
# define gzoffset z_gzoffset
|
||||||
|
# define gzoffset64 z_gzoffset64
|
||||||
|
# define gzopen z_gzopen
|
||||||
|
# define gzopen64 z_gzopen64
|
||||||
|
# ifdef _WIN32
|
||||||
|
# define gzopen_w z_gzopen_w
|
||||||
|
# endif
|
||||||
|
# define gzprintf z_gzprintf
|
||||||
|
# define gzputc z_gzputc
|
||||||
|
# define gzputs z_gzputs
|
||||||
|
# define gzread z_gzread
|
||||||
|
# define gzrewind z_gzrewind
|
||||||
|
# define gzseek z_gzseek
|
||||||
|
# define gzseek64 z_gzseek64
|
||||||
|
# define gzsetparams z_gzsetparams
|
||||||
|
# define gztell z_gztell
|
||||||
|
# define gztell64 z_gztell64
|
||||||
|
# define gzungetc z_gzungetc
|
||||||
|
# define gzwrite z_gzwrite
|
||||||
|
# endif
|
||||||
|
# define inflate z_inflate
|
||||||
|
# define inflateBack z_inflateBack
|
||||||
|
# define inflateBackEnd z_inflateBackEnd
|
||||||
|
# define inflateBackInit_ z_inflateBackInit_
|
||||||
|
# define inflateCopy z_inflateCopy
|
||||||
|
# define inflateEnd z_inflateEnd
|
||||||
|
# define inflateGetHeader z_inflateGetHeader
|
||||||
# define inflateInit2_ z_inflateInit2_
|
# define inflateInit2_ z_inflateInit2_
|
||||||
|
# define inflateInit_ z_inflateInit_
|
||||||
|
# define inflateMark z_inflateMark
|
||||||
|
# define inflatePrime z_inflatePrime
|
||||||
|
# define inflateReset z_inflateReset
|
||||||
|
# define inflateReset2 z_inflateReset2
|
||||||
# define inflateSetDictionary z_inflateSetDictionary
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
# define inflateSync z_inflateSync
|
# define inflateSync z_inflateSync
|
||||||
# define inflateSyncPoint z_inflateSyncPoint
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
# define inflateCopy z_inflateCopy
|
# define inflateUndermine z_inflateUndermine
|
||||||
# define inflateReset z_inflateReset
|
# define inflateResetKeep z_inflateResetKeep
|
||||||
# define inflateBack z_inflateBack
|
# define inflate_copyright z_inflate_copyright
|
||||||
# define inflateBackEnd z_inflateBackEnd
|
# define inflate_fast z_inflate_fast
|
||||||
# define compress z_compress
|
# define inflate_table z_inflate_table
|
||||||
# define compress2 z_compress2
|
# ifndef Z_SOLO
|
||||||
# define compressBound z_compressBound
|
# define uncompress z_uncompress
|
||||||
# define uncompress z_uncompress
|
# endif
|
||||||
# define adler32 z_adler32
|
|
||||||
# define crc32 z_crc32
|
|
||||||
# define get_crc_table z_get_crc_table
|
|
||||||
# define zError z_zError
|
# define zError z_zError
|
||||||
|
# ifndef Z_SOLO
|
||||||
|
# define zcalloc z_zcalloc
|
||||||
|
# define zcfree z_zcfree
|
||||||
|
# endif
|
||||||
|
# define zlibCompileFlags z_zlibCompileFlags
|
||||||
|
# define zlibVersion z_zlibVersion
|
||||||
|
|
||||||
# define alloc_func z_alloc_func
|
/* all zlib typedefs in zlib.h and zconf.h */
|
||||||
# define free_func z_free_func
|
|
||||||
# define in_func z_in_func
|
|
||||||
# define out_func z_out_func
|
|
||||||
# define Byte z_Byte
|
# define Byte z_Byte
|
||||||
# define uInt z_uInt
|
|
||||||
# define uLong z_uLong
|
|
||||||
# define Bytef z_Bytef
|
# define Bytef z_Bytef
|
||||||
|
# define alloc_func z_alloc_func
|
||||||
# define charf z_charf
|
# define charf z_charf
|
||||||
|
# define free_func z_free_func
|
||||||
|
# ifndef Z_SOLO
|
||||||
|
# define gzFile z_gzFile
|
||||||
|
# endif
|
||||||
|
# define gz_header z_gz_header
|
||||||
|
# define gz_headerp z_gz_headerp
|
||||||
|
# define in_func z_in_func
|
||||||
# define intf z_intf
|
# define intf z_intf
|
||||||
|
# define out_func z_out_func
|
||||||
|
# define uInt z_uInt
|
||||||
# define uIntf z_uIntf
|
# define uIntf z_uIntf
|
||||||
|
# define uLong z_uLong
|
||||||
# define uLongf z_uLongf
|
# define uLongf z_uLongf
|
||||||
# define voidpf z_voidpf
|
|
||||||
# define voidp z_voidp
|
# define voidp z_voidp
|
||||||
|
# define voidpc z_voidpc
|
||||||
|
# define voidpf z_voidpf
|
||||||
|
|
||||||
|
/* all zlib structs in zlib.h and zconf.h */
|
||||||
|
# define gz_header_s z_gz_header_s
|
||||||
|
# define internal_state z_internal_state
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||||
|
@ -125,6 +215,12 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ZLIB_CONST) && !defined(z_const)
|
||||||
|
# define z_const const
|
||||||
|
#else
|
||||||
|
# define z_const
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Some Mac compilers merge all .h files incorrectly: */
|
/* Some Mac compilers merge all .h files incorrectly: */
|
||||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||||
# define NO_DUMMY_DECL
|
# define NO_DUMMY_DECL
|
||||||
|
@ -171,6 +267,14 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef Z_ARG /* function prototypes for stdarg */
|
||||||
|
# if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||||
|
# define Z_ARG(args) args
|
||||||
|
# else
|
||||||
|
# define Z_ARG(args) ()
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||||
* model programming (small or medium model with some far allocations).
|
* model programming (small or medium model with some far allocations).
|
||||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||||
|
@ -284,49 +388,119 @@ typedef uLong FAR uLongf;
|
||||||
typedef Byte *voidp;
|
typedef Byte *voidp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
/* ./configure may #define Z_U4 here */
|
||||||
# include <sys/types.h> /* for off_t */
|
|
||||||
# include <unistd.h> /* for SEEK_* and off_t */
|
#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
|
||||||
# ifdef VMS
|
# include <limits.h>
|
||||||
# include <unixio.h> /* for off_t */
|
# if (UINT_MAX == 0xffffffffUL)
|
||||||
|
# define Z_U4 unsigned
|
||||||
|
# else
|
||||||
|
# if (ULONG_MAX == 0xffffffffUL)
|
||||||
|
# define Z_U4 unsigned long
|
||||||
|
# else
|
||||||
|
# if (USHRT_MAX == 0xffffffffUL)
|
||||||
|
# define Z_U4 unsigned short
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# define z_off_t off_t
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef SEEK_SET
|
|
||||||
|
#ifdef Z_U4
|
||||||
|
typedef Z_U4 z_crc_t;
|
||||||
|
#else
|
||||||
|
typedef unsigned long z_crc_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
|
||||||
|
# define Z_HAVE_UNISTD_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
|
||||||
|
# define Z_HAVE_STDARG_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STDC
|
||||||
|
# ifndef Z_SOLO
|
||||||
|
# include <sys/types.h> /* for off_t */
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# include <stddef.h> /* for wchar_t */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
|
||||||
|
* "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
|
||||||
|
* though the former does not conform to the LFS document), but considering
|
||||||
|
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||||
|
* equivalently requesting no 64-bit operations
|
||||||
|
*/
|
||||||
|
#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
|
||||||
|
# undef _LARGEFILE64_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
|
||||||
|
# define Z_HAVE_UNISTD_H
|
||||||
|
#endif
|
||||||
|
#ifndef Z_SOLO
|
||||||
|
# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
|
||||||
|
# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
|
||||||
|
# ifdef VMS
|
||||||
|
# include <unixio.h> /* for off_t */
|
||||||
|
# endif
|
||||||
|
# ifndef z_off_t
|
||||||
|
# define z_off_t off_t
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
|
||||||
|
# define Z_LFS64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
|
||||||
|
# define Z_LARGE64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
|
||||||
|
# define Z_WANT64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SEEK_SET) && !defined(Z_SOLO)
|
||||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||||
# define SEEK_CUR 1 /* Seek from current position. */
|
# define SEEK_CUR 1 /* Seek from current position. */
|
||||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef z_off_t
|
#ifndef z_off_t
|
||||||
# define z_off_t long
|
# define z_off_t long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__OS400__)
|
#if !defined(_WIN32) && defined(Z_LARGE64)
|
||||||
# define NO_vsnprintf
|
# define z_off64_t off64_t
|
||||||
#endif
|
#else
|
||||||
|
# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
|
||||||
#if defined(__MVS__)
|
# define z_off64_t __int64
|
||||||
# define NO_vsnprintf
|
# else
|
||||||
# ifdef FAR
|
# define z_off64_t z_off_t
|
||||||
# undef FAR
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MVS linker does not support external names larger than 8 bytes */
|
/* MVS linker does not support external names larger than 8 bytes */
|
||||||
#if defined(__MVS__)
|
#if defined(__MVS__)
|
||||||
# pragma map(deflateInit_,"DEIN")
|
#pragma map(deflateInit_,"DEIN")
|
||||||
# pragma map(deflateInit2_,"DEIN2")
|
#pragma map(deflateInit2_,"DEIN2")
|
||||||
# pragma map(deflateEnd,"DEEND")
|
#pragma map(deflateEnd,"DEEND")
|
||||||
# pragma map(deflateBound,"DEBND")
|
#pragma map(deflateBound,"DEBND")
|
||||||
# pragma map(inflateInit_,"ININ")
|
#pragma map(inflateInit_,"ININ")
|
||||||
# pragma map(inflateInit2_,"ININ2")
|
#pragma map(inflateInit2_,"ININ2")
|
||||||
# pragma map(inflateEnd,"INEND")
|
#pragma map(inflateEnd,"INEND")
|
||||||
# pragma map(inflateSync,"INSY")
|
#pragma map(inflateSync,"INSY")
|
||||||
# pragma map(inflateSetDictionary,"INSEDI")
|
#pragma map(inflateSetDictionary,"INSEDI")
|
||||||
# pragma map(compressBound,"CMBND")
|
#pragma map(compressBound,"CMBND")
|
||||||
# pragma map(inflate_table,"INTABL")
|
#pragma map(inflate_table,"INTABL")
|
||||||
# pragma map(inflate_fast,"INFA")
|
#pragma map(inflate_fast,"INFA")
|
||||||
# pragma map(inflate_copyright,"INCOPY")
|
#pragma map(inflate_copyright,"INCOPY")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZCONF_H */
|
#endif /* ZCONF_H */
|
||||||
|
|
1331
zlib/zlib.h
1331
zlib/zlib.h
File diff suppressed because it is too large
Load diff
54
zlib/zutil.c
54
zlib/zutil.c
|
@ -1,11 +1,14 @@
|
||||||
/* zutil.c -- target dependent utility functions for the compression library
|
/* zutil.c -- target dependent utility functions for the compression library
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
* Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
|
#ifndef Z_SOLO
|
||||||
|
# include "gzguts.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NO_DUMMY_DECL
|
#ifndef NO_DUMMY_DECL
|
||||||
struct internal_state {int dummy;}; /* for buggy compilers */
|
struct internal_state {int dummy;}; /* for buggy compilers */
|
||||||
|
@ -34,25 +37,25 @@ uLong ZEXPORT zlibCompileFlags()
|
||||||
uLong flags;
|
uLong flags;
|
||||||
|
|
||||||
flags = 0;
|
flags = 0;
|
||||||
switch (sizeof(uInt)) {
|
switch ((int)(sizeof(uInt))) {
|
||||||
case 2: break;
|
case 2: break;
|
||||||
case 4: flags += 1; break;
|
case 4: flags += 1; break;
|
||||||
case 8: flags += 2; break;
|
case 8: flags += 2; break;
|
||||||
default: flags += 3;
|
default: flags += 3;
|
||||||
}
|
}
|
||||||
switch (sizeof(uLong)) {
|
switch ((int)(sizeof(uLong))) {
|
||||||
case 2: break;
|
case 2: break;
|
||||||
case 4: flags += 1 << 2; break;
|
case 4: flags += 1 << 2; break;
|
||||||
case 8: flags += 2 << 2; break;
|
case 8: flags += 2 << 2; break;
|
||||||
default: flags += 3 << 2;
|
default: flags += 3 << 2;
|
||||||
}
|
}
|
||||||
switch (sizeof(voidpf)) {
|
switch ((int)(sizeof(voidpf))) {
|
||||||
case 2: break;
|
case 2: break;
|
||||||
case 4: flags += 1 << 4; break;
|
case 4: flags += 1 << 4; break;
|
||||||
case 8: flags += 2 << 4; break;
|
case 8: flags += 2 << 4; break;
|
||||||
default: flags += 3 << 4;
|
default: flags += 3 << 4;
|
||||||
}
|
}
|
||||||
switch (sizeof(z_off_t)) {
|
switch ((int)(sizeof(z_off_t))) {
|
||||||
case 2: break;
|
case 2: break;
|
||||||
case 4: flags += 1 << 6; break;
|
case 4: flags += 1 << 6; break;
|
||||||
case 8: flags += 2 << 6; break;
|
case 8: flags += 2 << 6; break;
|
||||||
|
@ -85,27 +88,27 @@ uLong ZEXPORT zlibCompileFlags()
|
||||||
#ifdef FASTEST
|
#ifdef FASTEST
|
||||||
flags += 1L << 21;
|
flags += 1L << 21;
|
||||||
#endif
|
#endif
|
||||||
#ifdef STDC
|
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
||||||
# ifdef NO_vsnprintf
|
# ifdef NO_vsnprintf
|
||||||
flags += 1L << 25;
|
flags += 1L << 25;
|
||||||
# ifdef HAS_vsprintf_void
|
# ifdef HAS_vsprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
# ifdef HAS_vsnprintf_void
|
# ifdef HAS_vsnprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
flags += 1L << 24;
|
flags += 1L << 24;
|
||||||
# ifdef NO_snprintf
|
# ifdef NO_snprintf
|
||||||
flags += 1L << 25;
|
flags += 1L << 25;
|
||||||
# ifdef HAS_sprintf_void
|
# ifdef HAS_sprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
# ifdef HAS_snprintf_void
|
# ifdef HAS_snprintf_void
|
||||||
flags += 1L << 26;
|
flags += 1L << 26;
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -117,9 +120,9 @@ uLong ZEXPORT zlibCompileFlags()
|
||||||
# ifndef verbose
|
# ifndef verbose
|
||||||
# define verbose 0
|
# define verbose 0
|
||||||
# endif
|
# endif
|
||||||
int z_verbose = verbose;
|
int ZLIB_INTERNAL z_verbose = verbose;
|
||||||
|
|
||||||
void z_error (m)
|
void ZLIB_INTERNAL z_error (m)
|
||||||
char *m;
|
char *m;
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s\n", m);
|
fprintf(stderr, "%s\n", m);
|
||||||
|
@ -146,7 +149,7 @@ const char * ZEXPORT zError(err)
|
||||||
|
|
||||||
#ifndef HAVE_MEMCPY
|
#ifndef HAVE_MEMCPY
|
||||||
|
|
||||||
void zmemcpy(dest, source, len)
|
void ZLIB_INTERNAL zmemcpy(dest, source, len)
|
||||||
Bytef* dest;
|
Bytef* dest;
|
||||||
const Bytef* source;
|
const Bytef* source;
|
||||||
uInt len;
|
uInt len;
|
||||||
|
@ -157,7 +160,7 @@ void zmemcpy(dest, source, len)
|
||||||
} while (--len != 0);
|
} while (--len != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmemcmp(s1, s2, len)
|
int ZLIB_INTERNAL zmemcmp(s1, s2, len)
|
||||||
const Bytef* s1;
|
const Bytef* s1;
|
||||||
const Bytef* s2;
|
const Bytef* s2;
|
||||||
uInt len;
|
uInt len;
|
||||||
|
@ -170,7 +173,7 @@ int zmemcmp(s1, s2, len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmemzero(dest, len)
|
void ZLIB_INTERNAL zmemzero(dest, len)
|
||||||
Bytef* dest;
|
Bytef* dest;
|
||||||
uInt len;
|
uInt len;
|
||||||
{
|
{
|
||||||
|
@ -181,6 +184,7 @@ void zmemzero(dest, len)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef Z_SOLO
|
||||||
|
|
||||||
#ifdef SYS16BIT
|
#ifdef SYS16BIT
|
||||||
|
|
||||||
|
@ -213,7 +217,7 @@ local ptr_table table[MAX_PTR];
|
||||||
* a protected system like OS/2. Use Microsoft C instead.
|
* a protected system like OS/2. Use Microsoft C instead.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||||
{
|
{
|
||||||
voidpf buf = opaque; /* just to make some compilers happy */
|
voidpf buf = opaque; /* just to make some compilers happy */
|
||||||
ulg bsize = (ulg)items*size;
|
ulg bsize = (ulg)items*size;
|
||||||
|
@ -237,7 +241,7 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zcfree (voidpf opaque, voidpf ptr)
|
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||||
|
@ -272,13 +276,13 @@ void zcfree (voidpf opaque, voidpf ptr)
|
||||||
# define _hfree hfree
|
# define _hfree hfree
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
if (opaque) opaque = 0; /* to make compiler happy */
|
if (opaque) opaque = 0; /* to make compiler happy */
|
||||||
return _halloc((long)items, size);
|
return _halloc((long)items, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zcfree (voidpf opaque, voidpf ptr)
|
void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
|
||||||
{
|
{
|
||||||
if (opaque) opaque = 0; /* to make compiler happy */
|
if (opaque) opaque = 0; /* to make compiler happy */
|
||||||
_hfree(ptr);
|
_hfree(ptr);
|
||||||
|
@ -297,7 +301,7 @@ extern voidp calloc OF((uInt items, uInt size));
|
||||||
extern void free OF((voidpf ptr));
|
extern void free OF((voidpf ptr));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
voidpf zcalloc (opaque, items, size)
|
voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
unsigned items;
|
unsigned items;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
|
@ -307,7 +311,7 @@ voidpf zcalloc (opaque, items, size)
|
||||||
(voidpf)calloc(items, size);
|
(voidpf)calloc(items, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zcfree (opaque, ptr)
|
void ZLIB_INTERNAL zcfree (opaque, ptr)
|
||||||
voidpf opaque;
|
voidpf opaque;
|
||||||
voidpf ptr;
|
voidpf ptr;
|
||||||
{
|
{
|
||||||
|
@ -316,3 +320,5 @@ void zcfree (opaque, ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MY_ZCALLOC */
|
#endif /* MY_ZCALLOC */
|
||||||
|
|
||||||
|
#endif /* !Z_SOLO */
|
||||||
|
|
137
zlib/zutil.h
137
zlib/zutil.h
|
@ -1,5 +1,5 @@
|
||||||
/* zutil.h -- internal interface and configuration of the compression library
|
/* zutil.h -- internal interface and configuration of the compression library
|
||||||
* Copyright (C) 1995-2005 Jean-loup Gailly.
|
* Copyright (C) 1995-2012 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -13,30 +13,24 @@
|
||||||
#ifndef ZUTIL_H
|
#ifndef ZUTIL_H
|
||||||
#define ZUTIL_H
|
#define ZUTIL_H
|
||||||
|
|
||||||
#define ZLIB_INTERNAL
|
#ifdef HAVE_HIDDEN
|
||||||
|
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
||||||
|
#else
|
||||||
|
# define ZLIB_INTERNAL
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|
||||||
#ifdef STDC
|
#if defined(STDC) && !defined(Z_SOLO)
|
||||||
# ifndef _WIN32_WCE
|
# if !(defined(_WIN32_WCE) && defined(_MSC_VER))
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
# endif
|
# endif
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef NO_ERRNO_H
|
|
||||||
# ifdef _WIN32_WCE
|
#ifdef Z_SOLO
|
||||||
/* The Microsoft C Run-Time Library for Windows CE doesn't have
|
typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
|
||||||
* errno. We define it as a global variable to simplify porting.
|
|
||||||
* Its value is always 0 and should not be used. We rename it to
|
|
||||||
* avoid conflict with other libraries that use the same workaround.
|
|
||||||
*/
|
|
||||||
# define errno z_errno
|
|
||||||
# endif
|
|
||||||
extern int errno;
|
|
||||||
#else
|
|
||||||
# ifndef _WIN32_WCE
|
|
||||||
# include <errno.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef local
|
#ifndef local
|
||||||
|
@ -88,16 +82,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
|
||||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||||
# define OS_CODE 0x00
|
# define OS_CODE 0x00
|
||||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
# ifndef Z_SOLO
|
||||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||||
/* Allow compilation with ANSI keywords only enabled */
|
# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||||
void _Cdecl farfree( void *block );
|
/* Allow compilation with ANSI keywords only enabled */
|
||||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
void _Cdecl farfree( void *block );
|
||||||
# else
|
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||||
# include <alloc.h>
|
# else
|
||||||
|
# include <alloc.h>
|
||||||
|
# endif
|
||||||
|
# else /* MSC or DJGPP */
|
||||||
|
# include <malloc.h>
|
||||||
# endif
|
# endif
|
||||||
# else /* MSC or DJGPP */
|
|
||||||
# include <malloc.h>
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -117,18 +113,20 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
|
||||||
#ifdef OS2
|
#ifdef OS2
|
||||||
# define OS_CODE 0x06
|
# define OS_CODE 0x06
|
||||||
# ifdef M_I86
|
# if defined(M_I86) && !defined(Z_SOLO)
|
||||||
#include <malloc.h>
|
# include <malloc.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
# define OS_CODE 0x07
|
# define OS_CODE 0x07
|
||||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
# ifndef Z_SOLO
|
||||||
# include <unix.h> /* for fdopen */
|
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||||
# else
|
# include <unix.h> /* for fdopen */
|
||||||
# ifndef fdopen
|
# else
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# ifndef fdopen
|
||||||
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -151,7 +149,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
|
||||||
# if defined(_WIN32_WCE)
|
# if defined(_WIN32_WCE)
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
# ifndef _PTRDIFF_T_DEFINED
|
# ifndef _PTRDIFF_T_DEFINED
|
||||||
|
@ -163,6 +161,18 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__BORLANDC__) && !defined(MSDOS)
|
||||||
|
#pragma warn -8004
|
||||||
|
#pragma warn -8008
|
||||||
|
#pragma warn -8066
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* provide prototypes for these when building zlib without LFS */
|
||||||
|
#if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
|
||||||
|
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
|
||||||
|
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* common defaults */
|
/* common defaults */
|
||||||
|
|
||||||
#ifndef OS_CODE
|
#ifndef OS_CODE
|
||||||
|
@ -175,40 +185,7 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
|
|
||||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
#if defined(pyr) || defined(Z_SOLO)
|
||||||
# ifndef HAVE_VSNPRINTF
|
|
||||||
# define HAVE_VSNPRINTF
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#if defined(__CYGWIN__)
|
|
||||||
# ifndef HAVE_VSNPRINTF
|
|
||||||
# define HAVE_VSNPRINTF
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifndef HAVE_VSNPRINTF
|
|
||||||
# ifdef MSDOS
|
|
||||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
|
||||||
but for now we just assume it doesn't. */
|
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
|
||||||
# ifdef __TURBOC__
|
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
|
||||||
# ifdef WIN32
|
|
||||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
|
||||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
|
||||||
# define vsnprintf _vsnprintf
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
# ifdef __SASC
|
|
||||||
# define NO_vsnprintf
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifdef VMS
|
|
||||||
# define NO_vsnprintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(pyr)
|
|
||||||
# define NO_MEMCPY
|
# define NO_MEMCPY
|
||||||
#endif
|
#endif
|
||||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||||
|
@ -232,16 +209,16 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||||
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||||
extern void zmemzero OF((Bytef* dest, uInt len));
|
void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Diagnostic functions */
|
/* Diagnostic functions */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
extern int z_verbose;
|
extern int ZLIB_INTERNAL z_verbose;
|
||||||
extern void z_error OF((char *m));
|
extern void ZLIB_INTERNAL z_error OF((char *m));
|
||||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||||
|
@ -257,13 +234,19 @@ extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
# define Tracecv(c,x)
|
# define Tracecv(c,x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef Z_SOLO
|
||||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
|
||||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
unsigned size));
|
||||||
|
void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ZALLOC(strm, items, size) \
|
#define ZALLOC(strm, items, size) \
|
||||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||||
|
|
||||||
|
/* Reverse the bytes in a 32-bit value */
|
||||||
|
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
|
||||||
|
(((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
|
||||||
|
|
||||||
#endif /* ZUTIL_H */
|
#endif /* ZUTIL_H */
|
||||||
|
|
Loading…
Reference in a new issue