52 #if defined( __MVS__ )
66 #pragma csect( CODE, "deflateC" )
67 #pragma csect( STATIC, "deflateS" )
68 #pragma csect( TEST, "deflateT" )
73 #if defined( INC_ALL )
82 " deflate 1.2.4 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
116 void match_init
OF((
void));
135 # define TOO_FAR 4096
181 #ifndef NO_DUMMY_DECL
191 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
205 #define INSERT_STRING(s, str, match_head) \
206 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
207 match_head = s->head[s->ins_h], \
208 s->head[s->ins_h] = (Pos)(str))
210 #define INSERT_STRING(s, str, match_head) \
211 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
212 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
213 s->head[s->ins_h] = (Pos)(str))
220 #define CLEAR_HASH(s) \
221 s->head[s->hash_size-1] = NIL; \
222 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
235 int windowBits,
int memLevel,
int strategy,
236 const char *version,
int stream_size)
247 if (version ==
Z_NULL || version[0] != my_version[0] ||
254 if (strm->zalloc == (alloc_func)0) {
258 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
261 if (level != 0) level = 1;
266 if (windowBits < 0) {
268 windowBits = -windowBits;
271 else if (windowBits > 15) {
277 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
278 strategy < 0 || strategy >
Z_FIXED) {
281 if (windowBits == 8) windowBits = 9;
337 strm->state->wrap == 2 ||
338 (strm->state->wrap == 1 && strm->state->status !=
INIT_STATE))
343 strm->adler =
adler32(strm->adler, dictionary, dictLength);
348 dictionary += dictLength -
length;
360 for (n = 0; n <= length -
MIN_MATCH; n++) {
363 if (hash_head) hash_head = 0;
373 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
377 strm->total_in = strm->total_out = 0;
407 strm->state->gzhead =
head;
415 strm->state->bi_valid = bits;
416 strm->state->bi_buf = (
ush)(value & ((1 << bits) - 1));
431 if (level != 0) level = 1;
435 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_FIXED) {
438 func = configuration_table[s->
level].func;
440 if ((strategy != s->
strategy || func != configuration_table[level].func) &&
441 strm->total_in != 0) {
445 if (s->
level != level) {
458 int nice_length,
int max_chain)
495 uLong complen, wraplen;
499 complen = sourceLen +
500 ((sourceLen + 7) >> 3) + ((
sourceLen + 63) >> 6) + 5;
513 wraplen = 6 + (s->strstart ? 4 : 0);
517 if (s->gzhead !=
Z_NULL) {
518 if (s->gzhead->extra !=
Z_NULL)
519 wraplen += 2 + s->gzhead->extra_len;
520 str = s->gzhead->name;
525 str = s->gzhead->comment;
539 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
540 return complen + wraplen;
567 unsigned len = strm->state->pending;
569 if (len > strm->avail_out) len = strm->avail_out;
570 if (len == 0)
return;
572 zmemcpy(strm->next_out, strm->state->pending_out, len);
573 strm->next_out += len;
574 strm->state->pending_out += len;
575 strm->total_out += len;
576 strm->avail_out -= len;
577 strm->state->pending -= len;
578 if (strm->state->pending == 0) {
579 strm->state->pending_out = strm->state->pending_buf;
590 flush >
Z_BLOCK || flush < 0) {
595 if (strm->next_out ==
Z_NULL ||
596 (strm->next_in ==
Z_NULL && strm->avail_in != 0) ||
610 strm->adler = crc32(0L,
Z_NULL, 0);
628 (s->
gzhead->hcrc ? 2 : 0) +
660 else if (s->
level < 6)
662 else if (s->
level == 6)
666 header |= (level_flags << 6);
668 header += 31 - (header % 31);
689 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
700 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
718 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
731 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
749 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
762 strm->adler = crc32(strm->adler, s->
pending_buf + beg,
777 strm->adler = crc32(0L,
Z_NULL, 0);
789 if (strm->avail_out == 0) {
804 }
else if (strm->avail_in == 0 && flush <= old_flush &&
816 if (strm->avail_in != 0 || s->
lookahead != 0 ||
822 (*(configuration_table[s->
level].func))(
s, flush));
828 if (strm->avail_out == 0) {
857 if (strm->avail_out == 0) {
863 Assert(strm->avail_out > 0,
"bug2");
901 status = strm->state->status;
913 TRY_FREE(strm, strm->state->pending_buf);
916 TRY_FREE(strm, strm->state->window);
918 ZFREE(strm, strm->state);
991 unsigned len = strm->avail_in;
993 if (len > size) len =
size;
994 if (len == 0)
return 0;
996 strm->avail_in -= len;
998 if (strm->state->wrap == 1) {
999 strm->adler =
adler32(strm->adler, strm->next_in, len);
1002 else if (strm->state->wrap == 2) {
1003 strm->adler = crc32(strm->adler, strm->next_in, len);
1006 zmemcpy(buf, strm->next_in, len);
1007 strm->next_in += len;
1008 strm->total_in += len;
1078 register ush scan_start = *(
ushf*)scan;
1079 register ush scan_end = *(
ushf*)(scan+best_len-1);
1082 register Byte scan_end1 = scan[best_len-1];
1083 register Byte scan_end = scan[best_len];
1104 match = s->
window + cur_match;
1114 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1118 if (*(
ushf*)(match+best_len-1) != scan_end ||
1119 *(
ushf*)match != scan_start)
continue;
1130 Assert(scan[2] == match[2],
"scan[2]?");
1133 }
while (*(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1134 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1135 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1136 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1142 if (*scan == *match) scan++;
1144 len = (
MAX_MATCH - 1) - (
int)(strend-scan);
1149 if (match[best_len] != scan_end ||
1150 match[best_len-1] != scan_end1 ||
1152 *++match != scan[1])
continue;
1161 Assert(*scan == *match,
"match[2]?");
1167 }
while (*++scan == *++match && *++scan == *++match &&
1168 *++scan == *++match && *++scan == *++match &&
1169 *++scan == *++match && *++scan == *++match &&
1170 *++scan == *++match && *++scan == *++match &&
1180 if (len > best_len) {
1183 if (len >= nice_match)
break;
1185 scan_end = *(
ushf*)(scan+best_len-1);
1187 scan_end1 = scan[best_len-1];
1188 scan_end = scan[best_len];
1191 }
while ((cur_match = prev[cur_match & wmask]) > limit
1192 && --chain_length != 0);
1222 match = s->window + cur_match;
1226 if (match[0] != scan[0] || match[1] != scan[1])
return MIN_MATCH-1;
1234 scan += 2, match += 2;
1235 Assert(*scan == *match,
"match[2]?");
1241 }
while (*++scan == *++match && *++scan == *++match &&
1242 *++scan == *++match && *++scan == *++match &&
1243 *++scan == *++match && *++scan == *++match &&
1244 *++scan == *++match && *++scan == *++match &&
1247 Assert(scan <= s->
window+(
unsigned)(s->window_size-1),
"wild scan");
1253 s->match_start = cur_match;
1254 return (
uInt)len <= s->lookahead ? (
uInt)len : s->lookahead;
1269 if (
zmemcmp(s->window + match,
1270 s->window + start, length) !=
EQUAL) {
1271 fprintf(stderr,
" start %u, match %u, length %d\n",
1272 start, match, length);
1274 fprintf(stderr,
"%c%c", s->window[match++], s->window[start++]);
1275 }
while (--length != 0);
1276 z_error(
"invalid match");
1278 if (z_verbose > 1) {
1279 fprintf(stderr,
"\\[%d,%d]", start-match, length);
1280 do { putc(s->window[start++], stderr); }
while (--length != 0);
1284 # define check_match(s, start, match, length)
1299 register unsigned n, m;
1308 if (
sizeof(
int) <= 2) {
1312 }
else if (more == (
unsigned)(-1)) {
1340 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1348 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1356 if (s->
strm->avail_in == 0)
return;
1369 Assert(more >= 2,
"more < 2");
1427 #define FLUSH_BLOCK_ONLY(s, last) { \
1428 _tr_flush_block(s, (s->block_start >= 0L ? \
1429 (charf *)&s->window[(unsigned)s->block_start] : \
1431 (ulg)((long)s->strstart - s->block_start), \
1433 s->block_start = s->strstart; \
1434 flush_pending(s->strm); \
1435 Tracev((stderr,"[FLUSH]")); \
1439 #define FLUSH_BLOCK(s, last) { \
1440 FLUSH_BLOCK_ONLY(s, last); \
1441 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1458 ulg max_block_size = 0xffff;
1730 Bytef *scan, *strend;
1750 if (prev == *++scan && prev == *++scan && prev == *++scan) {
1753 }
while (prev == *++scan && prev == *++scan &&
1754 prev == *++scan && prev == *++scan &&
1755 prev == *++scan && prev == *++scan &&
1756 prev == *++scan && prev == *++scan &&