1275793eaSopenharmony_ci/* deflate.h -- internal compression state
2275793eaSopenharmony_ci * Copyright (C) 1995-2024 Jean-loup Gailly
3275793eaSopenharmony_ci * For conditions of distribution and use, see copyright notice in zlib.h
4275793eaSopenharmony_ci */
5275793eaSopenharmony_ci
6275793eaSopenharmony_ci/* WARNING: this file should *not* be used by applications. It is
7275793eaSopenharmony_ci   part of the implementation of the compression library and is
8275793eaSopenharmony_ci   subject to change. Applications should only use zlib.h.
9275793eaSopenharmony_ci */
10275793eaSopenharmony_ci
11275793eaSopenharmony_ci/* @(#) $Id$ */
12275793eaSopenharmony_ci
13275793eaSopenharmony_ci#ifndef DEFLATE_H
14275793eaSopenharmony_ci#define DEFLATE_H
15275793eaSopenharmony_ci
16275793eaSopenharmony_ci#include "zutil.h"
17275793eaSopenharmony_ci
18275793eaSopenharmony_ci/* define NO_GZIP when compiling if you want to disable gzip header and
19275793eaSopenharmony_ci   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
20275793eaSopenharmony_ci   the crc code when it is not needed.  For shared libraries, gzip encoding
21275793eaSopenharmony_ci   should be left enabled. */
22275793eaSopenharmony_ci#ifndef NO_GZIP
23275793eaSopenharmony_ci#  define GZIP
24275793eaSopenharmony_ci#endif
25275793eaSopenharmony_ci
26275793eaSopenharmony_ci/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
27275793eaSopenharmony_ci   the cost of a larger memory footprint */
28275793eaSopenharmony_ci/* #define LIT_MEM */
29275793eaSopenharmony_ci
30275793eaSopenharmony_ci/* ===========================================================================
31275793eaSopenharmony_ci * Internal compression state.
32275793eaSopenharmony_ci */
33275793eaSopenharmony_ci
34275793eaSopenharmony_ci#define LENGTH_CODES 29
35275793eaSopenharmony_ci/* number of length codes, not counting the special END_BLOCK code */
36275793eaSopenharmony_ci
37275793eaSopenharmony_ci#define LITERALS  256
38275793eaSopenharmony_ci/* number of literal bytes 0..255 */
39275793eaSopenharmony_ci
40275793eaSopenharmony_ci#define L_CODES (LITERALS+1+LENGTH_CODES)
41275793eaSopenharmony_ci/* number of Literal or Length codes, including the END_BLOCK code */
42275793eaSopenharmony_ci
43275793eaSopenharmony_ci#define D_CODES   30
44275793eaSopenharmony_ci/* number of distance codes */
45275793eaSopenharmony_ci
46275793eaSopenharmony_ci#define BL_CODES  19
47275793eaSopenharmony_ci/* number of codes used to transfer the bit lengths */
48275793eaSopenharmony_ci
49275793eaSopenharmony_ci#define HEAP_SIZE (2*L_CODES+1)
50275793eaSopenharmony_ci/* maximum heap size */
51275793eaSopenharmony_ci
52275793eaSopenharmony_ci#define MAX_BITS 15
53275793eaSopenharmony_ci/* All codes must not exceed MAX_BITS bits */
54275793eaSopenharmony_ci
55275793eaSopenharmony_ci#define Buf_size 16
56275793eaSopenharmony_ci/* size of bit buffer in bi_buf */
57275793eaSopenharmony_ci
58275793eaSopenharmony_ci#define INIT_STATE    42    /* zlib header -> BUSY_STATE */
59275793eaSopenharmony_ci#ifdef GZIP
60275793eaSopenharmony_ci#  define GZIP_STATE  57    /* gzip header -> BUSY_STATE | EXTRA_STATE */
61275793eaSopenharmony_ci#endif
62275793eaSopenharmony_ci#define EXTRA_STATE   69    /* gzip extra block -> NAME_STATE */
63275793eaSopenharmony_ci#define NAME_STATE    73    /* gzip file name -> COMMENT_STATE */
64275793eaSopenharmony_ci#define COMMENT_STATE 91    /* gzip comment -> HCRC_STATE */
65275793eaSopenharmony_ci#define HCRC_STATE   103    /* gzip header CRC -> BUSY_STATE */
66275793eaSopenharmony_ci#define BUSY_STATE   113    /* deflate -> FINISH_STATE */
67275793eaSopenharmony_ci#define FINISH_STATE 666    /* stream complete */
68275793eaSopenharmony_ci/* Stream status */
69275793eaSopenharmony_ci
70275793eaSopenharmony_ci
71275793eaSopenharmony_ci/* Data structure describing a single value and its code string. */
72275793eaSopenharmony_citypedef struct ct_data_s {
73275793eaSopenharmony_ci    union {
74275793eaSopenharmony_ci        ush  freq;       /* frequency count */
75275793eaSopenharmony_ci        ush  code;       /* bit string */
76275793eaSopenharmony_ci    } fc;
77275793eaSopenharmony_ci    union {
78275793eaSopenharmony_ci        ush  dad;        /* father node in Huffman tree */
79275793eaSopenharmony_ci        ush  len;        /* length of bit string */
80275793eaSopenharmony_ci    } dl;
81275793eaSopenharmony_ci} FAR ct_data;
82275793eaSopenharmony_ci
83275793eaSopenharmony_ci#define Freq fc.freq
84275793eaSopenharmony_ci#define Code fc.code
85275793eaSopenharmony_ci#define Dad  dl.dad
86275793eaSopenharmony_ci#define Len  dl.len
87275793eaSopenharmony_ci
88275793eaSopenharmony_citypedef struct static_tree_desc_s  static_tree_desc;
89275793eaSopenharmony_ci
90275793eaSopenharmony_citypedef struct tree_desc_s {
91275793eaSopenharmony_ci    ct_data *dyn_tree;           /* the dynamic tree */
92275793eaSopenharmony_ci    int     max_code;            /* largest code with non zero frequency */
93275793eaSopenharmony_ci    const static_tree_desc *stat_desc;  /* the corresponding static tree */
94275793eaSopenharmony_ci} FAR tree_desc;
95275793eaSopenharmony_ci
96275793eaSopenharmony_citypedef ush Pos;
97275793eaSopenharmony_citypedef Pos FAR Posf;
98275793eaSopenharmony_citypedef unsigned IPos;
99275793eaSopenharmony_ci
100275793eaSopenharmony_ci/* A Pos is an index in the character window. We use short instead of int to
101275793eaSopenharmony_ci * save space in the various tables. IPos is used only for parameter passing.
102275793eaSopenharmony_ci */
103275793eaSopenharmony_ci
104275793eaSopenharmony_citypedef struct internal_state {
105275793eaSopenharmony_ci    z_streamp strm;      /* pointer back to this zlib stream */
106275793eaSopenharmony_ci    int   status;        /* as the name implies */
107275793eaSopenharmony_ci    Bytef *pending_buf;  /* output still pending */
108275793eaSopenharmony_ci    ulg   pending_buf_size; /* size of pending_buf */
109275793eaSopenharmony_ci    Bytef *pending_out;  /* next pending byte to output to the stream */
110275793eaSopenharmony_ci    ulg   pending;       /* nb of bytes in the pending buffer */
111275793eaSopenharmony_ci    int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
112275793eaSopenharmony_ci    gz_headerp  gzhead;  /* gzip header information to write */
113275793eaSopenharmony_ci    ulg   gzindex;       /* where in extra, name, or comment */
114275793eaSopenharmony_ci    Byte  method;        /* can only be DEFLATED */
115275793eaSopenharmony_ci    int   last_flush;    /* value of flush param for previous deflate call */
116275793eaSopenharmony_ci
117275793eaSopenharmony_ci                /* used by deflate.c: */
118275793eaSopenharmony_ci
119275793eaSopenharmony_ci    uInt  w_size;        /* LZ77 window size (32K by default) */
120275793eaSopenharmony_ci    uInt  w_bits;        /* log2(w_size)  (8..16) */
121275793eaSopenharmony_ci    uInt  w_mask;        /* w_size - 1 */
122275793eaSopenharmony_ci
123275793eaSopenharmony_ci    Bytef *window;
124275793eaSopenharmony_ci    /* Sliding window. Input bytes are read into the second half of the window,
125275793eaSopenharmony_ci     * and move to the first half later to keep a dictionary of at least wSize
126275793eaSopenharmony_ci     * bytes. With this organization, matches are limited to a distance of
127275793eaSopenharmony_ci     * wSize-MAX_MATCH bytes, but this ensures that IO is always
128275793eaSopenharmony_ci     * performed with a length multiple of the block size. Also, it limits
129275793eaSopenharmony_ci     * the window size to 64K, which is quite useful on MSDOS.
130275793eaSopenharmony_ci     * To do: use the user input buffer as sliding window.
131275793eaSopenharmony_ci     */
132275793eaSopenharmony_ci
133275793eaSopenharmony_ci    ulg window_size;
134275793eaSopenharmony_ci    /* Actual size of window: 2*wSize, except when the user input buffer
135275793eaSopenharmony_ci     * is directly used as sliding window.
136275793eaSopenharmony_ci     */
137275793eaSopenharmony_ci
138275793eaSopenharmony_ci    Posf *prev;
139275793eaSopenharmony_ci    /* Link to older string with same hash index. To limit the size of this
140275793eaSopenharmony_ci     * array to 64K, this link is maintained only for the last 32K strings.
141275793eaSopenharmony_ci     * An index in this array is thus a window index modulo 32K.
142275793eaSopenharmony_ci     */
143275793eaSopenharmony_ci
144275793eaSopenharmony_ci    Posf *head; /* Heads of the hash chains or NIL. */
145275793eaSopenharmony_ci
146275793eaSopenharmony_ci    uInt  ins_h;          /* hash index of string to be inserted */
147275793eaSopenharmony_ci    uInt  hash_size;      /* number of elements in hash table */
148275793eaSopenharmony_ci    uInt  hash_bits;      /* log2(hash_size) */
149275793eaSopenharmony_ci    uInt  hash_mask;      /* hash_size-1 */
150275793eaSopenharmony_ci
151275793eaSopenharmony_ci    uInt  hash_shift;
152275793eaSopenharmony_ci    /* Number of bits by which ins_h must be shifted at each input
153275793eaSopenharmony_ci     * step. It must be such that after MIN_MATCH steps, the oldest
154275793eaSopenharmony_ci     * byte no longer takes part in the hash key, that is:
155275793eaSopenharmony_ci     *   hash_shift * MIN_MATCH >= hash_bits
156275793eaSopenharmony_ci     */
157275793eaSopenharmony_ci
158275793eaSopenharmony_ci    long block_start;
159275793eaSopenharmony_ci    /* Window position at the beginning of the current output block. Gets
160275793eaSopenharmony_ci     * negative when the window is moved backwards.
161275793eaSopenharmony_ci     */
162275793eaSopenharmony_ci
163275793eaSopenharmony_ci    uInt match_length;           /* length of best match */
164275793eaSopenharmony_ci    IPos prev_match;             /* previous match */
165275793eaSopenharmony_ci    int match_available;         /* set if previous match exists */
166275793eaSopenharmony_ci    uInt strstart;               /* start of string to insert */
167275793eaSopenharmony_ci    uInt match_start;            /* start of matching string */
168275793eaSopenharmony_ci    uInt lookahead;              /* number of valid bytes ahead in window */
169275793eaSopenharmony_ci
170275793eaSopenharmony_ci    uInt prev_length;
171275793eaSopenharmony_ci    /* Length of the best match at previous step. Matches not greater than this
172275793eaSopenharmony_ci     * are discarded. This is used in the lazy match evaluation.
173275793eaSopenharmony_ci     */
174275793eaSopenharmony_ci
175275793eaSopenharmony_ci    uInt max_chain_length;
176275793eaSopenharmony_ci    /* To speed up deflation, hash chains are never searched beyond this
177275793eaSopenharmony_ci     * length.  A higher limit improves compression ratio but degrades the
178275793eaSopenharmony_ci     * speed.
179275793eaSopenharmony_ci     */
180275793eaSopenharmony_ci
181275793eaSopenharmony_ci    uInt max_lazy_match;
182275793eaSopenharmony_ci    /* Attempt to find a better match only when the current match is strictly
183275793eaSopenharmony_ci     * smaller than this value. This mechanism is used only for compression
184275793eaSopenharmony_ci     * levels >= 4.
185275793eaSopenharmony_ci     */
186275793eaSopenharmony_ci#   define max_insert_length  max_lazy_match
187275793eaSopenharmony_ci    /* Insert new strings in the hash table only if the match length is not
188275793eaSopenharmony_ci     * greater than this length. This saves time but degrades compression.
189275793eaSopenharmony_ci     * max_insert_length is used only for compression levels <= 3.
190275793eaSopenharmony_ci     */
191275793eaSopenharmony_ci
192275793eaSopenharmony_ci    int level;    /* compression level (1..9) */
193275793eaSopenharmony_ci    int strategy; /* favor or force Huffman coding*/
194275793eaSopenharmony_ci
195275793eaSopenharmony_ci    uInt good_match;
196275793eaSopenharmony_ci    /* Use a faster search when the previous match is longer than this */
197275793eaSopenharmony_ci
198275793eaSopenharmony_ci    int nice_match; /* Stop searching when current match exceeds this */
199275793eaSopenharmony_ci
200275793eaSopenharmony_ci                /* used by trees.c: */
201275793eaSopenharmony_ci    /* Didn't use ct_data typedef below to suppress compiler warning */
202275793eaSopenharmony_ci    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
203275793eaSopenharmony_ci    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
204275793eaSopenharmony_ci    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
205275793eaSopenharmony_ci
206275793eaSopenharmony_ci    struct tree_desc_s l_desc;               /* desc. for literal tree */
207275793eaSopenharmony_ci    struct tree_desc_s d_desc;               /* desc. for distance tree */
208275793eaSopenharmony_ci    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
209275793eaSopenharmony_ci
210275793eaSopenharmony_ci    ush bl_count[MAX_BITS+1];
211275793eaSopenharmony_ci    /* number of codes at each bit length for an optimal tree */
212275793eaSopenharmony_ci
213275793eaSopenharmony_ci    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
214275793eaSopenharmony_ci    int heap_len;               /* number of elements in the heap */
215275793eaSopenharmony_ci    int heap_max;               /* element of largest frequency */
216275793eaSopenharmony_ci    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
217275793eaSopenharmony_ci     * The same heap array is used to build all trees.
218275793eaSopenharmony_ci     */
219275793eaSopenharmony_ci
220275793eaSopenharmony_ci    uch depth[2*L_CODES+1];
221275793eaSopenharmony_ci    /* Depth of each subtree used as tie breaker for trees of equal frequency
222275793eaSopenharmony_ci     */
223275793eaSopenharmony_ci
224275793eaSopenharmony_ci#ifdef LIT_MEM
225275793eaSopenharmony_ci#   define LIT_BUFS 5
226275793eaSopenharmony_ci    ushf *d_buf;          /* buffer for distances */
227275793eaSopenharmony_ci    uchf *l_buf;          /* buffer for literals/lengths */
228275793eaSopenharmony_ci#else
229275793eaSopenharmony_ci#   define LIT_BUFS 4
230275793eaSopenharmony_ci    uchf *sym_buf;        /* buffer for distances and literals/lengths */
231275793eaSopenharmony_ci#endif
232275793eaSopenharmony_ci
233275793eaSopenharmony_ci    uInt  lit_bufsize;
234275793eaSopenharmony_ci    /* Size of match buffer for literals/lengths.  There are 4 reasons for
235275793eaSopenharmony_ci     * limiting lit_bufsize to 64K:
236275793eaSopenharmony_ci     *   - frequencies can be kept in 16 bit counters
237275793eaSopenharmony_ci     *   - if compression is not successful for the first block, all input
238275793eaSopenharmony_ci     *     data is still in the window so we can still emit a stored block even
239275793eaSopenharmony_ci     *     when input comes from standard input.  (This can also be done for
240275793eaSopenharmony_ci     *     all blocks if lit_bufsize is not greater than 32K.)
241275793eaSopenharmony_ci     *   - if compression is not successful for a file smaller than 64K, we can
242275793eaSopenharmony_ci     *     even emit a stored file instead of a stored block (saving 5 bytes).
243275793eaSopenharmony_ci     *     This is applicable only for zip (not gzip or zlib).
244275793eaSopenharmony_ci     *   - creating new Huffman trees less frequently may not provide fast
245275793eaSopenharmony_ci     *     adaptation to changes in the input data statistics. (Take for
246275793eaSopenharmony_ci     *     example a binary file with poorly compressible code followed by
247275793eaSopenharmony_ci     *     a highly compressible string table.) Smaller buffer sizes give
248275793eaSopenharmony_ci     *     fast adaptation but have of course the overhead of transmitting
249275793eaSopenharmony_ci     *     trees more frequently.
250275793eaSopenharmony_ci     *   - I can't count above 4
251275793eaSopenharmony_ci     */
252275793eaSopenharmony_ci
253275793eaSopenharmony_ci    uInt sym_next;      /* running index in symbol buffer */
254275793eaSopenharmony_ci    uInt sym_end;       /* symbol table full when sym_next reaches this */
255275793eaSopenharmony_ci
256275793eaSopenharmony_ci    ulg opt_len;        /* bit length of current block with optimal trees */
257275793eaSopenharmony_ci    ulg static_len;     /* bit length of current block with static trees */
258275793eaSopenharmony_ci    uInt matches;       /* number of string matches in current block */
259275793eaSopenharmony_ci    uInt insert;        /* bytes at end of window left to insert */
260275793eaSopenharmony_ci
261275793eaSopenharmony_ci#ifdef ZLIB_DEBUG
262275793eaSopenharmony_ci    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
263275793eaSopenharmony_ci    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
264275793eaSopenharmony_ci#endif
265275793eaSopenharmony_ci
266275793eaSopenharmony_ci    ush bi_buf;
267275793eaSopenharmony_ci    /* Output buffer. bits are inserted starting at the bottom (least
268275793eaSopenharmony_ci     * significant bits).
269275793eaSopenharmony_ci     */
270275793eaSopenharmony_ci    int bi_valid;
271275793eaSopenharmony_ci    /* Number of valid bits in bi_buf.  All bits above the last valid bit
272275793eaSopenharmony_ci     * are always zero.
273275793eaSopenharmony_ci     */
274275793eaSopenharmony_ci
275275793eaSopenharmony_ci    ulg high_water;
276275793eaSopenharmony_ci    /* High water mark offset in window for initialized bytes -- bytes above
277275793eaSopenharmony_ci     * this are set to zero in order to avoid memory check warnings when
278275793eaSopenharmony_ci     * longest match routines access bytes past the input.  This is then
279275793eaSopenharmony_ci     * updated to the new high water mark.
280275793eaSopenharmony_ci     */
281275793eaSopenharmony_ci
282275793eaSopenharmony_ci} FAR deflate_state;
283275793eaSopenharmony_ci
284275793eaSopenharmony_ci/* Output a byte on the stream.
285275793eaSopenharmony_ci * IN assertion: there is enough room in pending_buf.
286275793eaSopenharmony_ci */
287275793eaSopenharmony_ci#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
288275793eaSopenharmony_ci
289275793eaSopenharmony_ci
290275793eaSopenharmony_ci#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
291275793eaSopenharmony_ci/* Minimum amount of lookahead, except at the end of the input file.
292275793eaSopenharmony_ci * See deflate.c for comments about the MIN_MATCH+1.
293275793eaSopenharmony_ci */
294275793eaSopenharmony_ci
295275793eaSopenharmony_ci#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
296275793eaSopenharmony_ci/* In order to simplify the code, particularly on 16 bit machines, match
297275793eaSopenharmony_ci * distances are limited to MAX_DIST instead of WSIZE.
298275793eaSopenharmony_ci */
299275793eaSopenharmony_ci
300275793eaSopenharmony_ci#define WIN_INIT MAX_MATCH
301275793eaSopenharmony_ci/* Number of bytes after end of data in window to initialize in order to avoid
302275793eaSopenharmony_ci   memory checker errors from longest match routines */
303275793eaSopenharmony_ci
304275793eaSopenharmony_ci        /* in trees.c */
305275793eaSopenharmony_civoid ZLIB_INTERNAL _tr_init(deflate_state *s);
306275793eaSopenharmony_ciint ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
307275793eaSopenharmony_civoid ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
308275793eaSopenharmony_ci                                   ulg stored_len, int last);
309275793eaSopenharmony_civoid ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
310275793eaSopenharmony_civoid ZLIB_INTERNAL _tr_align(deflate_state *s);
311275793eaSopenharmony_civoid ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
312275793eaSopenharmony_ci                                    ulg stored_len, int last);
313275793eaSopenharmony_ci
314275793eaSopenharmony_ci#define d_code(dist) \
315275793eaSopenharmony_ci   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
316275793eaSopenharmony_ci/* Mapping from a distance to a distance code. dist is the distance - 1 and
317275793eaSopenharmony_ci * must not have side effects. _dist_code[256] and _dist_code[257] are never
318275793eaSopenharmony_ci * used.
319275793eaSopenharmony_ci */
320275793eaSopenharmony_ci
321275793eaSopenharmony_ci#ifndef ZLIB_DEBUG
322275793eaSopenharmony_ci/* Inline versions of _tr_tally for speed: */
323275793eaSopenharmony_ci
324275793eaSopenharmony_ci#if defined(GEN_TREES_H) || !defined(STDC)
325275793eaSopenharmony_ci  extern uch ZLIB_INTERNAL _length_code[];
326275793eaSopenharmony_ci  extern uch ZLIB_INTERNAL _dist_code[];
327275793eaSopenharmony_ci#else
328275793eaSopenharmony_ci  extern const uch ZLIB_INTERNAL _length_code[];
329275793eaSopenharmony_ci  extern const uch ZLIB_INTERNAL _dist_code[];
330275793eaSopenharmony_ci#endif
331275793eaSopenharmony_ci
332275793eaSopenharmony_ci#ifdef LIT_MEM
333275793eaSopenharmony_ci# define _tr_tally_lit(s, c, flush) \
334275793eaSopenharmony_ci  { uch cc = (c); \
335275793eaSopenharmony_ci    s->d_buf[s->sym_next] = 0; \
336275793eaSopenharmony_ci    s->l_buf[s->sym_next++] = cc; \
337275793eaSopenharmony_ci    s->dyn_ltree[cc].Freq++; \
338275793eaSopenharmony_ci    flush = (s->sym_next == s->sym_end); \
339275793eaSopenharmony_ci   }
340275793eaSopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
341275793eaSopenharmony_ci  { uch len = (uch)(length); \
342275793eaSopenharmony_ci    ush dist = (ush)(distance); \
343275793eaSopenharmony_ci    s->d_buf[s->sym_next] = dist; \
344275793eaSopenharmony_ci    s->l_buf[s->sym_next++] = len; \
345275793eaSopenharmony_ci    dist--; \
346275793eaSopenharmony_ci    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
347275793eaSopenharmony_ci    s->dyn_dtree[d_code(dist)].Freq++; \
348275793eaSopenharmony_ci    flush = (s->sym_next == s->sym_end); \
349275793eaSopenharmony_ci  }
350275793eaSopenharmony_ci#else
351275793eaSopenharmony_ci# define _tr_tally_lit(s, c, flush) \
352275793eaSopenharmony_ci  { uch cc = (c); \
353275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = 0; \
354275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = 0; \
355275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = cc; \
356275793eaSopenharmony_ci    s->dyn_ltree[cc].Freq++; \
357275793eaSopenharmony_ci    flush = (s->sym_next == s->sym_end); \
358275793eaSopenharmony_ci   }
359275793eaSopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
360275793eaSopenharmony_ci  { uch len = (uch)(length); \
361275793eaSopenharmony_ci    ush dist = (ush)(distance); \
362275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = (uch)dist; \
363275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
364275793eaSopenharmony_ci    s->sym_buf[s->sym_next++] = len; \
365275793eaSopenharmony_ci    dist--; \
366275793eaSopenharmony_ci    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
367275793eaSopenharmony_ci    s->dyn_dtree[d_code(dist)].Freq++; \
368275793eaSopenharmony_ci    flush = (s->sym_next == s->sym_end); \
369275793eaSopenharmony_ci  }
370275793eaSopenharmony_ci#endif
371275793eaSopenharmony_ci#else
372275793eaSopenharmony_ci# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
373275793eaSopenharmony_ci# define _tr_tally_dist(s, distance, length, flush) \
374275793eaSopenharmony_ci              flush = _tr_tally(s, distance, length)
375275793eaSopenharmony_ci#endif
376275793eaSopenharmony_ci
377275793eaSopenharmony_ci#endif /* DEFLATE_H */
378