aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorAaron Lehmann <aaronl@vitelius.com>2001-12-06 03:22:43 +0000
committerAaron Lehmann <aaronl@vitelius.com>2001-12-06 03:22:43 +0000
commitb9df470c4d886f03b26d9277ec059130e6472f40 (patch)
tree065055425b665de749ec94e478da724e199f48a4 /libbb
parent249f39a2650a1f002803b59c4be82ee98fca5652 (diff)
downloadbusybox-w32-b9df470c4d886f03b26d9277ec059130e6472f40.tar.gz
busybox-w32-b9df470c4d886f03b26d9277ec059130e6472f40.tar.bz2
busybox-w32-b9df470c4d886f03b26d9277ec059130e6472f40.zip
Commit my improvement on Rodney Brown's patch to g(un)zip, decreasing
binary size.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/unzip.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/libbb/unzip.c b/libbb/unzip.c
index a747baea5..6c3f3229a 100644
--- a/libbb/unzip.c
+++ b/libbb/unzip.c
@@ -186,6 +186,8 @@ static int huft_free(huft_t *t)
186 return 0; 186 return 0;
187} 187}
188 188
189typedef unsigned char extra_bits_t;
190
189/* Given a list of code lengths and a maximum table size, make a set of 191/* Given a list of code lengths and a maximum table size, make a set of
190 * tables to decode that set of codes. Return zero on success, one if 192 * tables to decode that set of codes. Return zero on success, one if
191 * the given code set is incomplete (the tables are still built in this 193 * the given code set is incomplete (the tables are still built in this
@@ -201,7 +203,7 @@ static int huft_free(huft_t *t)
201 * m: maximum lookup bits, returns actual 203 * m: maximum lookup bits, returns actual
202 */ 204 */
203static int huft_build(unsigned int *b, const unsigned int n, const unsigned int s, 205static int huft_build(unsigned int *b, const unsigned int n, const unsigned int s,
204 const unsigned short *d, const unsigned short *e, huft_t **t, int *m) 206 const unsigned short *d, const extra_bits_t *e, huft_t **t, int *m)
205{ 207{
206 unsigned a; /* counter for codes of length k */ 208 unsigned a; /* counter for codes of length k */
207 unsigned c[BMAX + 1]; /* bit length count table */ 209 unsigned c[BMAX + 1]; /* bit length count table */
@@ -489,6 +491,30 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd)
489 return 0; 491 return 0;
490} 492}
491 493
494static const unsigned short cplens[] = { /* Copy lengths for literal codes 257..285 */
495 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
496 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
497};
498/* note: see note #13 above about the 258 in this list. */
499static const extra_bits_t cplext[] = { /* Extra bits for literal codes 257..285 */
500 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
501 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
502}; /* 99==invalid */
503static const unsigned short cpdist[] = { /* Copy offsets for distance codes 0..29 */
504 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
505 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
506 8193, 12289, 16385, 24577
507};
508static const extra_bits_t cpdext[] = { /* Extra bits for distance codes */
509 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
510 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
511 12, 12, 13, 13
512};
513/* Tables for deflate from PKZIP's appnote.txt. */
514static const extra_bits_t border[] = { /* Order of the bit length code lengths */
515 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
516};
517
492/* 518/*
493 * decompress an inflated block 519 * decompress an inflated block
494 * e: last block flag 520 * e: last block flag
@@ -500,25 +526,6 @@ static int inflate_block(int *e)
500 unsigned t; /* block type */ 526 unsigned t; /* block type */
501 register unsigned long b; /* bit buffer */ 527 register unsigned long b; /* bit buffer */
502 register unsigned k; /* number of bits in bit buffer */ 528 register unsigned k; /* number of bits in bit buffer */
503 static unsigned short cplens[] = { /* Copy lengths for literal codes 257..285 */
504 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
505 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
506 };
507 /* note: see note #13 above about the 258 in this list. */
508 static unsigned short cplext[] = { /* Extra bits for literal codes 257..285 */
509 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
510 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
511 }; /* 99==invalid */
512 static unsigned short cpdist[] = { /* Copy offsets for distance codes 0..29 */
513 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
514 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
515 8193, 12289, 16385, 24577
516 };
517 static unsigned short cpdext[] = { /* Extra bits for distance codes */
518 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
519 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
520 12, 12, 13, 13
521 };
522 529
523 /* make local bit buffer */ 530 /* make local bit buffer */
524 b = bb; 531 b = bb;
@@ -657,12 +664,8 @@ static int inflate_block(int *e)
657 } 664 }
658 case 2: /* Inflate dynamic */ 665 case 2: /* Inflate dynamic */
659 { 666 {
660 /* Tables for deflate from PKZIP's appnote.txt. */ 667 const int dbits = 6; /* bits in base distance lookup table */
661 static unsigned border[] = { /* Order of the bit length code lengths */ 668 const int lbits = 9; /* bits in base literal/length lookup table */
662 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
663 };
664 int dbits = 6; /* bits in base distance lookup table */
665 int lbits = 9; /* bits in base literal/length lookup table */
666 669
667 int i; /* temporary variables */ 670 int i; /* temporary variables */
668 unsigned j; 671 unsigned j;