Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b834a58bd | ||
|
|
bdde4e09d2 | ||
|
|
1c71d8b13b |
27
ChangeLog
27
ChangeLog
@@ -1,5 +1,31 @@
|
||||
ChangeLog file for zlib
|
||||
|
||||
Changes in 0.93 (25 June 95)
|
||||
- temporarily disable inline functions
|
||||
- make deflate deterministic
|
||||
- give enough lookahead for PARTIAL_FLUSH
|
||||
- Set binary mode for stdin/stdout in minigzip.c for OS/2
|
||||
- don't even use signed char in inflate (not portable enough)
|
||||
- fix inflate memory leak for segmented architectures
|
||||
|
||||
Changes in 0.92 (3 May 95)
|
||||
- don't assume that char is signed (problem on SGI)
|
||||
- Clear bit buffer when starting a stored block
|
||||
- no memcpy on Pyramid
|
||||
- suppressed inftest.c
|
||||
- optimized fill_window, put longest_match inline for gcc
|
||||
- optimized inflate on stored blocks.
|
||||
- untabify all sources to simplify patches
|
||||
|
||||
Changes in 0.91 (2 May 95)
|
||||
- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
|
||||
- Document the memory requirements in zconf.h
|
||||
- added "make install"
|
||||
- fix sync search logic in inflateSync
|
||||
- deflate(Z_FULL_FLUSH) now works even if output buffer too short
|
||||
- after inflateSync, don't scare people with just "lo world"
|
||||
- added support for DJGPP
|
||||
|
||||
Changes in 0.9 (1 May 95)
|
||||
- don't assume that zalloc clears the allocated memory (the TurboC bug
|
||||
was Mark's bug after all :)
|
||||
@@ -10,6 +36,7 @@ Changes in 0.9 (1 May 95)
|
||||
- document explicitly that zalloc(64K) on MSDOS must return a normalized
|
||||
pointer (zero offset)
|
||||
- added Makefiles for Microsoft C, Turbo C, Borland C++
|
||||
- faster crc32()
|
||||
|
||||
Changes in 0.8 (29 April 95)
|
||||
- added fast inflate (inffast.c)
|
||||
|
||||
26
Makefile
26
Makefile
@@ -1,21 +1,37 @@
|
||||
# Makefile for zlib
|
||||
# Copyright (C) 1995 Jean-loup Gailly.
|
||||
# For conditions of distribution and use, see copyright notice in zlib.h
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-O
|
||||
#use -O3 for gcc to take advantage of inlining
|
||||
#CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
#CFLAGS=-g -DDEBUG
|
||||
LDFLAGS=-L. -lgz
|
||||
|
||||
RANLIB=ranlib
|
||||
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o inftest.o
|
||||
TEST_OBJS = example.o minigzip.o
|
||||
|
||||
all: example minigzip inftest
|
||||
all: example minigzip
|
||||
|
||||
test: all
|
||||
./example
|
||||
echo hello world | ./minigzip | ./minigzip -d
|
||||
|
||||
install: libgz.a
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp zlib.h zconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/zlib.h $(prefix)/include/zconf.h
|
||||
cp libgz.a $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libgz.a
|
||||
|
||||
libgz.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
@@ -26,11 +42,8 @@ example: example.o libgz.a
|
||||
minigzip: minigzip.o libgz.a
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
|
||||
|
||||
inftest: inftest.o libgz.a
|
||||
$(CC) $(CFLAGS) -o $@ inftest.o $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f *.o example minigzip inftest libgz.a foo.gz
|
||||
rm -f *.o example minigzip libgz.a foo.gz
|
||||
|
||||
zip:
|
||||
zip -ul9 zlib README ChangeLog Makefile Makefile.??? Makefile.?? *.[ch]
|
||||
@@ -51,7 +64,6 @@ infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
|
||||
infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h
|
||||
inffast.o: zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
|
||||
inflate.o: zutil.h zlib.h zconf.h infblock.h
|
||||
inftest.o: zutil.h zlib.h zconf.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
|
||||
59
Makefile.bak
59
Makefile.bak
@@ -1,59 +0,0 @@
|
||||
CC=gcc
|
||||
CFLAGS=-O2
|
||||
#CFLAGS=-g -DDEBUG
|
||||
LDFLAGS=-L. -lgz
|
||||
|
||||
RANLIB=ranlib
|
||||
|
||||
OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \
|
||||
zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o
|
||||
|
||||
TEST_OBJS = example.o minigzip.o inftest.o
|
||||
|
||||
all: example minigzip inftest
|
||||
|
||||
test: all
|
||||
./example
|
||||
echo hello world | ./minigzip | ./minigzip -d
|
||||
|
||||
libgz.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
example: example.o libgz.a
|
||||
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS)
|
||||
|
||||
minigzip: minigzip.o libgz.a
|
||||
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS)
|
||||
|
||||
inftest: inftest.o libgz.a
|
||||
$(CC) $(CFLAGS) -o $@ inftest.o $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f *.o example minigzip inftest libgz.a foo.gz
|
||||
|
||||
zip:
|
||||
zip -ul9 zlib README ChangeLog Makefile *.[ch]
|
||||
|
||||
tgz:
|
||||
cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \
|
||||
zlib/*.[ch]
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
adler32.o: zutil.h zlib.h zconf.h
|
||||
compress.o: zlib.h zconf.h
|
||||
crc32.o: zutil.h zlib.h zconf.h
|
||||
deflate.o: deflate.h zutil.h zlib.h zconf.h
|
||||
example.o: zlib.h zconf.h
|
||||
gzio.o: zutil.h zlib.h zconf.h
|
||||
infblock.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h
|
||||
infcodes.o: zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h
|
||||
inflate.o: zutil.h zlib.h zconf.h infblock.h
|
||||
inftest.o: zutil.h zlib.h zconf.h
|
||||
inftrees.o: zutil.h zlib.h zconf.h inftrees.h
|
||||
infutil.o: zutil.h zlib.h zconf.h inftrees.h infutil.h
|
||||
minigzip.o: zlib.h zconf.h
|
||||
trees.o: deflate.h zutil.h zlib.h zconf.h
|
||||
uncompr.o: zlib.h zconf.h
|
||||
zutil.o: zutil.h zlib.h zconf.h
|
||||
@@ -4,7 +4,10 @@
|
||||
# To use, do "make -fmakefile.bor"
|
||||
|
||||
# WARNING: the small model is supported but only for small values of
|
||||
# MAX_WBITS and MAX_MEM_LEVEL
|
||||
# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory
|
||||
# requirements (default 256K for big objects plus a few K), you can add
|
||||
# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
|
||||
# See zconf.h for details about the memory requirements.
|
||||
|
||||
# ------------- Turbo C++, Borland C++ -------------
|
||||
MODEL=-ml
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
# To use, do "make makefile.msc"
|
||||
|
||||
# WARNING: the small model is supported but only for small values of
|
||||
# MAX_WBITS and MAX_MEM_LEVEL
|
||||
# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory
|
||||
# requirements (default 256K for big objects plus a few K), you can add
|
||||
# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
|
||||
# See zconf.h for details about the memory requirements.
|
||||
|
||||
# ------------- Microsoft C 5.1 and later -------------
|
||||
MODEL=-AL
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
# To use, do "make -fmakefile.tc"
|
||||
|
||||
# WARNING: the small model is supported but only for small values of
|
||||
# MAX_WBITS and MAX_MEM_LEVEL
|
||||
# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory
|
||||
# requirements (default 256K for big objects plus a few K), you can add
|
||||
# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
|
||||
# See zconf.h for details about the memory requirements.
|
||||
|
||||
# ------------- Turbo C 2.0 -------------
|
||||
MODEL=-ml
|
||||
|
||||
38
README
38
README
@@ -1,25 +1,37 @@
|
||||
zlib 0.9 is a beta version of a general purpose compression library.
|
||||
zlib 0.93 is a beta version of a general purpose compression library.
|
||||
|
||||
The data format used by the zlib library is described in the
|
||||
file zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
|
||||
files zlib-3.1.doc, deflate-1.1.doc and gzip-4.1.doc, available
|
||||
in ftp.uu.net:/pub/archiving/zip/doc.
|
||||
|
||||
All functions of the compression library are documented in the file
|
||||
zlib.h. A usage example of the library is given in the file example.c
|
||||
which also tests that the library is working correctly.
|
||||
To compile all files and run the test program, just type: make test
|
||||
|
||||
The changes made in version 0.9 are documented in the file ChangeLog.
|
||||
The main changes since 0.8 are:
|
||||
- don't assume that zalloc clears the allocated memory
|
||||
- let again gzread copy uncompressed data unchanged (was working in 0.71)
|
||||
- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
|
||||
To compile all files and run the test program, just type: make test
|
||||
(For MSDOS, use one of the special makefiles such as Makefile.msc.)
|
||||
To install the zlib library (libgz.a) in /usr/local/lib, type: make install
|
||||
To install in a different directory, use for example: make install prefix=$HOME
|
||||
This will install in $HOME/lib instead of /usr/local/lib.
|
||||
|
||||
The changes made in version 0.93 are documented in the file ChangeLog.
|
||||
The main changes since 0.9 are:
|
||||
- temporarily disable inline functions
|
||||
- make deflate deterministic
|
||||
- don't use signed char in inflate (not portable enough)
|
||||
- fix inflate memory leak for segmented architectures
|
||||
- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
|
||||
- Document the memory requirements in zconf.h
|
||||
- added "make install"
|
||||
- added support for DJGPP and Pyramid
|
||||
- fix an inflate bug for stored blocks.
|
||||
- various speedups
|
||||
|
||||
On MSDOS, this version works in both large and small model. However
|
||||
small model compression works only for small values of MEM_LEVEL and
|
||||
WBITS (see zutil.h). Small model decompression should work up to WBITS=15.
|
||||
This version of zlib does not support small or medium model with far
|
||||
allocation of big objects.
|
||||
small model compression works only for small values of MAX_MEM_LEVEL
|
||||
and MAX_WBITS (see zconf.h). Small model decompression should work up
|
||||
to MAX_WBITS=15. This version of zlib does not support small or
|
||||
medium model with far allocation of big objects.
|
||||
|
||||
|
||||
Copyright (C) 1995 Jean-loup Gailly and Mark Adler
|
||||
@@ -41,7 +53,7 @@ allocation of big objects.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
gzip@prep.ai.mit.edu madler@cco.caltech.edu
|
||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
|
||||
|
||||
If you use the zlib library in a product, we would appreciate *not*
|
||||
receiving lengthy legal documents to sign. The sources are provided
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: adler32.c,v 1.5 1995/04/14 14:49:51 jloup Exp $ */
|
||||
/* $Id: adler32.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: compress.c,v 1.5 1995/04/29 17:18:43 jloup Exp $ */
|
||||
/* $Id: compress.c,v 1.6 1995/05/03 17:27:08 jloup Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
|
||||
69
crc32.c
69
crc32.c
@@ -7,57 +7,35 @@
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
extern uLong crc_table[]; /* crc table, defined below */
|
||||
|
||||
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
||||
#define DO2(buf) DO1(buf); DO1(buf);
|
||||
#define DO4(buf) DO2(buf); DO2(buf);
|
||||
#define DO8(buf) DO4(buf); DO4(buf);
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong crc32(crc, buf, len)
|
||||
uLong crc;
|
||||
Byte *buf;
|
||||
uInt len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0L;
|
||||
crc = crc ^ 0xffffffffL;
|
||||
while (len >= 8)
|
||||
{
|
||||
DO8(buf);
|
||||
len -= 8;
|
||||
}
|
||||
if (len) do {
|
||||
DO1(buf);
|
||||
} while (--len);
|
||||
return crc ^ 0xffffffffL;
|
||||
}
|
||||
#define local static
|
||||
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
/* =========================================================================
|
||||
* Make the crc table. This function is needed only if you want to compute
|
||||
* the table dynamically.
|
||||
*/
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
local int crc_table_empty = 1;
|
||||
local uLong crc_table[256];
|
||||
|
||||
local void make_crc_table()
|
||||
{
|
||||
uLong c;
|
||||
int n, k;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (uLong)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? 0xedb88320L ^ (c >> 1) : c >> 1;
|
||||
crc_table[n] = c;
|
||||
}
|
||||
crc_table_empty = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by make_crc_table)
|
||||
*/
|
||||
uLong crc_table[] = {
|
||||
local uLong crc_table[] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
@@ -111,3 +89,32 @@ uLong crc_table[] = {
|
||||
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
|
||||
0x2d02ef8dL
|
||||
};
|
||||
#endif
|
||||
|
||||
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
|
||||
#define DO2(buf) DO1(buf); DO1(buf);
|
||||
#define DO4(buf) DO2(buf); DO2(buf);
|
||||
#define DO8(buf) DO4(buf); DO4(buf);
|
||||
|
||||
/* ========================================================================= */
|
||||
uLong crc32(crc, buf, len)
|
||||
uLong crc;
|
||||
Byte *buf;
|
||||
uInt len;
|
||||
{
|
||||
if (buf == Z_NULL) return 0L;
|
||||
#ifdef DYNAMIC_CRC_TABLE
|
||||
if (crc_table_empty)
|
||||
make_crc_table();
|
||||
#endif
|
||||
crc = crc ^ 0xffffffffL;
|
||||
while (len >= 8)
|
||||
{
|
||||
DO8(buf);
|
||||
len -= 8;
|
||||
}
|
||||
if (len) do {
|
||||
DO1(buf);
|
||||
} while (--len);
|
||||
return crc ^ 0xffffffffL;
|
||||
}
|
||||
|
||||
89
deflate.c
89
deflate.c
@@ -47,7 +47,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* $Id: deflate.c,v 1.6 1995/05/01 17:23:57 jloup Exp $ */
|
||||
/* $Id: deflate.c,v 1.8 1995/05/03 17:27:08 jloup Exp $ */
|
||||
|
||||
#include "deflate.h"
|
||||
|
||||
@@ -117,7 +117,7 @@ local void fill_window __P((deflate_state *s));
|
||||
local int deflate_fast __P((deflate_state *s, int flush));
|
||||
local int deflate_slow __P((deflate_state *s, int flush));
|
||||
local void lm_init __P((deflate_state *s));
|
||||
local int longest_match __P((deflate_state *s, IPos cur_match));
|
||||
local inline int longest_match __P((deflate_state *s, IPos cur_match));
|
||||
local void putShortMSB __P((deflate_state *s, uInt b));
|
||||
local void flush_pending __P((z_stream *strm));
|
||||
local int read_buf __P((z_stream *strm, char *buf, unsigned size));
|
||||
@@ -165,7 +165,7 @@ int deflateInit (strm, level)
|
||||
z_stream *strm;
|
||||
int level;
|
||||
{
|
||||
return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, MAX_MEM_LEVEL, 0);
|
||||
return deflateInit2 (strm, level, DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 0);
|
||||
/* To do: ignore strm->next_in if we use it as window */
|
||||
}
|
||||
|
||||
@@ -344,22 +344,27 @@ int deflate (strm, flush)
|
||||
*/
|
||||
if (strm->avail_in != 0 ||
|
||||
(flush == Z_FINISH && strm->state->status != FINISH_STATE)) {
|
||||
int quit;
|
||||
|
||||
if (flush == Z_FINISH) {
|
||||
strm->state->status = FINISH_STATE;
|
||||
}
|
||||
if (strm->state->level <= 3) {
|
||||
if (deflate_fast(strm->state, flush)) return Z_OK;
|
||||
quit = deflate_fast(strm->state, flush);
|
||||
} else {
|
||||
if (deflate_slow(strm->state, flush)) return Z_OK;
|
||||
quit = deflate_slow(strm->state, flush);
|
||||
}
|
||||
/* ??? remember Z_FULL_FLUSH if we didn't have enough space */
|
||||
if (flush == Z_FULL_FLUSH) {
|
||||
if (flush == Z_FULL_FLUSH || flush == Z_SYNC_FLUSH) {
|
||||
ct_stored_block(strm->state, (char*)0, 0L, 0); /* special marker */
|
||||
flush_pending(strm);
|
||||
if (flush == Z_FULL_FLUSH) {
|
||||
CLEAR_HASH(strm->state); /* forget history */
|
||||
if (strm->avail_out == 0) return Z_OK;
|
||||
}
|
||||
} else if (flush == Z_PARTIAL_FLUSH) {
|
||||
ct_align(strm->state);
|
||||
flush_pending(strm);
|
||||
}
|
||||
if (quit || strm->avail_out == 0) return Z_OK;
|
||||
}
|
||||
Assert(strm->avail_out > 0, "bug2");
|
||||
|
||||
@@ -446,8 +451,6 @@ local int read_buf(strm, buf, size)
|
||||
local void lm_init (s)
|
||||
deflate_state *s;
|
||||
{
|
||||
register unsigned j;
|
||||
|
||||
s->window_size = (ulg)2L*s->w_size;
|
||||
|
||||
CLEAR_HASH(s);
|
||||
@@ -464,15 +467,10 @@ local void lm_init (s)
|
||||
s->lookahead = 0;
|
||||
s->match_length = MIN_MATCH-1;
|
||||
s->match_available = 0;
|
||||
s->ins_h = 0;
|
||||
#ifdef ASMV
|
||||
match_init(); /* initialize the asm code */
|
||||
#endif
|
||||
|
||||
s->ins_h = 0;
|
||||
for (j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(s, s->ins_h, s->window[j]);
|
||||
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
|
||||
* not important since only literal bytes will be emitted.
|
||||
*/
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -487,7 +485,7 @@ local void lm_init (s)
|
||||
/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
|
||||
* match.S. The code will be functionally equivalent.
|
||||
*/
|
||||
local int longest_match(s, cur_match)
|
||||
local inline int longest_match(s, cur_match)
|
||||
deflate_state *s;
|
||||
IPos cur_match; /* current match */
|
||||
{
|
||||
@@ -501,6 +499,8 @@ local int longest_match(s, cur_match)
|
||||
/* Stop when cur_match becomes <= limit. To simplify the code,
|
||||
* we prevent matches with the string of window index 0.
|
||||
*/
|
||||
Pos *prev = s->prev;
|
||||
uInt wmask = s->w_mask;
|
||||
|
||||
#ifdef UNALIGNED_OK
|
||||
/* Compare two bytes at a time. Note: this is not always beneficial.
|
||||
@@ -608,7 +608,7 @@ local int longest_match(s, cur_match)
|
||||
scan_end = scan[best_len];
|
||||
#endif
|
||||
}
|
||||
} while ((cur_match = s->prev[cur_match & s->w_mask]) > limit
|
||||
} while ((cur_match = prev[cur_match & wmask]) > limit
|
||||
&& --chain_length != 0);
|
||||
|
||||
return best_len;
|
||||
@@ -655,14 +655,16 @@ local void fill_window(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
register unsigned n, m;
|
||||
register Pos *p;
|
||||
unsigned more; /* Amount of free space at the end of the window. */
|
||||
uInt wsize = s->w_size;
|
||||
|
||||
do {
|
||||
more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
|
||||
|
||||
/* Deal with !@#$% 64K limit: */
|
||||
if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
|
||||
more = s->w_size;
|
||||
more = wsize;
|
||||
} else if (more == (unsigned)(-1)) {
|
||||
/* Very unlikely, but possible on 16 bit machine if strstart == 0
|
||||
* and lookahead == 1 (input done one byte at time)
|
||||
@@ -672,30 +674,39 @@ local void fill_window(s)
|
||||
/* If the window is almost full and there is insufficient lookahead,
|
||||
* move the upper half to the lower one to make room in the upper half.
|
||||
*/
|
||||
} else if (s->strstart >= s->w_size+MAX_DIST(s)) {
|
||||
} else if (s->strstart >= wsize+MAX_DIST(s)) {
|
||||
|
||||
/* By the IN assertion, the window is not empty so we can't confuse
|
||||
* more == 0 with more == 64K on a 16 bit machine.
|
||||
*/
|
||||
memcpy((char*)s->window, (char*)s->window+s->w_size,
|
||||
(unsigned)s->w_size);
|
||||
s->match_start -= s->w_size;
|
||||
s->strstart -= s->w_size; /* we now have strstart >= MAX_DIST */
|
||||
zmemcpy((char*)s->window, (char*)s->window+wsize,
|
||||
(unsigned)wsize);
|
||||
s->match_start -= wsize;
|
||||
s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
|
||||
|
||||
s->block_start -= (long) s->w_size;
|
||||
s->block_start -= (long) wsize;
|
||||
|
||||
for (n = 0; n < s->hash_size; n++) {
|
||||
m = s->head[n];
|
||||
s->head[n] = (Pos)(m >= s->w_size ? m-s->w_size : NIL);
|
||||
}
|
||||
for (n = 0; n < s->w_size; n++) {
|
||||
m = s->prev[n];
|
||||
s->prev[n] = (Pos)(m >= s->w_size ? m-s->w_size : NIL);
|
||||
/* Slide the hash table (could be avoided with 32 bit values
|
||||
at the expense of memory usage):
|
||||
*/
|
||||
n = s->hash_size;
|
||||
p = &s->head[n-1];
|
||||
do {
|
||||
m = *p;
|
||||
*p-- = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
} while (--n);
|
||||
|
||||
n = wsize;
|
||||
p = &s->prev[n-1];
|
||||
do {
|
||||
m = *p;
|
||||
*p-- = (Pos)(m >= wsize ? m-wsize : NIL);
|
||||
/* If n is not on any hash chain, prev[n] is garbage but
|
||||
* its value will never be used.
|
||||
*/
|
||||
}
|
||||
more += s->w_size;
|
||||
} while (--n);
|
||||
|
||||
more += wsize;
|
||||
}
|
||||
if (s->strm->avail_in == 0) return;
|
||||
|
||||
@@ -716,6 +727,16 @@ local void fill_window(s)
|
||||
more);
|
||||
s->lookahead += n;
|
||||
|
||||
/* Initialize the hash value now that we have some input: */
|
||||
if (s->strstart == 0 && s->lookahead >= MIN_MATCH-1) {
|
||||
for (n=0; n<MIN_MATCH-1; n++) {
|
||||
UPDATE_HASH(s, s->ins_h, s->window[n]);
|
||||
}
|
||||
}
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
} while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* $Id: deflate.h,v 1.4 1995/05/01 15:08:45 jloup Exp $ */
|
||||
/* $Id: deflate.h,v 1.5 1995/05/03 17:27:09 jloup Exp $ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
@@ -268,5 +268,6 @@ typedef struct internal_state {
|
||||
void ct_init __P((deflate_state *s));
|
||||
int ct_tally __P((deflate_state *s, int dist, int lc));
|
||||
ulg ct_flush_block __P((deflate_state *s, char *buf, ulg stored_len, int eof));
|
||||
void ct_align __P((deflate_state *s));
|
||||
void ct_stored_block __P((deflate_state *s, char *buf, ulg stored_len,
|
||||
int eof));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: example.c,v 1.7 1995/05/01 16:57:22 jloup Exp $ */
|
||||
/* $Id: example.c,v 1.9 1995/05/03 17:27:09 jloup Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
@@ -12,7 +12,9 @@
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef __GO32__
|
||||
extern void exit __P((int));
|
||||
#endif
|
||||
|
||||
#define BUFLEN 4096
|
||||
|
||||
@@ -253,7 +255,7 @@ void test_sync(compr)
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
printf("after inflateSync(): %s\n", uncompr);
|
||||
printf("after inflateSync(): hel%s\n", uncompr);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
|
||||
6
gzio.c
6
gzio.c
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: gzio.c,v 1.6 1995/04/30 19:52:21 jloup Exp $ */
|
||||
/* $Id: gzio.c,v 1.8 1995/05/03 17:27:09 jloup Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -128,7 +128,7 @@ local gzFile gz_open (path, mode, fd)
|
||||
|
||||
if (s->mode == 'w') {
|
||||
err = deflateInit2(&(s->stream), Z_DEFAULT_COMPRESSION,
|
||||
DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, 0);
|
||||
DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
|
||||
/* windowBits is passed < 0 to suppress zlib header */
|
||||
|
||||
s->stream.next_out = s->outbuf = ALLOC(Z_BUFSIZE);
|
||||
@@ -221,7 +221,7 @@ gzFile gzdopen (fd, mode)
|
||||
char *mode;
|
||||
{
|
||||
char name[20];
|
||||
sprintf(name, "_fd:%d_", fd); /* for debugging */
|
||||
sprintf(name, "<fd:%d>", fd); /* for debugging */
|
||||
|
||||
return gz_open (name, mode, fd);
|
||||
}
|
||||
|
||||
36
infblock.c
36
infblock.c
@@ -71,7 +71,11 @@ uLong *c;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES)
|
||||
inflate_codes_free(s->sub.codes, z);
|
||||
{
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
}
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
@@ -147,12 +151,14 @@ int r;
|
||||
inflate_huft *tl, *td;
|
||||
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td);
|
||||
s->sub.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.codes == Z_NULL)
|
||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.tl = Z_NULL; /* don't try to free these */
|
||||
s->sub.decode.td = Z_NULL;
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
@@ -180,17 +186,23 @@ int r;
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
k = 0; /* dump bits */
|
||||
s->sub.left = (uInt)b & 0xffff;
|
||||
b = k = 0; /* dump bits */
|
||||
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
||||
s->mode = s->sub.left ? STORED : TYPE;
|
||||
break;
|
||||
case STORED:
|
||||
do {
|
||||
NEEDBYTE
|
||||
if (n == 0)
|
||||
LEAVE
|
||||
NEEDOUT
|
||||
OUTBYTE(NEXTBYTE)
|
||||
} while (--s->sub.left);
|
||||
t = s->sub.left;
|
||||
if (t > n) t = n;
|
||||
if (t > m) t = m;
|
||||
zmemcpy(q, p, t);
|
||||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((s->sub.left -= t) != 0)
|
||||
break;
|
||||
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
@@ -312,7 +324,9 @@ int r;
|
||||
LEAVE
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->sub.codes = c;
|
||||
s->sub.decode.codes = c;
|
||||
s->sub.decode.tl = tl;
|
||||
s->sub.decode.td = td;
|
||||
}
|
||||
s->mode = CODES;
|
||||
case CODES:
|
||||
@@ -320,7 +334,9 @@ int r;
|
||||
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
||||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
inflate_codes_free(s->sub.codes, z);
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
inflate_trees_free(s->sub.decode.td, z);
|
||||
inflate_trees_free(s->sub.decode.tl, z);
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
|
||||
75
infcodes.c
75
infcodes.c
@@ -83,7 +83,7 @@ int r;
|
||||
{
|
||||
uInt j; /* temporary storage */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
int e; /* extra bits or operation */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Byte *p; /* input data pointer */
|
||||
@@ -91,7 +91,7 @@ int r;
|
||||
Byte *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
Byte *f; /* pointer to copy strings from */
|
||||
struct inflate_codes_state *c = s->sub.codes; /* codes state */
|
||||
struct inflate_codes_state *c = s->sub.decode.codes; /* codes state */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
@@ -121,27 +121,8 @@ int r;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
if ((e = (int)(t->exop)) < 0)
|
||||
{
|
||||
if (e == -128) /* invalid code */
|
||||
{
|
||||
c->mode = BADCODE;
|
||||
z->msg = "invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
e = -e;
|
||||
if (e & 64) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
break;
|
||||
}
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t->next;
|
||||
break;
|
||||
}
|
||||
if (e & 16) /* literal */
|
||||
e = (uInt)(t->exop);
|
||||
if (e == 0) /* literal */
|
||||
{
|
||||
c->sub.lit = t->base;
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
@@ -150,9 +131,29 @@ int r;
|
||||
c->mode = LIT;
|
||||
break;
|
||||
}
|
||||
c->sub.copy.get = e;
|
||||
if (e & 16) /* length */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->len = t->base;
|
||||
c->mode = LENEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t->next;
|
||||
break;
|
||||
}
|
||||
if (e & 32) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = "invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case LENEXT: /* i: getting length extra (have base) */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
@@ -167,22 +168,24 @@ int r;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
if ((e = (int)(t->exop)) < 0)
|
||||
e = (uInt)(t->exop);
|
||||
if (e & 16) /* distance */
|
||||
{
|
||||
if (e == -128)
|
||||
{
|
||||
c->mode = BADCODE;
|
||||
z->msg = "invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
c->sub.copy.get = e & 15;
|
||||
c->sub.copy.dist = t->base;
|
||||
c->mode = DISTEXT;
|
||||
break;
|
||||
}
|
||||
c->sub.code.need = -e;
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t->next;
|
||||
break;
|
||||
}
|
||||
c->sub.copy.dist = t->base;
|
||||
c->sub.copy.get = e;
|
||||
c->mode = DISTEXT;
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = "invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case DISTEXT: /* i: getting distance extra */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
@@ -231,8 +234,6 @@ void inflate_codes_free(c, z)
|
||||
struct inflate_codes_state *c;
|
||||
z_stream *z;
|
||||
{
|
||||
inflate_trees_free(c->dtree, z);
|
||||
inflate_trees_free(c->ltree, z);
|
||||
ZFREE(z, c);
|
||||
Tracev((stderr, "inflate: codes free\n"));
|
||||
}
|
||||
|
||||
107
inffast.c
107
inffast.c
@@ -17,10 +17,6 @@ struct inflate_codes_state {int dummy;}; /* for buggy compilers */
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* macros for bit input with no checking and for returning unused bytes */
|
||||
#ifdef DEBUG
|
||||
# undef NEXTBYTE
|
||||
# define NEXTBYTE (n--?0:fprintf(stderr,"inffast underrun\n"),*p++)
|
||||
#endif
|
||||
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define UNGRAB {n+=(c=k>>3);p-=c;k&=7;}
|
||||
|
||||
@@ -36,7 +32,7 @@ struct inflate_blocks_state *s;
|
||||
z_stream *z;
|
||||
{
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
int e; /* extra bits or operation */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Byte *p; /* input data pointer */
|
||||
@@ -52,7 +48,7 @@ z_stream *z;
|
||||
/* load input, output, bit values */
|
||||
LOAD
|
||||
|
||||
/* initialize masks in registers */
|
||||
/* initialize masks */
|
||||
ml = inflate_mask[bl];
|
||||
md = inflate_mask[bd];
|
||||
|
||||
@@ -60,81 +56,53 @@ z_stream *z;
|
||||
do { /* assume called with m >= 258 && n >= 10 */
|
||||
/* get literal/length code */
|
||||
GRABBITS(20) /* max bits for literal/length code */
|
||||
if ((e = (t = tl + ((uInt)b & ml))->exop) < 0)
|
||||
do {
|
||||
if (e == -128)
|
||||
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
|
||||
{
|
||||
z->msg = "invalid literal/length code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
DUMPBITS(t->bits)
|
||||
e = -e;
|
||||
if (e & 64) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: * end of block\n"));
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_STREAM_END;
|
||||
}
|
||||
} while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0);
|
||||
DUMPBITS(t->bits)
|
||||
|
||||
/* process literal or length (end of block already trapped) */
|
||||
if (e & 16) /* then it's a literal */
|
||||
{
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
continue;
|
||||
}
|
||||
else /* it's a length */
|
||||
do {
|
||||
DUMPBITS(t->bits)
|
||||
if (e & 16)
|
||||
{
|
||||
/* get length of block to copy (already have extra bits) */
|
||||
/* get extra bits for length */
|
||||
e &= 15;
|
||||
c = t->base + ((uInt)b & inflate_mask[e]);
|
||||
DUMPBITS(e);
|
||||
DUMPBITS(e)
|
||||
Tracevv((stderr, "inflate: * length %u\n", c));
|
||||
|
||||
/* decode distance base of block to copy */
|
||||
GRABBITS(15); /* max bits for distance code */
|
||||
if ((e = (t = td + ((uInt)b & md))->exop) < 0)
|
||||
e = (t = td + ((uInt)b & md))->exop;
|
||||
do {
|
||||
if (e == -128)
|
||||
DUMPBITS(t->bits)
|
||||
if (e & 16)
|
||||
{
|
||||
z->msg = "invalid distance code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
DUMPBITS(t->bits)
|
||||
e = -e;
|
||||
} while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0);
|
||||
DUMPBITS(t->bits)
|
||||
|
||||
/* get extra bits to add to distance base */
|
||||
GRABBITS((uInt)e) /* get extra bits (up to 13) */
|
||||
e &= 15;
|
||||
GRABBITS(e) /* get extra bits (up to 13) */
|
||||
d = t->base + ((uInt)b & inflate_mask[e]);
|
||||
DUMPBITS(e)
|
||||
Tracevv((stderr, "inflate: * distance %u\n", d));
|
||||
|
||||
/* do the copy */
|
||||
m -= c;
|
||||
if ((uInt)(q - s->window) >= d) /* if offset before destination, */
|
||||
if ((uInt)(q - s->window) >= d) /* offset before dest */
|
||||
{ /* just copy */
|
||||
r = q - d;
|
||||
*q++ = *r++; c--; /* minimum count is three, */
|
||||
*q++ = *r++; c--; /* so unroll loop a little */
|
||||
do {
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
}
|
||||
else /* else offset after destination */
|
||||
{
|
||||
e = d - (q - s->window); /* bytes from offset to end */
|
||||
r = s->end - e; /* pointer to offset */
|
||||
if (c > (uInt)e) /* if source crosses, */
|
||||
if (c > e) /* if source crosses, */
|
||||
{
|
||||
c -= e; /* copy to end of window */
|
||||
do {
|
||||
@@ -142,11 +110,52 @@ z_stream *z;
|
||||
} while (--e);
|
||||
r = s->window; /* copy rest from start of window */
|
||||
}
|
||||
}
|
||||
do { /* copy all or what's left */
|
||||
*q++ = *r++;
|
||||
} while (--c);
|
||||
break;
|
||||
}
|
||||
else if ((e & 64) == 0)
|
||||
e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop;
|
||||
else
|
||||
{
|
||||
z->msg = "invalid distance code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
} while (1);
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0)
|
||||
{
|
||||
if ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) == 0)
|
||||
{
|
||||
DUMPBITS(t->bits)
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: * literal '%c'\n" :
|
||||
"inflate: * literal 0x%02x\n", t->base));
|
||||
*q++ = (Byte)t->base;
|
||||
m--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (e & 32)
|
||||
{
|
||||
Tracevv((stderr, "inflate: * end of block\n"));
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_STREAM_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
z->msg = "invalid literal/length code";
|
||||
UNGRAB
|
||||
UPDATE
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
} while (1);
|
||||
} while (m >= 258 && n >= 10);
|
||||
|
||||
/* not enough input or output--restore pointers and return */
|
||||
|
||||
11
inflate.c
11
inflate.c
@@ -145,7 +145,7 @@ int f;
|
||||
{
|
||||
case METHOD:
|
||||
NEEDBYTE
|
||||
if (((z->state->sub.method = NEXTBYTE) & 0xf != DEFLATED))
|
||||
if (((z->state->sub.method = NEXTBYTE) & 0xf) != DEFLATED)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = "unknown compression method";
|
||||
@@ -243,7 +243,10 @@ z_stream *z;
|
||||
if (z == Z_NULL || z->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
if (z->state->mode != BAD)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->state->sub.marker = 0;
|
||||
}
|
||||
if ((n = z->avail_in) == 0)
|
||||
return Z_BUF_ERROR;
|
||||
p = z->next_in;
|
||||
@@ -252,10 +255,12 @@ z_stream *z;
|
||||
/* search */
|
||||
while (n && m < 4)
|
||||
{
|
||||
if (*p == (m < 2 ? 0 : 0xff))
|
||||
if (*p == (Byte)(m < 2 ? 0 : 0xff))
|
||||
m++;
|
||||
else if (*p || m > 2)
|
||||
else if (*p)
|
||||
m = 0;
|
||||
else
|
||||
m = 4 - m;
|
||||
p++, n--;
|
||||
}
|
||||
|
||||
|
||||
69
inftest.c
69
inftest.c
@@ -1,69 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "zutil.h"
|
||||
|
||||
void main __P((void));
|
||||
|
||||
/* This test is in honor of Ed Hamrick who suggested that the interface
|
||||
to inflate be a byte at a time--this implements that, and is, of course,
|
||||
monumentally slow. It has the virtue though of stressing the push-pull
|
||||
interface for testing purposes. */
|
||||
|
||||
void main()
|
||||
{
|
||||
int a, r;
|
||||
char c;
|
||||
z_stream z;
|
||||
|
||||
z.zalloc = Z_NULL;
|
||||
z.zfree = Z_NULL;
|
||||
r = inflateInit(&z);
|
||||
if (r != Z_OK)
|
||||
fprintf(stderr, "init error: %s\n", z_errmsg[1 - r]);
|
||||
while ((a = getchar()) != EOF)
|
||||
{
|
||||
/* feed one byte of input */
|
||||
z.avail_out = 0;
|
||||
c = (char)a;
|
||||
z.next_in = (Byte*)&c;
|
||||
z.avail_in = 1;
|
||||
r = inflate(&z, 0);
|
||||
if (r == Z_STREAM_END)
|
||||
break;
|
||||
if (r != Z_OK)
|
||||
{
|
||||
fprintf(stderr, "inflate error: %s\n", z_errmsg[1 - r]);
|
||||
break;
|
||||
}
|
||||
if (z.avail_in != 0)
|
||||
{
|
||||
fprintf(stderr, "inflate didn't eat byte and didn't say buf err!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/* empty output one byte at a time */
|
||||
while (1)
|
||||
{
|
||||
z.next_out = (Byte*)&c;
|
||||
z.avail_out = 1;
|
||||
r = inflate(&z, 0);
|
||||
if (r == Z_STREAM_END)
|
||||
break;
|
||||
if (r != Z_OK && r != Z_BUF_ERROR)
|
||||
{
|
||||
fprintf(stderr, "inflate error: %s\n", z_errmsg[1 - r]);
|
||||
break;
|
||||
}
|
||||
if (z.avail_out == 0)
|
||||
putchar(c);
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (r != Z_OK && r != Z_BUF_ERROR)
|
||||
break;
|
||||
}
|
||||
inflateEnd(&z);
|
||||
fprintf(stderr, "%ld bytes in, %ld bytes out\n", z.total_in, z.total_out);
|
||||
if (z.msg != NULL)
|
||||
fprintf(stderr, "msg is <%s>\n", z.msg);
|
||||
}
|
||||
18
inftrees.c
18
inftrees.c
@@ -41,7 +41,7 @@ local uInt cplens[] = { /* Copy lengths for literal codes 257..285 */
|
||||
/* actually lengths - 2; also see note #13 above about 258 */
|
||||
local uInt cplext[] = { /* Extra bits for literal codes 257..285 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 128, 128}; /* 128==invalid */
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 192, 192}; /* 192==invalid */
|
||||
local uInt cpdist[] = { /* Copy offsets for distance codes 0..29 */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
@@ -245,8 +245,8 @@ z_stream *zs; /* for zalloc function */
|
||||
if (h)
|
||||
{
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.bits = (char)l; /* bits to dump before this table */
|
||||
r.exop = -(char)j; /* bits in this table */
|
||||
r.bits = (Byte)l; /* bits to dump before this table */
|
||||
r.exop = j; /* bits in this table */
|
||||
r.next = q; /* pointer to this table */
|
||||
j = i >> (w - l); /* (get around Turbo C bug) */
|
||||
u[h-1][j] = r; /* connect to last table */
|
||||
@@ -254,17 +254,17 @@ z_stream *zs; /* for zalloc function */
|
||||
}
|
||||
|
||||
/* set up table entry in r */
|
||||
r.bits = (char)(k - w);
|
||||
r.bits = (Byte)(k - w);
|
||||
if (p >= v + n)
|
||||
r.exop = -128; /* out of values--invalid code */
|
||||
r.exop = 128 + 64; /* out of values--invalid code */
|
||||
else if (*p < s)
|
||||
{
|
||||
r.exop = (char)(*p < 256 ? 16 : -64); /* 256 is end-of-block code */
|
||||
r.exop = (*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
|
||||
r.base = *p++; /* simple code is just the value */
|
||||
}
|
||||
else
|
||||
{
|
||||
r.exop = (char)e[*p - s]; /* non-simple--look up in lists */
|
||||
r.exop = e[*p - s] + 16 + 64; /* non-simple--look up in lists */
|
||||
r.base = d[*p++ - s];
|
||||
}
|
||||
|
||||
@@ -457,10 +457,6 @@ z_stream *z; /* for zfree function */
|
||||
{
|
||||
register inflate_huft *p, *q;
|
||||
|
||||
/* Don't free fixed trees */
|
||||
if (t >= fixed_mem && t <= fixed_mem + FIXEDH)
|
||||
return Z_OK;
|
||||
|
||||
/* Go through linked list, freeing from the malloced (t[-1]) address. */
|
||||
p = t;
|
||||
while (p != Z_NULL)
|
||||
|
||||
11
inftrees.h
11
inftrees.h
@@ -9,19 +9,14 @@
|
||||
*/
|
||||
|
||||
/* Huffman code lookup table entry--this entry is four bytes for machines
|
||||
that have 16-bit pointers (e.g. PC's in the small or medium model).
|
||||
Valid extra bits (exop) are 0..13. exop == -64 is EOB (end of block),
|
||||
exop == 16 means that v is a literal, exop < 0 means that v is a pointer
|
||||
to the next table, which codes -exop bits, and lastly exop == -128
|
||||
indicates an unused code. If a code with exop == -128 is looked up,
|
||||
this implies an error in the data. */
|
||||
that have 16-bit pointers (e.g. PC's in the small or medium model). */
|
||||
|
||||
typedef struct inflate_huft_s inflate_huft;
|
||||
struct inflate_huft_s {
|
||||
union {
|
||||
struct {
|
||||
char Exop; /* number of extra bits or operation */
|
||||
char Bits; /* number of bits in this code or subcode */
|
||||
Byte Exop; /* number of extra bits or operation */
|
||||
Byte Bits; /* number of bits in this code or subcode */
|
||||
} what;
|
||||
Byte *pad; /* pad structure to a power of 2 (4 bytes for */
|
||||
} word; /* 16-bit, 8 bytes for 32-bit machines) */
|
||||
|
||||
@@ -35,8 +35,11 @@ struct inflate_blocks_state {
|
||||
uInt bb; /* bit length tree depth */
|
||||
inflate_huft *tb; /* bit length decoding tree */
|
||||
} trees; /* if DTREE, decoding info for trees */
|
||||
struct {
|
||||
inflate_huft *tl, *td; /* trees to free */
|
||||
struct inflate_codes_state
|
||||
*codes; /* if CODES, current state */
|
||||
*codes;
|
||||
} decode; /* if CODES, current state */
|
||||
} sub; /* submode */
|
||||
uInt last; /* true if this block is the last block */
|
||||
|
||||
|
||||
@@ -13,19 +13,21 @@
|
||||
* or in pipe mode.
|
||||
*/
|
||||
|
||||
/* $Id: minigzip.c,v 1.3 1995/04/29 14:27:21 jloup Exp $ */
|
||||
/* $Id: minigzip.c,v 1.5 1995/05/03 17:27:11 jloup Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "zlib.h"
|
||||
|
||||
#ifndef __GO32__
|
||||
extern void exit __P((int));
|
||||
#endif
|
||||
extern int unlink __P((const char *));
|
||||
|
||||
#ifdef STDC
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32)
|
||||
# include <fcntl.h>
|
||||
# include <io.h>
|
||||
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
|
||||
|
||||
13
trees.c
13
trees.c
@@ -29,7 +29,7 @@
|
||||
* Addison-Wesley, 1983. ISBN 0-201-06672-6.
|
||||
*/
|
||||
|
||||
/* $Id: trees.c,v 1.4 1995/05/01 16:53:44 jloup Exp $ */
|
||||
/* $Id: trees.c,v 1.5 1995/05/03 17:27:12 jloup Exp $ */
|
||||
|
||||
#include "deflate.h"
|
||||
|
||||
@@ -738,6 +738,17 @@ void ct_stored_block(s, buf, stored_len, eof)
|
||||
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Send one empty static block to give enough lookahead for inflate
|
||||
*/
|
||||
void ct_align(s)
|
||||
deflate_state *s;
|
||||
{
|
||||
send_bits(s, STATIC_TREES<<1, 3);
|
||||
send_code(s, END_BLOCK, static_ltree);
|
||||
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Determine the best encoding for the current block: dynamic trees, static
|
||||
* trees or store, and output the encoded block to the zip file. This function
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: uncompr.c,v 1.4 1995/04/10 16:22:22 jloup Exp $ */
|
||||
/* $Id: uncompr.c,v 1.5 1995/05/03 17:27:12 jloup Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
|
||||
25
zconf.h
25
zconf.h
@@ -3,7 +3,7 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: zconf.h,v 1.10 1995/04/30 19:27:14 jloup Exp $ */
|
||||
/* $Id: zconf.h,v 1.12 1995/05/03 17:27:12 jloup Exp $ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
@@ -28,10 +28,17 @@
|
||||
#if defined(MSDOS) && !defined(__32BIT__)
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#if !defined(STDC) && (defined(MSDOS) || defined(__STDC__))
|
||||
#ifndef STDC
|
||||
# if defined(MSDOS) || defined(__STDC__) || defined(__cplusplus)
|
||||
# define STDC
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(STDC) && !defined(const)
|
||||
# define const
|
||||
#endif
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
@@ -40,10 +47,24 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2 */
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
1 << (windowBits+2) + 1 << (memLevel+9)
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef __P /* function prototypes */
|
||||
|
||||
10
zlib.h
10
zlib.h
@@ -1,5 +1,5 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 0.9 April 30th, 1995.
|
||||
version 0.93 June 25th, 1995.
|
||||
|
||||
Copyright (C) 1995 Jean-loup Gailly and Mark Adler
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
gzip@prep.ai.mit.edu madler@cco.caltech.edu
|
||||
gzip@prep.ai.mit.edu madler@alumni.caltech.edu
|
||||
*/
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#define ZLIB_VERSION "0.9"
|
||||
#define ZLIB_VERSION "0.93"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
@@ -108,6 +108,7 @@ typedef struct z_stream_s {
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1
|
||||
#define Z_FULL_FLUSH 2
|
||||
#define Z_SYNC_FLUSH 3 /* experimental: partial_flush + byte align */
|
||||
#define Z_FINISH 4
|
||||
/* See deflate() below for the usage of these constants */
|
||||
|
||||
@@ -335,7 +336,8 @@ extern int deflateInit2 __P((z_stream *strm,
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||
for optimal speed. The default value is 8.
|
||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||
usage as a function of windowBits and memLevel.
|
||||
|
||||
The strategy parameter is used to tune the compression algorithm. Use
|
||||
the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
|
||||
|
||||
23
zutil.c
23
zutil.c
@@ -3,13 +3,15 @@
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* $Id: zutil.c,v 1.6 1995/04/29 14:54:02 jloup Exp $ */
|
||||
/* $Id: zutil.c,v 1.8 1995/05/03 17:27:12 jloup Exp $ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#ifndef __GO32__
|
||||
extern void exit __P((int));
|
||||
#endif
|
||||
|
||||
char *zlib_version = ZLIB_VERSION;
|
||||
|
||||
@@ -55,8 +57,9 @@ void zmemzero(dest, len)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) && !defined(__SMALL__) && !defined(M_I86SM)
|
||||
# ifdef __TURBOC__
|
||||
#if defined(__TURBOC__) && !defined(__SMALL__)
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||
@@ -124,8 +127,11 @@ void zcfree (voidp opaque, voidp ptr)
|
||||
ptr = opaque; /* just to make some compilers happy */
|
||||
z_error("zcfree: ptr not found");
|
||||
}
|
||||
#endif /* __TURBOC__ */
|
||||
|
||||
# else /* MSC */
|
||||
#if defined(M_I86CM) || defined(M_I86LM) /* MSC compact or large model */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
#if (!defined(_MSC_VER) || (_MSC_VER < 600))
|
||||
# define _halloc halloc
|
||||
@@ -144,12 +150,15 @@ void zcfree (voidp opaque, voidp ptr)
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
# endif /* __TURBOC__ ? */
|
||||
#endif /* defined(M_I86CM) || defined(M_I86LM) */
|
||||
|
||||
#else /* !MSDOS */
|
||||
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef __GO32__
|
||||
extern voidp calloc __P((uInt items, uInt size));
|
||||
extern void free __P((voidp ptr));
|
||||
#endif
|
||||
|
||||
voidp zcalloc (opaque, items, size)
|
||||
voidp opaque;
|
||||
@@ -166,4 +175,4 @@ void zcfree (opaque, ptr)
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#endif /* MSDOS */
|
||||
#endif /* MY_ZCALLOC */
|
||||
|
||||
21
zutil.h
21
zutil.h
@@ -8,15 +8,20 @@
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* $Id: zutil.h,v 1.7 1995/04/30 10:55:33 jloup Exp $ */
|
||||
/* $Id: zutil.h,v 1.9 1995/05/03 17:27:12 jloup Exp $ */
|
||||
|
||||
#ifndef _Z_UTIL_H
|
||||
#define _Z_UTIL_H
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
/* #ifndef __GNUC__ disable inline for now */
|
||||
# define inline
|
||||
/* #endif */
|
||||
|
||||
#ifdef MSDOS
|
||||
# include <stddef.h>
|
||||
# include <errno.h>
|
||||
#else
|
||||
extern int errno;
|
||||
#endif
|
||||
@@ -43,7 +48,14 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
|
||||
#define DEFLATED 8
|
||||
|
||||
#define DEF_WBITS 15
|
||||
/* default WBITS for decompression. MAX_WBITS is useful for compression only */
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
#define STORED_BLOCK 0
|
||||
#define STATIC_TREES 1
|
||||
@@ -118,7 +130,10 @@ extern char *z_errmsg[]; /* indexed by 1-zlib_error */
|
||||
# define zstrerror(errnum) ""
|
||||
#endif
|
||||
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY)
|
||||
#if defined(pyr) && !defined(NO_MEMCPY)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
|
||||
Reference in New Issue
Block a user