Lines Matching refs:s
69 typedef block_state (*compress_func) (deflate_state *s, int flush);
72 static void fill_window (deflate_state *s);
73 static block_state deflate_stored (deflate_state *s, int flush);
74 static block_state deflate_fast (deflate_state *s, int flush);
75 static block_state deflate_slow (deflate_state *s, int flush);
76 static void lm_init (deflate_state *s);
77 static void putShortMSB (deflate_state *s, uInt b);
79 static uInt longest_match (deflate_state *s, IPos cur_match);
82 static void check_match (deflate_state *s, IPos start, IPos match,
163 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) argument
174 #define INSERT_STRING(s, str, match_head) \ argument
175 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
176 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
177 s->head[s->ins_h] = (Pos)(str))
183 #define CLEAR_HASH(s) \ argument
184 s->head[s->hash_size-1] = NIL; \
185 memset((char *)s->head, 0, (unsigned)(s->hash_size-1)*sizeof(*s->head));
197 deflate_state *s; in zlib_deflateInit2() local
247 s = (deflate_state *) &(mem->deflate_memory); in zlib_deflateInit2()
248 strm->state = (struct internal_state *)s; in zlib_deflateInit2()
249 s->strm = strm; in zlib_deflateInit2()
251 s->noheader = noheader; in zlib_deflateInit2()
252 s->w_bits = windowBits; in zlib_deflateInit2()
253 s->w_size = 1 << s->w_bits; in zlib_deflateInit2()
254 s->w_mask = s->w_size - 1; in zlib_deflateInit2()
256 s->hash_bits = memLevel + 7; in zlib_deflateInit2()
257 s->hash_size = 1 << s->hash_bits; in zlib_deflateInit2()
258 s->hash_mask = s->hash_size - 1; in zlib_deflateInit2()
259 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); in zlib_deflateInit2()
261 s->window = (Byte *) mem->window_memory; in zlib_deflateInit2()
262 s->prev = (Pos *) mem->prev_memory; in zlib_deflateInit2()
263 s->head = (Pos *) mem->head_memory; in zlib_deflateInit2()
265 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ in zlib_deflateInit2()
268 s->pending_buf = (uch *) overlay; in zlib_deflateInit2()
269 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); in zlib_deflateInit2()
271 s->d_buf = overlay + s->lit_bufsize/sizeof(ush); in zlib_deflateInit2()
272 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; in zlib_deflateInit2()
274 s->level = level; in zlib_deflateInit2()
275 s->strategy = strategy; in zlib_deflateInit2()
276 s->method = (Byte)method; in zlib_deflateInit2()
286 deflate_state *s; in zlib_deflateReset() local
295 s = (deflate_state *)strm->state; in zlib_deflateReset()
296 s->pending = 0; in zlib_deflateReset()
297 s->pending_out = s->pending_buf; in zlib_deflateReset()
299 if (s->noheader < 0) { in zlib_deflateReset()
300 s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ in zlib_deflateReset()
302 s->status = s->noheader ? BUSY_STATE : INIT_STATE; in zlib_deflateReset()
304 s->last_flush = Z_NO_FLUSH; in zlib_deflateReset()
306 zlib_tr_init(s); in zlib_deflateReset()
307 lm_init(s); in zlib_deflateReset()
320 deflate_state *s, in putShortMSB() argument
324 put_byte(s, (Byte)(b >> 8)); in putShortMSB()
325 put_byte(s, (Byte)(b & 0xff)); in putShortMSB()
335 deflate_state *s; in zlib_deflate() local
341 s = (deflate_state *) strm->state; in zlib_deflate()
344 (s->status == FINISH_STATE && flush != Z_FINISH)) { in zlib_deflate()
349 s->strm = strm; /* just in case */ in zlib_deflate()
350 old_flush = s->last_flush; in zlib_deflate()
351 s->last_flush = flush; in zlib_deflate()
354 if (s->status == INIT_STATE) { in zlib_deflate()
356 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; in zlib_deflate()
357 uInt level_flags = (s->level-1) >> 1; in zlib_deflate()
361 if (s->strstart != 0) header |= PRESET_DICT; in zlib_deflate()
364 s->status = BUSY_STATE; in zlib_deflate()
365 putShortMSB(s, header); in zlib_deflate()
368 if (s->strstart != 0) { in zlib_deflate()
369 putShortMSB(s, (uInt)(strm->adler >> 16)); in zlib_deflate()
370 putShortMSB(s, (uInt)(strm->adler & 0xffff)); in zlib_deflate()
376 if (s->pending != 0) { in zlib_deflate()
385 s->last_flush = -1; in zlib_deflate()
399 if (s->status == FINISH_STATE && strm->avail_in != 0) { in zlib_deflate()
405 if (strm->avail_in != 0 || s->lookahead != 0 || in zlib_deflate()
406 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { in zlib_deflate()
410 (*(configuration_table[s->level].func))(s, flush); in zlib_deflate()
413 s->status = FINISH_STATE; in zlib_deflate()
417 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ in zlib_deflate()
430 zlib_tr_align(s); in zlib_deflate()
434 zlib_tr_stored_type_only(s); in zlib_deflate()
436 zlib_tr_stored_block(s, (char*)0, 0L, 0); in zlib_deflate()
441 CLEAR_HASH(s); /* forget history */ in zlib_deflate()
446 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ in zlib_deflate()
455 if (!s->noheader) { in zlib_deflate()
457 putShortMSB(s, (uInt)(strm->adler >> 16)); in zlib_deflate()
458 putShortMSB(s, (uInt)(strm->adler & 0xffff)); in zlib_deflate()
464 if (!s->noheader) { in zlib_deflate()
465 s->noheader = -1; /* write the trailer only once! */ in zlib_deflate()
467 if (s->pending == 0) { in zlib_deflate()
468 Assert(s->bi_valid == 0, "bi_buf not flushed"); in zlib_deflate()
480 deflate_state *s; in zlib_deflateEnd() local
483 s = (deflate_state *) strm->state; in zlib_deflateEnd()
485 status = s->status; in zlib_deflateEnd()
531 deflate_state *s in lm_init() argument
534 s->window_size = (ulg)2L*s->w_size; in lm_init()
536 CLEAR_HASH(s); in lm_init()
540 s->max_lazy_match = configuration_table[s->level].max_lazy; in lm_init()
541 s->good_match = configuration_table[s->level].good_length; in lm_init()
542 s->nice_match = configuration_table[s->level].nice_length; in lm_init()
543 s->max_chain_length = configuration_table[s->level].max_chain; in lm_init()
545 s->strstart = 0; in lm_init()
546 s->block_start = 0L; in lm_init()
547 s->lookahead = 0; in lm_init()
548 s->match_length = s->prev_length = MIN_MATCH-1; in lm_init()
549 s->match_available = 0; in lm_init()
550 s->ins_h = 0; in lm_init()
566 deflate_state *s, in longest_match() argument
570 unsigned chain_length = s->max_chain_length;/* max hash chain length */ in longest_match()
571 register Byte *scan = s->window + s->strstart; /* current string */ in longest_match()
574 int best_len = s->prev_length; /* best match length so far */ in longest_match()
575 int nice_match = s->nice_match; /* stop if match long enough */ in longest_match()
576 IPos limit = s->strstart > (IPos)MAX_DIST(s) ? in longest_match()
577 s->strstart - (IPos)MAX_DIST(s) : NIL; in longest_match()
581 Pos *prev = s->prev; in longest_match()
582 uInt wmask = s->w_mask; in longest_match()
588 register Byte *strend = s->window + s->strstart + MAX_MATCH - 1; in longest_match()
592 register Byte *strend = s->window + s->strstart + MAX_MATCH; in longest_match()
600 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); in longest_match()
603 if (s->prev_length >= s->good_match) { in longest_match()
609 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; in longest_match()
611 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); in longest_match()
614 Assert(cur_match < s->strstart, "no future"); in longest_match()
615 match = s->window + cur_match; in longest_match()
647 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); in longest_match()
679 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); in longest_match()
687 s->match_start = cur_match; in longest_match()
700 if ((uInt)best_len <= s->lookahead) return best_len; in longest_match()
701 return s->lookahead; in longest_match()
709 deflate_state *s, in check_match() argument
716 if (memcmp((char *)s->window + match, in check_match()
717 (char *)s->window + start, length) != EQUAL) { in check_match()
721 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); in check_match()
727 do { putc(s->window[start++], stderr); } while (--length != 0); in check_match()
731 # define check_match(s, start, match, length) argument
745 deflate_state *s in fill_window() argument
751 uInt wsize = s->w_size; in fill_window()
754 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); in fill_window()
757 if (more == 0 && s->strstart == 0 && s->lookahead == 0) { in fill_window()
769 } else if (s->strstart >= wsize+MAX_DIST(s)) { in fill_window()
771 memcpy((char *)s->window, (char *)s->window+wsize, in fill_window()
773 s->match_start -= wsize; in fill_window()
774 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ in fill_window()
775 s->block_start -= (long) wsize; in fill_window()
783 n = s->hash_size; in fill_window()
784 p = &s->head[n]; in fill_window()
791 p = &s->prev[n]; in fill_window()
801 if (s->strm->avail_in == 0) return; in fill_window()
816 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); in fill_window()
817 s->lookahead += n; in fill_window()
820 if (s->lookahead >= MIN_MATCH) { in fill_window()
821 s->ins_h = s->window[s->strstart]; in fill_window()
822 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); in fill_window()
831 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); in fill_window()
838 #define FLUSH_BLOCK_ONLY(s, eof) { \ argument
839 zlib_tr_flush_block(s, (s->block_start >= 0L ? \
840 (char *)&s->window[(unsigned)s->block_start] : \
842 (ulg)((long)s->strstart - s->block_start), \
844 s->block_start = s->strstart; \
845 flush_pending(s->strm); \
850 #define FLUSH_BLOCK(s, eof) { \ argument
851 FLUSH_BLOCK_ONLY(s, eof); \
852 if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
865 deflate_state *s, in deflate_stored() argument
875 if (max_block_size > s->pending_buf_size - 5) { in deflate_stored()
876 max_block_size = s->pending_buf_size - 5; in deflate_stored()
882 if (s->lookahead <= 1) { in deflate_stored()
884 Assert(s->strstart < s->w_size+MAX_DIST(s) || in deflate_stored()
885 s->block_start >= (long)s->w_size, "slide too late"); in deflate_stored()
887 fill_window(s); in deflate_stored()
888 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; in deflate_stored()
890 if (s->lookahead == 0) break; /* flush the current block */ in deflate_stored()
892 Assert(s->block_start >= 0L, "block gone"); in deflate_stored()
894 s->strstart += s->lookahead; in deflate_stored()
895 s->lookahead = 0; in deflate_stored()
898 max_start = s->block_start + max_block_size; in deflate_stored()
899 if (s->strstart == 0 || (ulg)s->strstart >= max_start) { in deflate_stored()
901 s->lookahead = (uInt)(s->strstart - max_start); in deflate_stored()
902 s->strstart = (uInt)max_start; in deflate_stored()
903 FLUSH_BLOCK(s, 0); in deflate_stored()
908 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { in deflate_stored()
909 FLUSH_BLOCK(s, 0); in deflate_stored()
912 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_stored()
924 deflate_state *s, in deflate_fast() argument
937 if (s->lookahead < MIN_LOOKAHEAD) { in deflate_fast()
938 fill_window(s); in deflate_fast()
939 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { in deflate_fast()
942 if (s->lookahead == 0) break; /* flush the current block */ in deflate_fast()
948 if (s->lookahead >= MIN_MATCH) { in deflate_fast()
949 INSERT_STRING(s, s->strstart, hash_head); in deflate_fast()
955 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { in deflate_fast()
960 if (s->strategy != Z_HUFFMAN_ONLY) { in deflate_fast()
961 s->match_length = longest_match (s, hash_head); in deflate_fast()
965 if (s->match_length >= MIN_MATCH) { in deflate_fast()
966 check_match(s, s->strstart, s->match_start, s->match_length); in deflate_fast()
968 bflush = zlib_tr_tally(s, s->strstart - s->match_start, in deflate_fast()
969 s->match_length - MIN_MATCH); in deflate_fast()
971 s->lookahead -= s->match_length; in deflate_fast()
976 if (s->match_length <= s->max_insert_length && in deflate_fast()
977 s->lookahead >= MIN_MATCH) { in deflate_fast()
978 s->match_length--; /* string at strstart already in hash table */ in deflate_fast()
980 s->strstart++; in deflate_fast()
981 INSERT_STRING(s, s->strstart, hash_head); in deflate_fast()
985 } while (--s->match_length != 0); in deflate_fast()
986 s->strstart++; in deflate_fast()
988 s->strstart += s->match_length; in deflate_fast()
989 s->match_length = 0; in deflate_fast()
990 s->ins_h = s->window[s->strstart]; in deflate_fast()
991 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); in deflate_fast()
1001 Tracevv((stderr,"%c", s->window[s->strstart])); in deflate_fast()
1002 bflush = zlib_tr_tally (s, 0, s->window[s->strstart]); in deflate_fast()
1003 s->lookahead--; in deflate_fast()
1004 s->strstart++; in deflate_fast()
1006 if (bflush) FLUSH_BLOCK(s, 0); in deflate_fast()
1008 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_fast()
1018 deflate_state *s, in deflate_slow() argument
1032 if (s->lookahead < MIN_LOOKAHEAD) { in deflate_slow()
1033 fill_window(s); in deflate_slow()
1034 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { in deflate_slow()
1037 if (s->lookahead == 0) break; /* flush the current block */ in deflate_slow()
1043 if (s->lookahead >= MIN_MATCH) { in deflate_slow()
1044 INSERT_STRING(s, s->strstart, hash_head); in deflate_slow()
1049 s->prev_length = s->match_length, s->prev_match = s->match_start; in deflate_slow()
1050 s->match_length = MIN_MATCH-1; in deflate_slow()
1052 if (hash_head != NIL && s->prev_length < s->max_lazy_match && in deflate_slow()
1053 s->strstart - hash_head <= MAX_DIST(s)) { in deflate_slow()
1058 if (s->strategy != Z_HUFFMAN_ONLY) { in deflate_slow()
1059 s->match_length = longest_match (s, hash_head); in deflate_slow()
1063 if (s->match_length <= 5 && (s->strategy == Z_FILTERED || in deflate_slow()
1064 (s->match_length == MIN_MATCH && in deflate_slow()
1065 s->strstart - s->match_start > TOO_FAR))) { in deflate_slow()
1070 s->match_length = MIN_MATCH-1; in deflate_slow()
1076 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { in deflate_slow()
1077 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; in deflate_slow()
1080 check_match(s, s->strstart-1, s->prev_match, s->prev_length); in deflate_slow()
1082 bflush = zlib_tr_tally(s, s->strstart -1 - s->prev_match, in deflate_slow()
1083 s->prev_length - MIN_MATCH); in deflate_slow()
1090 s->lookahead -= s->prev_length-1; in deflate_slow()
1091 s->prev_length -= 2; in deflate_slow()
1093 if (++s->strstart <= max_insert) { in deflate_slow()
1094 INSERT_STRING(s, s->strstart, hash_head); in deflate_slow()
1096 } while (--s->prev_length != 0); in deflate_slow()
1097 s->match_available = 0; in deflate_slow()
1098 s->match_length = MIN_MATCH-1; in deflate_slow()
1099 s->strstart++; in deflate_slow()
1101 if (bflush) FLUSH_BLOCK(s, 0); in deflate_slow()
1103 } else if (s->match_available) { in deflate_slow()
1108 Tracevv((stderr,"%c", s->window[s->strstart-1])); in deflate_slow()
1109 if (zlib_tr_tally (s, 0, s->window[s->strstart-1])) { in deflate_slow()
1110 FLUSH_BLOCK_ONLY(s, 0); in deflate_slow()
1112 s->strstart++; in deflate_slow()
1113 s->lookahead--; in deflate_slow()
1114 if (s->strm->avail_out == 0) return need_more; in deflate_slow()
1119 s->match_available = 1; in deflate_slow()
1120 s->strstart++; in deflate_slow()
1121 s->lookahead--; in deflate_slow()
1125 if (s->match_available) { in deflate_slow()
1126 Tracevv((stderr,"%c", s->window[s->strstart-1])); in deflate_slow()
1127 zlib_tr_tally (s, 0, s->window[s->strstart-1]); in deflate_slow()
1128 s->match_available = 0; in deflate_slow()
1130 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_slow()