xref: /dflybsd-src/usr.sbin/makefs/hammer2/zlib/hammer2_zlib_deflate.h (revision 2d60b848f2503f28d840ceae174d07eb149ccce9)
1*2d60b848STomohiro Kusumi /* deflate.h -- internal compression state
2*2d60b848STomohiro Kusumi  * Copyright (C) 1995-2012 Jean-loup Gailly
3*2d60b848STomohiro Kusumi  * For conditions of distribution and use, see copyright notice in zlib.h
4*2d60b848STomohiro Kusumi  */
5*2d60b848STomohiro Kusumi 
6*2d60b848STomohiro Kusumi /* WARNING: this file should *not* be used by applications. It is
7*2d60b848STomohiro Kusumi    part of the implementation of the compression library and is
8*2d60b848STomohiro Kusumi    subject to change. Applications should only use zlib.h.
9*2d60b848STomohiro Kusumi  */
10*2d60b848STomohiro Kusumi 
11*2d60b848STomohiro Kusumi /* @(#) $Id$ */
12*2d60b848STomohiro Kusumi 
13*2d60b848STomohiro Kusumi #ifndef DEFLATE_H
14*2d60b848STomohiro Kusumi #define DEFLATE_H
15*2d60b848STomohiro Kusumi 
16*2d60b848STomohiro Kusumi #include "hammer2_zlib_zutil.h"
17*2d60b848STomohiro Kusumi 
18*2d60b848STomohiro Kusumi /* ===========================================================================
19*2d60b848STomohiro Kusumi  * Internal compression state.
20*2d60b848STomohiro Kusumi  */
21*2d60b848STomohiro Kusumi 
22*2d60b848STomohiro Kusumi #define LENGTH_CODES 29
23*2d60b848STomohiro Kusumi /* number of length codes, not counting the special END_BLOCK code */
24*2d60b848STomohiro Kusumi 
25*2d60b848STomohiro Kusumi #define LITERALS  256
26*2d60b848STomohiro Kusumi /* number of literal bytes 0..255 */
27*2d60b848STomohiro Kusumi 
28*2d60b848STomohiro Kusumi #define L_CODES (LITERALS+1+LENGTH_CODES)
29*2d60b848STomohiro Kusumi /* number of Literal or Length codes, including the END_BLOCK code */
30*2d60b848STomohiro Kusumi 
31*2d60b848STomohiro Kusumi #define D_CODES   30
32*2d60b848STomohiro Kusumi /* number of distance codes */
33*2d60b848STomohiro Kusumi 
34*2d60b848STomohiro Kusumi #define BL_CODES  19
35*2d60b848STomohiro Kusumi /* number of codes used to transfer the bit lengths */
36*2d60b848STomohiro Kusumi 
37*2d60b848STomohiro Kusumi #define HEAP_SIZE (2*L_CODES+1)
38*2d60b848STomohiro Kusumi /* maximum heap size */
39*2d60b848STomohiro Kusumi 
40*2d60b848STomohiro Kusumi #define MAX_BITS 15
41*2d60b848STomohiro Kusumi /* All codes must not exceed MAX_BITS bits */
42*2d60b848STomohiro Kusumi 
43*2d60b848STomohiro Kusumi #define Buf_size 16
44*2d60b848STomohiro Kusumi /* size of bit buffer in bi_buf */
45*2d60b848STomohiro Kusumi 
46*2d60b848STomohiro Kusumi #define INIT_STATE    42
47*2d60b848STomohiro Kusumi #define EXTRA_STATE   69
48*2d60b848STomohiro Kusumi #define NAME_STATE    73
49*2d60b848STomohiro Kusumi #define COMMENT_STATE 91
50*2d60b848STomohiro Kusumi #define HCRC_STATE   103
51*2d60b848STomohiro Kusumi #define BUSY_STATE   113
52*2d60b848STomohiro Kusumi #define FINISH_STATE 666
53*2d60b848STomohiro Kusumi /* Stream status */
54*2d60b848STomohiro Kusumi 
55*2d60b848STomohiro Kusumi 
56*2d60b848STomohiro Kusumi /* Data structure describing a single value and its code string. */
57*2d60b848STomohiro Kusumi typedef struct ct_data_s {
58*2d60b848STomohiro Kusumi     union {
59*2d60b848STomohiro Kusumi         ush  freq;       /* frequency count */
60*2d60b848STomohiro Kusumi         ush  code;       /* bit string */
61*2d60b848STomohiro Kusumi     } fc;
62*2d60b848STomohiro Kusumi     union {
63*2d60b848STomohiro Kusumi         ush  dad;        /* father node in Huffman tree */
64*2d60b848STomohiro Kusumi         ush  len;        /* length of bit string */
65*2d60b848STomohiro Kusumi     } dl;
66*2d60b848STomohiro Kusumi } FAR ct_data;
67*2d60b848STomohiro Kusumi 
68*2d60b848STomohiro Kusumi #define Freq fc.freq
69*2d60b848STomohiro Kusumi #define Code fc.code
70*2d60b848STomohiro Kusumi #define Dad  dl.dad
71*2d60b848STomohiro Kusumi #define Len  dl.len
72*2d60b848STomohiro Kusumi 
73*2d60b848STomohiro Kusumi typedef struct static_tree_desc_s  static_tree_desc;
74*2d60b848STomohiro Kusumi 
75*2d60b848STomohiro Kusumi typedef struct tree_desc_s {
76*2d60b848STomohiro Kusumi     ct_data *dyn_tree;           /* the dynamic tree */
77*2d60b848STomohiro Kusumi     int     max_code;            /* largest code with non zero frequency */
78*2d60b848STomohiro Kusumi     static_tree_desc *stat_desc; /* the corresponding static tree */
79*2d60b848STomohiro Kusumi } FAR tree_desc;
80*2d60b848STomohiro Kusumi 
81*2d60b848STomohiro Kusumi typedef ush Pos;
82*2d60b848STomohiro Kusumi typedef Pos FAR Posf;
83*2d60b848STomohiro Kusumi typedef unsigned IPos;
84*2d60b848STomohiro Kusumi 
85*2d60b848STomohiro Kusumi /* A Pos is an index in the character window. We use short instead of int to
86*2d60b848STomohiro Kusumi  * save space in the various tables. IPos is used only for parameter passing.
87*2d60b848STomohiro Kusumi  */
88*2d60b848STomohiro Kusumi 
89*2d60b848STomohiro Kusumi typedef struct internal_state {
90*2d60b848STomohiro Kusumi     z_streamp strm;      /* pointer back to this zlib stream */
91*2d60b848STomohiro Kusumi     int   status;        /* as the name implies */
92*2d60b848STomohiro Kusumi     Bytef *pending_buf;  /* output still pending */
93*2d60b848STomohiro Kusumi     ulg   pending_buf_size; /* size of pending_buf */
94*2d60b848STomohiro Kusumi     Bytef *pending_out;  /* next pending byte to output to the stream */
95*2d60b848STomohiro Kusumi     uInt   pending;      /* nb of bytes in the pending buffer */
96*2d60b848STomohiro Kusumi     int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
97*2d60b848STomohiro Kusumi     uInt   gzindex;      /* where in extra, name, or comment */
98*2d60b848STomohiro Kusumi     Byte  method;        /* can only be DEFLATED */
99*2d60b848STomohiro Kusumi     int   last_flush;    /* value of flush param for previous deflate call */
100*2d60b848STomohiro Kusumi 
101*2d60b848STomohiro Kusumi                 /* used by deflate.c: */
102*2d60b848STomohiro Kusumi 
103*2d60b848STomohiro Kusumi     uInt  w_size;        /* LZ77 window size (32K by default) */
104*2d60b848STomohiro Kusumi     uInt  w_bits;        /* log2(w_size)  (8..16) */
105*2d60b848STomohiro Kusumi     uInt  w_mask;        /* w_size - 1 */
106*2d60b848STomohiro Kusumi 
107*2d60b848STomohiro Kusumi     Bytef *window;
108*2d60b848STomohiro Kusumi     /* Sliding window. Input bytes are read into the second half of the window,
109*2d60b848STomohiro Kusumi      * and move to the first half later to keep a dictionary of at least wSize
110*2d60b848STomohiro Kusumi      * bytes. With this organization, matches are limited to a distance of
111*2d60b848STomohiro Kusumi      * wSize-MAX_MATCH bytes, but this ensures that IO is always
112*2d60b848STomohiro Kusumi      * performed with a length multiple of the block size. Also, it limits
113*2d60b848STomohiro Kusumi      * the window size to 64K, which is quite useful on MSDOS.
114*2d60b848STomohiro Kusumi      * To do: use the user input buffer as sliding window.
115*2d60b848STomohiro Kusumi      */
116*2d60b848STomohiro Kusumi 
117*2d60b848STomohiro Kusumi     ulg window_size;
118*2d60b848STomohiro Kusumi     /* Actual size of window: 2*wSize, except when the user input buffer
119*2d60b848STomohiro Kusumi      * is directly used as sliding window.
120*2d60b848STomohiro Kusumi      */
121*2d60b848STomohiro Kusumi 
122*2d60b848STomohiro Kusumi     Posf *prev;
123*2d60b848STomohiro Kusumi     /* Link to older string with same hash index. To limit the size of this
124*2d60b848STomohiro Kusumi      * array to 64K, this link is maintained only for the last 32K strings.
125*2d60b848STomohiro Kusumi      * An index in this array is thus a window index modulo 32K.
126*2d60b848STomohiro Kusumi      */
127*2d60b848STomohiro Kusumi 
128*2d60b848STomohiro Kusumi     Posf *head; /* Heads of the hash chains or NIL. */
129*2d60b848STomohiro Kusumi 
130*2d60b848STomohiro Kusumi     uInt  ins_h;          /* hash index of string to be inserted */
131*2d60b848STomohiro Kusumi     uInt  hash_size;      /* number of elements in hash table */
132*2d60b848STomohiro Kusumi     uInt  hash_bits;      /* log2(hash_size) */
133*2d60b848STomohiro Kusumi     uInt  hash_mask;      /* hash_size-1 */
134*2d60b848STomohiro Kusumi 
135*2d60b848STomohiro Kusumi     uInt  hash_shift;
136*2d60b848STomohiro Kusumi     /* Number of bits by which ins_h must be shifted at each input
137*2d60b848STomohiro Kusumi      * step. It must be such that after MIN_MATCH steps, the oldest
138*2d60b848STomohiro Kusumi      * byte no longer takes part in the hash key, that is:
139*2d60b848STomohiro Kusumi      *   hash_shift * MIN_MATCH >= hash_bits
140*2d60b848STomohiro Kusumi      */
141*2d60b848STomohiro Kusumi 
142*2d60b848STomohiro Kusumi     long block_start;
143*2d60b848STomohiro Kusumi     /* Window position at the beginning of the current output block. Gets
144*2d60b848STomohiro Kusumi      * negative when the window is moved backwards.
145*2d60b848STomohiro Kusumi      */
146*2d60b848STomohiro Kusumi 
147*2d60b848STomohiro Kusumi     uInt match_length;           /* length of best match */
148*2d60b848STomohiro Kusumi     IPos prev_match;             /* previous match */
149*2d60b848STomohiro Kusumi     int match_available;         /* set if previous match exists */
150*2d60b848STomohiro Kusumi     uInt strstart;               /* start of string to insert */
151*2d60b848STomohiro Kusumi     uInt match_start;            /* start of matching string */
152*2d60b848STomohiro Kusumi     uInt lookahead;              /* number of valid bytes ahead in window */
153*2d60b848STomohiro Kusumi 
154*2d60b848STomohiro Kusumi     uInt prev_length;
155*2d60b848STomohiro Kusumi     /* Length of the best match at previous step. Matches not greater than this
156*2d60b848STomohiro Kusumi      * are discarded. This is used in the lazy match evaluation.
157*2d60b848STomohiro Kusumi      */
158*2d60b848STomohiro Kusumi 
159*2d60b848STomohiro Kusumi     uInt max_chain_length;
160*2d60b848STomohiro Kusumi     /* To speed up deflation, hash chains are never searched beyond this
161*2d60b848STomohiro Kusumi      * length.  A higher limit improves compression ratio but degrades the
162*2d60b848STomohiro Kusumi      * speed.
163*2d60b848STomohiro Kusumi      */
164*2d60b848STomohiro Kusumi 
165*2d60b848STomohiro Kusumi     uInt max_lazy_match;
166*2d60b848STomohiro Kusumi     /* Attempt to find a better match only when the current match is strictly
167*2d60b848STomohiro Kusumi      * smaller than this value. This mechanism is used only for compression
168*2d60b848STomohiro Kusumi      * levels >= 4.
169*2d60b848STomohiro Kusumi      */
170*2d60b848STomohiro Kusumi #   define max_insert_length  max_lazy_match
171*2d60b848STomohiro Kusumi     /* Insert new strings in the hash table only if the match length is not
172*2d60b848STomohiro Kusumi      * greater than this length. This saves time but degrades compression.
173*2d60b848STomohiro Kusumi      * max_insert_length is used only for compression levels <= 3.
174*2d60b848STomohiro Kusumi      */
175*2d60b848STomohiro Kusumi 
176*2d60b848STomohiro Kusumi     int level;    /* compression level (1..9) */
177*2d60b848STomohiro Kusumi     int strategy; /* favor or force Huffman coding*/
178*2d60b848STomohiro Kusumi 
179*2d60b848STomohiro Kusumi     uInt good_match;
180*2d60b848STomohiro Kusumi     /* Use a faster search when the previous match is longer than this */
181*2d60b848STomohiro Kusumi 
182*2d60b848STomohiro Kusumi     int nice_match; /* Stop searching when current match exceeds this */
183*2d60b848STomohiro Kusumi 
184*2d60b848STomohiro Kusumi                 /* used by trees.c: */
185*2d60b848STomohiro Kusumi     /* Didn't use ct_data typedef below to suppress compiler warning */
186*2d60b848STomohiro Kusumi     struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
187*2d60b848STomohiro Kusumi     struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
188*2d60b848STomohiro Kusumi     struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
189*2d60b848STomohiro Kusumi 
190*2d60b848STomohiro Kusumi     struct tree_desc_s l_desc;               /* desc. for literal tree */
191*2d60b848STomohiro Kusumi     struct tree_desc_s d_desc;               /* desc. for distance tree */
192*2d60b848STomohiro Kusumi     struct tree_desc_s bl_desc;              /* desc. for bit length tree */
193*2d60b848STomohiro Kusumi 
194*2d60b848STomohiro Kusumi     ush bl_count[MAX_BITS+1];
195*2d60b848STomohiro Kusumi     /* number of codes at each bit length for an optimal tree */
196*2d60b848STomohiro Kusumi 
197*2d60b848STomohiro Kusumi     int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
198*2d60b848STomohiro Kusumi     int heap_len;               /* number of elements in the heap */
199*2d60b848STomohiro Kusumi     int heap_max;               /* element of largest frequency */
200*2d60b848STomohiro Kusumi     /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
201*2d60b848STomohiro Kusumi      * The same heap array is used to build all trees.
202*2d60b848STomohiro Kusumi      */
203*2d60b848STomohiro Kusumi 
204*2d60b848STomohiro Kusumi     uch depth[2*L_CODES+1];
205*2d60b848STomohiro Kusumi     /* Depth of each subtree used as tie breaker for trees of equal frequency
206*2d60b848STomohiro Kusumi      */
207*2d60b848STomohiro Kusumi 
208*2d60b848STomohiro Kusumi     uchf *l_buf;          /* buffer for literals or lengths */
209*2d60b848STomohiro Kusumi 
210*2d60b848STomohiro Kusumi     uInt  lit_bufsize;
211*2d60b848STomohiro Kusumi     /* Size of match buffer for literals/lengths.  There are 4 reasons for
212*2d60b848STomohiro Kusumi      * limiting lit_bufsize to 64K:
213*2d60b848STomohiro Kusumi      *   - frequencies can be kept in 16 bit counters
214*2d60b848STomohiro Kusumi      *   - if compression is not successful for the first block, all input
215*2d60b848STomohiro Kusumi      *     data is still in the window so we can still emit a stored block even
216*2d60b848STomohiro Kusumi      *     when input comes from standard input.  (This can also be done for
217*2d60b848STomohiro Kusumi      *     all blocks if lit_bufsize is not greater than 32K.)
218*2d60b848STomohiro Kusumi      *   - if compression is not successful for a file smaller than 64K, we can
219*2d60b848STomohiro Kusumi      *     even emit a stored file instead of a stored block (saving 5 bytes).
220*2d60b848STomohiro Kusumi      *     This is applicable only for zip (not gzip or zlib).
221*2d60b848STomohiro Kusumi      *   - creating new Huffman trees less frequently may not provide fast
222*2d60b848STomohiro Kusumi      *     adaptation to changes in the input data statistics. (Take for
223*2d60b848STomohiro Kusumi      *     example a binary file with poorly compressible code followed by
224*2d60b848STomohiro Kusumi      *     a highly compressible string table.) Smaller buffer sizes give
225*2d60b848STomohiro Kusumi      *     fast adaptation but have of course the overhead of transmitting
226*2d60b848STomohiro Kusumi      *     trees more frequently.
227*2d60b848STomohiro Kusumi      *   - I can't count above 4
228*2d60b848STomohiro Kusumi      */
229*2d60b848STomohiro Kusumi 
230*2d60b848STomohiro Kusumi     uInt last_lit;      /* running index in l_buf */
231*2d60b848STomohiro Kusumi 
232*2d60b848STomohiro Kusumi     ushf *d_buf;
233*2d60b848STomohiro Kusumi     /* Buffer for distances. To simplify the code, d_buf and l_buf have
234*2d60b848STomohiro Kusumi      * the same number of elements. To use different lengths, an extra flag
235*2d60b848STomohiro Kusumi      * array would be necessary.
236*2d60b848STomohiro Kusumi      */
237*2d60b848STomohiro Kusumi 
238*2d60b848STomohiro Kusumi     ulg opt_len;        /* bit length of current block with optimal trees */
239*2d60b848STomohiro Kusumi     ulg static_len;     /* bit length of current block with static trees */
240*2d60b848STomohiro Kusumi     uInt matches;       /* number of string matches in current block */
241*2d60b848STomohiro Kusumi     uInt insert;        /* bytes at end of window left to insert */
242*2d60b848STomohiro Kusumi 
243*2d60b848STomohiro Kusumi #ifdef H2_ZLIB_DEBUG
244*2d60b848STomohiro Kusumi     ulg compressed_len; /* total bit length of compressed file mod 2^32 */
245*2d60b848STomohiro Kusumi     ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
246*2d60b848STomohiro Kusumi #endif
247*2d60b848STomohiro Kusumi 
248*2d60b848STomohiro Kusumi     ush bi_buf;
249*2d60b848STomohiro Kusumi     /* Output buffer. bits are inserted starting at the bottom (least
250*2d60b848STomohiro Kusumi      * significant bits).
251*2d60b848STomohiro Kusumi      */
252*2d60b848STomohiro Kusumi     int bi_valid;
253*2d60b848STomohiro Kusumi     /* Number of valid bits in bi_buf.  All bits above the last valid bit
254*2d60b848STomohiro Kusumi      * are always zero.
255*2d60b848STomohiro Kusumi      */
256*2d60b848STomohiro Kusumi 
257*2d60b848STomohiro Kusumi     ulg high_water;
258*2d60b848STomohiro Kusumi     /* High water mark offset in window for initialized bytes -- bytes above
259*2d60b848STomohiro Kusumi      * this are set to zero in order to avoid memory check warnings when
260*2d60b848STomohiro Kusumi      * longest match routines access bytes past the input.  This is then
261*2d60b848STomohiro Kusumi      * updated to the new high water mark.
262*2d60b848STomohiro Kusumi      */
263*2d60b848STomohiro Kusumi 
264*2d60b848STomohiro Kusumi } FAR deflate_state;
265*2d60b848STomohiro Kusumi 
266*2d60b848STomohiro Kusumi /* Output a byte on the stream.
267*2d60b848STomohiro Kusumi  * IN assertion: there is enough room in pending_buf.
268*2d60b848STomohiro Kusumi  */
269*2d60b848STomohiro Kusumi #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
270*2d60b848STomohiro Kusumi 
271*2d60b848STomohiro Kusumi 
272*2d60b848STomohiro Kusumi #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
273*2d60b848STomohiro Kusumi /* Minimum amount of lookahead, except at the end of the input file.
274*2d60b848STomohiro Kusumi  * See deflate.c for comments about the MIN_MATCH+1.
275*2d60b848STomohiro Kusumi  */
276*2d60b848STomohiro Kusumi 
277*2d60b848STomohiro Kusumi #define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
278*2d60b848STomohiro Kusumi /* In order to simplify the code, particularly on 16 bit machines, match
279*2d60b848STomohiro Kusumi  * distances are limited to MAX_DIST instead of WSIZE.
280*2d60b848STomohiro Kusumi  */
281*2d60b848STomohiro Kusumi 
282*2d60b848STomohiro Kusumi #define WIN_INIT MAX_MATCH
283*2d60b848STomohiro Kusumi /* Number of bytes after end of data in window to initialize in order to avoid
284*2d60b848STomohiro Kusumi    memory checker errors from longest match routines */
285*2d60b848STomohiro Kusumi 
286*2d60b848STomohiro Kusumi         /* in trees.c */
287*2d60b848STomohiro Kusumi void ZLIB_INTERNAL _tr_init(deflate_state *s);
288*2d60b848STomohiro Kusumi int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
289*2d60b848STomohiro Kusumi void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
290*2d60b848STomohiro Kusumi                         ulg stored_len, int last);
291*2d60b848STomohiro Kusumi void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
292*2d60b848STomohiro Kusumi void ZLIB_INTERNAL _tr_align(deflate_state *s);
293*2d60b848STomohiro Kusumi void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
294*2d60b848STomohiro Kusumi                         ulg stored_len, int last);
295*2d60b848STomohiro Kusumi 
296*2d60b848STomohiro Kusumi #define d_code(dist) \
297*2d60b848STomohiro Kusumi    ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
298*2d60b848STomohiro Kusumi /* Mapping from a distance to a distance code. dist is the distance - 1 and
299*2d60b848STomohiro Kusumi  * must not have side effects. _dist_code[256] and _dist_code[257] are never
300*2d60b848STomohiro Kusumi  * used.
301*2d60b848STomohiro Kusumi  */
302*2d60b848STomohiro Kusumi 
303*2d60b848STomohiro Kusumi #ifndef H2_ZLIB_DEBUG
304*2d60b848STomohiro Kusumi /* Inline versions of _tr_tally for speed: */
305*2d60b848STomohiro Kusumi 
306*2d60b848STomohiro Kusumi #if defined(GEN_TREES_H) || !defined(STDC)
307*2d60b848STomohiro Kusumi   extern uch ZLIB_INTERNAL _length_code[];
308*2d60b848STomohiro Kusumi   extern uch ZLIB_INTERNAL _dist_code[];
309*2d60b848STomohiro Kusumi #else
310*2d60b848STomohiro Kusumi   extern const uch ZLIB_INTERNAL _length_code[];
311*2d60b848STomohiro Kusumi   extern const uch ZLIB_INTERNAL _dist_code[];
312*2d60b848STomohiro Kusumi #endif
313*2d60b848STomohiro Kusumi 
314*2d60b848STomohiro Kusumi # define _tr_tally_lit(s, c, flush) \
315*2d60b848STomohiro Kusumi   { uch cc = (c); \
316*2d60b848STomohiro Kusumi     s->d_buf[s->last_lit] = 0; \
317*2d60b848STomohiro Kusumi     s->l_buf[s->last_lit++] = cc; \
318*2d60b848STomohiro Kusumi     s->dyn_ltree[cc].Freq++; \
319*2d60b848STomohiro Kusumi     flush = (s->last_lit == s->lit_bufsize-1); \
320*2d60b848STomohiro Kusumi    }
321*2d60b848STomohiro Kusumi # define _tr_tally_dist(s, distance, length, flush) \
322*2d60b848STomohiro Kusumi   { uch len = (length); \
323*2d60b848STomohiro Kusumi     ush dist = (distance); \
324*2d60b848STomohiro Kusumi     s->d_buf[s->last_lit] = dist; \
325*2d60b848STomohiro Kusumi     s->l_buf[s->last_lit++] = len; \
326*2d60b848STomohiro Kusumi     dist--; \
327*2d60b848STomohiro Kusumi     s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
328*2d60b848STomohiro Kusumi     s->dyn_dtree[d_code(dist)].Freq++; \
329*2d60b848STomohiro Kusumi     flush = (s->last_lit == s->lit_bufsize-1); \
330*2d60b848STomohiro Kusumi   }
331*2d60b848STomohiro Kusumi #else
332*2d60b848STomohiro Kusumi # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
333*2d60b848STomohiro Kusumi # define _tr_tally_dist(s, distance, length, flush) \
334*2d60b848STomohiro Kusumi               flush = _tr_tally(s, distance, length)
335*2d60b848STomohiro Kusumi #endif
336*2d60b848STomohiro Kusumi 
337*2d60b848STomohiro Kusumi #endif /* DEFLATE_H */
338