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