Lines Matching refs:s

71 typedef block_state (*compress_func) OF((deflate_state *s, int flush));
75 local void slide_hash OF((deflate_state *s));
76 local void fill_window OF((deflate_state *s));
77 local block_state deflate_stored OF((deflate_state *s, int flush));
78 local block_state deflate_fast OF((deflate_state *s, int flush));
80 local block_state deflate_slow OF((deflate_state *s, int flush));
82 local block_state deflate_rle OF((deflate_state *s, int flush));
83 local block_state deflate_huff OF((deflate_state *s, int flush));
84 local void lm_init OF((deflate_state *s));
85 local void putShortMSB OF((deflate_state *s, uInt b));
91 uInt longest_match OF((deflate_state *s, IPos cur_match));
93 local uInt longest_match OF((deflate_state *s, IPos cur_match));
97 local void check_match OF((deflate_state *s, IPos start, IPos match,
161 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) argument
175 #define INSERT_STRING(s, str, match_head) \ argument
176 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
177 match_head = s->head[s->ins_h], \
178 s->head[s->ins_h] = (Pos)(str))
180 #define INSERT_STRING(s, str, match_head) \ argument
181 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
182 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
183 s->head[s->ins_h] = (Pos)(str))
190 #define CLEAR_HASH(s) \ argument
192 s->head[s->hash_size-1] = NIL; \
193 zmemzero((Bytef *)s->head, \
194 (unsigned)(s->hash_size-1)*sizeof(*s->head)); \
202 local void slide_hash(s) in slide_hash() argument
203 deflate_state *s; in slide_hash()
207 uInt wsize = s->w_size;
209 n = s->hash_size;
210 p = &s->head[n];
217 p = &s->prev[n];
252 deflate_state *s; local
300 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
301 if (s == Z_NULL) return Z_MEM_ERROR;
302 strm->state = (struct internal_state FAR *)s;
303 s->strm = strm;
304 s->status = INIT_STATE; /* to pass state test in deflateReset() */
306 s->wrap = wrap;
307 s->gzhead = Z_NULL;
308 s->w_bits = (uInt)windowBits;
309 s->w_size = 1 << s->w_bits;
310 s->w_mask = s->w_size - 1;
312 s->hash_bits = (uInt)memLevel + 7;
313 s->hash_size = 1 << s->hash_bits;
314 s->hash_mask = s->hash_size - 1;
315 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
317 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
318 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
319 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
321 s->high_water = 0; /* nothing written to s->window yet */
323 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
364 s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4);
365 s->pending_buf_size = (ulg)s->lit_bufsize * 4;
367 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
368 s->pending_buf == Z_NULL) {
369 s->status = FINISH_STATE;
374 s->sym_buf = s->pending_buf + s->lit_bufsize;
375 s->sym_end = (s->lit_bufsize - 1) * 3;
381 s->level = level;
382 s->strategy = strategy;
383 s->method = (Byte)method;
394 deflate_state *s; local
398 s = strm->state;
399 if (s == Z_NULL || s->strm != strm || (s->status != INIT_STATE &&
401 s->status != GZIP_STATE &&
403 s->status != EXTRA_STATE &&
404 s->status != NAME_STATE &&
405 s->status != COMMENT_STATE &&
406 s->status != HCRC_STATE &&
407 s->status != BUSY_STATE &&
408 s->status != FINISH_STATE))
419 deflate_state *s; local
427 s = strm->state;
428 wrap = s->wrap;
429 if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
435 s->wrap = 0; /* avoid computing Adler-32 in read_buf */
438 if (dictLength >= s->w_size) {
440 CLEAR_HASH(s);
441 s->strstart = 0;
442 s->block_start = 0L;
443 s->insert = 0;
445 dictionary += dictLength - s->w_size; /* use the tail */
446 dictLength = s->w_size;
454 fill_window(s);
455 while (s->lookahead >= MIN_MATCH) {
456 str = s->strstart;
457 n = s->lookahead - (MIN_MATCH-1);
459 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
461 s->prev[str & s->w_mask] = s->head[s->ins_h];
463 s->head[s->ins_h] = (Pos)str;
466 s->strstart = str;
467 s->lookahead = MIN_MATCH-1;
468 fill_window(s);
470 s->strstart += s->lookahead;
471 s->block_start = (long)s->strstart;
472 s->insert = s->lookahead;
473 s->lookahead = 0;
474 s->match_length = s->prev_length = MIN_MATCH-1;
475 s->match_available = 0;
478 s->wrap = wrap;
488 deflate_state *s; local
493 s = strm->state;
494 len = s->strstart + s->lookahead;
495 if (len > s->w_size)
496 len = s->w_size;
498 zmemcpy(dictionary, s->window + s->strstart + s->lookahead - len, len);
508 deflate_state *s; local
518 s = (deflate_state *)strm->state;
519 s->pending = 0;
520 s->pending_out = s->pending_buf;
522 if (s->wrap < 0) {
523 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
525 s->status =
527 s->wrap == 2 ? GZIP_STATE :
532 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
535 s->last_flush = -2;
537 _tr_init(s);
585 deflate_state *s; local
589 s = strm->state;
591 s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3))
594 put = Buf_size - s->bi_valid;
597 s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid);
598 s->bi_valid += put;
599 _tr_flush_bits(s);
612 deflate_state *s; local
616 s = strm->state;
626 func = configuration_table[s->level].func;
628 if ((strategy != s->strategy || func != configuration_table[level].func) &&
629 s->last_flush != -2) {
634 if (strm->avail_in || (s->strstart - s->block_start) + s->lookahead)
637 if (s->level != level) {
638 if (s->level == 0 && s->matches != 0) {
639 if (s->matches == 1)
640 slide_hash(s);
642 CLEAR_HASH(s);
643 s->matches = 0;
645 s->level = level;
646 s->max_lazy_match = configuration_table[level].max_lazy;
647 s->good_match = configuration_table[level].good_length;
648 s->nice_match = configuration_table[level].nice_length;
649 s->max_chain_length = configuration_table[level].max_chain;
651 s->strategy = strategy;
663 deflate_state *s; local
666 s = strm->state;
667 s->good_match = (uInt)good_length;
668 s->max_lazy_match = (uInt)max_lazy;
669 s->nice_match = nice_length;
670 s->max_chain_length = (uInt)max_chain;
695 deflate_state *s; local
707 s = strm->state;
708 switch (s->wrap) {
713 wraplen = 6 + (s->strstart ? 4 : 0);
718 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
720 if (s->gzhead->extra != Z_NULL)
721 wraplen += 2 + s->gzhead->extra_len;
722 str = s->gzhead->name;
727 str = s->gzhead->comment;
732 if (s->gzhead->hcrc)
742 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
755 local void putShortMSB (s, b) in putShortMSB() argument
756 deflate_state *s; in putShortMSB()
759 put_byte(s, (Byte)(b >> 8));
760 put_byte(s, (Byte)(b & 0xff));
773 deflate_state *s = strm->state; local
775 _tr_flush_bits(s);
776 len = s->pending;
780 zmemcpy(strm->next_out, s->pending_out, len);
782 s->pending_out += len;
785 s->pending -= len;
786 if (s->pending == 0) {
787 s->pending_out = s->pending_buf;
796 if (s->gzhead->hcrc && s->pending > (beg)) \
797 strm->adler = crc32(strm->adler, s->pending_buf + (beg), \
798 s->pending - (beg)); \
807 deflate_state *s; local
812 s = strm->state;
816 (s->status == FINISH_STATE && flush != Z_FINISH)) {
821 old_flush = s->last_flush;
822 s->last_flush = flush;
825 if (s->pending != 0) {
834 s->last_flush = -1;
848 if (s->status == FINISH_STATE && strm->avail_in != 0) {
853 if (s->status == INIT_STATE && s->wrap == 0)
854 s->status = BUSY_STATE;
855 if (s->status == INIT_STATE) {
857 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
860 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
862 else if (s->level < 6)
864 else if (s->level == 6)
869 if (s->strstart != 0) header |= PRESET_DICT;
872 putShortMSB(s, header);
875 if (s->strstart != 0) {
876 putShortMSB(s, (uInt)(strm->adler >> 16));
877 putShortMSB(s, (uInt)(strm->adler & 0xffff));
880 s->status = BUSY_STATE;
884 if (s->pending != 0) {
885 s->last_flush = -1;
890 if (s->status == GZIP_STATE) {
893 put_byte(s, 31);
894 put_byte(s, 139);
895 put_byte(s, 8);
896 if (s->gzhead == Z_NULL) {
897 put_byte(s, 0);
898 put_byte(s, 0);
899 put_byte(s, 0);
900 put_byte(s, 0);
901 put_byte(s, 0);
902 put_byte(s, s->level == 9 ? 2 :
903 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
905 put_byte(s, OS_CODE);
906 s->status = BUSY_STATE;
910 if (s->pending != 0) {
911 s->last_flush = -1;
916 put_byte(s, (s->gzhead->text ? 1 : 0) +
917 (s->gzhead->hcrc ? 2 : 0) +
918 (s->gzhead->extra == Z_NULL ? 0 : 4) +
919 (s->gzhead->name == Z_NULL ? 0 : 8) +
920 (s->gzhead->comment == Z_NULL ? 0 : 16)
922 put_byte(s, (Byte)(s->gzhead->time & 0xff));
923 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
924 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
925 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
926 put_byte(s, s->level == 9 ? 2 :
927 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
929 put_byte(s, s->gzhead->os & 0xff);
930 if (s->gzhead->extra != Z_NULL) {
931 put_byte(s, s->gzhead->extra_len & 0xff);
932 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
934 if (s->gzhead->hcrc)
935 strm->adler = crc32(strm->adler, s->pending_buf,
936 s->pending);
937 s->gzindex = 0;
938 s->status = EXTRA_STATE;
941 if (s->status == EXTRA_STATE) {
942 if (s->gzhead->extra != Z_NULL) {
943 ulg beg = s->pending; /* start of bytes to update crc */
944 uInt left = (s->gzhead->extra_len & 0xffff) - s->gzindex;
945 while (s->pending + left > s->pending_buf_size) {
946 uInt copy = s->pending_buf_size - s->pending;
947 zmemcpy(s->pending_buf + s->pending,
948 s->gzhead->extra + s->gzindex, copy);
949 s->pending = s->pending_buf_size;
951 s->gzindex += copy;
953 if (s->pending != 0) {
954 s->last_flush = -1;
960 zmemcpy(s->pending_buf + s->pending,
961 s->gzhead->extra + s->gzindex, left);
962 s->pending += left;
964 s->gzindex = 0;
966 s->status = NAME_STATE;
968 if (s->status == NAME_STATE) {
969 if (s->gzhead->name != Z_NULL) {
970 ulg beg = s->pending; /* start of bytes to update crc */
973 if (s->pending == s->pending_buf_size) {
976 if (s->pending != 0) {
977 s->last_flush = -1;
982 val = s->gzhead->name[s->gzindex++];
983 put_byte(s, val);
986 s->gzindex = 0;
988 s->status = COMMENT_STATE;
990 if (s->status == COMMENT_STATE) {
991 if (s->gzhead->comment != Z_NULL) {
992 ulg beg = s->pending; /* start of bytes to update crc */
995 if (s->pending == s->pending_buf_size) {
998 if (s->pending != 0) {
999 s->last_flush = -1;
1004 val = s->gzhead->comment[s->gzindex++];
1005 put_byte(s, val);
1009 s->status = HCRC_STATE;
1011 if (s->status == HCRC_STATE) {
1012 if (s->gzhead->hcrc) {
1013 if (s->pending + 2 > s->pending_buf_size) {
1015 if (s->pending != 0) {
1016 s->last_flush = -1;
1020 put_byte(s, (Byte)(strm->adler & 0xff));
1021 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1024 s->status = BUSY_STATE;
1028 if (s->pending != 0) {
1029 s->last_flush = -1;
1037 if (strm->avail_in != 0 || s->lookahead != 0 ||
1038 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
1041 bstate = s->level == 0 ? deflate_stored(s, flush) :
1042 s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
1043 s->strategy == Z_RLE ? deflate_rle(s, flush) :
1044 (*(configuration_table[s->level].func))(s, flush);
1047 s->status = FINISH_STATE;
1051 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
1064 _tr_align(s);
1066 _tr_stored_block(s, (char*)0, 0L, 0);
1071 CLEAR_HASH(s); /* forget history */
1072 if (s->lookahead == 0) {
1073 s->strstart = 0;
1074 s->block_start = 0L;
1075 s->insert = 0;
1081 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
1088 if (s->wrap <= 0) return Z_STREAM_END;
1092 if (s->wrap == 2) {
1093 put_byte(s, (Byte)(strm->adler & 0xff));
1094 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
1095 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
1096 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
1097 put_byte(s, (Byte)(strm->total_in & 0xff));
1098 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
1099 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
1100 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
1105 putShortMSB(s, (uInt)(strm->adler >> 16));
1106 putShortMSB(s, (uInt)(strm->adler & 0xffff));
1112 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
1113 return s->pending != 0 ? Z_OK : Z_STREAM_END;
1232 local void lm_init (s) in lm_init() argument
1233 deflate_state *s; in lm_init()
1235 s->window_size = (ulg)2L*s->w_size;
1237 CLEAR_HASH(s);
1241 s->max_lazy_match = configuration_table[s->level].max_lazy;
1242 s->good_match = configuration_table[s->level].good_length;
1243 s->nice_match = configuration_table[s->level].nice_length;
1244 s->max_chain_length = configuration_table[s->level].max_chain;
1246 s->strstart = 0;
1247 s->block_start = 0L;
1248 s->lookahead = 0;
1249 s->insert = 0;
1250 s->match_length = s->prev_length = MIN_MATCH-1;
1251 s->match_available = 0;
1252 s->ins_h = 0;
1274 local uInt longest_match(s, cur_match) in longest_match() argument
1275 deflate_state *s; in longest_match()
1278 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1279 register Bytef *scan = s->window + s->strstart; /* current string */
1282 int best_len = (int)s->prev_length; /* best match length so far */
1283 int nice_match = s->nice_match; /* stop if match long enough */
1284 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1285 s->strstart - (IPos)MAX_DIST(s) : NIL;
1289 Posf *prev = s->prev;
1290 uInt wmask = s->w_mask;
1296 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1300 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1308 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1311 if (s->prev_length >= s->good_match) {
1317 if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
1319 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1322 Assert(cur_match < s->strstart, "no future");
1323 match = s->window + cur_match;
1360 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1392 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1400 s->match_start = cur_match;
1413 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1414 return s->lookahead;
1423 local uInt longest_match(s, cur_match) in longest_match() argument
1424 deflate_state *s; in longest_match()
1427 register Bytef *scan = s->window + s->strstart; /* current string */
1430 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1435 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1437 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1439 Assert(cur_match < s->strstart, "no future");
1441 match = s->window + cur_match;
1466 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1472 s->match_start = cur_match;
1473 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
1486 local void check_match(s, start, match, length) in check_match() argument
1487 deflate_state *s; in check_match()
1492 if (zmemcmp(s->window + match,
1493 s->window + start, length) != EQUAL) {
1497 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1503 do { putc(s->window[start++], stderr); } while (--length != 0);
1507 # define check_match(s, start, match, length) argument
1520 local void fill_window(s) in fill_window() argument
1521 deflate_state *s; in fill_window()
1525 uInt wsize = s->w_size;
1527 Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
1530 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1534 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1548 if (s->strstart >= wsize+MAX_DIST(s)) {
1550 zmemcpy(s->window, s->window+wsize, (unsigned)wsize - more);
1551 s->match_start -= wsize;
1552 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1553 s->block_start -= (long) wsize;
1554 if (s->insert > s->strstart)
1555 s->insert = s->strstart;
1556 slide_hash(s);
1559 if (s->strm->avail_in == 0) break;
1574 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1575 s->lookahead += n;
1578 if (s->lookahead + s->insert >= MIN_MATCH) {
1579 uInt str = s->strstart - s->insert;
1580 s->ins_h = s->window[str];
1581 UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
1585 while (s->insert) {
1586 UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
1588 s->prev[str & s->w_mask] = s->head[s->ins_h];
1590 s->head[s->ins_h] = (Pos)str;
1592 s->insert--;
1593 if (s->lookahead + s->insert < MIN_MATCH)
1601 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1610 if (s->high_water < s->window_size) {
1611 ulg curr = s->strstart + (ulg)(s->lookahead);
1614 if (s->high_water < curr) {
1618 init = s->window_size - curr;
1621 zmemzero(s->window + curr, (unsigned)init);
1622 s->high_water = curr + init;
1624 else if (s->high_water < (ulg)curr + WIN_INIT) {
1629 init = (ulg)curr + WIN_INIT - s->high_water;
1630 if (init > s->window_size - s->high_water)
1631 init = s->window_size - s->high_water;
1632 zmemzero(s->window + s->high_water, (unsigned)init);
1633 s->high_water += init;
1637 Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
1645 #define FLUSH_BLOCK_ONLY(s, last) { \ argument
1646 _tr_flush_block(s, (s->block_start >= 0L ? \
1647 (charf *)&s->window[(unsigned)s->block_start] : \
1649 (ulg)((long)s->strstart - s->block_start), \
1651 s->block_start = s->strstart; \
1652 flush_pending(s->strm); \
1657 #define FLUSH_BLOCK(s, last) { \ argument
1658 FLUSH_BLOCK_ONLY(s, last); \
1659 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1683 local block_state deflate_stored(s, flush) in deflate_stored() argument
1684 deflate_state *s; in deflate_stored()
1691 unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
1698 unsigned used = s->strm->avail_in;
1705 have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1706 if (s->strm->avail_out < have) /* need room for header */
1709 have = s->strm->avail_out - have;
1710 left = s->strstart - s->block_start; /* bytes left in window */
1711 if (len > (ulg)left + s->strm->avail_in)
1712 len = left + s->strm->avail_in; /* limit len to the input */
1723 len != left + s->strm->avail_in))
1729 last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
1730 _tr_stored_block(s, (char *)0, 0L, last);
1733 s->pending_buf[s->pending - 4] = len;
1734 s->pending_buf[s->pending - 3] = len >> 8;
1735 s->pending_buf[s->pending - 2] = ~len;
1736 s->pending_buf[s->pending - 1] = ~len >> 8;
1739 flush_pending(s->strm);
1743 s->compressed_len += len << 3;
1744 s->bits_sent += len << 3;
1751 zmemcpy(s->strm->next_out, s->window + s->block_start, left);
1752 s->strm->next_out += left;
1753 s->strm->avail_out -= left;
1754 s->strm->total_out += left;
1755 s->block_start += left;
1763 read_buf(s->strm, s->strm->next_out, len);
1764 s->strm->next_out += len;
1765 s->strm->avail_out -= len;
1766 s->strm->total_out += len;
1776 used -= s->strm->avail_in; /* number of input bytes directly copied */
1781 if (used >= s->w_size) { /* supplant the previous history */
1782 s->matches = 2; /* clear hash */
1783 zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
1784 s->strstart = s->w_size;
1785 s->insert = s->strstart;
1788 if (s->window_size - s->strstart <= used) {
1790 s->strstart -= s->w_size;
1791 zmemcpy(s->window, s->window + s->w_size, s->strstart);
1792 if (s->matches < 2)
1793 s->matches++; /* add a pending slide_hash() */
1794 if (s->insert > s->strstart)
1795 s->insert = s->strstart;
1797 zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
1798 s->strstart += used;
1799 s->insert += MIN(used, s->w_size - s->insert);
1801 s->block_start = s->strstart;
1803 if (s->high_water < s->strstart)
1804 s->high_water = s->strstart;
1812 s->strm->avail_in == 0 && (long)s->strstart == s->block_start)
1816 have = s->window_size - s->strstart;
1817 if (s->strm->avail_in > have && s->block_start >= (long)s->w_size) {
1819 s->block_start -= s->w_size;
1820 s->strstart -= s->w_size;
1821 zmemcpy(s->window, s->window + s->w_size, s->strstart);
1822 if (s->matches < 2)
1823 s->matches++; /* add a pending slide_hash() */
1824 have += s->w_size; /* more space now */
1825 if (s->insert > s->strstart)
1826 s->insert = s->strstart;
1828 if (have > s->strm->avail_in)
1829 have = s->strm->avail_in;
1831 read_buf(s->strm, s->window + s->strstart, have);
1832 s->strstart += have;
1833 s->insert += MIN(have, s->w_size - s->insert);
1835 if (s->high_water < s->strstart)
1836 s->high_water = s->strstart;
1843 have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1845 have = MIN(s->pending_buf_size - have, MAX_STORED);
1846 min_block = MIN(have, s->w_size);
1847 left = s->strstart - s->block_start;
1850 s->strm->avail_in == 0 && left <= have)) {
1852 last = flush == Z_FINISH && s->strm->avail_in == 0 &&
1854 _tr_stored_block(s, (charf *)s->window + s->block_start, len, last);
1855 s->block_start += len;
1856 flush_pending(s->strm);
1870 local block_state deflate_fast(s, flush) in deflate_fast() argument
1871 deflate_state *s; in deflate_fast()
1883 if (s->lookahead < MIN_LOOKAHEAD) {
1884 fill_window(s);
1885 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1888 if (s->lookahead == 0) break; /* flush the current block */
1895 if (s->lookahead >= MIN_MATCH) {
1896 INSERT_STRING(s, s->strstart, hash_head);
1902 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1907 s->match_length = longest_match (s, hash_head);
1910 if (s->match_length >= MIN_MATCH) {
1911 check_match(s, s->strstart, s->match_start, s->match_length);
1913 _tr_tally_dist(s, s->strstart - s->match_start,
1914 s->match_length - MIN_MATCH, bflush);
1916 s->lookahead -= s->match_length;
1922 if (s->match_length <= s->max_insert_length &&
1923 s->lookahead >= MIN_MATCH) {
1924 s->match_length--; /* string at strstart already in table */
1926 s->strstart++;
1927 INSERT_STRING(s, s->strstart, hash_head);
1931 } while (--s->match_length != 0);
1932 s->strstart++;
1936 s->strstart += s->match_length;
1937 s->match_length = 0;
1938 s->ins_h = s->window[s->strstart];
1939 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1949 Tracevv((stderr,"%c", s->window[s->strstart]));
1950 _tr_tally_lit (s, s->window[s->strstart], bflush);
1951 s->lookahead--;
1952 s->strstart++;
1954 if (bflush) FLUSH_BLOCK(s, 0);
1956 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
1958 FLUSH_BLOCK(s, 1);
1961 if (s->sym_next)
1962 FLUSH_BLOCK(s, 0);
1972 local block_state deflate_slow(s, flush) in deflate_slow() argument
1973 deflate_state *s; in deflate_slow()
1986 if (s->lookahead < MIN_LOOKAHEAD) {
1987 fill_window(s);
1988 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1991 if (s->lookahead == 0) break; /* flush the current block */
1998 if (s->lookahead >= MIN_MATCH) {
1999 INSERT_STRING(s, s->strstart, hash_head);
2004 s->prev_length = s->match_length, s->prev_match = s->match_start;
2005 s->match_length = MIN_MATCH-1;
2007 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
2008 s->strstart - hash_head <= MAX_DIST(s)) {
2013 s->match_length = longest_match (s, hash_head);
2016 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
2018 || (s->match_length == MIN_MATCH &&
2019 s->strstart - s->match_start > TOO_FAR)
2026 s->match_length = MIN_MATCH-1;
2032 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
2033 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
2036 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
2038 _tr_tally_dist(s, s->strstart -1 - s->prev_match,
2039 s->prev_length - MIN_MATCH, bflush);
2046 s->lookahead -= s->prev_length-1;
2047 s->prev_length -= 2;
2049 if (++s->strstart <= max_insert) {
2050 INSERT_STRING(s, s->strstart, hash_head);
2052 } while (--s->prev_length != 0);
2053 s->match_available = 0;
2054 s->match_length = MIN_MATCH-1;
2055 s->strstart++;
2057 if (bflush) FLUSH_BLOCK(s, 0);
2059 } else if (s->match_available) {
2064 Tracevv((stderr,"%c", s->window[s->strstart-1]));
2065 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
2067 FLUSH_BLOCK_ONLY(s, 0);
2069 s->strstart++;
2070 s->lookahead--;
2071 if (s->strm->avail_out == 0) return need_more;
2076 s->match_available = 1;
2077 s->strstart++;
2078 s->lookahead--;
2082 if (s->match_available) {
2083 Tracevv((stderr,"%c", s->window[s->strstart-1]));
2084 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
2085 s->match_available = 0;
2087 s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
2089 FLUSH_BLOCK(s, 1);
2092 if (s->sym_next)
2093 FLUSH_BLOCK(s, 0);
2103 local block_state deflate_rle(s, flush) in deflate_rle() argument
2104 deflate_state *s; in deflate_rle()
2116 if (s->lookahead <= MAX_MATCH) {
2117 fill_window(s);
2118 if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) {
2121 if (s->lookahead == 0) break; /* flush the current block */
2125 s->match_length = 0;
2126 if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
2127 scan = s->window + s->strstart - 1;
2130 strend = s->window + s->strstart + MAX_MATCH;
2137 s->match_length = MAX_MATCH - (uInt)(strend - scan);
2138 if (s->match_length > s->lookahead)
2139 s->match_length = s->lookahead;
2141 Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
2145 if (s->match_length >= MIN_MATCH) {
2146 check_match(s, s->strstart, s->strstart - 1, s->match_length);
2148 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
2150 s->lookahead -= s->match_length;
2151 s->strstart += s->match_length;
2152 s->match_length = 0;
2155 Tracevv((stderr,"%c", s->window[s->strstart]));
2156 _tr_tally_lit (s, s->window[s->strstart], bflush);
2157 s->lookahead--;
2158 s->strstart++;
2160 if (bflush) FLUSH_BLOCK(s, 0);
2162 s->insert = 0;
2164 FLUSH_BLOCK(s, 1);
2167 if (s->sym_next)
2168 FLUSH_BLOCK(s, 0);
2176 local block_state deflate_huff(s, flush) in deflate_huff() argument
2177 deflate_state *s; in deflate_huff()
2184 if (s->lookahead == 0) {
2185 fill_window(s);
2186 if (s->lookahead == 0) {
2194 s->match_length = 0;
2195 Tracevv((stderr,"%c", s->window[s->strstart]));
2196 _tr_tally_lit (s, s->window[s->strstart], bflush);
2197 s->lookahead--;
2198 s->strstart++;
2199 if (bflush) FLUSH_BLOCK(s, 0);
2201 s->insert = 0;
2203 FLUSH_BLOCK(s, 1);
2206 if (s->sym_next)
2207 FLUSH_BLOCK(s, 0);