55 " deflate 1.2.12 Copyright 1995-2022 Jean-loup Gailly and Mark Adler ";
91 # pragma message("Assembler code may have bugs -- use at your own risk")
92 void match_init
OF((
void));
111 # define TOO_FAR 4096
155 #define RANK(f) (((f) * 2) - ((f) > 4 ? 9 : 0))
163 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
177 #define INSERT_STRING(s, str, match_head) \
178 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
179 match_head = s->head[s->ins_h], \
180 s->head[s->ins_h] = (Pos)(str))
182 #define INSERT_STRING(s, str, match_head) \
183 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
184 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
185 s->head[s->ins_h] = (Pos)(str))
192 #define CLEAR_HASH(s) \
194 s->head[s->hash_size-1] = NIL; \
195 zmemzero((Bytef *)s->head, \
196 (unsigned)(s->hash_size-1)*sizeof(*s->head)); \
209 uInt wsize =
s->w_size;
215 *
p = (
Pos)(
m >= wsize ?
m - wsize :
NIL);
222 *
p = (
Pos)(
m >= wsize ?
m - wsize :
NIL);
265 if (
strm->zalloc == (alloc_func)0) {
273 if (
strm->zfree == (free_func)0)
286 if (windowBits < 0) {
288 windowBits = -windowBits;
291 else if (windowBits > 15) {
297 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
298 strategy < 0 || strategy >
Z_FIXED || (windowBits == 8 && wrap != 1)) {
301 if (windowBits == 8) windowBits = 9;
310 s->w_bits = (
uInt)windowBits;
311 s->w_size = 1 <<
s->w_bits;
312 s->w_mask =
s->w_size - 1;
314 s->hash_bits = (
uInt)memLevel + 7;
315 s->hash_size = 1 <<
s->hash_bits;
316 s->hash_mask =
s->hash_size - 1;
325 s->lit_bufsize = 1 << (memLevel + 6);
367 s->pending_buf_size = (
ulg)
s->lit_bufsize * 4;
376 s->sym_buf =
s->pending_buf +
s->lit_bufsize;
377 s->sym_end = (
s->lit_bufsize - 1) * 3;
398 strm->zalloc == (alloc_func)0 ||
strm->zfree == (free_func)0)
418 const Bytef *dictionary;
440 if (dictLength >=
s->w_size) {
447 dictionary += dictLength -
s->w_size;
448 dictLength =
s->w_size;
463 s->prev[
str &
s->w_mask] =
s->head[
s->ins_h];
472 s->strstart +=
s->lookahead;
473 s->block_start = (
long)
s->strstart;
474 s->insert =
s->lookahead;
477 s->match_available = 0;
496 len =
s->strstart +
s->lookahead;
522 s->pending_out =
s->pending_buf;
592 if (bits < 0 || bits > 16 ||
593 s->sym_buf <
s->pending_out + ((
Buf_size + 7) >> 3))
599 s->bi_buf |= (
ush)((
value & ((1 << put) - 1)) <<
s->bi_valid);
625 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_FIXED) {
631 s->last_flush != -2) {
640 if (
s->level == 0 &&
s->matches != 0) {
669 s->good_match = (
uInt)good_length;
670 s->max_lazy_match = (
uInt)max_lazy;
671 s->nice_match = nice_length;
672 s->max_chain_length = (
uInt)max_chain;
698 uLong complen, wraplen;
701 complen = sourceLen +
702 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
715 wraplen = 6 + (
s->strstart ? 4 : 0);
722 if (
s->gzhead->extra !=
Z_NULL)
723 wraplen += 2 +
s->gzhead->extra_len;
724 str =
s->gzhead->name;
729 str =
s->gzhead->comment;
744 if (
s->w_bits != 15 ||
s->hash_bits != 8 + 7)
745 return complen + wraplen;
748 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
749 (sourceLen >> 25) + 13 - 6 + wraplen;
780 if (
len == 0)
return;
784 s->pending_out +=
len;
788 if (
s->pending == 0) {
789 s->pending_out =
s->pending_buf;
796 #define HCRC_UPDATE(beg) \
798 if (s->gzhead->hcrc && s->pending > (beg)) \
799 strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
800 s->pending - (beg)); \
823 old_flush =
s->last_flush;
824 s->last_flush = flush;
827 if (
s->pending != 0) {
864 else if (
s->level < 6)
866 else if (
s->level == 6)
870 header |= (level_flags << 6);
877 if (
s->strstart != 0) {
886 if (
s->pending != 0) {
912 if (
s->pending != 0) {
919 (
s->gzhead->hcrc ? 2 : 0) +
920 (
s->gzhead->extra ==
Z_NULL ? 0 : 4) +
921 (
s->gzhead->name ==
Z_NULL ? 0 : 8) +
922 (
s->gzhead->comment ==
Z_NULL ? 0 : 16)
932 if (
s->gzhead->extra !=
Z_NULL) {
934 put_byte(
s, (
s->gzhead->extra_len >> 8) & 0xff);
944 if (
s->gzhead->extra !=
Z_NULL) {
945 ulg beg =
s->pending;
946 uInt left = (
s->gzhead->extra_len & 0xffff) -
s->gzindex;
947 while (
s->pending + left >
s->pending_buf_size) {
948 uInt copy =
s->pending_buf_size -
s->pending;
950 s->gzhead->extra +
s->gzindex, copy);
951 s->pending =
s->pending_buf_size;
955 if (
s->pending != 0) {
963 s->gzhead->extra +
s->gzindex, left);
971 if (
s->gzhead->name !=
Z_NULL) {
972 ulg beg =
s->pending;
975 if (
s->pending ==
s->pending_buf_size) {
978 if (
s->pending != 0) {
984 val =
s->gzhead->name[
s->gzindex++];
993 if (
s->gzhead->comment !=
Z_NULL) {
994 ulg beg =
s->pending;
997 if (
s->pending ==
s->pending_buf_size) {
1000 if (
s->pending != 0) {
1006 val =
s->gzhead->comment[
s->gzindex++];
1014 if (
s->gzhead->hcrc) {
1015 if (
s->pending + 2 >
s->pending_buf_size) {
1017 if (
s->pending != 0) {
1030 if (
s->pending != 0) {
1067 }
else if (flush !=
Z_BLOCK) {
1074 if (
s->lookahead == 0) {
1076 s->block_start = 0
L;
1114 if (
s->wrap > 0)
s->wrap = -
s->wrap;
1212 if (
len == 0)
return 0;
1217 if (
strm->state->wrap == 1) {
1221 else if (
strm->state->wrap == 2) {
1237 s->window_size = (
ulg)2L*
s->w_size;
1249 s->block_start = 0
L;
1253 s->match_available = 0;
1280 unsigned chain_length =
s->max_chain_length;
1281 register Bytef *scan =
s->window +
s->strstart;
1284 int best_len = (
int)
s->prev_length;
1292 uInt wmask =
s->w_mask;
1299 register ush scan_start = *(
ushf*)scan;
1300 register ush scan_end = *(
ushf*)(scan+best_len-1);
1303 register Byte scan_end1 = scan[best_len-1];
1304 register Byte scan_end = scan[best_len];
1313 if (
s->prev_length >=
s->good_match) {
1325 match =
s->window + cur_match;
1335 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1339 if (*(
ushf*)(
match+best_len-1) != scan_end ||
1362 Assert(scan <= s->
window+(
unsigned)(
s->window_size-1),
"wild scan");
1363 if (*scan == *
match) scan++;
1370 if (
match[best_len] != scan_end ||
1371 match[best_len-1] != scan_end1 ||
1373 *++
match != scan[1])
continue;
1388 }
while (*++scan == *++
match && *++scan == *++
match &&
1389 *++scan == *++
match && *++scan == *++
match &&
1390 *++scan == *++
match && *++scan == *++
match &&
1391 *++scan == *++
match && *++scan == *++
match &&
1394 Assert(scan <= s->
window+(
unsigned)(
s->window_size-1),
"wild scan");
1401 if (
len > best_len) {
1402 s->match_start = cur_match;
1406 scan_end = *(
ushf*)(scan+best_len-1);
1408 scan_end1 = scan[best_len-1];
1409 scan_end = scan[best_len];
1412 }
while ((cur_match =
prev[cur_match & wmask]) >
limit
1413 && --chain_length != 0);
1415 if ((
uInt)best_len <=
s->lookahead)
return (
uInt)best_len;
1416 return s->lookahead;
1429 register Bytef *scan =
s->window +
s->strstart;
1443 match =
s->window + cur_match;
1455 scan += 2,
match += 2;
1462 }
while (*++scan == *++
match && *++scan == *++
match &&
1463 *++scan == *++
match && *++scan == *++
match &&
1464 *++scan == *++
match && *++scan == *++
match &&
1465 *++scan == *++
match && *++scan == *++
match &&
1468 Assert(scan <= s->
window+(
unsigned)(
s->window_size-1),
"wild scan");
1474 s->match_start = cur_match;
1496 fprintf(stderr,
" start %u, match %u, length %d\n",
1499 fprintf(stderr,
"%c%c",
s->window[
match++],
s->window[
start++]);
1501 z_error(
"invalid match");
1503 if (z_verbose > 1) {
1505 do { putc(
s->window[
start++], stderr); }
while (--
length != 0);
1509 # define check_match(s, start, match, length)
1527 uInt wsize =
s->w_size;
1535 if (
sizeof(
int) <= 2) {
1536 if (more == 0 &&
s->strstart == 0 &&
s->lookahead == 0) {
1539 }
else if (more == (
unsigned)(-1)) {
1552 zmemcpy(
s->window,
s->window+wsize, (
unsigned)wsize - more);
1553 s->match_start -= wsize;
1554 s->strstart -= wsize;
1555 s->block_start -= (
long) wsize;
1556 if (
s->insert >
s->strstart)
1557 s->insert =
s->strstart;
1561 if (
s->strm->avail_in == 0)
break;
1574 Assert(more >= 2,
"more < 2");
1576 n =
read_buf(
s->strm,
s->window +
s->strstart +
s->lookahead, more);
1582 s->ins_h =
s->window[
str];
1590 s->prev[
str &
s->w_mask] =
s->head[
s->ins_h];
1612 if (
s->high_water <
s->window_size) {
1613 ulg curr =
s->strstart + (
ulg)(
s->lookahead);
1616 if (
s->high_water < curr) {
1620 init =
s->window_size - curr;
1624 s->high_water = curr +
init;
1632 if (
init >
s->window_size -
s->high_water)
1633 init =
s->window_size -
s->high_water;
1635 s->high_water +=
init;
1640 "not enough room for search");
1647 #define FLUSH_BLOCK_ONLY(s, last) { \
1648 _tr_flush_block(s, (s->block_start >= 0L ? \
1649 (charf *)&s->window[(unsigned)s->block_start] : \
1651 (ulg)((long)s->strstart - s->block_start), \
1653 s->block_start = s->strstart; \
1654 flush_pending(s->strm); \
1655 Tracev((stderr,"[FLUSH]")); \
1659 #define FLUSH_BLOCK(s, last) { \
1660 FLUSH_BLOCK_ONLY(s, last); \
1661 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1665 #define MAX_STORED 65535
1668 #define MIN(a, b) ((a) > (b) ? (b) : (a))
1693 unsigned min_block =
MIN(
s->pending_buf_size - 5,
s->w_size);
1699 unsigned len, left, have, last = 0;
1700 unsigned used =
s->strm->avail_in;
1707 have = (
s->bi_valid + 42) >> 3;
1708 if (
s->strm->avail_out < have)
1711 have =
s->strm->avail_out - have;
1712 left =
s->strstart -
s->block_start;
1713 if (
len > (
ulg)left +
s->strm->avail_in)
1714 len = left +
s->strm->avail_in;
1725 len != left +
s->strm->avail_in))
1731 last = flush ==
Z_FINISH &&
len == left +
s->strm->avail_in ? 1 : 0;
1735 s->pending_buf[
s->pending - 4] =
len;
1736 s->pending_buf[
s->pending - 3] =
len >> 8;
1737 s->pending_buf[
s->pending - 2] = ~
len;
1738 s->pending_buf[
s->pending - 1] = ~
len >> 8;
1745 s->compressed_len +=
len << 3;
1746 s->bits_sent +=
len << 3;
1753 zmemcpy(
s->strm->next_out,
s->window +
s->block_start, left);
1754 s->strm->next_out += left;
1755 s->strm->avail_out -= left;
1756 s->strm->total_out += left;
1757 s->block_start += left;
1766 s->strm->next_out +=
len;
1767 s->strm->avail_out -=
len;
1768 s->strm->total_out +=
len;
1770 }
while (last == 0);
1778 used -=
s->strm->avail_in;
1783 if (used >=
s->w_size) {
1785 zmemcpy(
s->window,
s->strm->next_in -
s->w_size,
s->w_size);
1786 s->strstart =
s->w_size;
1787 s->insert =
s->strstart;
1790 if (
s->window_size -
s->strstart <= used) {
1792 s->strstart -=
s->w_size;
1793 zmemcpy(
s->window,
s->window +
s->w_size,
s->strstart);
1796 if (
s->insert >
s->strstart)
1797 s->insert =
s->strstart;
1799 zmemcpy(
s->window +
s->strstart,
s->strm->next_in - used, used);
1800 s->strstart += used;
1801 s->insert +=
MIN(used,
s->w_size -
s->insert);
1803 s->block_start =
s->strstart;
1805 if (
s->high_water <
s->strstart)
1806 s->high_water =
s->strstart;
1814 s->strm->avail_in == 0 && (
long)
s->strstart ==
s->block_start)
1818 have =
s->window_size -
s->strstart;
1819 if (
s->strm->avail_in > have &&
s->block_start >= (
long)
s->w_size) {
1821 s->block_start -=
s->w_size;
1822 s->strstart -=
s->w_size;
1823 zmemcpy(
s->window,
s->window +
s->w_size,
s->strstart);
1827 if (
s->insert >
s->strstart)
1828 s->insert =
s->strstart;
1830 if (have >
s->strm->avail_in)
1831 have =
s->strm->avail_in;
1834 s->strstart += have;
1835 s->insert +=
MIN(have,
s->w_size -
s->insert);
1837 if (
s->high_water <
s->strstart)
1838 s->high_water =
s->strstart;
1845 have = (
s->bi_valid + 42) >> 3;
1848 min_block =
MIN(have,
s->w_size);
1849 left =
s->strstart -
s->block_start;
1850 if (left >= min_block ||
1852 s->strm->avail_in == 0 && left <= have)) {
1854 last = flush ==
Z_FINISH &&
s->strm->avail_in == 0 &&
1855 len == left ? 1 : 0;
1857 s->block_start +=
len;
1890 if (
s->lookahead == 0)
break;
1904 if (hash_head !=
NIL &&
s->strstart - hash_head <=
MAX_DIST(
s)) {
1918 s->lookahead -=
s->match_length;
1924 if (
s->match_length <=
s->max_insert_length &&
1933 }
while (--
s->match_length != 0);
1938 s->strstart +=
s->match_length;
1939 s->match_length = 0;
1940 s->ins_h =
s->window[
s->strstart];
1951 Tracevv((stderr,
"%c",
s->window[
s->strstart]));
1993 if (
s->lookahead == 0)
break;
2006 s->prev_length =
s->match_length,
s->prev_match =
s->match_start;
2009 if (hash_head !=
NIL &&
s->prev_length <
s->max_lazy_match &&
2034 if (
s->prev_length >=
MIN_MATCH &&
s->match_length <=
s->prev_length) {
2048 s->lookahead -=
s->prev_length-1;
2049 s->prev_length -= 2;
2051 if (++
s->strstart <= max_insert) {
2054 }
while (--
s->prev_length != 0);
2055 s->match_available = 0;
2061 }
else if (
s->match_available) {
2066 Tracevv((stderr,
"%c",
s->window[
s->strstart-1]));
2073 if (
s->strm->avail_out == 0)
return need_more;
2078 s->match_available = 1;
2084 if (
s->match_available) {
2085 Tracevv((stderr,
"%c",
s->window[
s->strstart-1]));
2087 s->match_available = 0;
2111 Bytef *scan, *strend;
2123 if (
s->lookahead == 0)
break;
2127 s->match_length = 0;
2128 if (
s->lookahead >=
MIN_MATCH &&
s->strstart > 0) {
2129 scan =
s->window +
s->strstart - 1;
2131 if (
prev == *++scan &&
prev == *++scan &&
prev == *++scan) {
2134 }
while (
prev == *++scan &&
prev == *++scan &&
2135 prev == *++scan &&
prev == *++scan &&
2136 prev == *++scan &&
prev == *++scan &&
2137 prev == *++scan &&
prev == *++scan &&
2140 if (
s->match_length >
s->lookahead)
2141 s->match_length =
s->lookahead;
2152 s->lookahead -=
s->match_length;
2153 s->strstart +=
s->match_length;
2154 s->match_length = 0;
2157 Tracevv((stderr,
"%c",
s->window[
s->strstart]));
2186 if (
s->lookahead == 0) {
2188 if (
s->lookahead == 0) {
2196 s->match_length = 0;
2197 Tracevv((stderr,
"%c",
s->window[
s->strstart]));
int bits(struct state *s, int need)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags long
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
const config configuration_table[10]
int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
#define FLUSH_BLOCK_ONLY(s, last)
int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits)
block_state deflate_stored(deflate_state *s, int flush)
#define check_match(s, start, match, length)
void putShortMSB(deflate_state *s, uInt b)
#define UPDATE_HASH(s, h, c)
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
void flush_pending(z_streamp strm)
int ZEXPORT deflateReset(z_streamp strm)
#define INSERT_STRING(s, str, match_head)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
block_state compress_func OF((deflate_state *s, int flush))
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size)
const char deflate_copyright[]
block_state deflate_fast(deflate_state *s, int flush)
block_state deflate_slow(deflate_state *s, int flush)
#define FLUSH_BLOCK(s, last)
int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
uInt longest_match(deflate_state *s, IPos cur_match)
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength)
block_state deflate_huff(deflate_state *s, int flush)
int deflateStateCheck(z_streamp strm)
int ZEXPORT deflateResetKeep(z_streamp strm)
int ZEXPORT deflateEnd(z_streamp strm)
void fill_window(deflate_state *s)
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
void lm_init(deflate_state *s)
int ZEXPORT deflate(z_streamp strm, int flush)
void slide_hash(deflate_state *s)
block_state deflate_rle(deflate_state *s, int flush)
#define _tr_tally_dist(s, distance, length, flush)
#define _tr_tally_lit(s, c, flush)
unsigned char match[65280+2]
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd times
static const char struct stat static buf struct stat static buf static vhangup int status
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
#define header(is_bt, len_min, ret_op)
while(len< limit &&buf1[len]==buf2[len])++len
static uint32_t const uint8_t uint32_t uint32_t limit
struct tree_desc_s l_desc
struct ct_data_s dyn_dtree[2 *D_CODES+1]
struct ct_data_s bl_tree[2 *BL_CODES+1]
struct tree_desc_s bl_desc
struct tree_desc_s d_desc
struct ct_data_s dyn_ltree[HEAP_SIZE]
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
void ZLIB_INTERNAL _tr_init(deflate_state *s)
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
void ZLIB_INTERNAL _tr_align(deflate_state *s)
if(dbg->bits==RZ_SYS_BITS_64)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
gz_header FAR * gz_headerp
#define Z_DEFAULT_STRATEGY
#define Z_DEFAULT_COMPRESSION
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
int ZLIB_INTERNAL zmemcmp(Bytef *s1, const Bytef *s2, uInt len) const
#define ERR_RETURN(strm, err)
#define ZALLOC(strm, items, size)
#define Assert(cond, msg)
#define ZFREE(strm, addr)