* found for specific files.
*/
typedef struct config_s {
- ush good_length; /* reduce lazy search above this match length */
- ush max_lazy; /* do not perform lazy search above this match length */
- ush nice_length; /* quit search above this match length */
- ush max_chain;
+ uint16_t good_length; /* reduce lazy search above this match length */
+ uint16_t max_lazy; /* do not perform lazy search above this match length */
+ uint16_t nice_length; /* quit search above this match length */
+ uint16_t max_chain;
compress_func func;
} config;
int wrap = 1;
static const char my_version[] = ZLIB_VERSION;
- ush *overlay;
+ uint16_t *overlay;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/
s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
- overlay = (ush *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+ overlay = (uint16_t *) ZALLOC(strm, s->lit_bufsize, sizeof(uint16_t)+2);
s->pending_buf = (uch *) overlay;
- s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
+ s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(uint16_t)+2L);
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
s->pending_buf == Z_NULL) {
deflateEnd (strm);
return Z_MEM_ERROR;
}
- s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
- s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+ s->d_buf = overlay + s->lit_bufsize/sizeof(uint16_t);
+ s->l_buf = s->pending_buf + (1+sizeof(uint16_t))*s->lit_bufsize;
s->level = level;
s->strategy = strategy;
put = Buf_size - s->bi_valid;
if (put > bits)
put = bits;
- s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
+ s->bi_buf |= (uint16_t)((value & ((1 << put) - 1)) << s->bi_valid);
s->bi_valid += put;
_tr_flush_bits(s);
value >>= put;
{
deflate_state *ds;
deflate_state *ss;
- ush *overlay;
+ uint16_t *overlay;
if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
ds->window = (unsigned char *) ZALLOC(dest, ds->w_size, 2*sizeof(unsigned char));
ds->prev = (Pos *) ZALLOC(dest, ds->w_size, sizeof(Pos));
ds->head = (Pos *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
- overlay = (ush *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+ overlay = (uint16_t *) ZALLOC(dest, ds->lit_bufsize, sizeof(uint16_t)+2);
ds->pending_buf = (uch *) overlay;
if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
memcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
- ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
- ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+ ds->d_buf = overlay + ds->lit_bufsize/sizeof(uint16_t);
+ ds->l_buf = ds->pending_buf + (1+sizeof(uint16_t))*ds->lit_bufsize;
ds->l_desc.dyn_tree = ds->dyn_ltree;
ds->d_desc.dyn_tree = ds->dyn_dtree;
/* Data structure describing a single value and its code string. */
typedef struct ct_data_s {
union {
- ush freq; /* frequency count */
- ush code; /* bit string */
+ uint16_t freq; /* frequency count */
+ uint16_t code; /* bit string */
} fc;
union {
- ush dad; /* father node in Huffman tree */
- ush len; /* length of bit string */
+ uint16_t dad; /* father node in Huffman tree */
+ uint16_t len; /* length of bit string */
} dl;
} ct_data;
static_tree_desc *stat_desc; /* the corresponding static tree */
} tree_desc;
-typedef ush Pos;
+typedef uint16_t Pos;
typedef unsigned IPos;
/* A Pos is an index in the character window. We use short instead of int to
struct tree_desc_s d_desc; /* desc. for distance tree */
struct tree_desc_s bl_desc; /* desc. for bit length tree */
- ush bl_count[MAX_BITS+1];
+ uint16_t bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
uInt last_lit; /* running index in l_buf */
- ush *d_buf;
+ uint16_t *d_buf;
/* Buffer for distances. To simplify the code, d_buf and l_buf have
* the same number of elements. To use different lengths, an extra flag
* array would be necessary.
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
- ush bi_buf;
+ uint16_t bi_buf;
/* Output buffer. bits are inserted starting at the bottom (least
* significant bits).
*/
*/
#define put_short(s, w) { \
s->pending += 2; \
- *(ush*)(&s->pending_buf[s->pending - 2]) = (w) ; \
+ *(uint16_t*)(&s->pending_buf[s->pending - 2]) = (w) ; \
}
#else
#define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \
- put_byte(s, (uch)((ush)(w) >> 8)); \
+ put_byte(s, (uch)((uint16_t)(w) >> 8)); \
}
#endif
}
# define _tr_tally_dist(s, distance, length, flush) \
{ uch len = (length); \
- ush dist = (distance); \
+ uint16_t dist = (distance); \
s->d_buf[s->last_lit] = dist; \
s->l_buf[s->last_lit++] = len; \
dist--; \
* unused bits in value.
*/
if (s->bi_valid > (int)Buf_size - length) {
- s->bi_buf |= (ush)value << s->bi_valid;
+ s->bi_buf |= (uint16_t)value << s->bi_valid;
put_short(s, s->bi_buf);
- s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
+ s->bi_buf = (uint16_t)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size;
} else {
- s->bi_buf |= (ush)value << s->bi_valid;
+ s->bi_buf |= (uint16_t)value << s->bi_valid;
s->bi_valid += length;
}
}
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
int val = value;\
- s->bi_buf |= (ush)val << s->bi_valid;\
+ s->bi_buf |= (uint16_t)val << s->bi_valid;\
put_short(s, s->bi_buf);\
- s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
+ s->bi_buf = (uint16_t)val >> (Buf_size - s->bi_valid);\
s->bi_valid += len - Buf_size;\
} else {\
- s->bi_buf |= (ush)(value) << s->bi_valid;\
+ s->bi_buf |= (uint16_t)(value) << s->bi_valid;\
s->bi_valid += len;\
}\
}
local void init_block (deflate_state *s);
local void pqdownheap (deflate_state *s, ct_data *tree, int k);
local void gen_bitlen (deflate_state *s, tree_desc *desc);
-local void gen_codes (ct_data *tree, int max_code, ush *bl_count);
+local void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count);
local void build_tree (deflate_state *s, tree_desc *desc);
local void scan_tree (deflate_state *s, ct_data *tree, int max_code);
local void send_tree (deflate_state *s, ct_data *tree, int max_code);
int length; /* length value */
int code; /* code value */
int dist; /* distance index */
- ush bl_count[MAX_BITS+1];
+ uint16_t bl_count[MAX_BITS+1];
/* number of codes at each bit length for an optimal tree */
if (static_init_done) return;
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int xbits; /* extra bits */
- ush f; /* frequency */
+ uint16_t f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */
for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
n = s->heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > max_length) bits = max_length, overflow++;
- tree[n].Len = (ush)bits;
+ tree[n].Len = (uint16_t)bits;
/* We overwrite tree[n].Dad which is no longer needed */
if (n > max_code) continue; /* not a leaf node */
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
s->opt_len += ((long)bits - (long)tree[m].Len)
*(long)tree[m].Freq;
- tree[m].Len = (ush)bits;
+ tree[m].Len = (uint16_t)bits;
}
n--;
}
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
-local void gen_codes (ct_data *tree, int max_code, ush *bl_count)
+local void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count)
{
/* tree: the tree to decorate */
/* max_code: largest code with non zero frequency */
/* bl_count: number of codes at each bit length */
- ush next_code[MAX_BITS+1]; /* next code value for each bit length */
- ush code = 0; /* running code value */
- int bits; /* bit index */
- int n; /* code index */
+ uint16_t next_code[MAX_BITS+1]; /* next code value for each bit length */
+ uint16_t code = 0; /* running code value */
+ int bits; /* bit index */
+ int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
tree[node].Freq = tree[n].Freq + tree[m].Freq;
s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
s->depth[n] : s->depth[m]) + 1);
- tree[n].Dad = tree[m].Dad = (ush)node;
+ tree[n].Dad = tree[m].Dad = (uint16_t)node;
#ifdef DUMP_BL_TREE
if (tree == s->bl_tree) {
fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
int min_count = 4; /* min repeat count */
if (nextlen == 0) max_count = 138, min_count = 3;
- tree[max_code+1].Len = (ush)0xffff; /* guard */
+ tree[max_code+1].Len = (uint16_t)0xffff; /* guard */
for (n = 0; n <= max_code; n++) {
curlen = nextlen; nextlen = tree[n+1].Len;
{
/* dist: distance of matched string */
/* lc: match length-MIN_MATCH or unmatched char (if dist==0) */
- s->d_buf[s->last_lit] = (ush)dist;
+ s->d_buf[s->last_lit] = (uint16_t)dist;
s->l_buf[s->last_lit++] = (uch)lc;
if (dist == 0) {
/* lc is the unmatched char */
s->matches++;
/* Here, lc is the match length - MIN_MATCH */
dist--; /* dist = match distance - 1 */
- Assert((ush)dist < (ush)MAX_DIST(s) &&
- (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
- (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
+ Assert((uint16_t)dist < (uint16_t)MAX_DIST(s) &&
+ (uint16_t)lc <= (uint16_t)(MAX_MATCH-MIN_MATCH) &&
+ (uint16_t)d_code(dist) < (uint16_t)D_CODES, "_tr_tally: bad match");
s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
s->dyn_dtree[d_code(dist)].Freq++;
bi_windup(s); /* align on byte boundary */
if (header) {
- put_short(s, (ush)len);
- put_short(s, (ush)~len);
+ put_short(s, (uint16_t)len);
+ put_short(s, (uint16_t)~len);
#ifdef DEBUG
s->bits_sent += 2*16;
#endif
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
-typedef unsigned char uch;
-typedef unsigned short ush;
+typedef unsigned char uch; /* Included for compatibility with external code only */
+typedef uint16_t ush; /* Included for compatibility with external code only */
typedef unsigned long ulg;
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */