Lines Matching full:s
66 typedef block_state (*compress_func) (deflate_state *s, int flush);
69 static void fill_window (deflate_state *s);
70 static block_state deflate_stored (deflate_state *s, int flush);
71 static block_state deflate_fast (deflate_state *s, int flush);
72 static block_state deflate_slow (deflate_state *s, int flush);
73 static void lm_init (deflate_state *s);
74 static void putShortMSB (deflate_state *s, uInt b);
77 static uInt longest_match (deflate_state *s, IPos cur_match);
80 static void check_match (deflate_state *s, IPos start, IPos match,
142 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) argument
153 #define INSERT_STRING(s, str, match_head) \ argument
154 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
155 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
156 s->head[s->ins_h] = (Pos)(str))
162 #define CLEAR_HASH(s) \ argument
163 s->head[s->hash_size-1] = NIL; \
164 memset((char *)s->head, 0, (unsigned)(s->hash_size-1)*sizeof(*s->head));
176 deflate_state *s; in zlib_deflateInit2() local
205 * Direct the workspace's pointers to the chunks that were allocated in zlib_deflateInit2()
218 s = (deflate_state *) &(mem->deflate_memory); in zlib_deflateInit2()
219 strm->state = (struct internal_state *)s; in zlib_deflateInit2()
220 s->strm = strm; in zlib_deflateInit2()
222 s->noheader = noheader; in zlib_deflateInit2()
223 s->w_bits = windowBits; in zlib_deflateInit2()
224 s->w_size = 1 << s->w_bits; in zlib_deflateInit2()
225 s->w_mask = s->w_size - 1; in zlib_deflateInit2()
227 s->hash_bits = memLevel + 7; in zlib_deflateInit2()
228 s->hash_size = 1 << s->hash_bits; in zlib_deflateInit2()
229 s->hash_mask = s->hash_size - 1; in zlib_deflateInit2()
230 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); in zlib_deflateInit2()
232 s->window = (Byte *) mem->window_memory; in zlib_deflateInit2()
233 s->prev = (Pos *) mem->prev_memory; in zlib_deflateInit2()
234 s->head = (Pos *) mem->head_memory; in zlib_deflateInit2()
236 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ in zlib_deflateInit2()
239 s->pending_buf = (uch *) overlay; in zlib_deflateInit2()
240 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); in zlib_deflateInit2()
242 s->d_buf = overlay + s->lit_bufsize/sizeof(ush); in zlib_deflateInit2()
243 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; in zlib_deflateInit2()
245 s->level = level; in zlib_deflateInit2()
246 s->strategy = strategy; in zlib_deflateInit2()
247 s->method = (Byte)method; in zlib_deflateInit2()
257 deflate_state *s; in zlib_deflateReset() local
266 s = (deflate_state *)strm->state; in zlib_deflateReset()
267 s->pending = 0; in zlib_deflateReset()
268 s->pending_out = s->pending_buf; in zlib_deflateReset()
270 if (s->noheader < 0) { in zlib_deflateReset()
271 s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */ in zlib_deflateReset()
273 s->status = s->noheader ? BUSY_STATE : INIT_STATE; in zlib_deflateReset()
275 s->last_flush = Z_NO_FLUSH; in zlib_deflateReset()
277 zlib_tr_init(s); in zlib_deflateReset()
278 lm_init(s); in zlib_deflateReset()
289 deflate_state *s, in putShortMSB() argument
293 put_byte(s, (Byte)(b >> 8)); in putShortMSB()
294 put_byte(s, (Byte)(b & 0xff)); in putShortMSB()
307 deflate_state *s = (deflate_state *) strm->state; in flush_pending() local
308 unsigned len = s->pending; in flush_pending()
314 memcpy(strm->next_out, s->pending_out, len); in flush_pending()
317 s->pending_out += len; in flush_pending()
320 s->pending -= len; in flush_pending()
321 if (s->pending == 0) { in flush_pending()
322 s->pending_out = s->pending_buf; in flush_pending()
333 deflate_state *s; in zlib_deflate() local
339 s = (deflate_state *) strm->state; in zlib_deflate()
342 (s->status == FINISH_STATE && flush != Z_FINISH)) { in zlib_deflate()
347 s->strm = strm; /* just in case */ in zlib_deflate()
348 old_flush = s->last_flush; in zlib_deflate()
349 s->last_flush = flush; in zlib_deflate()
352 if (s->status == INIT_STATE) { in zlib_deflate()
354 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; in zlib_deflate()
355 uInt level_flags = (s->level-1) >> 1; in zlib_deflate()
359 if (s->strstart != 0) header |= PRESET_DICT; in zlib_deflate()
362 s->status = BUSY_STATE; in zlib_deflate()
363 putShortMSB(s, header); in zlib_deflate()
366 if (s->strstart != 0) { in zlib_deflate()
367 putShortMSB(s, (uInt)(strm->adler >> 16)); in zlib_deflate()
368 putShortMSB(s, (uInt)(strm->adler & 0xffff)); in zlib_deflate()
374 if (s->pending != 0) { in zlib_deflate()
383 s->last_flush = -1; in zlib_deflate()
397 if (s->status == FINISH_STATE && strm->avail_in != 0) { in zlib_deflate()
403 if (strm->avail_in != 0 || s->lookahead != 0 || in zlib_deflate()
404 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { in zlib_deflate()
407 bstate = (*(configuration_table[s->level].func))(s, flush); in zlib_deflate()
410 s->status = FINISH_STATE; in zlib_deflate()
414 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ in zlib_deflate()
427 zlib_tr_align(s); in zlib_deflate()
431 zlib_tr_stored_type_only(s); in zlib_deflate()
433 zlib_tr_stored_block(s, (char*)0, 0L, 0); in zlib_deflate()
438 CLEAR_HASH(s); /* forget history */ in zlib_deflate()
443 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ in zlib_deflate()
451 if (s->noheader) return Z_STREAM_END; in zlib_deflate()
454 putShortMSB(s, (uInt)(strm->adler >> 16)); in zlib_deflate()
455 putShortMSB(s, (uInt)(strm->adler & 0xffff)); in zlib_deflate()
460 s->noheader = -1; /* write the trailer only once! */ in zlib_deflate()
461 return s->pending != 0 ? Z_OK : Z_STREAM_END; in zlib_deflate()
470 deflate_state *s; in zlib_deflateEnd() local
473 s = (deflate_state *) strm->state; in zlib_deflateEnd()
475 status = s->status; in zlib_deflateEnd()
520 deflate_state *s in lm_init() argument
523 s->window_size = (ulg)2L*s->w_size; in lm_init()
525 CLEAR_HASH(s); in lm_init()
529 s->max_lazy_match = configuration_table[s->level].max_lazy; in lm_init()
530 s->good_match = configuration_table[s->level].good_length; in lm_init()
531 s->nice_match = configuration_table[s->level].nice_length; in lm_init()
532 s->max_chain_length = configuration_table[s->level].max_chain; in lm_init()
534 s->strstart = 0; in lm_init()
535 s->block_start = 0L; in lm_init()
536 s->lookahead = 0; in lm_init()
537 s->match_length = s->prev_length = MIN_MATCH-1; in lm_init()
538 s->match_available = 0; in lm_init()
539 s->ins_h = 0; in lm_init()
549 * OUT assertion: the match length is not greater than s->lookahead.
552 * match.S. The code will be functionally equivalent.
555 deflate_state *s, in longest_match() argument
559 unsigned chain_length = s->max_chain_length;/* max hash chain length */ in longest_match()
560 register Byte *scan = s->window + s->strstart; /* current string */ in longest_match()
563 int best_len = s->prev_length; /* best match length so far */ in longest_match()
564 int nice_match = s->nice_match; /* stop if match long enough */ in longest_match()
565 IPos limit = s->strstart > (IPos)MAX_DIST(s) ? in longest_match()
566 s->strstart - (IPos)MAX_DIST(s) : NIL; in longest_match()
570 Pos *prev = s->prev; in longest_match()
571 uInt wmask = s->w_mask; in longest_match()
577 register Byte *strend = s->window + s->strstart + MAX_MATCH - 1; in longest_match()
581 register Byte *strend = s->window + s->strstart + MAX_MATCH; in longest_match()
589 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); in longest_match()
592 if (s->prev_length >= s->good_match) { in longest_match()
598 if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; in longest_match()
600 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); in longest_match()
603 Assert(cur_match < s->strstart, "no future"); in longest_match()
604 match = s->window + cur_match; in longest_match()
636 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); in longest_match()
668 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); in longest_match()
676 s->match_start = cur_match; in longest_match()
689 if ((uInt)best_len <= s->lookahead) return best_len; in longest_match()
690 return s->lookahead; in longest_match()
698 deflate_state *s, in check_match() argument
705 if (memcmp((char *)s->window + match, in check_match()
706 (char *)s->window + start, length) != EQUAL) { in check_match()
710 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); in check_match()
716 do { putc(s->window[start++], stderr); } while (--length != 0); in check_match()
720 # define check_match(s, start, match, length) argument
734 deflate_state *s in fill_window() argument
740 uInt wsize = s->w_size; in fill_window()
743 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); in fill_window()
746 if (more == 0 && s->strstart == 0 && s->lookahead == 0) { in fill_window()
758 } else if (s->strstart >= wsize+MAX_DIST(s)) { in fill_window()
760 memcpy((char *)s->window, (char *)s->window+wsize, in fill_window()
762 s->match_start -= wsize; in fill_window()
763 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ in fill_window()
764 s->block_start -= (long) wsize; in fill_window()
772 n = s->hash_size; in fill_window()
773 p = &s->head[n]; in fill_window()
780 p = &s->prev[n]; in fill_window()
790 if (s->strm->avail_in == 0) return; in fill_window()
799 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. in fill_window()
805 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); in fill_window()
806 s->lookahead += n; in fill_window()
809 if (s->lookahead >= MIN_MATCH) { in fill_window()
810 s->ins_h = s->window[s->strstart]; in fill_window()
811 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); in fill_window()
820 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); in fill_window()
827 #define FLUSH_BLOCK_ONLY(s, eof) { \ argument
828 zlib_tr_flush_block(s, (s->block_start >= 0L ? \
829 (char *)&s->window[(unsigned)s->block_start] : \
831 (ulg)((long)s->strstart - s->block_start), \
833 s->block_start = s->strstart; \
834 flush_pending(s->strm); \
839 #define FLUSH_BLOCK(s, eof) { \ argument
840 FLUSH_BLOCK_ONLY(s, eof); \
841 if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
854 deflate_state *s, in deflate_stored() argument
864 if (max_block_size > s->pending_buf_size - 5) { in deflate_stored()
865 max_block_size = s->pending_buf_size - 5; in deflate_stored()
871 if (s->lookahead <= 1) { in deflate_stored()
873 Assert(s->strstart < s->w_size+MAX_DIST(s) || in deflate_stored()
874 s->block_start >= (long)s->w_size, "slide too late"); in deflate_stored()
876 fill_window(s); in deflate_stored()
877 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; in deflate_stored()
879 if (s->lookahead == 0) break; /* flush the current block */ in deflate_stored()
881 Assert(s->block_start >= 0L, "block gone"); in deflate_stored()
883 s->strstart += s->lookahead; in deflate_stored()
884 s->lookahead = 0; in deflate_stored()
887 max_start = s->block_start + max_block_size; in deflate_stored()
888 if (s->strstart == 0 || (ulg)s->strstart >= max_start) { in deflate_stored()
890 s->lookahead = (uInt)(s->strstart - max_start); in deflate_stored()
891 s->strstart = (uInt)max_start; in deflate_stored()
892 FLUSH_BLOCK(s, 0); in deflate_stored()
897 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { in deflate_stored()
898 FLUSH_BLOCK(s, 0); in deflate_stored()
901 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_stored()
913 deflate_state *s, in deflate_fast() argument
926 if (s->lookahead < MIN_LOOKAHEAD) { in deflate_fast()
927 fill_window(s); in deflate_fast()
928 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { in deflate_fast()
931 if (s->lookahead == 0) break; /* flush the current block */ in deflate_fast()
937 if (s->lookahead >= MIN_MATCH) { in deflate_fast()
938 INSERT_STRING(s, s->strstart, hash_head); in deflate_fast()
944 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { in deflate_fast()
949 if (s->strategy != Z_HUFFMAN_ONLY) { in deflate_fast()
950 s->match_length = longest_match (s, hash_head); in deflate_fast()
954 if (s->match_length >= MIN_MATCH) { in deflate_fast()
955 check_match(s, s->strstart, s->match_start, s->match_length); in deflate_fast()
957 bflush = zlib_tr_tally(s, s->strstart - s->match_start, in deflate_fast()
958 s->match_length - MIN_MATCH); in deflate_fast()
960 s->lookahead -= s->match_length; in deflate_fast()
965 if (s->match_length <= s->max_insert_length && in deflate_fast()
966 s->lookahead >= MIN_MATCH) { in deflate_fast()
967 s->match_length--; /* string at strstart already in hash table */ in deflate_fast()
969 s->strstart++; in deflate_fast()
970 INSERT_STRING(s, s->strstart, hash_head); in deflate_fast()
974 } while (--s->match_length != 0); in deflate_fast()
975 s->strstart++; in deflate_fast()
977 s->strstart += s->match_length; in deflate_fast()
978 s->match_length = 0; in deflate_fast()
979 s->ins_h = s->window[s->strstart]; in deflate_fast()
980 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); in deflate_fast()
990 Tracevv((stderr,"%c", s->window[s->strstart])); in deflate_fast()
991 bflush = zlib_tr_tally (s, 0, s->window[s->strstart]); in deflate_fast()
992 s->lookahead--; in deflate_fast()
993 s->strstart++; in deflate_fast()
995 if (bflush) FLUSH_BLOCK(s, 0); in deflate_fast()
997 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_fast()
1007 deflate_state *s, in deflate_slow() argument
1021 if (s->lookahead < MIN_LOOKAHEAD) { in deflate_slow()
1022 fill_window(s); in deflate_slow()
1023 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { in deflate_slow()
1026 if (s->lookahead == 0) break; /* flush the current block */ in deflate_slow()
1032 if (s->lookahead >= MIN_MATCH) { in deflate_slow()
1033 INSERT_STRING(s, s->strstart, hash_head); in deflate_slow()
1038 s->prev_length = s->match_length, s->prev_match = s->match_start; in deflate_slow()
1039 s->match_length = MIN_MATCH-1; in deflate_slow()
1041 if (hash_head != NIL && s->prev_length < s->max_lazy_match && in deflate_slow()
1042 s->strstart - hash_head <= MAX_DIST(s)) { in deflate_slow()
1047 if (s->strategy != Z_HUFFMAN_ONLY) { in deflate_slow()
1048 s->match_length = longest_match (s, hash_head); in deflate_slow()
1052 if (s->match_length <= 5 && (s->strategy == Z_FILTERED || in deflate_slow()
1053 (s->match_length == MIN_MATCH && in deflate_slow()
1054 s->strstart - s->match_start > TOO_FAR))) { in deflate_slow()
1059 s->match_length = MIN_MATCH-1; in deflate_slow()
1065 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { in deflate_slow()
1066 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; in deflate_slow()
1069 check_match(s, s->strstart-1, s->prev_match, s->prev_length); in deflate_slow()
1071 bflush = zlib_tr_tally(s, s->strstart -1 - s->prev_match, in deflate_slow()
1072 s->prev_length - MIN_MATCH); in deflate_slow()
1079 s->lookahead -= s->prev_length-1; in deflate_slow()
1080 s->prev_length -= 2; in deflate_slow()
1082 if (++s->strstart <= max_insert) { in deflate_slow()
1083 INSERT_STRING(s, s->strstart, hash_head); in deflate_slow()
1085 } while (--s->prev_length != 0); in deflate_slow()
1086 s->match_available = 0; in deflate_slow()
1087 s->match_length = MIN_MATCH-1; in deflate_slow()
1088 s->strstart++; in deflate_slow()
1090 if (bflush) FLUSH_BLOCK(s, 0); in deflate_slow()
1092 } else if (s->match_available) { in deflate_slow()
1097 Tracevv((stderr,"%c", s->window[s->strstart-1])); in deflate_slow()
1098 if (zlib_tr_tally (s, 0, s->window[s->strstart-1])) { in deflate_slow()
1099 FLUSH_BLOCK_ONLY(s, 0); in deflate_slow()
1101 s->strstart++; in deflate_slow()
1102 s->lookahead--; in deflate_slow()
1103 if (s->strm->avail_out == 0) return need_more; in deflate_slow()
1108 s->match_available = 1; in deflate_slow()
1109 s->strstart++; in deflate_slow()
1110 s->lookahead--; in deflate_slow()
1114 if (s->match_available) { in deflate_slow()
1115 Tracevv((stderr,"%c", s->window[s->strstart-1])); in deflate_slow()
1116 zlib_tr_tally (s, 0, s->window[s->strstart-1]); in deflate_slow()
1117 s->match_available = 0; in deflate_slow()
1119 FLUSH_BLOCK(s, flush == Z_FINISH); in deflate_slow()