diff --git a/Source/zlib/INFBLOCK.C b/Source/zlib/INFBLOCK.C index 87856f10..32588d1d 100644 --- a/Source/zlib/INFBLOCK.C +++ b/Source/zlib/INFBLOCK.C @@ -11,8 +11,6 @@ #include "infcodes.h" #include "infutil.h" -struct inflate_codes_state {int dummy;}; /* for buggy compilers */ - /* simplify the use of the inflate_huft type with some defines */ #define exop word.what.Exop #define bits word.what.Bits @@ -21,33 +19,22 @@ local const char border[] = { /* Order of the bit length code lengths */ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; -void inflate_blocks_reset(s, z, c) -inflate_blocks_statef *s; -z_streamp z; -uLongf *c; +void inflateReset(z_streamp z) { - if (c) *c = s->check; + inflate_blocks_statef *s=&z->blocks; if (s->mode == BTREE || s->mode == DTREE) ZFREE(z, s->sub.trees.blens); if (s->mode == CODES) inflate_codes_free(s->sub.decode.codes, z); s->mode = TYPE; - s->bitk = 0; - s->bitb = 0; + s->bitk = s->bitb = 0; s->read = s->write = s->window; Tracev((stderr, "inflate: blocks reset\n")); } -void inflate_blocks_init(z_streamp z,inflate_blocks_statef *s) -{ - s->end = s->window + (1 << DEF_WBITS); - s->mode = TYPE; - inflate_blocks_reset(s, z, Z_NULL); -} - int inflate(z_streamp z) { - inflate_blocks_statef *s=&z->state->blocks; + inflate_blocks_statef *s=&z->blocks; // lousy two bytes saved by doing this struct @@ -98,8 +85,8 @@ int r=Z_OK; uInt bl, bd; inflate_huft *tl, *td; - inflate_trees_fixed(&bl, &bd, &tl, &td, z); - s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z); + inflate_trees_fixed(&bl, &bd, &tl, &td); + s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td); if (s->sub.decode.codes == Z_NULL) { r = Z_MEM_ERROR; @@ -187,7 +174,7 @@ int r=Z_OK; s->sub.trees.blens[border[s->sub.trees.index++]] = 0; s->sub.trees.bb = 7; t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb, - &s->sub.trees.tb, s->hufts, z); + &s->sub.trees.tb, s->hufts); if (t != Z_OK) { ZFREE(z, s->sub.trees.blens); @@ -253,7 +240,7 @@ int r=Z_OK; t = s->sub.trees.table; t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), s->sub.trees.blens, &bl, &bd, &tl, &td, - s->hufts, z); + s->hufts); ZFREE(z, s->sub.trees.blens); if (t != Z_OK) { @@ -263,7 +250,7 @@ int r=Z_OK; LEAVE } Tracev((stderr, "inflate: trees ok\n")); - if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL) + if ((c = inflate_codes_new(bl, bd, tl, td)) == Z_NULL) { r = Z_MEM_ERROR; LEAVE @@ -273,8 +260,8 @@ int r=Z_OK; s->mode = CODES; case CODES: UPDATE - if ((r = inflate_codes(s, z, r)) != Z_STREAM_END) - return inflate_flush(s, z, r); + if ((r = inflate_codes(z, r)) != Z_STREAM_END) + return inflate_flush(z, r); r = Z_OK; inflate_codes_free(s->sub.decode.codes, z); LOAD @@ -304,15 +291,4 @@ int r=Z_OK; } } - -/*int inflate_blocks_free(s, z) -inflate_blocks_statef *s; -z_streamp z; -{ - inflate_blocks_reset(s, z, Z_NULL); - ZFREE(z, s); - Tracev((stderr, "inflate: blocks freed\n")); - return Z_OK; -} -*/ #endif \ No newline at end of file diff --git a/Source/zlib/INFBLOCK.H b/Source/zlib/INFBLOCK.H index aa946315..96b3a29e 100644 --- a/Source/zlib/INFBLOCK.H +++ b/Source/zlib/INFBLOCK.H @@ -5,28 +5,3 @@ struct inflate_blocks_state; typedef struct inflate_blocks_state FAR inflate_blocks_statef; - -extern inflate_blocks_statef * inflate_blocks_new OF(( - z_streamp z)); /* window size */ - -extern int inflate_blocks OF(( - inflate_blocks_statef *, - z_streamp , - int)); /* initial return code */ - -extern void inflate_blocks_reset OF(( - inflate_blocks_statef *, - z_streamp , - uLongf *)); /* check value on output */ - -extern int inflate_blocks_free OF(( - inflate_blocks_statef *, - z_streamp)); - -extern void inflate_set_dictionary OF(( - inflate_blocks_statef *s, - const Bytef *d, /* dictionary */ - uInt n)); /* dictionary length */ - -extern int inflate_blocks_sync_point OF(( - inflate_blocks_statef *s)); diff --git a/Source/zlib/INFCODES.C b/Source/zlib/INFCODES.C index dc623720..f26aa580 100644 --- a/Source/zlib/INFCODES.C +++ b/Source/zlib/INFCODES.C @@ -57,16 +57,15 @@ struct inflate_codes_state { }; -inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z) +inflate_codes_statef *inflate_codes_new(bl, bd, tl, td) uInt bl, bd; inflate_huft *tl; inflate_huft *td; /* need separate declaration for Borland C++ */ -z_streamp z; { inflate_codes_statef *c; if ((c = (inflate_codes_statef *) - ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL) + ZALLOC(0,1,sizeof(struct inflate_codes_state))) != Z_NULL) { c->mode = START; c->lbits = (Byte)bl; @@ -79,11 +78,11 @@ z_streamp z; } -int inflate_codes(s, z, r) -inflate_blocks_statef *s; +int inflate_codes(z, r) z_streamp z; int r; { + inflate_blocks_statef *s=&z->blocks; uInt j; /* temporary storage */ inflate_huft *t; /* temporary pointer */ uInt e; /* extra bits or operation */ @@ -236,11 +235,4 @@ int r; } -void inflate_codes_free(c, z) -inflate_codes_statef *c; -z_streamp z; -{ - ZFREE(z, c); - Tracev((stderr, "inflate: codes free\n")); -} #endif diff --git a/Source/zlib/INFCODES.H b/Source/zlib/INFCODES.H index db401cac..8a420c16 100644 --- a/Source/zlib/INFCODES.H +++ b/Source/zlib/INFCODES.H @@ -8,15 +8,11 @@ typedef struct inflate_codes_state FAR inflate_codes_statef; extern inflate_codes_statef *inflate_codes_new OF(( uInt, uInt, - inflate_huft *, inflate_huft *, - z_streamp )); + inflate_huft *, inflate_huft *)); extern int inflate_codes OF(( - inflate_blocks_statef *, z_streamp , int)); -extern void inflate_codes_free OF(( - inflate_codes_statef *, - z_streamp )); +#define inflate_codes_free(z,c) ZFREE(z,c) diff --git a/Source/zlib/INFLATE.C b/Source/zlib/INFLATE.C index b1c8d21f..115dd0a7 100644 --- a/Source/zlib/INFLATE.C +++ b/Source/zlib/INFLATE.C @@ -15,28 +15,12 @@ #include "infcodes.h" #include "infutil.h" - - -int ZEXPORT inflateReset(z_streamp z) -{ - if (z == Z_NULL || z->state == Z_NULL) - return Z_STREAM_ERROR; - inflate_blocks_reset(&z->state->blocks, z, Z_NULL); - return Z_OK; -} - -static struct internal_state __mstate; - int ZEXPORT inflateInit(z_streamp z) { - void inflate_blocks_init(z_streamp z,struct inflate_blocks_state *s); + z->blocks.end = z->blocks.window + (1 << DEF_WBITS); + z->blocks.mode = TYPE; - z->state=&__mstate; -// if ((z->state = - // (struct internal_state FAR *) ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL) - //return Z_MEM_ERROR; - - inflate_blocks_init(z,&z->state->blocks); + inflateReset(z); return Z_OK; } diff --git a/Source/zlib/INFTREES.C b/Source/zlib/INFTREES.C index 8db38028..414fa724 100644 --- a/Source/zlib/INFTREES.C +++ b/Source/zlib/INFTREES.C @@ -222,12 +222,11 @@ uInt *hn) /* working area: values in order of bit length */ return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK; } -int inflate_trees_bits(c, bb, tb, hp, z) +int inflate_trees_bits(c, bb, tb, hp) uIntf *c; /* 19 code lengths */ uIntf *bb; /* bits tree desired/actual depth */ inflate_huft * FAR *tb; /* bits tree result */ inflate_huft *hp; /* space for trees */ -z_streamp z; /* for messages */ { int r; uInt hn = 0; /* hufts used in space */ @@ -241,7 +240,7 @@ z_streamp z; /* for messages */ return r; } -int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z) +int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp) uInt nl; /* number of literal/length codes */ uInt nd; /* number of distance codes */ uIntf *c; /* that many (total) code lengths */ @@ -250,7 +249,6 @@ uIntf *bd; /* distance desired/actual bit depth */ inflate_huft * FAR *tl; /* literal/length tree result */ inflate_huft * FAR *td; /* distance tree result */ inflate_huft *hp; /* space for trees */ -z_streamp z; /* for messages */ { int r; uInt hn = 0; /* hufts used in space */ @@ -285,12 +283,11 @@ local inflate_huft *fixed_tl; local inflate_huft *fixed_td; -int inflate_trees_fixed(bl, bd, tl, td, z) +int inflate_trees_fixed(bl, bd, tl, td) uIntf *bl; /* literal desired/actual bit depth */ uIntf *bd; /* distance desired/actual bit depth */ inflate_huft * FAR *tl; /* literal/length tree result */ inflate_huft * FAR *td; /* distance tree result */ -z_streamp z; /* for memory allocation */ { /* build fixed tables if not already */ if (!fixed_built) diff --git a/Source/zlib/INFTREES.H b/Source/zlib/INFTREES.H index 0eb2e968..6464a51c 100644 --- a/Source/zlib/INFTREES.H +++ b/Source/zlib/INFTREES.H @@ -4,27 +4,11 @@ */ -typedef struct inflate_huft_s FAR inflate_huft; - -struct inflate_huft_s { - union { - struct { - Byte Exop; /* number of extra bits or operation */ - Byte Bits; /* number of bits in this code or subcode */ - } what; - } word; - unsigned short base; /* literal, length base, distance base, - or table offset */ -}; - -#define MANY 1440 - extern int inflate_trees_bits OF(( uIntf *, uIntf *, inflate_huft * FAR *, - inflate_huft *, - z_streamp)); + inflate_huft *)); extern int inflate_trees_dynamic OF(( uInt, @@ -34,12 +18,10 @@ extern int inflate_trees_dynamic OF(( uIntf *, inflate_huft * FAR *, inflate_huft * FAR *, - inflate_huft *, - z_streamp)); + inflate_huft *)); extern int inflate_trees_fixed OF(( uIntf *, uIntf *, inflate_huft * FAR *, - inflate_huft * FAR *, - z_streamp)); + inflate_huft * FAR *)); diff --git a/Source/zlib/INFUTIL.C b/Source/zlib/INFUTIL.C index 28de5c5a..2c2fd390 100644 --- a/Source/zlib/INFUTIL.C +++ b/Source/zlib/INFUTIL.C @@ -11,7 +11,7 @@ #include "infcodes.h" #include "infutil.h" -struct inflate_codes_state {int dummy;}; /* for buggy compilers */ +struct inflate_codes_state; /* And'ing with mask[n] masks the lower n bits */ unsigned short inflate_mask[17] = { @@ -32,18 +32,19 @@ void NSISCALL genrtable() } */ -int __myleave(inflate_blocks_statef *s, z_streamp z, int r, int b, int k, Bytef *p, int n, Bytef *q) +int __myleave(z_streamp z, int r, int b, int k, Bytef *p, int n, Bytef *q) { + inflate_blocks_statef *s = &z->blocks; UPDATE - return inflate_flush(s,z,r); + return inflate_flush(z,r); } /* copy as much as possible from the sliding window to the output area */ -int inflate_flush(s, z, r) -inflate_blocks_statef *s; +int inflate_flush(z, r) z_streamp z; int r; { + inflate_blocks_statef *s=&z->blocks; uInt n; Bytef *p; Bytef *q; diff --git a/Source/zlib/INFUTIL.H b/Source/zlib/INFUTIL.H index 2fc2e78a..39cbd61d 100644 --- a/Source/zlib/INFUTIL.H +++ b/Source/zlib/INFUTIL.H @@ -6,53 +6,6 @@ #ifndef _INFUTIL_H #define _INFUTIL_H -typedef enum { - TYPE, /* get type bits (3, including end bit) */ - LENS, /* get lengths for stored */ - STORED, /* processing stored block */ - TABLE, /* get table lengths */ - BTREE, /* get bit lengths tree for a dynamic block */ - DTREE, /* get length, distance trees for a dynamic block */ - CODES, /* processing fixed or dynamic block */ - DRY, /* output remaining window bytes */ - DONE, /* finished last block, done */ - BAD} /* got a data error--stuck here */ -inflate_block_mode; - -/* inflate blocks semi-private state */ -struct inflate_blocks_state { - - /* mode */ - inflate_block_mode mode; /* current inflate_block mode */ - - /* mode dependent information */ - union { - uInt left; /* if STORED, bytes left to copy */ - struct { - uInt table; /* table lengths (14 bits) */ - uInt index; /* index into blens (or border) */ - uIntf *blens; /* bit lengths of codes */ - uInt bb; /* bit length tree depth */ - inflate_huft *tb; /* bit length decoding tree */ - } trees; /* if DTREE, decoding info for trees */ - struct { - inflate_codes_statef - *codes; - } decode; /* if CODES, current state */ - } sub; /* submode */ - uInt last; /* true if this block is the last block */ - - /* mode independent information */ - uInt bitk; /* bits in bit buffer */ - uLong bitb; /* bit buffer */ - inflate_huft hufts[MANY]; /* single malloc for tree space */ - Bytef window[1 << DEF_WBITS]; /* sliding window */ - Bytef *end; /* one byte after sliding window */ - Bytef *read; /* window read pointer */ - Bytef *write; /* window write pointer */ - uLong check; /* check on output */ - -}; /* defines for inflate input/output */ @@ -61,8 +14,8 @@ struct inflate_blocks_state { #define UPDIN {z->avail_in=n;z->next_in=p;} #define UPDOUT {s->write=q;} #define UPDATE {UPDBITS UPDIN UPDOUT} -#define LEAVE return __myleave(s,z,r,b,k,p,n,q); -extern int __myleave(inflate_blocks_statef *s, z_streamp z, int r, int b, int k, Bytef *p, int n, Bytef *q); +#define LEAVE return __myleave(z,r,b,k,p,n,q); +extern int __myleave(z_streamp z, int r, int b, int k, Bytef *p, int n, Bytef *q); /* get bytes and bits */ #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} @@ -77,7 +30,7 @@ extern int __myleave(inflate_blocks_statef *s, z_streamp z, int r, int b, int k, #define WAVAIL (uInt)(qread?s->read-q-1:s->end-q) #define LOADOUT {q=s->write;m=(uInt)WAVAIL;} #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} -#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} +#define FLUSH {UPDOUT r=inflate_flush(z,r); LOADOUT} #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} #define OUTBYTE(a) {*q++=(Byte)(a);m--;} /* load local pointers */ @@ -88,23 +41,7 @@ extern unsigned short inflate_mask[17]; /* copy as much as possible from the sliding window to the output area */ extern int inflate_flush OF(( - inflate_blocks_statef *, z_streamp , int)); -struct internal_state { - - /* mode dependent information */ - union { - uInt method; /* if FLAGS, method byte */ - struct { - uLong was; /* computed check value */ - uLong need; /* stream check value */ - } check; /* if CHECK, check values to compare */ - uInt marker; /* if BAD, inflateSync's marker bytes count */ - } sub; /* submode */ - - struct inflate_blocks_state blocks; /* current inflate_blocks state */ -}; - #endif diff --git a/Source/zlib/ZLIB.H b/Source/zlib/ZLIB.H index 002a1599..b0871490 100644 --- a/Source/zlib/ZLIB.H +++ b/Source/zlib/ZLIB.H @@ -43,13 +43,87 @@ #define _ZLIB_H #include "zconf.h" +#include "zutil.h" #ifdef __cplusplus extern "C" { #endif +#ifdef EXEHEAD + + + + typedef enum { + TYPE, /* get type bits (3, including end bit) */ + LENS, /* get lengths for stored */ + STORED, /* processing stored block */ + TABLE, /* get table lengths */ + BTREE, /* get bit lengths tree for a dynamic block */ + DTREE, /* get length, distance trees for a dynamic block */ + CODES, /* processing fixed or dynamic block */ + DRY, /* output remaining window bytes */ + DONE, /* finished last block, done */ + BAD} /* got a data error--stuck here */ +inflate_block_mode; + +typedef struct inflate_huft_s FAR inflate_huft; + +struct inflate_huft_s { + union { + struct { + Byte Exop; /* number of extra bits or operation */ + Byte Bits; /* number of bits in this code or subcode */ + } what; + } word; + unsigned short base; /* literal, length base, distance base, + or table offset */ +}; + +#define MANY 1440 + +struct inflate_codes_state; +typedef struct inflate_codes_state inflate_codes_statef; + +struct inflate_blocks_state { + + /* mode */ + inflate_block_mode mode; /* current inflate_block mode */ + + /* mode dependent information */ + union { + uInt left; /* if STORED, bytes left to copy */ + struct { + uInt table; /* table lengths (14 bits) */ + uInt index; /* index into blens (or border) */ + uIntf *blens; /* bit lengths of codes */ + uInt bb; /* bit length tree depth */ + inflate_huft *tb; /* bit length decoding tree */ + } trees; /* if DTREE, decoding info for trees */ + struct { + inflate_codes_statef + *codes; + } decode; /* if CODES, current state */ + } sub; /* submode */ + uInt last; /* true if this block is the last block */ + + /* mode independent information */ + uInt bitk; /* bits in bit buffer */ + uLong bitb; /* bit buffer */ + inflate_huft hufts[MANY]; /* single malloc for tree space */ + Bytef window[1 << MAX_WBITS]; /* sliding window */ + Bytef *end; /* one byte after sliding window */ + Bytef *read; /* window read pointer */ + Bytef *write; /* window write pointer */ + uLong check; /* check on output */ + +}; + + + +#else struct internal_state; +#endif typedef struct z_stream_s { Bytef *next_in; /* next input byte */ @@ -65,7 +139,12 @@ typedef struct z_stream_s { #endif // char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ + //struct internal_state FAR *state; /* not visible by applications */ +#ifdef EXEHEAD + struct inflate_blocks_state blocks; /* current inflate_blocks state */ +#else + struct internal_state *state; +#endif } z_stream; @@ -130,8 +209,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -int ZEXPORT inflateReset(z_streamp z); +void ZEXPORT inflateReset OF(( + z_streamp)); /* various hacks, don't look :) */ @@ -146,8 +226,7 @@ ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); + #define deflateInit(strm, level) \ deflateInit_((strm), (level), "", sizeof(z_stream))