• Home
  • Raw
  • Download

Lines Matching refs:s

73 typedef block_state (*compress_func) OF((deflate_state *s, int flush));
77 local void slide_hash OF((deflate_state *s));
78 local void fill_window OF((deflate_state *s));
79 local block_state deflate_stored OF((deflate_state *s, int flush));
80 local block_state deflate_fast OF((deflate_state *s, int flush));
82 local block_state deflate_slow OF((deflate_state *s, int flush));
84 local block_state deflate_rle OF((deflate_state *s, int flush));
85 local block_state deflate_huff OF((deflate_state *s, int flush));
86 local void lm_init OF((deflate_state *s));
87 local void putShortMSB OF((deflate_state *s, uInt b));
90 local uInt longest_match OF((deflate_state *s, IPos cur_match));
93 local void check_match OF((deflate_state *s, IPos start, IPos match,
157 #define UPDATE_HASH(s,h,c) (h = (((h) << s->hash_shift) ^ (c)) & s->hash_mask) argument
171 #define INSERT_STRING(s, str, match_head) \ argument
172 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
173 match_head = s->head[s->ins_h], \
174 s->head[s->ins_h] = (Pos)(str))
176 #define INSERT_STRING(s, str, match_head) \ argument
177 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
178 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
179 s->head[s->ins_h] = (Pos)(str))
186 #define CLEAR_HASH(s) \ argument
188 s->head[s->hash_size - 1] = NIL; \
189 zmemzero((Bytef *)s->head, \
190 (unsigned)(s->hash_size - 1)*sizeof(*s->head)); \
198 local void slide_hash(s) in slide_hash() argument
199 deflate_state *s; in slide_hash()
203 uInt wsize = s->w_size;
205 n = s->hash_size;
206 p = &s->head[n];
213 p = &s->prev[n];
248 deflate_state *s; local
298 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
299 if (s == Z_NULL) return Z_MEM_ERROR;
300 strm->state = (struct internal_state FAR *)s;
301 s->strm = strm;
302 s->status = INIT_STATE; /* to pass state test in deflateReset() */
304 s->wrap = wrap;
305 s->gzhead = Z_NULL;
306 s->w_bits = (uInt)windowBits;
307 s->w_size = 1 << s->w_bits;
308 s->w_mask = s->w_size - 1;
310 s->hash_bits = (uInt)memLevel + 7;
311 s->hash_size = 1 << s->hash_bits;
312 s->hash_mask = s->hash_size - 1;
313 s->hash_shift = ((s->hash_bits + MIN_MATCH-1) / MIN_MATCH);
315 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
316 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
317 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
319 s->high_water = 0; /* nothing written to s->window yet */
321 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
362 s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
363 s->pending_buf_size = (ulg)s->lit_bufsize * 4;
365 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
366 s->pending_buf == Z_NULL) {
367 s->status = FINISH_STATE;
372 s->sym_buf = s->pending_buf + s->lit_bufsize;
373 s->sym_end = (s->lit_bufsize - 1) * 3;
379 s->level = level;
380 s->strategy = strategy;
381 s->method = (Byte)method;
392 deflate_state *s; local
396 s = strm->state;
397 if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE &&
399 s->status != GZIP_STATE &&
401 s->status != EXTRA_STATE &&
402 s->status != NAME_STATE &&
403 s->status != COMMENT_STATE &&
404 s->status != HCRC_STATE &&
405 s->status != BUSY_STATE &&
406 s->status != FINISH_STATE))
417 deflate_state *s; local
425 s = strm->state;
426 wrap = s->wrap;
427 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
433 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
436 if (dictLength >= s->w_size) {
438 CLEAR_HASH(s);
439 s->strstart = 0;
440 s->block_start = 0L;
441 s->insert = 0;
443 dictionary += dictLength - s->w_size; /* use the tail */
444 dictLength = s->w_size;
452 fill_window(s);
453 while (s->lookahead >= MIN_MATCH) {
454 str = s->strstart;
455 n = s->lookahead - (MIN_MATCH-1);
457 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
459 s->prev[str & s->w_mask] = s->head[s->ins_h];
461 s->head[s->ins_h] = (Pos)str;
464 s->strstart = str;
465 s->lookahead = MIN_MATCH-1;
466 fill_window(s);
468 s->strstart += s->lookahead;
469 s->block_start = (long)s->strstart;
470 s->insert = s->lookahead;
471 s->lookahead = 0;
472 s->match_length = s->prev_length = MIN_MATCH-1;
473 s->match_available = 0;
476 s->wrap = wrap;
486 deflate_state *s; local
491 s = strm->state;
492 len = s->strstart + s->lookahead;
493 if (len > s->w_size)
494 len = s->w_size;
496 zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
506 deflate_state *s; local
516 s = (deflate_state *)strm->state;
517 s->pending = 0;
518 s->pending_out = s->pending_buf;
520 if (s->wrap < 0) {
521 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
523 s->status =
525 s->wrap == 2 ? GZIP_STATE :
530 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
533 s->last_flush = -2;
535 _tr_init(s);
583 deflate_state *s; local
587 s = strm->state;
589 s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
592 put = Buf_size - s->bi_valid;
595 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
596 s->bi_valid += put;
597 _tr_flush_bits(s);
610 deflate_state *s; local
614 s = strm->state;
624 func = configuration_table[s->level].func;
626 if ((strategy != s->strategy || func != configuration_table[level].func) &&
627 s->last_flush != -2) {
632 if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
635 if (s->level != level) {
636 if (s->level == 0 && s->matches != 0) {
637 if (s->matches == 1)
638 slide_hash(s);
640 CLEAR_HASH(s);
641 s->matches = 0;
643 s->level = level;
644 s->max_lazy_match = configuration_table[level].max_lazy;
645 s->good_match = configuration_table[level].good_length;
646 s->nice_match = configuration_table[level].nice_length;
647 s->max_chain_length = configuration_table[level].max_chain;
649 s->strategy = strategy;
661 deflate_state *s; local
664 s = strm->state;
665 s->good_match = (uInt)good_length;
666 s->max_lazy_match = (uInt)max_lazy;
667 s->nice_match = nice_length;
668 s->max_chain_length = (uInt)max_chain;
700 deflate_state *s; local
719 s = strm->state;
720 switch (s->wrap) {
725 wraplen = 6 + (s->strstart ? 4 : 0);
730 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
732 if (s->gzhead->extra != Z_NULL)
733 wraplen += 2 + s->gzhead->extra_len;
734 str = s->gzhead->name;
739 str = s->gzhead->comment;
744 if (s->gzhead->hcrc)
754 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
755 return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
768 local void putShortMSB(s, b) in putShortMSB() argument
769 deflate_state *s; in putShortMSB()
772 put_byte(s, (Byte)(b >> 8));
773 put_byte(s, (Byte)(b & 0xff));
786 deflate_state *s = strm->state; local
788 _tr_flush_bits(s);
789 len = s->pending;
793 zmemcpy(strm->next_out, s->pending_out, len);
795 s->pending_out += len;
798 s->pending -= len;
799 if (s->pending == 0) {
800 s->pending_out = s->pending_buf;
809 if (s->gzhead->hcrc && s->pending > (beg)) \
810 strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
811 s->pending - (beg)); \
820 deflate_state *s; local
825 s = strm->state;
829 (s->status == FINISH_STATE && flush != Z_FINISH)) {
834 old_flush = s->last_flush;
835 s->last_flush = flush;
838 if (s->pending != 0) {
847 s->last_flush = -1;
861 if (s->status == FINISH_STATE && strm->avail_in != 0) {
866 if (s->status == INIT_STATE && s->wrap == 0)
867 s->status = BUSY_STATE;
868 if (s->status == INIT_STATE) {
870 uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8;
873 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
875 else if (s->level < 6)
877 else if (s->level == 6)
882 if (s->strstart != 0) header |= PRESET_DICT;
885 putShortMSB(s, header);
888 if (s->strstart != 0) {
889 putShortMSB(s, (uInt)(strm->adler >> 16));
890 putShortMSB(s, (uInt)(strm->adler & 0xffff));
893 s->status = BUSY_STATE;
897 if (s->pending != 0) {
898 s->last_flush = -1;
903 if (s->status == GZIP_STATE) {
906 put_byte(s, 31);
907 put_byte(s, 139);
908 put_byte(s, 8);
909 if (s->gzhead == Z_NULL) {
910 put_byte(s, 0);
911 put_byte(s, 0);
912 put_byte(s, 0);
913 put_byte(s, 0);
914 put_byte(s, 0);
915 put_byte(s, s->level == 9 ? 2 :
916 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
918 put_byte(s, OS_CODE);
919 s->status = BUSY_STATE;
923 if (s->pending != 0) {
924 s->last_flush = -1;
929 put_byte(s, (s->gzhead->text ? 1 : 0) +
930 (s->gzhead->hcrc ? 2 : 0) +
931 (s->gzhead->extra == Z_NULL ? 0 : 4) +
932 (s->gzhead->name == Z_NULL ? 0 : 8) +
933 (s->gzhead->comment == Z_NULL ? 0 : 16)
935 put_byte(s, (Byte)(s->gzhead->time & 0xff));
936 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
937 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
938 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
939 put_byte(s, s->level == 9 ? 2 :
940 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
942 put_byte(s, s->gzhead->os & 0xff);
943 if (s->gzhead->extra != Z_NULL) {
944 put_byte(s, s->gzhead->extra_len & 0xff);
945 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
947 if (s->gzhead->hcrc)
948 strm->adler = crc32(strm->adler, s->pending_buf,
949 s->pending);
950 s->gzindex = 0;
951 s->status = EXTRA_STATE;
954 if (s->status == EXTRA_STATE) {
955 if (s->gzhead->extra != Z_NULL) {
956 ulg beg = s->pending; /* start of bytes to update crc */
957 uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
958 while (s->pending + left > s->pending_buf_size) {
959 uInt copy = s->pending_buf_size - s->pending;
960 zmemcpy(s->pending_buf + s->pending,
961 s->gzhead->extra + s->gzindex, copy);
962 s->pending = s->pending_buf_size;
964 s->gzindex += copy;
966 if (s->pending != 0) {
967 s->last_flush = -1;
973 zmemcpy(s->pending_buf + s->pending,
974 s->gzhead->extra + s->gzindex, left);
975 s->pending += left;
977 s->gzindex = 0;
979 s->status = NAME_STATE;
981 if (s->status == NAME_STATE) {
982 if (s->gzhead->name != Z_NULL) {
983 ulg beg = s->pending; /* start of bytes to update crc */
986 if (s->pending == s->pending_buf_size) {
989 if (s->pending != 0) {
990 s->last_flush = -1;
995 val = s->gzhead->name[s->gzindex++];
996 put_byte(s, val);
999 s->gzindex = 0;
1001 s->status = COMMENT_STATE;
1003 if (s->status == COMMENT_STATE) {
1004 if (s->gzhead->comment != Z_NULL) {
1005 ulg beg = s->pending; /* start of bytes to update crc */
1008 if (s->pending == s->pending_buf_size) {
1011 if (s->pending != 0) {
1012 s->last_flush = -1;
1017 val = s->gzhead->comment[s->gzindex++];
1018 put_byte(s, val);
1022 s->status = HCRC_STATE;
1024 if (s->status == HCRC_STATE) {
1025 if (s->gzhead->hcrc) {
1026 if (s->pending + 2 > s->pending_buf_size) {
1028 if (s->pending != 0) {
1029 s->last_flush = -1;
1033 put_byte(s, (Byte)(strm->adler & 0xff));
1034 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1037 s->status = BUSY_STATE;
1041 if (s->pending != 0) {
1042 s->last_flush = -1;
1050 if (strm->avail_in != 0 || s->lookahead != 0 ||
1051 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
1054 bstate = s->level == 0 ? deflate_stored(s, flush) :
1055 s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
1056 s->strategy == Z_RLE ? deflate_rle(s, flush) :
1057 (*(configuration_table[s->level].func))(s, flush);
1060 s->status = FINISH_STATE;
1064 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
1077 _tr_align(s);
1079 _tr_stored_block(s, (char*)0, 0L, 0);
1084 CLEAR_HASH(s); /* forget history */
1085 if (s->lookahead == 0) {
1086 s->strstart = 0;
1087 s->block_start = 0L;
1088 s->insert = 0;
1094 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
1101 if (s->wrap <= 0) return Z_STREAM_END;
1105 if (s->wrap == 2) {
1106 put_byte(s, (Byte)(strm->adler & 0xff));
1107 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1108 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
1109 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
1110 put_byte(s, (Byte)(strm->total_in & 0xff));
1111 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
1112 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
1113 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
1118 putShortMSB(s, (uInt)(strm->adler >> 16));
1119 putShortMSB(s, (uInt)(strm->adler & 0xffff));
1125 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
1126 return s->pending != 0 ? Z_OK : Z_STREAM_END;
1245 local void lm_init(s) in lm_init() argument
1246 deflate_state *s; in lm_init()
1248 s->window_size = (ulg)2L*s->w_size;
1250 CLEAR_HASH(s);
1254 s->max_lazy_match = configuration_table[s->level].max_lazy;
1255 s->good_match = configuration_table[s->level].good_length;
1256 s->nice_match = configuration_table[s->level].nice_length;
1257 s->max_chain_length = configuration_table[s->level].max_chain;
1259 s->strstart = 0;
1260 s->block_start = 0L;
1261 s->lookahead = 0;
1262 s->insert = 0;
1263 s->match_length = s->prev_length = MIN_MATCH-1;
1264 s->match_available = 0;
1265 s->ins_h = 0;
1278 local uInt longest_match(s, cur_match) in longest_match() argument
1279 deflate_state *s; in longest_match()
1282 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1283 register Bytef *scan = s->window + s->strstart; /* current string */
1286 int best_len = (int)s->prev_length; /* best match length so far */
1287 int nice_match = s->nice_match; /* stop if match long enough */
1288 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1289 s->strstart - (IPos)MAX_DIST(s) : NIL;
1293 Posf *prev = s->prev;
1294 uInt wmask = s->w_mask;
1300 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1304 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1312 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1315 if (s->prev_length >= s->good_match) {
1321 if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
1323 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1327 Assert(cur_match < s->strstart, "no future");
1328 match = s->window + cur_match;
1365 Assert(scan <= s->window + (unsigned)(s->window_size - 1),
1398 Assert(scan <= s->window + (unsigned)(s->window_size - 1),
1407 s->match_start = cur_match;
1420 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1421 return s->lookahead;
1429 local uInt longest_match(s, cur_match) in longest_match() argument
1430 deflate_state *s; in longest_match()
1433 register Bytef *scan = s->window + s->strstart; /* current string */
1436 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1441 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1443 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1446 Assert(cur_match < s->strstart, "no future");
1448 match = s->window + cur_match;
1473 Assert(scan <= s->window + (unsigned)(s->window_size - 1), "wild scan");
1479 s->match_start = cur_match;
1480 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
1493 local void check_match(s, start, match, length) in check_match() argument
1494 deflate_state *s; in check_match()
1499 if (zmemcmp(s->window + match,
1500 s->window + start, length) != EQUAL) {
1504 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1510 do { putc(s->window[start++], stderr); } while (--length != 0);
1514 # define check_match(s, start, match, length) argument
1527 local void fill_window(s) in fill_window() argument
1528 deflate_state *s; in fill_window()
1532 uInt wsize = s->w_size;
1534 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1537 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1541 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1555 if (s->strstart >= wsize + MAX_DIST(s)) {
1557 zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more);
1558 s->match_start -= wsize;
1559 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1560 s->block_start -= (long) wsize;
1561 if (s->insert > s->strstart)
1562 s->insert = s->strstart;
1563 slide_hash(s);
1566 if (s->strm->avail_in == 0) break;
1581 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1582 s->lookahead += n;
1585 if (s->lookahead + s->insert >= MIN_MATCH) {
1586 uInt str = s->strstart - s->insert;
1587 s->ins_h = s->window[str];
1588 UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1592 while (s->insert) {
1593 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1595 s->prev[str & s->w_mask] = s->head[s->ins_h];
1597 s->head[s->ins_h] = (Pos)str;
1599 s->insert--;
1600 if (s->lookahead + s->insert < MIN_MATCH)
1608 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1617 if (s->high_water < s->window_size) {
1618 ulg curr = s->strstart + (ulg)(s->lookahead);
1621 if (s->high_water < curr) {
1625 init = s->window_size - curr;
1628 zmemzero(s->window + curr, (unsigned)init);
1629 s->high_water = curr + init;
1631 else if (s->high_water < (ulg)curr + WIN_INIT) {
1636 init = (ulg)curr + WIN_INIT - s->high_water;
1637 if (init > s->window_size - s->high_water)
1638 init = s->window_size - s->high_water;
1639 zmemzero(s->window + s->high_water, (unsigned)init);
1640 s->high_water += init;
1644 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1652 #define FLUSH_BLOCK_ONLY(s, last) { \ argument
1653 _tr_flush_block(s, (s->block_start >= 0L ? \
1654 (charf *)&s->window[(unsigned)s->block_start] : \
1656 (ulg)((long)s->strstart - s->block_start), \
1658 s->block_start = s->strstart; \
1659 flush_pending(s->strm); \
1664 #define FLUSH_BLOCK(s, last) { \ argument
1665 FLUSH_BLOCK_ONLY(s, last); \
1666 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1690 local block_state deflate_stored(s, flush) in deflate_stored() argument
1691 deflate_state *s; in deflate_stored()
1698 unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
1705 unsigned used = s->strm->avail_in;
1712 have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1713 if (s->strm->avail_out < have) /* need room for header */
1716 have = s->strm->avail_out - have;
1717 left = s->strstart - s->block_start; /* bytes left in window */
1718 if (len > (ulg)left + s->strm->avail_in)
1719 len = left + s->strm->avail_in; /* limit len to the input */
1730 len != left + s->strm->avail_in))
1736 last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
1737 _tr_stored_block(s, (char *)0, 0L, last);
1740 s->pending_buf[s->pending - 4] = len;
1741 s->pending_buf[s->pending - 3] = len >> 8;
1742 s->pending_buf[s->pending - 2] = ~len;
1743 s->pending_buf[s->pending - 1] = ~len >> 8;
1746 flush_pending(s->strm);
1750 s->compressed_len += len << 3;
1751 s->bits_sent += len << 3;
1758 zmemcpy(s->strm->next_out, s->window + s->block_start, left);
1759 s->strm->next_out += left;
1760 s->strm->avail_out -= left;
1761 s->strm->total_out += left;
1762 s->block_start += left;
1770 read_buf(s->strm, s->strm->next_out, len);
1771 s->strm->next_out += len;
1772 s->strm->avail_out -= len;
1773 s->strm->total_out += len;
1783 used -= s->strm->avail_in; /* number of input bytes directly copied */
1788 if (used >= s->w_size) { /* supplant the previous history */
1789 s->matches = 2; /* clear hash */
1790 zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
1791 s->strstart = s->w_size;
1792 s->insert = s->strstart;
1795 if (s->window_size - s->strstart <= used) {
1797 s->strstart -= s->w_size;
1798 zmemcpy(s->window, s->window + s->w_size, s->strstart);
1799 if (s->matches < 2)
1800 s->matches++; /* add a pending slide_hash() */
1801 if (s->insert > s->strstart)
1802 s->insert = s->strstart;
1804 zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
1805 s->strstart += used;
1806 s->insert += MIN(used, s->w_size - s->insert);
1808 s->block_start = s->strstart;
1810 if (s->high_water < s->strstart)
1811 s->high_water = s->strstart;
1819 s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
1823 have = s->window_size - s->strstart;
1824 if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
1826 s->block_start -= s->w_size;
1827 s->strstart -= s->w_size;
1828 zmemcpy(s->window, s->window + s->w_size, s->strstart);
1829 if (s->matches < 2)
1830 s->matches++; /* add a pending slide_hash() */
1831 have += s->w_size; /* more space now */
1832 if (s->insert > s->strstart)
1833 s->insert = s->strstart;
1835 if (have > s->strm->avail_in)
1836 have = s->strm->avail_in;
1838 read_buf(s->strm, s->window + s->strstart, have);
1839 s->strstart += have;
1840 s->insert += MIN(have, s->w_size - s->insert);
1842 if (s->high_water < s->strstart)
1843 s->high_water = s->strstart;
1850 have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1852 have = MIN(s->pending_buf_size - have, MAX_STORED);
1853 min_block = MIN(have, s->w_size);
1854 left = s->strstart - s->block_start;
1857 s->strm->avail_in == 0 && left <= have)) {
1859 last = flush == Z_FINISH && s->strm->avail_in == 0 &&
1861 _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
1862 s->block_start += len;
1863 flush_pending(s->strm);
1877 local block_state deflate_fast(s, flush) in deflate_fast() argument
1878 deflate_state *s; in deflate_fast()
1890 if (s->lookahead < MIN_LOOKAHEAD) {
1891 fill_window(s);
1892 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1895 if (s->lookahead == 0) break; /* flush the current block */
1902 if (s->lookahead >= MIN_MATCH) {
1903 INSERT_STRING(s, s->strstart, hash_head);
1909 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1914 s->match_length = longest_match (s, hash_head);
1917 if (s->match_length >= MIN_MATCH) {
1918 check_match(s, s->strstart, s->match_start, s->match_length);
1920 _tr_tally_dist(s, s->strstart - s->match_start,
1921 s->match_length - MIN_MATCH, bflush);
1923 s->lookahead -= s->match_length;
1929 if (s->match_length <= s->max_insert_length &&
1930 s->lookahead >= MIN_MATCH) {
1931 s->match_length--; /* string at strstart already in table */
1933 s->strstart++;
1934 INSERT_STRING(s, s->strstart, hash_head);
1938 } while (--s->match_length != 0);
1939 s->strstart++;
1943 s->strstart += s->match_length;
1944 s->match_length = 0;
1945 s->ins_h = s->window[s->strstart];
1946 UPDATE_HASH(s, s->ins_h, s->window[s->strstart + 1]);
1956 Tracevv((stderr,"%c", s->window[s->strstart]));
1957 _tr_tally_lit(s, s->window[s->strstart], bflush);
1958 s->lookahead--;
1959 s->strstart++;
1961 if (bflush) FLUSH_BLOCK(s, 0);
1963 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1965 FLUSH_BLOCK(s, 1);
1968 if (s->sym_next)
1969 FLUSH_BLOCK(s, 0);
1979 local block_state deflate_slow(s, flush) in deflate_slow() argument
1980 deflate_state *s; in deflate_slow()
1993 if (s->lookahead < MIN_LOOKAHEAD) {
1994 fill_window(s);
1995 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1998 if (s->lookahead == 0) break; /* flush the current block */
2005 if (s->lookahead >= MIN_MATCH) {
2006 INSERT_STRING(s, s->strstart, hash_head);
2011 s->prev_length = s->match_length, s->prev_match = s->match_start;
2012 s->match_length = MIN_MATCH-1;
2014 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
2015 s->strstart - hash_head <= MAX_DIST(s)) {
2020 s->match_length = longest_match (s, hash_head);
2023 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
2025 || (s->match_length == MIN_MATCH &&
2026 s->strstart - s->match_start > TOO_FAR)
2033 s->match_length = MIN_MATCH-1;
2039 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
2040 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
2043 check_match(s, s->strstart - 1, s->prev_match, s->prev_length);
2045 _tr_tally_dist(s, s->strstart - 1 - s->prev_match,
2046 s->prev_length - MIN_MATCH, bflush);
2053 s->lookahead -= s->prev_length - 1;
2054 s->prev_length -= 2;
2056 if (++s->strstart <= max_insert) {
2057 INSERT_STRING(s, s->strstart, hash_head);
2059 } while (--s->prev_length != 0);
2060 s->match_available = 0;
2061 s->match_length = MIN_MATCH-1;
2062 s->strstart++;
2064 if (bflush) FLUSH_BLOCK(s, 0);
2066 } else if (s->match_available) {
2071 Tracevv((stderr,"%c", s->window[s->strstart - 1]));
2072 _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
2074 FLUSH_BLOCK_ONLY(s, 0);
2076 s->strstart++;
2077 s->lookahead--;
2078 if (s->strm->avail_out == 0) return need_more;
2083 s->match_available = 1;
2084 s->strstart++;
2085 s->lookahead--;
2089 if (s->match_available) {
2090 Tracevv((stderr,"%c", s->window[s->strstart - 1]));
2091 _tr_tally_lit(s, s->window[s->strstart - 1], bflush);
2092 s->match_available = 0;
2094 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
2096 FLUSH_BLOCK(s, 1);
2099 if (s->sym_next)
2100 FLUSH_BLOCK(s, 0);
2110 local block_state deflate_rle(s, flush) in deflate_rle() argument
2111 deflate_state *s; in deflate_rle()
2123 if (s->lookahead <= MAX_MATCH) {
2124 fill_window(s);
2125 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
2128 if (s->lookahead == 0) break; /* flush the current block */
2132 s->match_length = 0;
2133 if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
2134 scan = s->window + s->strstart - 1;
2137 strend = s->window + s->strstart + MAX_MATCH;
2144 s->match_length = MAX_MATCH - (uInt)(strend - scan);
2145 if (s->match_length > s->lookahead)
2146 s->match_length = s->lookahead;
2148 Assert(scan <= s->window + (uInt)(s->window_size - 1),
2153 if (s->match_length >= MIN_MATCH) {
2154 check_match(s, s->strstart, s->strstart - 1, s->match_length);
2156 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
2158 s->lookahead -= s->match_length;
2159 s->strstart += s->match_length;
2160 s->match_length = 0;
2163 Tracevv((stderr,"%c", s->window[s->strstart]));
2164 _tr_tally_lit(s, s->window[s->strstart], bflush);
2165 s->lookahead--;
2166 s->strstart++;
2168 if (bflush) FLUSH_BLOCK(s, 0);
2170 s->insert = 0;
2172 FLUSH_BLOCK(s, 1);
2175 if (s->sym_next)
2176 FLUSH_BLOCK(s, 0);
2184 local block_state deflate_huff(s, flush) in deflate_huff() argument
2185 deflate_state *s; in deflate_huff()
2192 if (s->lookahead == 0) {
2193 fill_window(s);
2194 if (s->lookahead == 0) {
2202 s->match_length = 0;
2203 Tracevv((stderr,"%c", s->window[s->strstart]));
2204 _tr_tally_lit(s, s->window[s->strstart], bflush);
2205 s->lookahead--;
2206 s->strstart++;
2207 if (bflush) FLUSH_BLOCK(s, 0);
2209 s->insert = 0;
2211 FLUSH_BLOCK(s, 1);
2214 if (s->sym_next)
2215 FLUSH_BLOCK(s, 0);