| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef DEFLATE_P_H |
| 10 |
#define DEFLATE_P_H |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifdef ZLIB_DEBUG |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
static inline void check_match(deflate_state *s, Pos start, Pos match, int length) { |
| 19 |
|
| 20 |
if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) { |
| 21 |
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
| 22 |
z_error("invalid match length"); |
| 23 |
} |
| 24 |
|
| 25 |
if (match == start) { |
| 26 |
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
| 27 |
z_error("invalid match position"); |
| 28 |
} |
| 29 |
|
| 30 |
if (memcmp(s->window + match, s->window + start, length) != 0) { |
| 31 |
int32_t i = 0; |
| 32 |
fprintf(stderr, " start %u, match %u, length %d\n", start, match, length); |
| 33 |
do { |
| 34 |
fprintf(stderr, " %03d: match [%02x] start [%02x]\n", i++, |
| 35 |
s->window[match++], s->window[start++]); |
| 36 |
} while (--length != 0); |
| 37 |
z_error("invalid match"); |
| 38 |
} |
| 39 |
if (z_verbose > 1) { |
| 40 |
fprintf(stderr, "\\[%u,%d]", start-match, length); |
| 41 |
do { |
| 42 |
putc(s->window[start++], stderr); |
| 43 |
} while (--length != 0); |
| 44 |
} |
| 45 |
} |
| 46 |
#else |
| 47 |
#define check_match(s, start, match, length) |
| 48 |
#endif |
| 49 |
|
| 50 |
Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm); |
| 51 |
Z_INTERNAL unsigned read_buf(PREFIX3(stream) *strm, unsigned char *buf, unsigned size); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
extern const unsigned char Z_INTERNAL zng_length_code[]; |
| 59 |
extern const unsigned char Z_INTERNAL zng_dist_code[]; |
| 60 |
|
| 61 |
static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) { |
| 62 |
|
| 63 |
s->sym_buf[s->sym_next++] = 0; |
| 64 |
s->sym_buf[s->sym_next++] = 0; |
| 65 |
s->sym_buf[s->sym_next++] = c; |
| 66 |
s->dyn_ltree[c].Freq++; |
| 67 |
Tracevv((stderr, "%c", c)); |
| 68 |
Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal"); |
| 69 |
return (s->sym_next == s->sym_end); |
| 70 |
} |
| 71 |
|
| 72 |
static inline int zng_tr_tally_dist(deflate_state *s, uint32_t dist, uint32_t len) { |
| 73 |
|
| 74 |
|
| 75 |
s->sym_buf[s->sym_next++] = (uint8_t)(dist); |
| 76 |
s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8); |
| 77 |
s->sym_buf[s->sym_next++] = (uint8_t)len; |
| 78 |
s->matches++; |
| 79 |
dist--; |
| 80 |
Assert(dist < MAX_DIST(s) && (uint16_t)d_code(dist) < (uint16_t)D_CODES, |
| 81 |
"zng_tr_tally: bad match"); |
| 82 |
|
| 83 |
s->dyn_ltree[zng_length_code[len]+LITERALS+1].Freq++; |
| 84 |
s->dyn_dtree[d_code(dist)].Freq++; |
| 85 |
return (s->sym_next == s->sym_end); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
#define FLUSH_BLOCK_ONLY(s, last) { \ |
| 93 |
zng_tr_flush_block(s, (s->block_start >= 0 ? \ |
| 94 |
(char *)&s->window[(unsigned)s->block_start] : \ |
| 95 |
NULL), \ |
| 96 |
(uint32_t)((int)s->strstart - s->block_start), \ |
| 97 |
(last)); \ |
| 98 |
s->block_start = (int)s->strstart; \ |
| 99 |
PREFIX(flush_pending)(s->strm); \ |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
#define FLUSH_BLOCK(s, last) { \ |
| 104 |
FLUSH_BLOCK_ONLY(s, last); \ |
| 105 |
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
#define MAX_STORED 65535 |
| 110 |
|
| 111 |
|
| 112 |
typedef block_state (*compress_func) (deflate_state *s, int flush); |
| 113 |
|
| 114 |
typedef uint32_t (*match_func) (deflate_state *const s, Pos cur_match); |
| 115 |
|
| 116 |
#endif |