89 void match_init
OF((
void));
108 # define TOO_FAR 4096
154 #ifndef NO_DUMMY_DECL
159 #define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0))
167 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
181 #define INSERT_STRING(s, str, match_head) \
182 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
183 match_head = s->head[s->ins_h], \
184 s->head[s->ins_h] = (Pos)(str))
186 #define INSERT_STRING(s, str, match_head) \
187 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
188 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
189 s->head[s->ins_h] = (Pos)(str))
196 #define CLEAR_HASH(s) \
197 s->head[s->hash_size-1] = NIL; \
198 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
210 const char *
version,
int stream_size)
221 if (version ==
Z_NULL || version[0] != my_version[0] ||
228 if (strm->zalloc == (alloc_func)0) {
233 strm->opaque = (voidpf)0;
236 if (strm->zfree == (free_func)0)
244 if (level != 0) level = 1;
249 if (windowBits < 0) {
251 windowBits = -windowBits;
254 else if (windowBits > 15) {
259 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !=
Z_DEFLATED ||
260 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
261 strategy < 0 || strategy >
Z_FIXED) {
264 if (windowBits == 8) windowBits = 9;
317 z_const
unsigned char *next;
328 strm->adler =
adler32(strm->adler, dictionary, dictLength);
332 if (dictLength >= s->
w_size) {
339 dictionary += dictLength - s->
w_size;
344 avail = strm->avail_in;
345 next = strm->next_in;
346 strm->avail_in = dictLength;
347 strm->next_in = (z_const Bytef *)dictionary;
370 strm->next_in = next;
371 strm->avail_in = avail;
382 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
386 strm->total_in = strm->total_out = 0;
426 strm->state->gzhead =
head;
435 *pending = strm->state->pending;
437 *bits = strm->state->bi_valid;
475 if (level != 0) level = 1;
479 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_FIXED) {
482 func = configuration_table[s->
level].func;
484 if ((strategy != s->
strategy || func != configuration_table[level].func) &&
485 strm->total_in != 0) {
491 if (s->
level != level) {
536 uLong complen, wraplen;
540 complen = sourceLen +
541 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
554 wraplen = 6 + (s->
strstart ? 4 : 0);
560 wraplen += 2 + s->
gzhead->extra_len;
581 return complen + wraplen;
584 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
585 (sourceLen >> 25) + 13 - 6 + wraplen;
612 if (len > strm->avail_out) len = strm->avail_out;
613 if (len == 0)
return;
616 strm->next_out +=
len;
618 strm->total_out +=
len;
619 strm->avail_out -=
len;
633 flush >
Z_BLOCK || flush < 0) {
638 if (strm->next_out ==
Z_NULL ||
639 (strm->next_in ==
Z_NULL && strm->avail_in != 0) ||
671 (s->
gzhead->hcrc ? 2 : 0) +
703 else if (s->
level < 6)
705 else if (s->
level == 6)
709 header |= (level_flags << 6);
711 header += 31 - (header % 31);
818 put_byte(s, (Byte)(strm->adler & 0xff));
819 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
832 if (strm->avail_out == 0) {
847 }
else if (strm->avail_in == 0 &&
RANK(flush) <=
RANK(old_flush) &&
859 if (strm->avail_in != 0 || s->
lookahead != 0 ||
865 (*(configuration_table[s->
level].func))(
s, flush));
871 if (strm->avail_out == 0) {
901 if (strm->avail_out == 0) {
907 Assert(strm->avail_out > 0,
"bug2");
915 put_byte(s, (Byte)(strm->adler & 0xff));
916 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
917 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
918 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
919 put_byte(s, (Byte)(strm->total_in & 0xff));
920 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
921 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
922 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
945 status = strm->state->status;
957 TRY_FREE(strm, strm->state->pending_buf);
960 TRY_FREE(strm, strm->state->window);
962 ZFREE(strm, strm->state);
997 ds->window = (Bytef *)
ZALLOC(dest, ds->w_size, 2*
sizeof(Byte));
999 ds->head = (
Posf *)
ZALLOC(dest, ds->hash_size,
sizeof(
Pos));
1000 overlay = (
ushf *)
ZALLOC(dest, ds->lit_bufsize,
sizeof(
ush)+2);
1001 ds->pending_buf = (
uchf *) overlay;
1004 ds->pending_buf ==
Z_NULL) {
1009 zmemcpy(ds->window, ss->window, ds->w_size * 2 *
sizeof(Byte));
1010 zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size *
sizeof(
Pos));
1011 zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size *
sizeof(
Pos));
1012 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
1014 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
1015 ds->d_buf = overlay + ds->lit_bufsize/
sizeof(
ush);
1016 ds->l_buf = ds->pending_buf + (1+
sizeof(
ush))*ds->lit_bufsize;
1018 ds->l_desc.dyn_tree = ds->dyn_ltree;
1019 ds->d_desc.dyn_tree = ds->dyn_dtree;
1020 ds->bl_desc.dyn_tree = ds->bl_tree;
1035 unsigned len = strm->avail_in;
1037 if (len > size) len = size;
1038 if (len == 0)
return 0;
1040 strm->avail_in -=
len;
1042 zmemcpy(buf, strm->next_in, len);
1043 if (strm->state->wrap == 1) {
1044 strm->adler =
adler32(strm->adler, buf, len);
1047 else if (strm->state->wrap == 2) {
1048 strm->adler =
crc32(strm->adler, buf, len);
1051 strm->next_in +=
len;
1052 strm->total_in +=
len;
1122 ush scan_start = *(
ushf*)scan;
1123 ush scan_end = *(
ushf*)(scan+best_len-1);
1126 Byte scan_end1 = scan[best_len-1];
1127 Byte scan_end = scan[best_len];
1148 match = s->
window + cur_match;
1158 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1162 if (*(
ushf*)(match+best_len-1) != scan_end ||
1163 *(
ushf*)match != scan_start)
continue;
1174 Assert(scan[2] == match[2],
"scan[2]?");
1177 }
while (*(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1178 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1179 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1180 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1186 if (*scan == *match) scan++;
1188 len = (
MAX_MATCH - 1) - (
int)(strend-scan);
1193 if (match[best_len] != scan_end ||
1194 match[best_len-1] != scan_end1 ||
1196 *++match != scan[1])
continue;
1205 Assert(*scan == *match,
"match[2]?");
1211 }
while (*++scan == *++match && *++scan == *++match &&
1212 *++scan == *++match && *++scan == *++match &&
1213 *++scan == *++match && *++scan == *++match &&
1214 *++scan == *++match && *++scan == *++match &&
1224 if (len > best_len) {
1227 if (len >= nice_match)
break;
1229 scan_end = *(
ushf*)(scan+best_len-1);
1231 scan_end1 = scan[best_len-1];
1232 scan_end = scan[best_len];
1235 }
while ((cur_match = prev[cur_match & wmask]) > limit
1236 && --chain_length != 0);
1238 if ((uInt)best_len <= s->
lookahead)
return (uInt)best_len;
1264 match = s->
window + cur_match;
1268 if (match[0] != scan[0] || match[1] != scan[1])
return MIN_MATCH-1;
1276 scan += 2, match += 2;
1277 Assert(*scan == *match,
"match[2]?");
1283 }
while (*++scan == *++match && *++scan == *++match &&
1284 *++scan == *++match && *++scan == *++match &&
1285 *++scan == *++match && *++scan == *++match &&
1286 *++scan == *++match && *++scan == *++match &&
1310 fprintf(stderr,
" start %u, match %u, length %d\n",
1311 start, match, length);
1313 fprintf(stderr,
"%c%c", s->
window[match++], s->
window[start++]);
1314 }
while (--length != 0);
1315 z_error(
"invalid match");
1317 if (z_verbose > 1) {
1318 fprintf(stderr,
"\\[%d,%d]", start-match, length);
1319 do { putc(s->
window[start++], stderr); }
while (--length != 0);
1323 # define check_match(s, start, match, length)
1349 if (
sizeof(
int) <= 2) {
1353 }
else if (more == (
unsigned)(-1)) {
1381 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1389 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1397 if (s->
strm->avail_in == 0)
break;
1410 Assert(more >= 2,
"more < 2");
1476 "not enough room for search");
1483 #define FLUSH_BLOCK_ONLY(s, last) { \
1484 _tr_flush_block(s, (s->block_start >= 0L ? \
1485 (charf *)&s->window[(unsigned)s->block_start] : \
1487 (ulg)((long)s->strstart - s->block_start), \
1489 s->block_start = s->strstart; \
1490 flush_pending(s->strm); \
1491 Tracev((stderr,"[FLUSH]")); \
1495 #define FLUSH_BLOCK(s, last) { \
1496 FLUSH_BLOCK_ONLY(s, last); \
1497 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1514 ulg max_block_size = 0xffff;
1804 Bytef *scan, *strend;
1824 if (prev == *++scan && prev == *++scan && prev == *++scan) {
1827 }
while (prev == *++scan && prev == *++scan &&
1828 prev == *++scan && prev == *++scan &&
1829 prev == *++scan && prev == *++scan &&
1830 prev == *++scan && prev == *++scan &&
int ZEXPORT deflateEnd(z_streamp strm)
local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
local void putShortMSB(deflate_state *s, uInt b)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
local block_state deflate_huff(deflate_state *s, int flush)
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source)
local void flush_pending(z_streamp strm)
void ZLIB_INTERNAL _tr_init(deflate_state *s)
#define UPDATE_HASH(s, h, c)
int ZEXPORT deflateResetKeep(z_streamp strm)
#define Assert(cond, msg)
local void lm_init(deflate_state *s)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
void ZLIB_INTERNAL _tr_align(deflate_state *s)
#define FLUSH_BLOCK_ONLY(s, last)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
gz_header FAR * gz_headerp
int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
#define _tr_tally_lit(s, c, flush)
#define ZALLOC(strm, items, size)
#define check_match(s, start, match, length)
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head)
local void fill_window(deflate_state *s)
static constexpr double m
const XML_Char int const XML_Char * value
local block_state deflate_fast(deflate_state *s, int flush)
#define ZFREE(strm, addr)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
#define INSERT_STRING(s, str, match_head)
#define _tr_tally_dist(s, distance, length, flush)
#define FLUSH_BLOCK(s, last)
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
local const config configuration_table[10]
local uInt longest_match(deflate_state *s, IPos cur_match)
local block_state deflate_slow(deflate_state *s, int flush)
int ZEXPORT deflate(z_streamp strm, int flush)
#define ERR_RETURN(strm, err)
local block_state deflate_stored(deflate_state *s, int flush)
int ZLIB_INTERNAL zmemcmp(const Bytef *s1, const Bytef *s2, uInt len)
#define Z_DEFAULT_STRATEGY
local block_state deflate_rle(deflate_state *s, int flush)
static constexpr double L
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits)
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
int ZEXPORT deflateReset(z_streamp strm)
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
#define Z_DEFAULT_COMPRESSION
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))