ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
deflate.c
Go to the documentation of this file.
1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/*
7 * ALGORITHM
8 *
9 * The "deflation" process depends on being able to identify portions
10 * of the input text which are identical to earlier input (within a
11 * sliding window trailing behind the input currently being processed).
12 *
13 * The most straightforward technique turns out to be the fastest for
14 * most input files: try all possible matches and select the longest.
15 * The key feature of this algorithm is that insertions into the string
16 * dictionary are very simple and thus fast, and deletions are avoided
17 * completely. Insertions are performed at each input character, whereas
18 * string matches are performed only when the previous match ends. So it
19 * is preferable to spend more time in matches to allow very fast string
20 * insertions and avoid deletions. The matching algorithm for small
21 * strings is inspired from that of Rabin & Karp. A brute force approach
22 * is used to find longer strings when a small match has been found.
23 * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
24 * (by Leonid Broukhis).
25 * A previous version of this file used a more sophisticated algorithm
26 * (by Fiala and Greene) which is guaranteed to run in linear amortized
27 * time, but has a larger average cost, uses more memory and is patented.
28 * However the F&G algorithm may be faster for some highly redundant
29 * files if the parameter max_chain_length (described below) is too large.
30 *
31 * ACKNOWLEDGEMENTS
32 *
33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
34 * I found it in 'freeze' written by Leonid Broukhis.
35 * Thanks to many people for bug reports and testing.
36 *
37 * REFERENCES
38 *
39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
40 * Available in http://www.ietf.org/rfc/rfc1951.txt
41 *
42 * A description of the Rabin and Karp algorithm is given in the book
43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
44 *
45 * Fiala,E.R., and Greene,D.H.
46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
47 *
48 */
49
50/* @(#) $Id$ */
51
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
56
57#include "deflate.h"
58
60
61const char deflate_copyright[] =
62 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
63/*
64 If you use the zlib library in a product, an acknowledgment is welcome
65 in the documentation of your product. If for some reason you cannot
66 include such an acknowledgment, I would appreciate that you keep this
67 copyright string in the executable of your product.
68 */
69
70/* ===========================================================================
71 * Function prototypes.
72 */
73typedef enum {
74 need_more, /* block not completed, need more input or more output */
75 block_done, /* block flush performed */
76 finish_started, /* finish started, need only more output at next deflate */
77 finish_done /* finish done, accept no more input or output */
79
80typedef block_state (*compress_func) OF((deflate_state *s, int flush));
81/* Compression function. Returns the block state after the call. */
82
86#ifndef FASTEST
88#endif
91local void lm_init OF((deflate_state *s));
94local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
95#ifdef ASMV
96 void match_init OF((void)); /* asm code initialization */
97 uInt longest_match OF((deflate_state *s, IPos cur_match));
98#else
100#endif
101
102#ifdef DEBUG
103local void check_match OF((deflate_state *s, IPos start, IPos match,
104 int length));
105#endif
106
107/* ===========================================================================
108 * Local data
109 */
110
111#define NIL 0
112/* Tail of hash chains */
113
114#ifndef TOO_FAR
115# define TOO_FAR 4096
116#endif
117/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
118
119/* Values for max_lazy_match, good_match and max_chain_length, depending on
120 * the desired pack level (0..9). The values given below have been tuned to
121 * exclude worst case performance for pathological files. Better values may be
122 * found for specific files.
123 */
124typedef struct config_s {
125 ush good_length; /* reduce lazy search above this match length */
126 ush max_lazy; /* do not perform lazy search above this match length */
127 ush nice_length; /* quit search above this match length */
129 compress_func func;
131
132#ifdef FASTEST
134/* good lazy nice chain */
135/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
136/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
137#else
139/* good lazy nice chain */
140/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
141/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
142/* 2 */ {4, 5, 16, 8, deflate_fast},
143/* 3 */ {4, 6, 32, 32, deflate_fast},
144
145/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
146/* 5 */ {8, 16, 32, 32, deflate_slow},
147/* 6 */ {8, 16, 128, 128, deflate_slow},
148/* 7 */ {8, 32, 128, 256, deflate_slow},
149/* 8 */ {32, 128, 258, 1024, deflate_slow},
150/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
151#endif
152
153/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
154 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
155 * meaning.
156 */
157
158#define EQUAL 0
159/* result of memcmp for equal strings */
160
161#ifndef NO_DUMMY_DECL
162struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
163#endif
164
165/* ===========================================================================
166 * Update a hash value with the given input byte
167 * IN assertion: all calls to to UPDATE_HASH are made with consecutive
168 * input characters, so that a running hash key can be computed from the
169 * previous key instead of complete recalculation each time.
170 */
171#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
172
173
174/* ===========================================================================
175 * Insert string str in the dictionary and set match_head to the previous head
176 * of the hash chain (the most recent string with same hash key). Return
177 * the previous length of the hash chain.
178 * If this file is compiled with -DFASTEST, the compression level is forced
179 * to 1, and no hash chains are maintained.
180 * IN assertion: all calls to to INSERT_STRING are made with consecutive
181 * input characters and the first MIN_MATCH bytes of str are valid
182 * (except for the last MIN_MATCH-1 bytes of the input file).
183 */
184#ifdef FASTEST
185#define INSERT_STRING(s, str, match_head) \
186 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
187 match_head = s->head[s->ins_h], \
188 s->head[s->ins_h] = (Pos)(str))
189#else
190#define INSERT_STRING(s, str, match_head) \
191 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
192 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
193 s->head[s->ins_h] = (Pos)(str))
194#endif
195
196/* ===========================================================================
197 * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
198 * prev[] will be initialized on the fly.
199 */
200#define CLEAR_HASH(s) \
201 s->head[s->hash_size-1] = NIL; \
202 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
203
204/* ========================================================================= */
205int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
206{
207 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
208 Z_DEFAULT_STRATEGY, version, stream_size);
209 /* To do: ignore strm->next_in if we use it as window */
210}
211
212/* ========================================================================= */
213int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy,
214 const char *version, int stream_size)
215{
216 deflate_state *s;
217 int wrap = 1;
218 static const char my_version[] = ZLIB_VERSION;
219
220 ushf *overlay;
221 /* We overlay pending_buf and d_buf+l_buf. This works since the average
222 * output size for (length,distance) codes is <= 24 bits.
223 */
224
225 if (version == Z_NULL || version[0] != my_version[0] ||
226 stream_size != sizeof(z_stream)) {
227 return Z_VERSION_ERROR;
228 }
229 if (strm == Z_NULL) return Z_STREAM_ERROR;
230
231 strm->msg = Z_NULL;
232 if (strm->zalloc == (alloc_func)0) {
233 strm->zalloc = zcalloc;
234 strm->opaque = (voidpf)0;
235 }
236 if (strm->zfree == (free_func)0) strm->zfree = zcfree;
237
238#ifdef FASTEST
239 if (level != 0) level = 1;
240#else
241 if (level == Z_DEFAULT_COMPRESSION) level = 6;
242#endif
243
244 if (windowBits < 0) { /* suppress zlib wrapper */
245 wrap = 0;
246 windowBits = -windowBits;
247 }
248#ifdef GZIP
249 else if (windowBits > 15) {
250 wrap = 2; /* write gzip wrapper instead */
251 windowBits -= 16;
252 }
253#endif
254 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
255 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
256 strategy < 0 || strategy > Z_FIXED) {
257 return Z_STREAM_ERROR;
258 }
259 if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
260 s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
261 if (s == Z_NULL) return Z_MEM_ERROR;
262 strm->state = (struct internal_state FAR *)s;
263 s->strm = strm;
264
265 s->wrap = wrap;
266 s->gzhead = Z_NULL;
267 s->w_bits = windowBits;
268 s->w_size = 1 << s->w_bits;
269 s->w_mask = s->w_size - 1;
270
271 s->hash_bits = memLevel + 7;
272 s->hash_size = 1 << s->hash_bits;
273 s->hash_mask = s->hash_size - 1;
275
276 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
277 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
278 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
279
280 s->high_water = 0; /* nothing written to s->window yet */
281
282 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
283
284 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
285 s->pending_buf = (uchf *) overlay;
286 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
287
288 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
289 s->pending_buf == Z_NULL) {
290 s->status = FINISH_STATE;
291 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
293 return Z_MEM_ERROR;
294 }
295 s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
296 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
297
298 s->level = level;
299 s->strategy = strategy;
300 s->method = (Byte)method;
301
302 return deflateReset(strm);
303}
304
305/* ========================================================================= */
306int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
307{
308 deflate_state *s;
309 uInt length = dictLength;
310 uInt n;
311 IPos hash_head = 0;
312
313 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
314 strm->state->wrap == 2 ||
315 (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
316 return Z_STREAM_ERROR;
317
318 s = strm->state;
319 if (s->wrap)
320 strm->adler = adler32(strm->adler, dictionary, dictLength);
321
322 if (length < MIN_MATCH) return Z_OK;
323 if (length > s->w_size) {
324 length = s->w_size;
325 dictionary += dictLength - length; /* use the tail of the dictionary */
326 }
327 zmemcpy(s->window, dictionary, length);
328 s->strstart = length;
329 s->block_start = (long)length;
330
331 /* Insert all strings in the hash table (except for the last two bytes).
332 * s->lookahead stays null, so s->ins_h will be recomputed at the next
333 * call of fill_window.
334 */
335 s->ins_h = s->window[0];
336 UPDATE_HASH(s, s->ins_h, s->window[1]);
337 for (n = 0; n <= length - MIN_MATCH; n++) {
338 INSERT_STRING(s, n, hash_head);
339 }
340 if (hash_head) hash_head = 0; /* to make compiler happy */
341 return Z_OK;
342}
343
344/* ========================================================================= */
346{
347 deflate_state *s;
348
349 if (strm == Z_NULL || strm->state == Z_NULL ||
350 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
351 return Z_STREAM_ERROR;
352 }
353
354 strm->total_in = strm->total_out = 0;
355 strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
356 strm->data_type = Z_UNKNOWN;
357
358 s = (deflate_state *)strm->state;
359 s->pending = 0;
360 s->pending_out = s->pending_buf;
361
362 if (s->wrap < 0) {
363 s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
364 }
365 s->status = s->wrap ? INIT_STATE : BUSY_STATE;
366 strm->adler =
367#ifdef GZIP
368 s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
369#endif
370 adler32(0L, Z_NULL, 0);
372
373 _tr_init(s);
374 lm_init(s);
375
376 return Z_OK;
377}
378
379/* ========================================================================= */
381{
382 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
383 if (strm->state->wrap != 2) return Z_STREAM_ERROR;
384 strm->state->gzhead = head;
385 return Z_OK;
386}
387
388/* ========================================================================= */
390{
391 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
392 strm->state->bi_valid = bits;
393 strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
394 return Z_OK;
395}
396
397/* ========================================================================= */
399{
400 deflate_state *s;
401 compress_func func;
402 int err = Z_OK;
403
404 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
405 s = strm->state;
406
407#ifdef FASTEST
408 if (level != 0) level = 1;
409#else
411#endif
413 return Z_STREAM_ERROR;
414 }
415 func = configuration_table[s->level].func;
416
417 if ((strategy != s->strategy || func != configuration_table[level].func) &&
418 strm->total_in != 0) {
419 /* Flush the last buffer: */
420 err = deflate(strm, Z_BLOCK);
421 }
422 if (s->level != level) {
423 s->level = level;
425 s->good_match = configuration_table[level].good_length;
426 s->nice_match = configuration_table[level].nice_length;
428 }
429 s->strategy = strategy;
430 return err;
431}
432
433/* ========================================================================= */
434int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
435{
436 deflate_state *s;
437
438 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
439 s = strm->state;
440 s->good_match = good_length;
441 s->max_lazy_match = max_lazy;
442 s->nice_match = nice_length;
443 s->max_chain_length = max_chain;
444 return Z_OK;
445}
446
447/* =========================================================================
448 * For the default windowBits of 15 and memLevel of 8, this function returns
449 * a close to exact, as well as small, upper bound on the compressed size.
450 * They are coded as constants here for a reason--if the #define's are
451 * changed, then this function needs to be changed as well. The return
452 * value for 15 and 8 only works for those exact settings.
453 *
454 * For any setting other than those defaults for windowBits and memLevel,
455 * the value returned is a conservative worst case for the maximum expansion
456 * resulting from using fixed blocks instead of stored blocks, which deflate
457 * can emit on compressed data for some combinations of the parameters.
458 *
459 * This function could be more sophisticated to provide closer upper bounds for
460 * every combination of windowBits and memLevel. But even the conservative
461 * upper bound of about 14% expansion does not seem onerous for output buffer
462 * allocation.
463 */
465{
466 deflate_state *s;
467 uLong complen, wraplen;
468 Bytef *str;
469
470 /* conservative upper bound for compressed data */
471 complen = sourceLen +
472 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
473
474 /* if can't get parameters, return conservative bound plus zlib wrapper */
475 if (strm == Z_NULL || strm->state == Z_NULL)
476 return complen + 6;
477
478 /* compute wrapper length */
479 s = strm->state;
480 switch (s->wrap) {
481 case 0: /* raw deflate */
482 wraplen = 0;
483 break;
484 case 1: /* zlib wrapper */
485 wraplen = 6 + (s->strstart ? 4 : 0);
486 break;
487 case 2: /* gzip wrapper */
488 wraplen = 18;
489 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
490 if (s->gzhead->extra != Z_NULL)
491 wraplen += 2 + s->gzhead->extra_len;
492 str = s->gzhead->name;
493 if (str != Z_NULL)
494 do {
495 wraplen++;
496 } while (*str++);
497 str = s->gzhead->comment;
498 if (str != Z_NULL)
499 do {
500 wraplen++;
501 } while (*str++);
502 if (s->gzhead->hcrc)
503 wraplen += 2;
504 }
505 break;
506 default: /* for compiler happiness */
507 wraplen = 6;
508 }
509
510 /* if not default parameters, return conservative bound */
511 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
512 return complen + wraplen;
513
514 /* default settings: return tight bound for that case */
515 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
516 (sourceLen >> 25) + 13 - 6 + wraplen;
517}
518
519/* =========================================================================
520 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
521 * IN assertion: the stream state is correct and there is enough room in
522 * pending_buf.
523 */
525{
526 put_byte(s, (Byte)(b >> 8));
527 put_byte(s, (Byte)(b & 0xff));
528}
529
530/* =========================================================================
531 * Flush as much pending output as possible. All deflate() output goes
532 * through this function so some applications may wish to modify it
533 * to avoid allocating a large strm->next_out buffer and copying into it.
534 * (See also read_buf()).
535 */
537{
538 unsigned len = strm->state->pending;
539
540 if (len > strm->avail_out) len = strm->avail_out;
541 if (len == 0) return;
542
543 zmemcpy(strm->next_out, strm->state->pending_out, len);
544 strm->next_out += len;
545 strm->state->pending_out += len;
546 strm->total_out += len;
547 strm->avail_out -= len;
548 strm->state->pending -= len;
549 if (strm->state->pending == 0) {
550 strm->state->pending_out = strm->state->pending_buf;
551 }
552}
553
554/* ========================================================================= */
556{
557 int old_flush; /* value of flush param for previous deflate call */
558 deflate_state *s;
559
560 if (strm == Z_NULL || strm->state == Z_NULL ||
561 flush > Z_BLOCK || flush < 0) {
562 return Z_STREAM_ERROR;
563 }
564 s = strm->state;
565
566 if (strm->next_out == Z_NULL ||
567 (strm->next_in == Z_NULL && strm->avail_in != 0) ||
568 (s->status == FINISH_STATE && flush != Z_FINISH)) {
570 }
571 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
572
573 s->strm = strm; /* just in case */
574 old_flush = s->last_flush;
575 s->last_flush = flush;
576
577 /* Write the header */
578 if (s->status == INIT_STATE) {
579#ifdef GZIP
580 if (s->wrap == 2) {
581 strm->adler = crc32(0L, Z_NULL, 0);
582 put_byte(s, 31);
583 put_byte(s, 139);
584 put_byte(s, 8);
585 if (s->gzhead == Z_NULL) {
586 put_byte(s, 0);
587 put_byte(s, 0);
588 put_byte(s, 0);
589 put_byte(s, 0);
590 put_byte(s, 0);
591 put_byte(s, s->level == 9 ? 2 :
592 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
593 4 : 0));
594 put_byte(s, OS_CODE);
595 s->status = BUSY_STATE;
596 }
597 else {
598 put_byte(s, (s->gzhead->text ? 1 : 0) +
599 (s->gzhead->hcrc ? 2 : 0) +
600 (s->gzhead->extra == Z_NULL ? 0 : 4) +
601 (s->gzhead->name == Z_NULL ? 0 : 8) +
602 (s->gzhead->comment == Z_NULL ? 0 : 16)
603 );
604 put_byte(s, (Byte)(s->gzhead->time & 0xff));
605 put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
606 put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
607 put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
608 put_byte(s, s->level == 9 ? 2 :
609 (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
610 4 : 0));
611 put_byte(s, s->gzhead->os & 0xff);
612 if (s->gzhead->extra != Z_NULL) {
613 put_byte(s, s->gzhead->extra_len & 0xff);
614 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
615 }
616 if (s->gzhead->hcrc)
617 strm->adler = crc32(strm->adler, s->pending_buf,
618 s->pending);
619 s->gzindex = 0;
620 s->status = EXTRA_STATE;
621 }
622 }
623 else
624#endif
625 {
626 uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
627 uInt level_flags;
628
629 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
630 level_flags = 0;
631 else if (s->level < 6)
632 level_flags = 1;
633 else if (s->level == 6)
634 level_flags = 2;
635 else
636 level_flags = 3;
637 header |= (level_flags << 6);
638 if (s->strstart != 0) header |= PRESET_DICT;
639 header += 31 - (header % 31);
640
641 s->status = BUSY_STATE;
642 putShortMSB(s, header);
643
644 /* Save the adler32 of the preset dictionary: */
645 if (s->strstart != 0) {
646 putShortMSB(s, (uInt)(strm->adler >> 16));
647 putShortMSB(s, (uInt)(strm->adler & 0xffff));
648 }
649 strm->adler = adler32(0L, Z_NULL, 0);
650 }
651 }
652#ifdef GZIP
653 if (s->status == EXTRA_STATE) {
654 if (s->gzhead->extra != Z_NULL) {
655 uInt beg = s->pending; /* start of bytes to update crc */
656
657 while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
658 if (s->pending == s->pending_buf_size) {
659 if (s->gzhead->hcrc && s->pending > beg)
660 strm->adler = crc32(strm->adler, s->pending_buf + beg,
661 s->pending - beg);
663 beg = s->pending;
664 if (s->pending == s->pending_buf_size)
665 break;
666 }
667 put_byte(s, s->gzhead->extra[s->gzindex]);
668 s->gzindex++;
669 }
670 if (s->gzhead->hcrc && s->pending > beg)
671 strm->adler = crc32(strm->adler, s->pending_buf + beg,
672 s->pending - beg);
673 if (s->gzindex == s->gzhead->extra_len) {
674 s->gzindex = 0;
675 s->status = NAME_STATE;
676 }
677 }
678 else
679 s->status = NAME_STATE;
680 }
681 if (s->status == NAME_STATE) {
682 if (s->gzhead->name != Z_NULL) {
683 uInt beg = s->pending; /* start of bytes to update crc */
684 int val;
685
686 do {
687 if (s->pending == s->pending_buf_size) {
688 if (s->gzhead->hcrc && s->pending > beg)
689 strm->adler = crc32(strm->adler, s->pending_buf + beg,
690 s->pending - beg);
692 beg = s->pending;
693 if (s->pending == s->pending_buf_size) {
694 val = 1;
695 break;
696 }
697 }
698 val = s->gzhead->name[s->gzindex++];
699 put_byte(s, val);
700 } while (val != 0);
701 if (s->gzhead->hcrc && s->pending > beg)
702 strm->adler = crc32(strm->adler, s->pending_buf + beg,
703 s->pending - beg);
704 if (val == 0) {
705 s->gzindex = 0;
707 }
708 }
709 else
711 }
712 if (s->status == COMMENT_STATE) {
713 if (s->gzhead->comment != Z_NULL) {
714 uInt beg = s->pending; /* start of bytes to update crc */
715 int val;
716
717 do {
718 if (s->pending == s->pending_buf_size) {
719 if (s->gzhead->hcrc && s->pending > beg)
720 strm->adler = crc32(strm->adler, s->pending_buf + beg,
721 s->pending - beg);
723 beg = s->pending;
724 if (s->pending == s->pending_buf_size) {
725 val = 1;
726 break;
727 }
728 }
729 val = s->gzhead->comment[s->gzindex++];
730 put_byte(s, val);
731 } while (val != 0);
732 if (s->gzhead->hcrc && s->pending > beg)
733 strm->adler = crc32(strm->adler, s->pending_buf + beg,
734 s->pending - beg);
735 if (val == 0)
736 s->status = HCRC_STATE;
737 }
738 else
739 s->status = HCRC_STATE;
740 }
741 if (s->status == HCRC_STATE) {
742 if (s->gzhead->hcrc) {
743 if (s->pending + 2 > s->pending_buf_size)
745 if (s->pending + 2 <= s->pending_buf_size) {
746 put_byte(s, (Byte)(strm->adler & 0xff));
747 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
748 strm->adler = crc32(0L, Z_NULL, 0);
749 s->status = BUSY_STATE;
750 }
751 }
752 else
753 s->status = BUSY_STATE;
754 }
755#endif
756
757 /* Flush as much pending output as possible */
758 if (s->pending != 0) {
760 if (strm->avail_out == 0) {
761 /* Since avail_out is 0, deflate will be called again with
762 * more output space, but possibly with both pending and
763 * avail_in equal to zero. There won't be anything to do,
764 * but this is not an error situation so make sure we
765 * return OK instead of BUF_ERROR at next call of deflate:
766 */
767 s->last_flush = -1;
768 return Z_OK;
769 }
770
771 /* Make sure there is something to do and avoid duplicate consecutive
772 * flushes. For repeated and useless calls with Z_FINISH, we keep
773 * returning Z_STREAM_END instead of Z_BUF_ERROR.
774 */
775 } else if (strm->avail_in == 0 && flush <= old_flush &&
776 flush != Z_FINISH) {
778 }
779
780 /* User must not provide more input after the first FINISH: */
781 if (s->status == FINISH_STATE && strm->avail_in != 0) {
783 }
784
785 /* Start a new block or continue the current one.
786 */
787 if (strm->avail_in != 0 || s->lookahead != 0 ||
788 (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
789 block_state bstate;
790
791 bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) :
792 (s->strategy == Z_RLE ? deflate_rle(s, flush) :
793 (*(configuration_table[s->level].func))(s, flush));
794
795 if (bstate == finish_started || bstate == finish_done) {
796 s->status = FINISH_STATE;
797 }
798 if (bstate == need_more || bstate == finish_started) {
799 if (strm->avail_out == 0) {
800 s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
801 }
802 return Z_OK;
803 /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
804 * of deflate should use the same flush parameter to make sure
805 * that the flush is complete. So we don't have to output an
806 * empty block here, this will be done at next call. This also
807 * ensures that for a very small output buffer, we emit at most
808 * one empty block.
809 */
810 }
811 if (bstate == block_done) {
812 if (flush == Z_PARTIAL_FLUSH) {
813 _tr_align(s);
814 } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
815 _tr_stored_block(s, (char*)0, 0L, 0);
816 /* For a full flush, this empty block will be recognized
817 * as a special marker by inflate_sync().
818 */
819 if (flush == Z_FULL_FLUSH) {
820 CLEAR_HASH(s); /* forget history */
821 if (s->lookahead == 0) {
822 s->strstart = 0;
823 s->block_start = 0L;
824 }
825 }
826 }
828 if (strm->avail_out == 0) {
829 s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
830 return Z_OK;
831 }
832 }
833 }
834 Assert(strm->avail_out > 0, "bug2");
835
836 if (flush != Z_FINISH) return Z_OK;
837 if (s->wrap <= 0) return Z_STREAM_END;
838
839 /* Write the trailer */
840#ifdef GZIP
841 if (s->wrap == 2) {
842 put_byte(s, (Byte)(strm->adler & 0xff));
843 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
844 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
845 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
846 put_byte(s, (Byte)(strm->total_in & 0xff));
847 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
848 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
849 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
850 }
851 else
852#endif
853 {
854 putShortMSB(s, (uInt)(strm->adler >> 16));
855 putShortMSB(s, (uInt)(strm->adler & 0xffff));
856 }
858 /* If avail_out is zero, the application will call deflate again
859 * to flush the rest.
860 */
861 if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
862 return s->pending != 0 ? Z_OK : Z_STREAM_END;
863}
864
865/* ========================================================================= */
867{
868 int status;
869
870 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
871
872 status = strm->state->status;
873 if (status != INIT_STATE &&
874 status != EXTRA_STATE &&
875 status != NAME_STATE &&
877 status != HCRC_STATE &&
878 status != BUSY_STATE &&
879 status != FINISH_STATE) {
880 return Z_STREAM_ERROR;
881 }
882
883 /* Deallocate in reverse order of allocations: */
884 TRY_FREE(strm, strm->state->pending_buf);
885 TRY_FREE(strm, strm->state->head);
886 TRY_FREE(strm, strm->state->prev);
887 TRY_FREE(strm, strm->state->window);
888
889 ZFREE(strm, strm->state);
890 strm->state = Z_NULL;
891
892 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
893}
894
895/* =========================================================================
896 * Copy the source state to the destination state.
897 * To simplify the source, this is not supported for 16-bit MSDOS (which
898 * doesn't have enough memory anyway to duplicate compression states).
899 */
901{
902#ifdef MAXSEG_64K
903 return Z_STREAM_ERROR;
904#else
905 deflate_state *ds;
906 deflate_state *ss;
907 ushf *overlay;
908
909
910 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
911 return Z_STREAM_ERROR;
912 }
913
914 ss = source->state;
915
916 zmemcpy(dest, source, sizeof(z_stream));
917
918 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
919 if (ds == Z_NULL) return Z_MEM_ERROR;
920 dest->state = (struct internal_state FAR *) ds;
921 zmemcpy(ds, ss, sizeof(deflate_state));
922 ds->strm = dest;
923
924 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
925 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
926 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
927 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
928 ds->pending_buf = (uchf *) overlay;
929
930 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
931 ds->pending_buf == Z_NULL) {
932 deflateEnd (dest);
933 return Z_MEM_ERROR;
934 }
935 /* following zmemcpy do not work for 16-bit MSDOS */
936 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
937 zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
938 zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
940
941 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
942 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
943 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
944
945 ds->l_desc.dyn_tree = ds->dyn_ltree;
946 ds->d_desc.dyn_tree = ds->dyn_dtree;
947 ds->bl_desc.dyn_tree = ds->bl_tree;
948
949 return Z_OK;
950#endif /* MAXSEG_64K */
951}
952
953/* ===========================================================================
954 * Read a new buffer from the current input stream, update the adler32
955 * and total number of bytes read. All deflate() input goes through
956 * this function so some applications may wish to modify it to avoid
957 * allocating a large strm->next_in buffer and copying from it.
958 * (See also flush_pending()).
959 */
960local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
961{
962 unsigned len = strm->avail_in;
963
964 if (len > size) len = size;
965 if (len == 0) return 0;
966
967 strm->avail_in -= len;
968
969 if (strm->state->wrap == 1) {
970 strm->adler = adler32(strm->adler, strm->next_in, len);
971 }
972#ifdef GZIP
973 else if (strm->state->wrap == 2) {
974 strm->adler = crc32(strm->adler, strm->next_in, len);
975 }
976#endif
977 zmemcpy(buf, strm->next_in, len);
978 strm->next_in += len;
979 strm->total_in += len;
980
981 return (int)len;
982}
983
984/* ===========================================================================
985 * Initialize the "longest match" routines for a new zlib stream
986 */
988{
989 s->window_size = (ulg)2L*s->w_size;
990
991 CLEAR_HASH(s);
992
993 /* Set the default configuration parameters:
994 */
995 s->max_lazy_match = configuration_table[s->level].max_lazy;
996 s->good_match = configuration_table[s->level].good_length;
997 s->nice_match = configuration_table[s->level].nice_length;
998 s->max_chain_length = configuration_table[s->level].max_chain;
999
1000 s->strstart = 0;
1001 s->block_start = 0L;
1002 s->lookahead = 0;
1004 s->match_available = 0;
1005 s->ins_h = 0;
1006#ifndef FASTEST
1007#ifdef ASMV
1008 match_init(); /* initialize the asm code */
1009#endif
1010#endif
1011}
1012
1013#ifndef FASTEST
1014/* ===========================================================================
1015 * Set match_start to the longest match starting at the given string and
1016 * return its length. Matches shorter or equal to prev_length are discarded,
1017 * in which case the result is equal to prev_length and match_start is
1018 * garbage.
1019 * IN assertions: cur_match is the head of the hash chain for the current
1020 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
1021 * OUT assertion: the match length is not greater than s->lookahead.
1022 */
1023#ifndef ASMV
1024/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
1025 * match.S. The code will be functionally equivalent.
1026 */
1028{
1029 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1030 Bytef *scan = s->window + s->strstart; /* current string */
1031 Bytef *match; /* matched string */
1032 int len; /* length of current match */
1033 int best_len = s->prev_length; /* best match length so far */
1034 int nice_match = s->nice_match; /* stop if match long enough */
1035 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1036 s->strstart - (IPos)MAX_DIST(s) : NIL;
1037 /* Stop when cur_match becomes <= limit. To simplify the code,
1038 * we prevent matches with the string of window index 0.
1039 */
1040 Posf *prev = s->prev;
1041 uInt wmask = s->w_mask;
1042
1043#ifdef UNALIGNED_OK
1044 /* Compare two bytes at a time. Note: this is not always beneficial.
1045 * Try with and without -DUNALIGNED_OK to check.
1046 */
1047 Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1048 ush scan_start = *(ushf*)scan;
1049 ush scan_end = *(ushf*)(scan+best_len-1);
1050#else
1051 Bytef *strend = s->window + s->strstart + MAX_MATCH;
1052 Byte scan_end1 = scan[best_len-1];
1053 Byte scan_end = scan[best_len];
1054#endif
1055
1056 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1057 * It is easy to get rid of this optimization if necessary.
1058 */
1059 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1060
1061 /* Do not waste too much time if we already have a good match: */
1062 if (s->prev_length >= s->good_match) {
1063 chain_length >>= 2;
1064 }
1065 /* Do not look for matches beyond the end of the input. This is necessary
1066 * to make deflate deterministic.
1067 */
1069
1070 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1071
1072 do {
1073 Assert(cur_match < s->strstart, "no future");
1074 match = s->window + cur_match;
1075
1076 /* Skip to next match if the match length cannot increase
1077 * or if the match length is less than 2. Note that the checks below
1078 * for insufficient lookahead only occur occasionally for performance
1079 * reasons. Therefore uninitialized memory will be accessed, and
1080 * conditional jumps will be made that depend on those values.
1081 * However the length of the match is limited to the lookahead, so
1082 * the output of deflate is not affected by the uninitialized values.
1083 */
1084#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1085 /* This code assumes sizeof(unsigned short) == 2. Do not use
1086 * UNALIGNED_OK if your compiler uses a different size.
1087 */
1088 if (*(ushf*)(match+best_len-1) != scan_end ||
1089 *(ushf*)match != scan_start) continue;
1090
1091 /* It is not necessary to compare scan[2] and match[2] since they are
1092 * always equal when the other bytes match, given that the hash keys
1093 * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
1094 * strstart+3, +5, ... up to strstart+257. We check for insufficient
1095 * lookahead only every 4th comparison; the 128th check will be made
1096 * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
1097 * necessary to put more guard bytes at the end of the window, or
1098 * to check more often for insufficient lookahead.
1099 */
1100 Assert(scan[2] == match[2], "scan[2]?");
1101 scan++, match++;
1102 do {
1103 } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1104 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1105 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1106 *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
1107 scan < strend);
1108 /* The funny "do {}" generates better code on most compilers */
1109
1110 /* Here, scan <= window+strstart+257 */
1111 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1112 if (*scan == *match) scan++;
1113
1114 len = (MAX_MATCH - 1) - (int)(strend-scan);
1115 scan = strend - (MAX_MATCH-1);
1116
1117#else /* UNALIGNED_OK */
1118
1119 if (match[best_len] != scan_end ||
1120 match[best_len-1] != scan_end1 ||
1121 *match != *scan ||
1122 *++match != scan[1]) continue;
1123
1124 /* The check at best_len-1 can be removed because it will be made
1125 * again later. (This heuristic is not always a win.)
1126 * It is not necessary to compare scan[2] and match[2] since they
1127 * are always equal when the other bytes match, given that
1128 * the hash keys are equal and that HASH_BITS >= 8.
1129 */
1130 scan += 2, match++;
1131 Assert(*scan == *match, "match[2]?");
1132
1133 /* We check for insufficient lookahead only every 8th comparison;
1134 * the 256th check will be made at strstart+258.
1135 */
1136 do {
1137 } while (*++scan == *++match && *++scan == *++match &&
1138 *++scan == *++match && *++scan == *++match &&
1139 *++scan == *++match && *++scan == *++match &&
1140 *++scan == *++match && *++scan == *++match &&
1141 scan < strend);
1142
1143 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1144
1145 len = MAX_MATCH - (int)(strend - scan);
1146 scan = strend - MAX_MATCH;
1147
1148#endif /* UNALIGNED_OK */
1149
1150 if (len > best_len) {
1151 s->match_start = cur_match;
1152 best_len = len;
1153 if (len >= nice_match) break;
1154#ifdef UNALIGNED_OK
1155 scan_end = *(ushf*)(scan+best_len-1);
1156#else
1157 scan_end1 = scan[best_len-1];
1158 scan_end = scan[best_len];
1159#endif
1160 }
1161 } while ((cur_match = prev[cur_match & wmask]) > limit
1162 && --chain_length != 0);
1163
1164 if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
1165 return s->lookahead;
1166}
1167#endif /* ASMV */
1168
1169#else /* FASTEST */
1170
1171/* ---------------------------------------------------------------------------
1172 * Optimized version for FASTEST only
1173 */
1175{
1176 Bytef *scan = s->window + s->strstart; /* current string */
1177 Bytef *match; /* matched string */
1178 int len; /* length of current match */
1179 Bytef *strend = s->window + s->strstart + MAX_MATCH;
1180
1181 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1182 * It is easy to get rid of this optimization if necessary.
1183 */
1184 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1185
1186 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1187
1188 Assert(cur_match < s->strstart, "no future");
1189
1190 match = s->window + cur_match;
1191
1192 /* Return failure if the match length is less than 2:
1193 */
1194 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
1195
1196 /* The check at best_len-1 can be removed because it will be made
1197 * again later. (This heuristic is not always a win.)
1198 * It is not necessary to compare scan[2] and match[2] since they
1199 * are always equal when the other bytes match, given that
1200 * the hash keys are equal and that HASH_BITS >= 8.
1201 */
1202 scan += 2, match += 2;
1203 Assert(*scan == *match, "match[2]?");
1204
1205 /* We check for insufficient lookahead only every 8th comparison;
1206 * the 256th check will be made at strstart+258.
1207 */
1208 do {
1209 } while (*++scan == *++match && *++scan == *++match &&
1210 *++scan == *++match && *++scan == *++match &&
1211 *++scan == *++match && *++scan == *++match &&
1212 *++scan == *++match && *++scan == *++match &&
1213 scan < strend);
1214
1215 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1216
1217 len = MAX_MATCH - (int)(strend - scan);
1218
1219 if (len < MIN_MATCH) return MIN_MATCH - 1;
1220
1221 s->match_start = cur_match;
1222 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
1223}
1224
1225#endif /* FASTEST */
1226
1227#ifdef DEBUG
1228/* ===========================================================================
1229 * Check that the match at match_start is indeed a match.
1230 */
1231local void check_match(deflate_state *s, IPos start, IPos match, int length)
1232{
1233 /* check that the match is indeed a match */
1234 if (zmemcmp(s->window + match,
1235 s->window + start, (size_t)length) != EQUAL) {
1236 fprintf(stderr, " start %u, match %u, length %d\n",
1237 start, match, length);
1238 do {
1239 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
1240 } while (--length != 0);
1241 z_error("invalid match");
1242 }
1243 if (z_verbose > 1) {
1244 fprintf(stderr,"\\[%d,%d]", start-match, length);
1245 do { putc(s->window[start++], stderr); } while (--length != 0);
1246 }
1247}
1248#else
1249# define check_match(s, start, match, length)
1250#endif /* DEBUG */
1251
1252/* ===========================================================================
1253 * Fill the window when the lookahead becomes insufficient.
1254 * Updates strstart and lookahead.
1255 *
1256 * IN assertion: lookahead < MIN_LOOKAHEAD
1257 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
1258 * At least one byte has been read, or avail_in == 0; reads are
1259 * performed for at least two bytes (required for the zip translate_eol
1260 * option -- not supported here).
1261 */
1263{
1264 unsigned n, m;
1265 Posf *p;
1266 unsigned more; /* Amount of free space at the end of the window. */
1267 uInt wsize = s->w_size;
1268
1269 do {
1270 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1271
1272 /* Deal with !@#$% 64K limit: */
1273 if (sizeof(int) <= 2) {
1274 if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
1275 more = wsize;
1276
1277 } else if (more == (unsigned)(-1)) {
1278 /* Very unlikely, but possible on 16 bit machine if
1279 * strstart == 0 && lookahead == 1 (input done a byte at time)
1280 */
1281 more--;
1282 }
1283 }
1284
1285 /* If the window is almost full and there is insufficient lookahead,
1286 * move the upper half to the lower one to make room in the upper half.
1287 */
1288 if (s->strstart >= wsize+MAX_DIST(s)) {
1289
1290 zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
1291 s->match_start -= wsize;
1292 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
1293 s->block_start -= (long) wsize;
1294
1295 /* Slide the hash table (could be avoided with 32 bit values
1296 at the expense of memory usage). We slide even when level == 0
1297 to keep the hash table consistent if we switch back to level > 0
1298 later. (Using level 0 permanently is not an optimal usage of
1299 zlib, so we don't care about this pathological case.)
1300 */
1301 n = s->hash_size;
1302 p = &s->head[n];
1303 do {
1304 m = *--p;
1305 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1306 } while (--n);
1307
1308 n = wsize;
1309#ifndef FASTEST
1310 p = &s->prev[n];
1311 do {
1312 m = *--p;
1313 *p = (Pos)(m >= wsize ? m-wsize : NIL);
1314 /* If n is not on any hash chain, prev[n] is garbage but
1315 * its value will never be used.
1316 */
1317 } while (--n);
1318#endif
1319 more += wsize;
1320 }
1321 if (s->strm->avail_in == 0) return;
1322
1323 /* If there was no sliding:
1324 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
1325 * more == window_size - lookahead - strstart
1326 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
1327 * => more >= window_size - 2*WSIZE + 2
1328 * In the BIG_MEM or MMAP case (not yet supported),
1329 * window_size == input_size + MIN_LOOKAHEAD &&
1330 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
1331 * Otherwise, window_size == 2*WSIZE so more >= 2.
1332 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
1333 */
1334 Assert(more >= 2, "more < 2");
1335
1336 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
1337 s->lookahead += n;
1338
1339 /* Initialize the hash value now that we have some input: */
1340 if (s->lookahead >= MIN_MATCH) {
1341 s->ins_h = s->window[s->strstart];
1342 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1343#if MIN_MATCH != 3
1344 Call UPDATE_HASH() MIN_MATCH-3 more times
1345#endif
1346 }
1347 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
1348 * but this is not important since only literal bytes will be emitted.
1349 */
1350
1351 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
1352
1353 /* If the WIN_INIT bytes after the end of the current data have never been
1354 * written, then zero those bytes in order to avoid memory check reports of
1355 * the use of uninitialized (or uninitialised as Julian writes) bytes by
1356 * the longest match routines. Update the high water mark for the next
1357 * time through here. WIN_INIT is set to MAX_MATCH since the longest match
1358 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
1359 */
1360 if (s->high_water < s->window_size) {
1361 ulg curr = s->strstart + (ulg)(s->lookahead);
1362 ulg init;
1363
1364 if (s->high_water < curr) {
1365 /* Previous high water mark below current data -- zero WIN_INIT
1366 * bytes or up to end of window, whichever is less.
1367 */
1368 init = s->window_size - curr;
1369 if (init > WIN_INIT)
1370 init = WIN_INIT;
1371 zmemzero(s->window + curr, (unsigned)init);
1372 s->high_water = curr + init;
1373 }
1374 else if (s->high_water < (ulg)curr + WIN_INIT) {
1375 /* High water mark at or above current data, but below current data
1376 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
1377 * to end of window, whichever is less.
1378 */
1379 init = (ulg)curr + WIN_INIT - s->high_water;
1380 if (init > s->window_size - s->high_water)
1381 init = s->window_size - s->high_water;
1382 zmemzero(s->window + s->high_water, (unsigned)init);
1383 s->high_water += init;
1384 }
1385 }
1386}
1387
1388/* ===========================================================================
1389 * Flush the current block, with given end-of-file flag.
1390 * IN assertion: strstart is set to the end of the current match.
1391 */
1392#define FLUSH_BLOCK_ONLY(s, last) { \
1393 _tr_flush_block(s, (s->block_start >= 0L ? \
1394 (charf *)&s->window[(unsigned)s->block_start] : \
1395 (charf *)Z_NULL), \
1396 (ulg)((long)s->strstart - s->block_start), \
1397 (last)); \
1398 s->block_start = s->strstart; \
1399 flush_pending(s->strm); \
1400 Tracev((stderr,"[FLUSH]")); \
1401}
1402
1403/* Same but force premature exit if necessary. */
1404#define FLUSH_BLOCK(s, last) { \
1405 FLUSH_BLOCK_ONLY(s, last); \
1406 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1407}
1408
1409/* ===========================================================================
1410 * Copy without compression as much as possible from the input stream, return
1411 * the current block state.
1412 * This function does not insert new strings in the dictionary since
1413 * uncompressible data is probably not useful. This function is used
1414 * only for the level=0 compression option.
1415 * NOTE: this function should be optimized to avoid extra copying from
1416 * window to pending_buf.
1417 */
1419{
1420 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
1421 * to pending_buf_size, and each stored block has a 5 byte header:
1422 */
1423 ulg max_block_size = 0xffff;
1424 ulg max_start;
1425
1426 if (max_block_size > s->pending_buf_size - 5) {
1427 max_block_size = s->pending_buf_size - 5;
1428 }
1429
1430 /* Copy as much as possible from input to output: */
1431 for (;;) {
1432 /* Fill the window as much as possible: */
1433 if (s->lookahead <= 1) {
1434
1435 Assert(s->strstart < s->w_size+MAX_DIST(s) ||
1436 s->block_start >= (long)s->w_size, "slide too late");
1437
1438 fill_window(s);
1439 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
1440
1441 if (s->lookahead == 0) break; /* flush the current block */
1442 }
1443 Assert(s->block_start >= 0L, "block gone");
1444
1445 s->strstart += s->lookahead;
1446 s->lookahead = 0;
1447
1448 /* Emit a stored block if pending_buf will be full: */
1449 max_start = s->block_start + max_block_size;
1450 if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
1451 /* strstart == 0 is possible when wraparound on 16-bit machine */
1452 s->lookahead = (uInt)(s->strstart - max_start);
1453 s->strstart = (uInt)max_start;
1454 FLUSH_BLOCK(s, 0);
1455 }
1456 /* Flush if we may have to slide, otherwise block_start may become
1457 * negative and the data will be gone:
1458 */
1459 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
1460 FLUSH_BLOCK(s, 0);
1461 }
1462 }
1463 FLUSH_BLOCK(s, flush == Z_FINISH);
1464 return flush == Z_FINISH ? finish_done : block_done;
1465}
1466
1467/* ===========================================================================
1468 * Compress as much as possible from the input stream, return the current
1469 * block state.
1470 * This function does not perform lazy evaluation of matches and inserts
1471 * new strings in the dictionary only for unmatched strings or for short
1472 * matches. It is used only for the fast compression options.
1473 */
1475{
1476 IPos hash_head; /* head of the hash chain */
1477 int bflush; /* set if current block must be flushed */
1478
1479 for (;;) {
1480 /* Make sure that we always have enough lookahead, except
1481 * at the end of the input file. We need MAX_MATCH bytes
1482 * for the next match, plus MIN_MATCH bytes to insert the
1483 * string following the next match.
1484 */
1485 if (s->lookahead < MIN_LOOKAHEAD) {
1486 fill_window(s);
1487 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1488 return need_more;
1489 }
1490 if (s->lookahead == 0) break; /* flush the current block */
1491 }
1492
1493 /* Insert the string window[strstart .. strstart+2] in the
1494 * dictionary, and set hash_head to the head of the hash chain:
1495 */
1496 hash_head = NIL;
1497 if (s->lookahead >= MIN_MATCH) {
1498 INSERT_STRING(s, s->strstart, hash_head);
1499 }
1500
1501 /* Find the longest match, discarding those <= prev_length.
1502 * At this point we have always match_length < MIN_MATCH
1503 */
1504 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1505 /* To simplify the code, we prevent matches with the string
1506 * of window index 0 (in particular we have to avoid a match
1507 * of the string with itself at the start of the input file).
1508 */
1509 s->match_length = longest_match (s, hash_head);
1510 /* longest_match() sets match_start */
1511 }
1512 if (s->match_length >= MIN_MATCH) {
1514
1516 s->match_length - MIN_MATCH, bflush);
1517
1518 s->lookahead -= s->match_length;
1519
1520 /* Insert new strings in the hash table only if the match length
1521 * is not too large. This saves time but degrades compression.
1522 */
1523#ifndef FASTEST
1524 if (s->match_length <= s->max_insert_length &&
1525 s->lookahead >= MIN_MATCH) {
1526 s->match_length--; /* string at strstart already in table */
1527 do {
1528 s->strstart++;
1529 INSERT_STRING(s, s->strstart, hash_head);
1530 /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1531 * always MIN_MATCH bytes ahead.
1532 */
1533 } while (--s->match_length != 0);
1534 s->strstart++;
1535 } else
1536#endif
1537 {
1538 s->strstart += s->match_length;
1539 s->match_length = 0;
1540 s->ins_h = s->window[s->strstart];
1541 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
1542#if MIN_MATCH != 3
1543 Call UPDATE_HASH() MIN_MATCH-3 more times
1544#endif
1545 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
1546 * matter since it will be recomputed at next deflate call.
1547 */
1548 }
1549 } else {
1550 /* No match, output a literal byte */
1551 Tracevv((stderr,"%c", s->window[s->strstart]));
1552 _tr_tally_lit (s, s->window[s->strstart], bflush);
1553 s->lookahead--;
1554 s->strstart++;
1555 }
1556 if (bflush) FLUSH_BLOCK(s, 0);
1557 }
1558 FLUSH_BLOCK(s, flush == Z_FINISH);
1559 return flush == Z_FINISH ? finish_done : block_done;
1560}
1561
1562#ifndef FASTEST
1563/* ===========================================================================
1564 * Same as above, but achieves better compression. We use a lazy
1565 * evaluation for matches: a match is finally adopted only if there is
1566 * no better match at the next window position.
1567 */
1569{
1570 IPos hash_head; /* head of hash chain */
1571 int bflush; /* set if current block must be flushed */
1572
1573 /* Process the input block. */
1574 for (;;) {
1575 /* Make sure that we always have enough lookahead, except
1576 * at the end of the input file. We need MAX_MATCH bytes
1577 * for the next match, plus MIN_MATCH bytes to insert the
1578 * string following the next match.
1579 */
1580 if (s->lookahead < MIN_LOOKAHEAD) {
1581 fill_window(s);
1582 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1583 return need_more;
1584 }
1585 if (s->lookahead == 0) break; /* flush the current block */
1586 }
1587
1588 /* Insert the string window[strstart .. strstart+2] in the
1589 * dictionary, and set hash_head to the head of the hash chain:
1590 */
1591 hash_head = NIL;
1592 if (s->lookahead >= MIN_MATCH) {
1593 INSERT_STRING(s, s->strstart, hash_head);
1594 }
1595
1596 /* Find the longest match, discarding those <= prev_length.
1597 */
1599 s->match_length = MIN_MATCH-1;
1600
1601 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
1602 s->strstart - hash_head <= MAX_DIST(s)) {
1603 /* To simplify the code, we prevent matches with the string
1604 * of window index 0 (in particular we have to avoid a match
1605 * of the string with itself at the start of the input file).
1606 */
1607 s->match_length = longest_match (s, hash_head);
1608 /* longest_match() sets match_start */
1609
1610 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
1611#if TOO_FAR <= 32767
1612 || (s->match_length == MIN_MATCH &&
1613 s->strstart - s->match_start > TOO_FAR)
1614#endif
1615 )) {
1616
1617 /* If prev_match is also MIN_MATCH, match_start is garbage
1618 * but we will ignore the current match anyway.
1619 */
1620 s->match_length = MIN_MATCH-1;
1621 }
1622 }
1623 /* If there was a match at the previous step and the current
1624 * match is not better, output the previous match:
1625 */
1626 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
1627 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
1628 /* Do not insert strings in hash table beyond this. */
1629
1630 check_match(s, s->strstart-1, s->prev_match, s->prev_length);
1631
1632 _tr_tally_dist(s, s->strstart -1 - s->prev_match,
1633 s->prev_length - MIN_MATCH, bflush);
1634
1635 /* Insert in hash table all strings up to the end of the match.
1636 * strstart-1 and strstart are already inserted. If there is not
1637 * enough lookahead, the last two strings are not inserted in
1638 * the hash table.
1639 */
1640 s->lookahead -= s->prev_length-1;
1641 s->prev_length -= 2;
1642 do {
1643 if (++s->strstart <= max_insert) {
1644 INSERT_STRING(s, s->strstart, hash_head);
1645 }
1646 } while (--s->prev_length != 0);
1647 s->match_available = 0;
1648 s->match_length = MIN_MATCH-1;
1649 s->strstart++;
1650
1651 if (bflush) FLUSH_BLOCK(s, 0);
1652
1653 } else if (s->match_available) {
1654 /* If there was no match at the previous position, output a
1655 * single literal. If there was a match but the current match
1656 * is longer, truncate the previous match to a single literal.
1657 */
1658 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1659 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1660 if (bflush) {
1661 FLUSH_BLOCK_ONLY(s, 0);
1662 }
1663 s->strstart++;
1664 s->lookahead--;
1665 if (s->strm->avail_out == 0) return need_more;
1666 } else {
1667 /* There is no previous match to compare with, wait for
1668 * the next step to decide.
1669 */
1670 s->match_available = 1;
1671 s->strstart++;
1672 s->lookahead--;
1673 }
1674 }
1675 Assert (flush != Z_NO_FLUSH, "no flush?");
1676 if (s->match_available) {
1677 Tracevv((stderr,"%c", s->window[s->strstart-1]));
1678 _tr_tally_lit(s, s->window[s->strstart-1], bflush);
1679 s->match_available = 0;
1680 }
1681 FLUSH_BLOCK(s, flush == Z_FINISH);
1682 return flush == Z_FINISH ? finish_done : block_done;
1683}
1684#endif /* FASTEST */
1685
1686/* ===========================================================================
1687 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
1688 * one. Do not maintain a hash table. (It will be regenerated if this run of
1689 * deflate switches away from Z_RLE.)
1690 */
1692{
1693 int bflush; /* set if current block must be flushed */
1694 uInt prev; /* byte at distance one to match */
1695 Bytef *scan, *strend; /* scan goes up to strend for length of run */
1696
1697 for (;;) {
1698 /* Make sure that we always have enough lookahead, except
1699 * at the end of the input file. We need MAX_MATCH bytes
1700 * for the longest encodable run.
1701 */
1702 if (s->lookahead < MAX_MATCH) {
1703 fill_window(s);
1704 if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
1705 return need_more;
1706 }
1707 if (s->lookahead == 0) break; /* flush the current block */
1708 }
1709
1710 /* See how many times the previous byte repeats */
1711 s->match_length = 0;
1712 if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
1713 scan = s->window + s->strstart - 1;
1714 prev = *scan;
1715 if (prev == *++scan && prev == *++scan && prev == *++scan) {
1716 strend = s->window + s->strstart + MAX_MATCH;
1717 do {
1718 } while (prev == *++scan && prev == *++scan &&
1719 prev == *++scan && prev == *++scan &&
1720 prev == *++scan && prev == *++scan &&
1721 prev == *++scan && prev == *++scan &&
1722 scan < strend);
1723 s->match_length = MAX_MATCH - (int)(strend - scan);
1724 if (s->match_length > s->lookahead)
1725 s->match_length = s->lookahead;
1726 }
1727 }
1728
1729 /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1730 if (s->match_length >= MIN_MATCH) {
1731 check_match(s, s->strstart, s->strstart - 1, s->match_length);
1732
1733 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush);
1734
1735 s->lookahead -= s->match_length;
1736 s->strstart += s->match_length;
1737 s->match_length = 0;
1738 } else {
1739 /* No match, output a literal byte */
1740 Tracevv((stderr,"%c", s->window[s->strstart]));
1741 _tr_tally_lit (s, s->window[s->strstart], bflush);
1742 s->lookahead--;
1743 s->strstart++;
1744 }
1745 if (bflush) FLUSH_BLOCK(s, 0);
1746 }
1747 FLUSH_BLOCK(s, flush == Z_FINISH);
1748 return flush == Z_FINISH ? finish_done : block_done;
1749}
1750
1751/* ===========================================================================
1752 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
1753 * (It will be regenerated if this run of deflate switches away from Huffman.)
1754 */
1756{
1757 int bflush; /* set if current block must be flushed */
1758
1759 for (;;) {
1760 /* Make sure that we have a literal to write. */
1761 if (s->lookahead == 0) {
1762 fill_window(s);
1763 if (s->lookahead == 0) {
1764 if (flush == Z_NO_FLUSH)
1765 return need_more;
1766 break; /* flush the current block */
1767 }
1768 }
1769
1770 /* Output a literal byte */
1771 s->match_length = 0;
1772 Tracevv((stderr,"%c", s->window[s->strstart]));
1773 _tr_tally_lit (s, s->window[s->strstart], bflush);
1774 s->lookahead--;
1775 s->strstart++;
1776 if (bflush) FLUSH_BLOCK(s, 0);
1777 }
1778 FLUSH_BLOCK(s, flush == Z_FINISH);
1779 return flush == Z_FINISH ? finish_done : block_done;
1780}
1781
1782
1784
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define local
Definition adler32.c:17
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
Definition adler32.c:67
#define NIL(type)
Definition avl.h:25
ABC_NAMESPACE_IMPL_START typedef signed char value
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition crc32.c:230
int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head)
Definition deflate.c:380
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
Definition deflate.c:205
block_state
Definition deflate.c:73
@ finish_started
Definition deflate.c:76
@ block_done
Definition deflate.c:75
@ need_more
Definition deflate.c:74
@ finish_done
Definition deflate.c:77
#define FLUSH_BLOCK_ONLY(s, last)
Definition deflate.c:1392
local block_state deflate_fast(deflate_state *s, int flush)
Definition deflate.c:1474
struct config_s config
local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
Definition deflate.c:960
#define check_match(s, start, match, length)
Definition deflate.c:1249
#define UPDATE_HASH(s, h, c)
Definition deflate.c:171
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source)
Definition deflate.c:900
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
Definition deflate.c:306
int ZEXPORT deflateReset(z_streamp strm)
Definition deflate.c:345
#define INSERT_STRING(s, str, match_head)
Definition deflate.c:190
ABC_NAMESPACE_IMPL_START const char deflate_copyright[]
Definition deflate.c:61
local block_state deflate_huff(deflate_state *s, int flush)
Definition deflate.c:1755
local block_state deflate_stored(deflate_state *s, int flush)
Definition deflate.c:1418
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
Definition deflate.c:398
local void fill_window(deflate_state *s)
Definition deflate.c:1262
local void putShortMSB(deflate_state *s, uInt b)
Definition deflate.c:524
block_state compress_func OF((deflate_state *s, int flush))
Definition deflate.c:80
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
Definition deflate.c:464
local uInt longest_match(deflate_state *s, IPos cur_match)
Definition deflate.c:1027
local const config configuration_table[10]
Definition deflate.c:138
local block_state deflate_slow(deflate_state *s, int flush)
Definition deflate.c:1568
#define FLUSH_BLOCK(s, last)
Definition deflate.c:1404
int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
Definition deflate.c:434
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
Definition deflate.c:389
local void lm_init(deflate_state *s)
Definition deflate.c:987
#define TOO_FAR
Definition deflate.c:115
int ZEXPORT deflateEnd(z_streamp strm)
Definition deflate.c:866
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
Definition deflate.c:213
local void flush_pending(z_streamp strm)
Definition deflate.c:536
local block_state deflate_rle(deflate_state *s, int flush)
Definition deflate.c:1691
int ZEXPORT deflate(z_streamp strm, int flush)
Definition deflate.c:555
#define CLEAR_HASH(s)
Definition deflate.c:200
#define FINISH_STATE
Definition deflate.h:59
#define COMMENT_STATE
Definition deflate.h:56
#define HCRC_STATE
Definition deflate.h:57
#define MAX_DIST(s)
Definition deflate.h:285
#define BUSY_STATE
Definition deflate.h:58
#define put_byte(s, c)
Definition deflate.h:277
#define _tr_tally_dist(s, distance, length, flush)
Definition deflate.h:328
Pos FAR Posf
Definition deflate.h:89
ush Pos
Definition deflate.h:88
#define INIT_STATE
Definition deflate.h:53
#define MIN_LOOKAHEAD
Definition deflate.h:280
#define WIN_INIT
Definition deflate.h:290
#define NAME_STATE
Definition deflate.h:55
unsigned IPos
Definition deflate.h:90
struct internal_state deflate_state
#define _tr_tally_lit(s, c, flush)
Definition deflate.h:321
#define EXTRA_STATE
Definition deflate.h:54
Cube * p
Definition exorList.c:222
#define EQUAL(func, x, y)
Definition st.c:23
ush good_length
Definition deflate.c:125
ush max_chain
Definition deflate.c:128
compress_func func
Definition deflate.c:129
ush nice_length
Definition deflate.c:127
ush max_lazy
Definition deflate.c:126
struct tree_desc_s l_desc
Definition deflate.h:198
IPos prev_match
Definition deflate.h:156
uInt lit_bufsize
Definition deflate.h:218
struct ct_data_s dyn_dtree[2 *D_CODES+1]
Definition deflate.h:195
long block_start
Definition deflate.h:150
uchf * l_buf
Definition deflate.h:216
uInt good_match
Definition deflate.h:187
Bytef * pending_out
Definition deflate.h:101
uInt prev_length
Definition deflate.h:162
Bytef * window
Definition deflate.h:115
ulg pending_buf_size
Definition deflate.h:100
Posf * prev
Definition deflate.h:130
struct ct_data_s bl_tree[2 *BL_CODES+1]
Definition deflate.h:196
struct tree_desc_s bl_desc
Definition deflate.h:200
uInt match_length
Definition deflate.h:155
z_streamp strm
Definition deflate.h:97
Posf * head
Definition deflate.h:136
uInt max_chain_length
Definition deflate.h:167
struct tree_desc_s d_desc
Definition deflate.h:199
uInt max_lazy_match
Definition deflate.h:173
gz_headerp gzhead
Definition deflate.h:104
ushf * d_buf
Definition deflate.h:240
int match_available
Definition deflate.h:157
uInt match_start
Definition deflate.h:159
struct ct_data_s dyn_ltree[HEAP_SIZE]
Definition deflate.h:194
Bytef * pending_buf
Definition deflate.h:99
uInt hash_shift
Definition deflate.h:143
ct_data * dyn_tree
Definition deflate.h:83
void ZLIB_INTERNAL _tr_init(deflate_state *s)
Definition trees.c:394
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition trees.c:861
void ZLIB_INTERNAL _tr_align(deflate_state *s)
Definition trees.c:882
Byte FAR * voidpf
Definition zconf.h:355
#define ZEXPORT
Definition zconf.h:322
unsigned int uInt
Definition zconf.h:335
#define MAX_MEM_LEVEL
Definition zconf.h:210
#define MAX_WBITS
Definition zconf.h:220
unsigned long uLong
Definition zconf.h:336
unsigned char Byte
Definition zconf.h:333
Byte FAR Bytef
Definition zconf.h:342
#define FAR
Definition zconf.h:329
#define Z_HUFFMAN_ONLY
Definition zlib.h:201
#define Z_DEFLATED
Definition zlib.h:213
gz_header FAR * gz_headerp
Definition zlib.h:137
#define Z_BUF_ERROR
Definition zlib.h:188
#define Z_UNKNOWN
Definition zlib.h:210
#define ZLIB_VERSION
Definition zlib.h:48
#define Z_DEFAULT_STRATEGY
Definition zlib.h:204
z_stream FAR * z_streamp
Definition zlib.h:114
#define Z_BLOCK
Definition zlib.h:177
#define Z_VERSION_ERROR
Definition zlib.h:189
#define Z_STREAM_END
Definition zlib.h:182
#define Z_FINISH
Definition zlib.h:176
#define Z_OK
Definition zlib.h:181
#define Z_DATA_ERROR
Definition zlib.h:186
struct z_stream_s z_stream
#define Z_FIXED
Definition zlib.h:203
#define Z_STREAM_ERROR
Definition zlib.h:185
#define Z_NO_FLUSH
Definition zlib.h:172
#define Z_NULL
Definition zlib.h:216
#define Z_PARTIAL_FLUSH
Definition zlib.h:173
#define Z_MEM_ERROR
Definition zlib.h:187
#define Z_FULL_FLUSH
Definition zlib.h:175
#define Z_FILTERED
Definition zlib.h:200
#define Z_RLE
Definition zlib.h:202
#define Z_DEFAULT_COMPRESSION
Definition zlib.h:197
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
Definition zutil.c:307
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition zutil.c:300
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
Definition zutil.c:175
int ZLIB_INTERNAL zmemcmp(const Bytef *s1, const Bytef *s2, uInt len)
Definition zutil.c:165
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
Definition zutil.c:157
#define ERR_RETURN(strm, err)
Definition zutil.h:50
#define PRESET_DICT
Definition zutil.h:77
#define DEF_MEM_LEVEL
Definition zutil.h:62
unsigned short ush
Definition zutil.h:41
#define ZALLOC(strm, items, size)
Definition zutil.h:281
#define Assert(cond, msg)
Definition zutil.h:268
#define ERR_MSG(err)
Definition zutil.h:48
#define ZFREE(strm, addr)
Definition zutil.h:283
#define MIN_MATCH
Definition zutil.h:73
#define TRY_FREE(s, p)
Definition zutil.h:284
#define OS_CODE
Definition zutil.h:181
uch FAR uchf
Definition zutil.h:40
#define MAX_MATCH
Definition zutil.h:74
ush FAR ushf
Definition zutil.h:42
unsigned long ulg
Definition zutil.h:43
#define Tracevv(x)
Definition zutil.h:271