1/* deflate_p.h -- Private inline functions and macros shared with more than
2 * one deflate method
3 *
4 * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
5 * For conditions of distribution and use, see copyright notice in zlib.h
6 *
7 */
8
9#ifndef DEFLATE_P_H
10#define DEFLATE_P_H
11
12/* Forward declare common non-inlined functions declared in deflate.c */
13
14#ifdef ZLIB_DEBUG
15void check_match(deflate_state *s, IPos start, IPos match, int length);
16#else
17#define check_match(s, start, match, length)
18#endif
19void flush_pending(PREFIX3(stream) *strm);
20
21/* ===========================================================================
22 * Insert string str in the dictionary and set match_head to the previous head
23 * of the hash chain (the most recent string with same hash key). Return
24 * the previous length of the hash chain.
25 * IN assertion: all calls to to INSERT_STRING are made with consecutive
26 * input characters and the first MIN_MATCH bytes of str are valid
27 * (except for the last MIN_MATCH-1 bytes of the input file).
28 */
29
30static inline Pos insert_string_c(deflate_state *const s, const Pos str, unsigned int count) {
31 Pos ret = 0;
32 unsigned int idx;
33
34 for (idx = 0; idx < count; idx++) {
35 UPDATE_HASH(s, s->ins_h, str+idx);
36
37 Pos head = s->head[s->ins_h];
38 if (head != str+idx) {
39 s->prev[(str+idx) & s->w_mask] = head;
40 s->head[s->ins_h] = str+idx;
41 if (idx == count - 1)
42 ret = head;
43 } else if (idx == count - 1) {
44 ret = str + idx;
45 }
46 }
47 return ret;
48}
49
50/* ===========================================================================
51 * Flush the current block, with given end-of-file flag.
52 * IN assertion: strstart is set to the end of the current match.
53 */
54#define FLUSH_BLOCK_ONLY(s, last) { \
55 zng_tr_flush_block(s, (s->block_start >= 0L ? \
56 (char *)&s->window[(unsigned)s->block_start] : \
57 NULL), \
58 (unsigned long)((long)s->strstart - s->block_start), \
59 (last)); \
60 s->block_start = s->strstart; \
61 flush_pending(s->strm); \
62 Tracev((stderr, "[FLUSH]")); \
63}
64
65/* Same but force premature exit if necessary. */
66#define FLUSH_BLOCK(s, last) { \
67 FLUSH_BLOCK_ONLY(s, last); \
68 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
69}
70
71/* Maximum stored block length in deflate format (not including header). */
72#define MAX_STORED 65535
73
74/* Minimum of a and b. */
75#define MIN(a, b) ((a) > (b) ? (b) : (a))
76
77#endif
78