aboutsummaryrefslogtreecommitdiff
path: root/archival/gzip.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-07 19:40:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-07 19:40:34 +0000
commit89af56b3e533fe910324333ae36d811e17f02f98 (patch)
tree20d7a047fa715ae13e99922699f977a65deeb710 /archival/gzip.c
parent52933d47bd86d6d992f7290fad93d63b53f7a15f (diff)
downloadbusybox-w32-89af56b3e533fe910324333ae36d811e17f02f98.tar.gz
busybox-w32-89af56b3e533fe910324333ae36d811e17f02f98.tar.bz2
busybox-w32-89af56b3e533fe910324333ae36d811e17f02f98.zip
gzip cleanup part #9
Diffstat (limited to 'archival/gzip.c')
-rw-r--r--archival/gzip.c189
1 files changed, 84 insertions, 105 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index 2c8f69d91..c882a4a2a 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -67,6 +67,7 @@ aa: 85.1% -- replaced with aa.gz
67# endif 67# endif
68#endif 68#endif
69 69
70//remove??
70#define INBUF_EXTRA 64 /* required by unlzw() */ 71#define INBUF_EXTRA 64 /* required by unlzw() */
71 72
72#ifndef OUTBUFSIZ 73#ifndef OUTBUFSIZ
@@ -76,6 +77,7 @@ aa: 85.1% -- replaced with aa.gz
76# define OUTBUFSIZ 16384 /* output buffer size */ 77# define OUTBUFSIZ 16384 /* output buffer size */
77# endif 78# endif
78#endif 79#endif
80//remove??
79#define OUTBUF_EXTRA 2048 /* required by unlzw() */ 81#define OUTBUF_EXTRA 2048 /* required by unlzw() */
80 82
81#ifndef DIST_BUFSIZE 83#ifndef DIST_BUFSIZE
@@ -166,15 +168,6 @@ aa: 85.1% -- replaced with aa.gz
166 /* For portability to 16 bit machines, do not use values above 15. */ 168 /* For portability to 16 bit machines, do not use values above 15. */
167#endif 169#endif
168 170
169/* To save space (see unlzw.c), we overlay prev+head with tab_prefix and
170 * window with tab_suffix. Check that we can do this:
171 */
172#if (WSIZE<<1) > (1<<BITS)
173# error cannot overlay window with tab_suffix and prev with tab_prefix0
174#endif
175#if HASH_BITS > BITS-1
176# error cannot overlay head with tab_prefix1
177#endif
178#define HASH_SIZE (unsigned)(1<<HASH_BITS) 171#define HASH_SIZE (unsigned)(1<<HASH_BITS)
179#define HASH_MASK (HASH_SIZE-1) 172#define HASH_MASK (HASH_SIZE-1)
180#define WMASK (WSIZE-1) 173#define WMASK (WSIZE-1)
@@ -213,26 +206,6 @@ typedef unsigned IPos;
213 array = NULL; \ 206 array = NULL; \
214} 207}
215 208
216/* DECLARE(uch, window, 2L*WSIZE); */
217/* Sliding window. Input bytes are read into the second half of the window,
218 * and move to the first half later to keep a dictionary of at least WSIZE
219 * bytes. With this organization, matches are limited to a distance of
220 * WSIZE-MAX_MATCH bytes, but this ensures that IO is always
221 * performed with a length multiple of the block size. Also, it limits
222 * the window size to 64K, which is quite useful on MSDOS.
223 * To do: limit the window size to WSIZE+BSZ if SMALL_MEM (the code would
224 * be less efficient).
225 */
226
227/* DECLARE(Pos, prev, WSIZE); */
228/* Link to older string with same hash index. To limit the size of this
229 * array to 64K, this link is maintained only for the last 32K strings.
230 * An index in this array is thus a window index modulo 32K.
231 */
232
233/* DECLARE(Pos, head, 1<<HASH_BITS); */
234/* Heads of the hash chains or 0. */
235
236static long block_start; 209static long block_start;
237 210
238/* window position at the beginning of the current output block. Gets 211/* window position at the beginning of the current output block. Gets
@@ -300,7 +273,6 @@ enum {
300 273
301 274
302/* =========================================================================== 275/* ===========================================================================
303 * Prototypes for local functions.
304 */ 276 */
305static void fill_window(void); 277static void fill_window(void);
306 278
@@ -311,41 +283,59 @@ static void check_match(IPos start, IPos match, int length);
311#endif 283#endif
312 284
313 285
314/* from deflate.c */
315static void lm_init(ush * flags);
316static ulg deflate(void);
317
318/* from trees.c */ 286/* from trees.c */
319static void ct_init(ush * attr, int *methodp);
320static int ct_tally(int dist, int lc); 287static int ct_tally(int dist, int lc);
321static ulg flush_block(char *buf, ulg stored_len, int eof); 288static ulg flush_block(char *buf, ulg stored_len, int eof);
322 289
323/* from bits.c */
324static void bi_init(int zipfile);
325static void send_bits(int value, int length);
326static unsigned bi_reverse(unsigned value, int length);
327static void bi_windup(void);
328static void copy_block(char *buf, unsigned len, int header);
329
330/* global buffers */ 290/* global buffers */
331 291
332/* To save memory for 16 bit systems, some arrays are overlaid between 292/* To save memory for 16 bit systems, some arrays are overlaid between
333 * the various modules: 293 * the various modules:
334 * deflate: prev+head window d_buf l_buf outbuf 294 * deflate: prev+head window d_buf l_buf outbuf
335 * unlzw: tab_prefix tab_suffix stack inbuf outbuf 295 * unlzw: tab_prefix tab_suffix stack inbuf outbuf
296//remove unlzw??
336 * For compression, input is done in window[]. For decompression, output 297 * For compression, input is done in window[]. For decompression, output
337 * is done in window except for unlzw. 298 * is done in window except for unlzw.
338 */ 299 */
300/* To save space (see unlzw.c), we overlay prev+head with tab_prefix and
301 * window with tab_suffix. Check that we can do this:
302 */
303#if (WSIZE<<1) > (1<<BITS)
304# error cannot overlay window with tab_suffix and prev with tab_prefix0
305#endif
306#if HASH_BITS > BITS-1
307# error cannot overlay head with tab_prefix1
308#endif
339 309
340#define tab_suffix window 310//#define tab_suffix window
341#define tab_prefix prev /* hash link (see deflate.c) */ 311//#define tab_prefix prev /* hash link (see deflate.c) */
342#define head (prev+WSIZE) /* hash head (see deflate.c) */ 312#define head (prev+WSIZE) /* hash head (see deflate.c) */
343 313
344DECLARE(uch, inbuf, INBUFSIZ + INBUF_EXTRA); 314/* DECLARE(uch, window, 2L*WSIZE); */
315/* Sliding window. Input bytes are read into the second half of the window,
316 * and move to the first half later to keep a dictionary of at least WSIZE
317 * bytes. With this organization, matches are limited to a distance of
318 * WSIZE-MAX_MATCH bytes, but this ensures that IO is always
319 * performed with a length multiple of the block size. Also, it limits
320 * the window size to 64K, which is quite useful on MSDOS.
321 * To do: limit the window size to WSIZE+BSZ if SMALL_MEM (the code would
322 * be less efficient).
323 */
324
325/* DECLARE(Pos, prev, WSIZE); */
326/* Link to older string with same hash index. To limit the size of this
327 * array to 64K, this link is maintained only for the last 32K strings.
328 * An index in this array is thus a window index modulo 32K.
329 */
330
331/* DECLARE(Pos, head, 1<<HASH_BITS); */
332/* Heads of the hash chains or 0. */
333
334DECLARE(uch, inbuf, INBUFSIZ + INBUF_EXTRA); //remove + XX_EXTRA (unlzw)??
345DECLARE(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA); 335DECLARE(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA);
346DECLARE(ush, d_buf, DIST_BUFSIZE); 336DECLARE(ush, d_buf, DIST_BUFSIZE);
347DECLARE(uch, window, 2L * WSIZE); 337DECLARE(uch, window, 2L * WSIZE);
348DECLARE(ush, tab_prefix, 1L << BITS); 338DECLARE(ush, prev, 1L << BITS);
349 339
350static long isize; /* number of input bytes */ 340static long isize; /* number of input bytes */
351 341
@@ -544,11 +534,12 @@ static unsigned bi_reverse(unsigned code, int len)
544{ 534{
545 unsigned res = 0; 535 unsigned res = 0;
546 536
547 do { 537 while (1) {
548 res |= code & 1; 538 res |= code & 1;
549 code >>= 1, res <<= 1; 539 if (--len <= 0) return res;
550 } while (--len > 0); 540 code >>= 1;
551 return res >> 1; 541 res <<= 1;
542 }
552} 543}
553 544
554 545
@@ -957,14 +948,11 @@ static ulg deflate(void)
957 * terms of the GNU General Public License, see the file COPYING. 948 * terms of the GNU General Public License, see the file COPYING.
958 */ 949 */
959 950
960/* 951/* PURPOSE
961 * PURPOSE
962 *
963 * Encode various sets of source values using variable-length 952 * Encode various sets of source values using variable-length
964 * binary code trees. 953 * binary code trees.
965 * 954 *
966 * DISCUSSION 955 * DISCUSSION
967 *
968 * The PKZIP "deflation" process uses several Huffman trees. The more 956 * The PKZIP "deflation" process uses several Huffman trees. The more
969 * common source values are represented by shorter bit sequences. 957 * common source values are represented by shorter bit sequences.
970 * 958 *
@@ -976,7 +964,6 @@ static ulg deflate(void)
976 * (APPNOTE.TXT) distributed as part of PKWARE's PKZIP program. 964 * (APPNOTE.TXT) distributed as part of PKWARE's PKZIP program.
977 * 965 *
978 * REFERENCES 966 * REFERENCES
979 *
980 * Lynch, Thomas J. 967 * Lynch, Thomas J.
981 * Data Compression: Techniques and Applications, pp. 53-55. 968 * Data Compression: Techniques and Applications, pp. 53-55.
982 * Lifetime Learning Publications, 1985. ISBN 0-534-03418-7. 969 * Lifetime Learning Publications, 1985. ISBN 0-534-03418-7.
@@ -990,7 +977,6 @@ static ulg deflate(void)
990 * Addison-Wesley, 1983. ISBN 0-201-06672-6. 977 * Addison-Wesley, 1983. ISBN 0-201-06672-6.
991 * 978 *
992 * INTERFACE 979 * INTERFACE
993 *
994 * void ct_init(ush *attr, int *methodp) 980 * void ct_init(ush *attr, int *methodp)
995 * Allocate the match buffer, initialize the various tables and save 981 * Allocate the match buffer, initialize the various tables and save
996 * the location of the internal file attribute (ascii/binary) and 982 * the location of the internal file attribute (ascii/binary) and
@@ -1003,7 +989,6 @@ static ulg deflate(void)
1003 * Determine the best encoding for the current block: dynamic trees, 989 * Determine the best encoding for the current block: dynamic trees,
1004 * static trees or store, and output the encoded block to the zip 990 * static trees or store, and output the encoded block to the zip
1005 * file. Returns the total compressed length for the file so far. 991 * file. Returns the total compressed length for the file so far.
1006 *
1007 */ 992 */
1008 993
1009/* =========================================================================== 994/* ===========================================================================
@@ -1037,20 +1022,20 @@ static ulg deflate(void)
1037typedef uch extra_bits_t; 1022typedef uch extra_bits_t;
1038 1023
1039/* extra bits for each length code */ 1024/* extra bits for each length code */
1040static const extra_bits_t extra_lbits[LENGTH_CODES] 1025static const extra_bits_t extra_lbits[LENGTH_CODES]= {
1041 = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 1026 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
1042 4, 4, 5, 5, 5, 5, 0 1027 4, 4, 5, 5, 5, 5, 0
1043}; 1028};
1044 1029
1045/* extra bits for each distance code */ 1030/* extra bits for each distance code */
1046static const extra_bits_t extra_dbits[D_CODES] 1031static const extra_bits_t extra_dbits[D_CODES] = {
1047 = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 1032 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
1048 10, 10, 11, 11, 12, 12, 13, 13 1033 10, 10, 11, 11, 12, 12, 13, 13
1049}; 1034};
1050 1035
1051/* extra bits for each bit length code */ 1036/* extra bits for each bit length code */
1052static const extra_bits_t extra_blbits[BL_CODES] 1037static const extra_bits_t extra_blbits[BL_CODES] = {
1053= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; 1038 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 };
1054 1039
1055#define STORED_BLOCK 0 1040#define STORED_BLOCK 0
1056#define STATIC_TREES 1 1041#define STATIC_TREES 1
@@ -1245,11 +1230,8 @@ static ush *file_type; /* pointer to UNKNOWN, BINARY or ASCII */
1245static int *file_method; /* pointer to DEFLATE or STORE */ 1230static int *file_method; /* pointer to DEFLATE or STORE */
1246 1231
1247/* =========================================================================== 1232/* ===========================================================================
1248 * Local (static) routines in this file.
1249 */ 1233 */
1250
1251static void init_block(void); 1234static void init_block(void);
1252static void pqdownheap(ct_data * tree, int k);
1253static void gen_bitlen(tree_desc * desc); 1235static void gen_bitlen(tree_desc * desc);
1254static void gen_codes(ct_data * tree, int max_code); 1236static void gen_codes(ct_data * tree, int max_code);
1255static void build_tree(tree_desc * desc); 1237static void build_tree(tree_desc * desc);
@@ -1263,16 +1245,16 @@ static void set_file_type(void);
1263 1245
1264#ifndef DEBUG 1246#ifndef DEBUG
1265/* Send a code of the given tree. c and tree must not have side effects */ 1247/* Send a code of the given tree. c and tree must not have side effects */
1266# define send_code(c, tree) send_bits(tree[c].Code, tree[c].Len) 1248# define SEND_CODE(c, tree) send_bits(tree[c].Code, tree[c].Len)
1267#else /* DEBUG */ 1249#else
1268# define send_code(c, tree) \ 1250# define SEND_CODE(c, tree) \
1269{ \ 1251{ \
1270 if (verbose > 1) bb_error_msg("\ncd %3d ",(c)); \ 1252 if (verbose > 1) bb_error_msg("\ncd %3d ",(c)); \
1271 send_bits(tree[c].Code, tree[c].Len); \ 1253 send_bits(tree[c].Code, tree[c].Len); \
1272} 1254}
1273#endif 1255#endif
1274 1256
1275#define d_code(dist) \ 1257#define D_CODE(dist) \
1276 ((dist) < 256 ? dist_code[dist] : dist_code[256 + ((dist)>>7)]) 1258 ((dist) < 256 ? dist_code[dist] : dist_code[256 + ((dist)>>7)])
1277/* Mapping from a distance to a distance code. dist is the distance - 1 and 1259/* Mapping from a distance to a distance code. dist is the distance - 1 and
1278 * must not have side effects. dist_code[256] and dist_code[257] are never 1260 * must not have side effects. dist_code[256] and dist_code[257] are never
@@ -1397,22 +1379,6 @@ static void init_block(void)
1397 1379
1398 1380
1399/* =========================================================================== 1381/* ===========================================================================
1400 * Remove the smallest element from the heap and recreate the heap with
1401 * one less element. Updates heap and heap_len.
1402 */
1403
1404#define SMALLEST 1
1405/* Index within the heap array of least frequent node in the Huffman tree */
1406
1407#define pqremove(tree, top) \
1408{ \
1409 top = heap[SMALLEST]; \
1410 heap[SMALLEST] = heap[heap_len--]; \
1411 pqdownheap(tree, SMALLEST); \
1412}
1413
1414
1415/* ===========================================================================
1416 * Restore the heap property by moving down the tree starting at node k, 1382 * Restore the heap property by moving down the tree starting at node k,
1417 * exchanging a node with the smallest of its two sons if necessary, stopping 1383 * exchanging a node with the smallest of its two sons if necessary, stopping
1418 * when the heap property is re-established (each father smaller than its 1384 * when the heap property is re-established (each father smaller than its
@@ -1420,9 +1386,8 @@ static void init_block(void)
1420 */ 1386 */
1421 1387
1422/* Compares to subtrees, using the tree depth as tie breaker when 1388/* Compares to subtrees, using the tree depth as tie breaker when
1423 * the subtrees have equal frequency. This minimizes the worst case length. 1389 * the subtrees have equal frequency. This minimizes the worst case length. */
1424 */ 1390#define SMALLER(tree, n, m) \
1425#define smaller(tree, n, m) \
1426 (tree[n].Freq < tree[m].Freq \ 1391 (tree[n].Freq < tree[m].Freq \
1427 || (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) 1392 || (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
1428 1393
@@ -1433,11 +1398,11 @@ static void pqdownheap(ct_data * tree, int k)
1433 1398
1434 while (j <= heap_len) { 1399 while (j <= heap_len) {
1435 /* Set j to the smallest of the two sons: */ 1400 /* Set j to the smallest of the two sons: */
1436 if (j < heap_len && smaller(tree, heap[j + 1], heap[j])) 1401 if (j < heap_len && SMALLER(tree, heap[j + 1], heap[j]))
1437 j++; 1402 j++;
1438 1403
1439 /* Exit if v is smaller than both sons */ 1404 /* Exit if v is smaller than both sons */
1440 if (smaller(tree, v, heap[j])) 1405 if (SMALLER(tree, v, heap[j]))
1441 break; 1406 break;
1442 1407
1443 /* Exchange v with the smallest son */ 1408 /* Exchange v with the smallest son */
@@ -1599,6 +1564,20 @@ static void gen_codes(ct_data * tree, int max_code)
1599 * and corresponding code. The length opt_len is updated; static_len is 1564 * and corresponding code. The length opt_len is updated; static_len is
1600 * also updated if stree is not null. The field max_code is set. 1565 * also updated if stree is not null. The field max_code is set.
1601 */ 1566 */
1567
1568/* Remove the smallest element from the heap and recreate the heap with
1569 * one less element. Updates heap and heap_len. */
1570
1571#define SMALLEST 1
1572/* Index within the heap array of least frequent node in the Huffman tree */
1573
1574#define PQREMOVE(tree, top) \
1575{ \
1576 top = heap[SMALLEST]; \
1577 heap[SMALLEST] = heap[heap_len--]; \
1578 pqdownheap(tree, SMALLEST); \
1579}
1580
1602static void build_tree(tree_desc * desc) 1581static void build_tree(tree_desc * desc)
1603{ 1582{
1604 ct_data *tree = desc->dyn_tree; 1583 ct_data *tree = desc->dyn_tree;
@@ -1650,7 +1629,7 @@ static void build_tree(tree_desc * desc)
1650 * frequent nodes. 1629 * frequent nodes.
1651 */ 1630 */
1652 do { 1631 do {
1653 pqremove(tree, n); /* n = node of least frequency */ 1632 PQREMOVE(tree, n); /* n = node of least frequency */
1654 m = heap[SMALLEST]; /* m = node of next least frequency */ 1633 m = heap[SMALLEST]; /* m = node of next least frequency */
1655 1634
1656 heap[--heap_max] = n; /* keep the nodes sorted by frequency */ 1635 heap[--heap_max] = n; /* keep the nodes sorted by frequency */
@@ -1761,21 +1740,21 @@ static void send_tree(ct_data * tree, int max_code)
1761 continue; 1740 continue;
1762 } else if (count < min_count) { 1741 } else if (count < min_count) {
1763 do { 1742 do {
1764 send_code(curlen, bl_tree); 1743 SEND_CODE(curlen, bl_tree);
1765 } while (--count); 1744 } while (--count);
1766 } else if (curlen != 0) { 1745 } else if (curlen != 0) {
1767 if (curlen != prevlen) { 1746 if (curlen != prevlen) {
1768 send_code(curlen, bl_tree); 1747 SEND_CODE(curlen, bl_tree);
1769 count--; 1748 count--;
1770 } 1749 }
1771 Assert(count >= 3 && count <= 6, " 3_6?"); 1750 Assert(count >= 3 && count <= 6, " 3_6?");
1772 send_code(REP_3_6, bl_tree); 1751 SEND_CODE(REP_3_6, bl_tree);
1773 send_bits(count - 3, 2); 1752 send_bits(count - 3, 2);
1774 } else if (count <= 10) { 1753 } else if (count <= 10) {
1775 send_code(REPZ_3_10, bl_tree); 1754 SEND_CODE(REPZ_3_10, bl_tree);
1776 send_bits(count - 3, 3); 1755 send_bits(count - 3, 3);
1777 } else { 1756 } else {
1778 send_code(REPZ_11_138, bl_tree); 1757 SEND_CODE(REPZ_11_138, bl_tree);
1779 send_bits(count - 11, 7); 1758 send_bits(count - 11, 7);
1780 } 1759 }
1781 count = 0; 1760 count = 0;
@@ -1964,11 +1943,11 @@ static int ct_tally(int dist, int lc)
1964 dist--; /* dist = match distance - 1 */ 1943 dist--; /* dist = match distance - 1 */
1965 Assert((ush) dist < (ush) MAX_DIST 1944 Assert((ush) dist < (ush) MAX_DIST
1966 && (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH) 1945 && (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH)
1967 && (ush) d_code(dist) < (ush) D_CODES, "ct_tally: bad match" 1946 && (ush) D_CODE(dist) < (ush) D_CODES, "ct_tally: bad match"
1968 ); 1947 );
1969 1948
1970 dyn_ltree[length_code[lc] + LITERALS + 1].Freq++; 1949 dyn_ltree[length_code[lc] + LITERALS + 1].Freq++;
1971 dyn_dtree[d_code(dist)].Freq++; 1950 dyn_dtree[D_CODE(dist)].Freq++;
1972 1951
1973 d_buf[last_dist++] = dist; 1952 d_buf[last_dist++] = dist;
1974 flags |= flag_bit; 1953 flags |= flag_bit;
@@ -2025,12 +2004,12 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
2025 flag = flag_buf[fx++]; 2004 flag = flag_buf[fx++];
2026 lc = l_buf[lx++]; 2005 lc = l_buf[lx++];
2027 if ((flag & 1) == 0) { 2006 if ((flag & 1) == 0) {
2028 send_code(lc, ltree); /* send a literal byte */ 2007 SEND_CODE(lc, ltree); /* send a literal byte */
2029 Tracecv(isgraph(lc), (stderr, " '%c' ", lc)); 2008 Tracecv(isgraph(lc), (stderr, " '%c' ", lc));
2030 } else { 2009 } else {
2031 /* Here, lc is the match length - MIN_MATCH */ 2010 /* Here, lc is the match length - MIN_MATCH */
2032 code = length_code[lc]; 2011 code = length_code[lc];
2033 send_code(code + LITERALS + 1, ltree); /* send the length code */ 2012 SEND_CODE(code + LITERALS + 1, ltree); /* send the length code */
2034 extra = extra_lbits[code]; 2013 extra = extra_lbits[code];
2035 if (extra != 0) { 2014 if (extra != 0) {
2036 lc -= base_length[code]; 2015 lc -= base_length[code];
@@ -2038,10 +2017,10 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
2038 } 2017 }
2039 dist = d_buf[dx++]; 2018 dist = d_buf[dx++];
2040 /* Here, dist is the match distance - 1 */ 2019 /* Here, dist is the match distance - 1 */
2041 code = d_code(dist); 2020 code = D_CODE(dist);
2042 Assert(code < D_CODES, "bad d_code"); 2021 Assert(code < D_CODES, "bad d_code");
2043 2022
2044 send_code(code, dtree); /* send the distance code */ 2023 SEND_CODE(code, dtree); /* send the distance code */
2045 extra = extra_dbits[code]; 2024 extra = extra_dbits[code];
2046 if (extra != 0) { 2025 if (extra != 0) {
2047 dist -= base_dist[code]; 2026 dist -= base_dist[code];
@@ -2052,7 +2031,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
2052 } while (lx < last_lit); 2031 } while (lx < last_lit);
2053 } 2032 }
2054 2033
2055 send_code(END_BLOCK, ltree); 2034 SEND_CODE(END_BLOCK, ltree);
2056} 2035}
2057 2036
2058/* =========================================================================== 2037/* ===========================================================================
@@ -2192,7 +2171,7 @@ int gzip_main(int argc, char **argv)
2192 ALLOC(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA); 2171 ALLOC(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA);
2193 ALLOC(ush, d_buf, DIST_BUFSIZE); 2172 ALLOC(ush, d_buf, DIST_BUFSIZE);
2194 ALLOC(uch, window, 2L * WSIZE); 2173 ALLOC(uch, window, 2L * WSIZE);
2195 ALLOC(ush, tab_prefix, 1L << BITS); 2174 ALLOC(ush, prev, 1L << BITS);
2196 2175
2197 /* Initialise the CRC32 table */ 2176 /* Initialise the CRC32 table */
2198 crc_32_tab = crc32_filltable(0); 2177 crc_32_tab = crc32_filltable(0);