Run through indent
This commit is contained in:
195
archival/gzip.c
195
archival/gzip.c
@ -212,31 +212,31 @@ typedef int file_t; /* Do not use stdio */
|
|||||||
|
|
||||||
|
|
||||||
/* from zip.c: */
|
/* from zip.c: */
|
||||||
static int zip (int in, int out);
|
static int zip(int in, int out);
|
||||||
static int file_read (char *buf, unsigned size);
|
static int file_read(char *buf, unsigned size);
|
||||||
|
|
||||||
/* from gzip.c */
|
/* from gzip.c */
|
||||||
static RETSIGTYPE abort_gzip (void);
|
static RETSIGTYPE abort_gzip(void);
|
||||||
|
|
||||||
/* from deflate.c */
|
/* from deflate.c */
|
||||||
static void lm_init (ush * flags);
|
static void lm_init(ush * flags);
|
||||||
static ulg deflate (void);
|
static ulg deflate(void);
|
||||||
|
|
||||||
/* from trees.c */
|
/* from trees.c */
|
||||||
static void ct_init (ush * attr, int *methodp);
|
static void ct_init(ush * attr, int *methodp);
|
||||||
static int ct_tally (int dist, int lc);
|
static int ct_tally(int dist, int lc);
|
||||||
static ulg flush_block (char *buf, ulg stored_len, int eof);
|
static ulg flush_block(char *buf, ulg stored_len, int eof);
|
||||||
|
|
||||||
/* from bits.c */
|
/* from bits.c */
|
||||||
static void bi_init (file_t zipfile);
|
static void bi_init(file_t zipfile);
|
||||||
static void send_bits (int value, int length);
|
static void send_bits(int value, int length);
|
||||||
static unsigned bi_reverse (unsigned value, int length);
|
static unsigned bi_reverse(unsigned value, int length);
|
||||||
static void bi_windup (void);
|
static void bi_windup(void);
|
||||||
static void copy_block (char *buf, unsigned len, int header);
|
static void copy_block(char *buf, unsigned len, int header);
|
||||||
static int (*read_buf) (char *buf, unsigned size);
|
static int (*read_buf) (char *buf, unsigned size);
|
||||||
|
|
||||||
/* from util.c: */
|
/* from util.c: */
|
||||||
static void flush_outbuf (void);
|
static void flush_outbuf(void);
|
||||||
|
|
||||||
/* lzw.h -- define the lzw functions.
|
/* lzw.h -- define the lzw functions.
|
||||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||||
@ -326,12 +326,12 @@ static unsigned outcnt; /* bytes in output buffer */
|
|||||||
/* Output a 16 bit value, lsb first */
|
/* Output a 16 bit value, lsb first */
|
||||||
static void put_short(ush w)
|
static void put_short(ush w)
|
||||||
{
|
{
|
||||||
if (outcnt < OUTBUFSIZ-2) {
|
if (outcnt < OUTBUFSIZ - 2) {
|
||||||
outbuf[outcnt++] = (uch) ((w) & 0xff);
|
outbuf[outcnt++] = (uch) ((w) & 0xff);
|
||||||
outbuf[outcnt++] = (uch) ((ush)(w) >> 8);
|
outbuf[outcnt++] = (uch) ((ush) (w) >> 8);
|
||||||
} else {
|
} else {
|
||||||
put_byte((uch)((w) & 0xff));
|
put_byte((uch) ((w) & 0xff));
|
||||||
put_byte((uch)((ush)(w) >> 8));
|
put_byte((uch) ((ush) (w) >> 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,11 +382,12 @@ static void write_buf(int fd, void *buf, unsigned cnt)
|
|||||||
* pointer, then initialize the crc shift register contents instead.
|
* pointer, then initialize the crc shift register contents instead.
|
||||||
* Return the current crc in either case.
|
* Return the current crc in either case.
|
||||||
*/
|
*/
|
||||||
static ulg updcrc(uch *s, unsigned n)
|
static ulg updcrc(uch * s, unsigned n)
|
||||||
{
|
{
|
||||||
static ulg crc = (ulg) 0xffffffffL; /* shift register contents */
|
static ulg crc = (ulg) 0xffffffffL; /* shift register contents */
|
||||||
register ulg c; /* temporary variable */
|
register ulg c; /* temporary variable */
|
||||||
static unsigned long crc_32_tab[256];
|
static unsigned long crc_32_tab[256];
|
||||||
|
|
||||||
if (crc_table_empty) {
|
if (crc_table_empty) {
|
||||||
unsigned long csr; /* crc shift register */
|
unsigned long csr; /* crc shift register */
|
||||||
const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */
|
const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */
|
||||||
@ -402,7 +403,7 @@ static ulg updcrc(uch *s, unsigned n)
|
|||||||
*/
|
*/
|
||||||
for (k = 8; k; k--)
|
for (k = 8; k; k--)
|
||||||
csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1;
|
csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1;
|
||||||
crc_32_tab[i]=csr;
|
crc_32_tab[i] = csr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,13 +771,13 @@ static unsigned match_start; /* start of matching string */
|
|||||||
static int eofile; /* flag set at end of input file */
|
static int eofile; /* flag set at end of input file */
|
||||||
static unsigned lookahead; /* number of valid bytes ahead in window */
|
static unsigned lookahead; /* number of valid bytes ahead in window */
|
||||||
|
|
||||||
static const unsigned max_chain_length=4096;
|
static const unsigned max_chain_length = 4096;
|
||||||
|
|
||||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||||
* A higher limit improves compression ratio but degrades the speed.
|
* A higher limit improves compression ratio but degrades the speed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const unsigned int max_lazy_match=258;
|
static const unsigned int max_lazy_match = 258;
|
||||||
|
|
||||||
/* Attempt to find a better match only when the current match is strictly
|
/* Attempt to find a better match only when the current match is strictly
|
||||||
* smaller than this value. This mechanism is used only for compression
|
* smaller than this value. This mechanism is used only for compression
|
||||||
@ -788,7 +789,7 @@ static const unsigned int max_lazy_match=258;
|
|||||||
* max_insert_length is used only for compression levels <= 3.
|
* max_insert_length is used only for compression levels <= 3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const unsigned good_match=32;
|
static const unsigned good_match = 32;
|
||||||
|
|
||||||
/* Use a faster search when the previous match is longer than this */
|
/* Use a faster search when the previous match is longer than this */
|
||||||
|
|
||||||
@ -799,7 +800,7 @@ static const unsigned good_match=32;
|
|||||||
* found for specific files.
|
* found for specific files.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const int nice_match=258; /* Stop searching when current match exceeds this */
|
static const int nice_match = 258; /* Stop searching when current match exceeds this */
|
||||||
|
|
||||||
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
|
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
|
||||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||||
@ -812,12 +813,12 @@ static const int nice_match=258; /* Stop searching when current match exceeds
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Prototypes for local functions.
|
* Prototypes for local functions.
|
||||||
*/
|
*/
|
||||||
static void fill_window (void);
|
static void fill_window(void);
|
||||||
|
|
||||||
static int longest_match (IPos cur_match);
|
static int longest_match(IPos cur_match);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void check_match (IPos start, IPos match, int length);
|
static void check_match(IPos start, IPos match, int length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
@ -844,7 +845,7 @@ static void check_match (IPos start, IPos match, int length);
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Initialize the "longest match" routines for a new file
|
* Initialize the "longest match" routines for a new file
|
||||||
*/
|
*/
|
||||||
static void lm_init(ush *flags)
|
static void lm_init(ush * flags)
|
||||||
{
|
{
|
||||||
register unsigned j;
|
register unsigned j;
|
||||||
|
|
||||||
@ -901,7 +902,6 @@ static int longest_match(IPos cur_match)
|
|||||||
register int len; /* length of current match */
|
register int len; /* length of current match */
|
||||||
int best_len = prev_length; /* best match length so far */
|
int best_len = prev_length; /* best match length so far */
|
||||||
IPos limit =
|
IPos limit =
|
||||||
|
|
||||||
strstart > (IPos) MAX_DIST ? strstart - (IPos) MAX_DIST : NIL;
|
strstart > (IPos) MAX_DIST ? strstart - (IPos) MAX_DIST : NIL;
|
||||||
/* Stop when cur_match becomes <= limit. To simplify the code,
|
/* Stop when cur_match becomes <= limit. To simplify the code,
|
||||||
* we prevent matches with the string of window index 0.
|
* we prevent matches with the string of window index 0.
|
||||||
@ -921,8 +921,7 @@ static int longest_match(IPos cur_match)
|
|||||||
if (prev_length >= good_match) {
|
if (prev_length >= good_match) {
|
||||||
chain_length >>= 2;
|
chain_length >>= 2;
|
||||||
}
|
}
|
||||||
Assert(strstart <= window_size - MIN_LOOKAHEAD,
|
Assert(strstart <= window_size - MIN_LOOKAHEAD, "insufficient lookahead");
|
||||||
"insufficient lookahead");
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Assert(cur_match < strstart, "no future");
|
Assert(cur_match < strstart, "no future");
|
||||||
@ -951,8 +950,7 @@ static int longest_match(IPos cur_match)
|
|||||||
} while (*++scan == *++match && *++scan == *++match &&
|
} while (*++scan == *++match && *++scan == *++match &&
|
||||||
*++scan == *++match && *++scan == *++match &&
|
*++scan == *++match && *++scan == *++match &&
|
||||||
*++scan == *++match && *++scan == *++match &&
|
*++scan == *++match && *++scan == *++match &&
|
||||||
*++scan == *++match && *++scan == *++match &&
|
*++scan == *++match && *++scan == *++match && scan < strend);
|
||||||
scan < strend);
|
|
||||||
|
|
||||||
len = MAX_MATCH - (int) (strend - scan);
|
len = MAX_MATCH - (int) (strend - scan);
|
||||||
scan = strend - MAX_MATCH;
|
scan = strend - MAX_MATCH;
|
||||||
@ -1007,7 +1005,6 @@ static void fill_window()
|
|||||||
{
|
{
|
||||||
register unsigned n, m;
|
register unsigned n, m;
|
||||||
unsigned more =
|
unsigned more =
|
||||||
|
|
||||||
(unsigned) (window_size - (ulg) lookahead - (ulg) strstart);
|
(unsigned) (window_size - (ulg) lookahead - (ulg) strstart);
|
||||||
/* Amount of free space at the end of the window. */
|
/* Amount of free space at the end of the window. */
|
||||||
|
|
||||||
@ -1100,8 +1097,7 @@ static ulg deflate()
|
|||||||
match_length = lookahead;
|
match_length = lookahead;
|
||||||
|
|
||||||
/* Ignore a length 3 match if it is too distant: */
|
/* Ignore a length 3 match if it is too distant: */
|
||||||
if (match_length == MIN_MATCH
|
if (match_length == MIN_MATCH && strstart - match_start > TOO_FAR) {
|
||||||
&& strstart - match_start > TOO_FAR) {
|
|
||||||
/* If prev_match is also MIN_MATCH, match_start is garbage
|
/* If prev_match is also MIN_MATCH, match_start is garbage
|
||||||
* but we will ignore the current match anyway.
|
* but we will ignore the current match anyway.
|
||||||
*/
|
*/
|
||||||
@ -1116,8 +1112,7 @@ static ulg deflate()
|
|||||||
check_match(strstart - 1, prev_match, prev_length);
|
check_match(strstart - 1, prev_match, prev_length);
|
||||||
|
|
||||||
flush =
|
flush =
|
||||||
ct_tally(strstart - 1 - prev_match,
|
ct_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH);
|
||||||
prev_length - MIN_MATCH);
|
|
||||||
|
|
||||||
/* Insert in hash table all strings up to the end of the match.
|
/* Insert in hash table all strings up to the end of the match.
|
||||||
* strstart-1 and strstart are already inserted.
|
* strstart-1 and strstart are already inserted.
|
||||||
@ -1201,9 +1196,6 @@ typedef struct dirent dir_type;
|
|||||||
typedef RETSIGTYPE(*sig_type) (int);
|
typedef RETSIGTYPE(*sig_type) (int);
|
||||||
|
|
||||||
/* ======================================================================== */
|
/* ======================================================================== */
|
||||||
// int main (argc, argv)
|
|
||||||
// int argc;
|
|
||||||
// char **argv;
|
|
||||||
int gzip_main(int argc, char **argv)
|
int gzip_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@ -1224,8 +1216,15 @@ int gzip_main(int argc, char **argv)
|
|||||||
force = 1;
|
force = 1;
|
||||||
break;
|
break;
|
||||||
/* Ignore 1-9 (compression level) options */
|
/* Ignore 1-9 (compression level) options */
|
||||||
case '1': case '2': case '3': case '4': case '5':
|
case '1':
|
||||||
case '6': case '7': case '8': case '9':
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
break;
|
break;
|
||||||
@ -1284,7 +1283,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
outFileNum = STDOUT_FILENO;
|
outFileNum = STDOUT_FILENO;
|
||||||
} else {
|
} else {
|
||||||
inFileNum = open(argv[i], O_RDONLY);
|
inFileNum = open(argv[i], O_RDONLY);
|
||||||
if (inFileNum < 0 || fstat (inFileNum, &statBuf) < 0)
|
if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0)
|
||||||
perror_msg_and_die("%s", argv[i]);
|
perror_msg_and_die("%s", argv[i]);
|
||||||
time_stamp = statBuf.st_ctime;
|
time_stamp = statBuf.st_ctime;
|
||||||
ifile_size = statBuf.st_size;
|
ifile_size = statBuf.st_size;
|
||||||
@ -1296,7 +1295,8 @@ int gzip_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Open output file */
|
/* Open output file */
|
||||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||||
outFileNum = open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW);
|
outFileNum =
|
||||||
|
open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW);
|
||||||
#else
|
#else
|
||||||
outFileNum = open(path, O_RDWR | O_CREAT | O_EXCL);
|
outFileNum = open(path, O_RDWR | O_CREAT | O_EXCL);
|
||||||
#endif
|
#endif
|
||||||
@ -1313,7 +1313,8 @@ int gzip_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path == NULL && isatty(outFileNum) && force == 0) {
|
if (path == NULL && isatty(outFileNum) && force == 0) {
|
||||||
error_msg("compressed data not written to a terminal. Use -f to force compression.");
|
error_msg
|
||||||
|
("compressed data not written to a terminal. Use -f to force compression.");
|
||||||
free(path);
|
free(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1321,8 +1322,8 @@ int gzip_main(int argc, char **argv)
|
|||||||
result = zip(inFileNum, outFileNum);
|
result = zip(inFileNum, outFileNum);
|
||||||
|
|
||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
close (inFileNum);
|
close(inFileNum);
|
||||||
close (outFileNum);
|
close(outFileNum);
|
||||||
|
|
||||||
/* Delete the original file */
|
/* Delete the original file */
|
||||||
if (result == OK)
|
if (result == OK)
|
||||||
@ -1338,7 +1339,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(exit_code);
|
return (exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* trees.c -- output deflated data using Huffman coding
|
/* trees.c -- output deflated data using Huffman coding
|
||||||
@ -1429,12 +1430,14 @@ typedef uch extra_bits_t;
|
|||||||
/* extra bits for each length code */
|
/* extra bits for each length code */
|
||||||
static const extra_bits_t extra_lbits[LENGTH_CODES]
|
static const extra_bits_t extra_lbits[LENGTH_CODES]
|
||||||
= { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
|
= { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
|
||||||
4, 4, 5, 5, 5, 5, 0 };
|
4, 4, 5, 5, 5, 5, 0
|
||||||
|
};
|
||||||
|
|
||||||
/* extra bits for each distance code */
|
/* extra bits for each distance code */
|
||||||
static const extra_bits_t extra_dbits[D_CODES]
|
static const extra_bits_t extra_dbits[D_CODES]
|
||||||
= { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
= { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
|
||||||
10, 10, 11, 11, 12, 12, 13, 13 };
|
10, 10, 11, 11, 12, 12, 13, 13
|
||||||
|
};
|
||||||
|
|
||||||
/* extra bits for each bit length code */
|
/* extra bits for each bit length code */
|
||||||
static const extra_bits_t extra_blbits[BL_CODES]
|
static const extra_bits_t extra_blbits[BL_CODES]
|
||||||
@ -1487,9 +1490,14 @@ static const extra_bits_t extra_blbits[BL_CODES]
|
|||||||
#define REPZ_3_10 17
|
#define REPZ_3_10 17
|
||||||
/* repeat a zero length 3-10 times (3 bits of repeat count) */
|
/* repeat a zero length 3-10 times (3 bits of repeat count) */
|
||||||
#define REPZ_11_138 18
|
#define REPZ_11_138 18
|
||||||
/* repeat a zero length 11-138 times (7 bits of repeat count) *//* ===========================================================================
|
/* repeat a zero length 11-138 times (7 bits of repeat count) */
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
* Local data
|
* Local data
|
||||||
*//* Data structure describing a single value and its code string. */ typedef struct ct_data {
|
*/
|
||||||
|
|
||||||
|
/* Data structure describing a single value and its code string. */
|
||||||
|
typedef struct ct_data {
|
||||||
union {
|
union {
|
||||||
ush freq; /* frequency count */
|
ush freq; /* frequency count */
|
||||||
ush code; /* bit string */
|
ush code; /* bit string */
|
||||||
@ -1541,14 +1549,16 @@ typedef struct tree_desc {
|
|||||||
|
|
||||||
static tree_desc l_desc =
|
static tree_desc l_desc =
|
||||||
{ dyn_ltree, static_ltree, extra_lbits, LITERALS + 1, L_CODES,
|
{ dyn_ltree, static_ltree, extra_lbits, LITERALS + 1, L_CODES,
|
||||||
MAX_BITS, 0 };
|
MAX_BITS, 0
|
||||||
|
};
|
||||||
|
|
||||||
static tree_desc d_desc =
|
static tree_desc d_desc =
|
||||||
{ dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0 };
|
{ dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0 };
|
||||||
|
|
||||||
static tree_desc bl_desc =
|
static tree_desc bl_desc =
|
||||||
{ bl_tree, (ct_data *) 0, extra_blbits, 0, BL_CODES, MAX_BL_BITS,
|
{ bl_tree, (ct_data *) 0, extra_blbits, 0, BL_CODES, MAX_BL_BITS,
|
||||||
0 };
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static ush bl_count[MAX_BITS + 1];
|
static ush bl_count[MAX_BITS + 1];
|
||||||
@ -1628,17 +1638,17 @@ static int *file_method; /* pointer to DEFLATE or STORE */
|
|||||||
* Local (static) routines in this file.
|
* Local (static) routines in this file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void init_block (void);
|
static void init_block(void);
|
||||||
static void pqdownheap (ct_data * tree, int k);
|
static void pqdownheap(ct_data * tree, int k);
|
||||||
static void gen_bitlen (tree_desc * desc);
|
static void gen_bitlen(tree_desc * desc);
|
||||||
static void gen_codes (ct_data * tree, int max_code);
|
static void gen_codes(ct_data * tree, int max_code);
|
||||||
static void build_tree (tree_desc * desc);
|
static void build_tree(tree_desc * desc);
|
||||||
static void scan_tree (ct_data * tree, int max_code);
|
static void scan_tree(ct_data * tree, int max_code);
|
||||||
static void send_tree (ct_data * tree, int max_code);
|
static void send_tree(ct_data * tree, int max_code);
|
||||||
static int build_bl_tree (void);
|
static int build_bl_tree(void);
|
||||||
static void send_all_trees (int lcodes, int dcodes, int blcodes);
|
static void send_all_trees(int lcodes, int dcodes, int blcodes);
|
||||||
static void compress_block (ct_data * ltree, ct_data * dtree);
|
static void compress_block(ct_data * ltree, ct_data * dtree);
|
||||||
static void set_file_type (void);
|
static void set_file_type(void);
|
||||||
|
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
@ -1665,7 +1675,7 @@ static void set_file_type (void);
|
|||||||
* location of the internal file attribute (ascii/binary) and method
|
* location of the internal file attribute (ascii/binary) and method
|
||||||
* (DEFLATE/STORE).
|
* (DEFLATE/STORE).
|
||||||
*/
|
*/
|
||||||
static void ct_init(ush *attr, int *methodp)
|
static void ct_init(ush * attr, int *methodp)
|
||||||
{
|
{
|
||||||
int n; /* iterates over tree elements */
|
int n; /* iterates over tree elements */
|
||||||
int bits; /* bit counter */
|
int bits; /* bit counter */
|
||||||
@ -1792,7 +1802,7 @@ static void init_block()
|
|||||||
* when the heap property is re-established (each father smaller than its
|
* when the heap property is re-established (each father smaller than its
|
||||||
* two sons).
|
* two sons).
|
||||||
*/
|
*/
|
||||||
static void pqdownheap(ct_data *tree, int k)
|
static void pqdownheap(ct_data * tree, int k)
|
||||||
{
|
{
|
||||||
int v = heap[k];
|
int v = heap[k];
|
||||||
int j = k << 1; /* left son of k */
|
int j = k << 1; /* left son of k */
|
||||||
@ -1826,7 +1836,7 @@ static void pqdownheap(ct_data *tree, int k)
|
|||||||
* The length opt_len is updated; static_len is also updated if stree is
|
* The length opt_len is updated; static_len is also updated if stree is
|
||||||
* not null.
|
* not null.
|
||||||
*/
|
*/
|
||||||
static void gen_bitlen(tree_desc *desc)
|
static void gen_bitlen(tree_desc * desc)
|
||||||
{
|
{
|
||||||
ct_data *tree = desc->dyn_tree;
|
ct_data *tree = desc->dyn_tree;
|
||||||
const extra_bits_t *extra = desc->extra_bits;
|
const extra_bits_t *extra = desc->extra_bits;
|
||||||
@ -1902,12 +1912,10 @@ static void gen_bitlen(tree_desc *desc)
|
|||||||
if (m > max_code)
|
if (m > max_code)
|
||||||
continue;
|
continue;
|
||||||
if (tree[m].Len != (unsigned) bits) {
|
if (tree[m].Len != (unsigned) bits) {
|
||||||
Trace(
|
Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len,
|
||||||
(stderr, "code %d bits %d->%d\n", m, tree[m].Len,
|
|
||||||
bits));
|
bits));
|
||||||
opt_len +=
|
opt_len +=
|
||||||
((long) bits -
|
((long) bits - (long) tree[m].Len) * (long) tree[m].Freq;
|
||||||
(long) tree[m].Len) * (long) tree[m].Freq;
|
|
||||||
tree[m].Len = (ush) bits;
|
tree[m].Len = (ush) bits;
|
||||||
}
|
}
|
||||||
n--;
|
n--;
|
||||||
@ -1923,7 +1931,7 @@ static void gen_bitlen(tree_desc *desc)
|
|||||||
* OUT assertion: the field code is set for all tree elements of non
|
* OUT assertion: the field code is set for all tree elements of non
|
||||||
* zero code length.
|
* zero code length.
|
||||||
*/
|
*/
|
||||||
static void gen_codes(ct_data *tree, int max_code)
|
static void gen_codes(ct_data * tree, int max_code)
|
||||||
{
|
{
|
||||||
ush next_code[MAX_BITS + 1]; /* next code value for each bit length */
|
ush next_code[MAX_BITS + 1]; /* next code value for each bit length */
|
||||||
ush code = 0; /* running code value */
|
ush code = 0; /* running code value */
|
||||||
@ -1966,7 +1974,7 @@ static void gen_codes(ct_data *tree, int max_code)
|
|||||||
* and corresponding code. The length opt_len is updated; static_len is
|
* and corresponding code. The length opt_len is updated; static_len is
|
||||||
* also updated if stree is not null. The field max_code is set.
|
* also updated if stree is not null. The field max_code is set.
|
||||||
*/
|
*/
|
||||||
static void build_tree(tree_desc *desc)
|
static void build_tree(tree_desc * desc)
|
||||||
{
|
{
|
||||||
ct_data *tree = desc->dyn_tree;
|
ct_data *tree = desc->dyn_tree;
|
||||||
ct_data *stree = desc->static_tree;
|
ct_data *stree = desc->static_tree;
|
||||||
@ -2030,8 +2038,7 @@ static void build_tree(tree_desc *desc)
|
|||||||
#ifdef DUMP_BL_TREE
|
#ifdef DUMP_BL_TREE
|
||||||
if (tree == bl_tree) {
|
if (tree == bl_tree) {
|
||||||
fprintf(stderr, "\nnode %d(%d), sons %d(%d) %d(%d)",
|
fprintf(stderr, "\nnode %d(%d), sons %d(%d) %d(%d)",
|
||||||
node, tree[node].Freq, n, tree[n].Freq, m,
|
node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
|
||||||
tree[m].Freq);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* and insert the new node in the heap */
|
/* and insert the new node in the heap */
|
||||||
@ -2057,7 +2064,7 @@ static void build_tree(tree_desc *desc)
|
|||||||
* counts. (The contribution of the bit length codes will be added later
|
* counts. (The contribution of the bit length codes will be added later
|
||||||
* during the construction of bl_tree.)
|
* during the construction of bl_tree.)
|
||||||
*/
|
*/
|
||||||
static void scan_tree(ct_data *tree, int max_code)
|
static void scan_tree(ct_data * tree, int max_code)
|
||||||
{
|
{
|
||||||
int n; /* iterates over all tree elements */
|
int n; /* iterates over all tree elements */
|
||||||
int prevlen = -1; /* last emitted length */
|
int prevlen = -1; /* last emitted length */
|
||||||
@ -2103,7 +2110,7 @@ static void scan_tree(ct_data *tree, int max_code)
|
|||||||
* Send a literal or distance tree in compressed form, using the codes in
|
* Send a literal or distance tree in compressed form, using the codes in
|
||||||
* bl_tree.
|
* bl_tree.
|
||||||
*/
|
*/
|
||||||
static void send_tree(ct_data *tree, int max_code)
|
static void send_tree(ct_data * tree, int max_code)
|
||||||
{
|
{
|
||||||
int n; /* iterates over all tree elements */
|
int n; /* iterates over all tree elements */
|
||||||
int prevlen = -1; /* last emitted length */
|
int prevlen = -1; /* last emitted length */
|
||||||
@ -2184,9 +2191,7 @@ static const int build_bl_tree()
|
|||||||
}
|
}
|
||||||
/* Update opt_len to include the bit length tree and counts */
|
/* Update opt_len to include the bit length tree and counts */
|
||||||
opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
|
opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
|
||||||
Tracev(
|
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", opt_len, static_len));
|
||||||
(stderr, "\ndyn trees: dyn %ld, stat %ld", opt_len,
|
|
||||||
static_len));
|
|
||||||
|
|
||||||
return max_blindex;
|
return max_blindex;
|
||||||
}
|
}
|
||||||
@ -2200,8 +2205,7 @@ static void send_all_trees(int lcodes, int dcodes, int blcodes)
|
|||||||
{
|
{
|
||||||
int rank; /* index in bl_order */
|
int rank; /* index in bl_order */
|
||||||
|
|
||||||
Assert(lcodes >= 257 && dcodes >= 1
|
Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
|
||||||
&& blcodes >= 4, "not enough codes");
|
|
||||||
Assert(lcodes <= L_CODES && dcodes <= D_CODES
|
Assert(lcodes <= L_CODES && dcodes <= D_CODES
|
||||||
&& blcodes <= BL_CODES, "too many codes");
|
&& blcodes <= BL_CODES, "too many codes");
|
||||||
Tracev((stderr, "\nbl counts: "));
|
Tracev((stderr, "\nbl counts: "));
|
||||||
@ -2242,9 +2246,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
|||||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", opt_len, static_len));
|
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", opt_len, static_len));
|
||||||
|
|
||||||
build_tree((tree_desc *) (&d_desc));
|
build_tree((tree_desc *) (&d_desc));
|
||||||
Tracev(
|
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", opt_len, static_len));
|
||||||
(stderr, "\ndist data: dyn %ld, stat %ld", opt_len,
|
|
||||||
static_len));
|
|
||||||
/* At this point, opt_len and static_len are the total bit lengths of
|
/* At this point, opt_len and static_len are the total bit lengths of
|
||||||
* the compressed block data, excluding the tree representations.
|
* the compressed block data, excluding the tree representations.
|
||||||
*/
|
*/
|
||||||
@ -2258,8 +2260,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
|||||||
opt_lenb = (opt_len + 3 + 7) >> 3;
|
opt_lenb = (opt_len + 3 + 7) >> 3;
|
||||||
static_lenb = (static_len + 3 + 7) >> 3;
|
static_lenb = (static_len + 3 + 7) >> 3;
|
||||||
|
|
||||||
Trace(
|
Trace((stderr,
|
||||||
(stderr,
|
|
||||||
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
|
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
|
||||||
opt_lenb, opt_len, static_lenb, static_len, stored_len,
|
opt_lenb, opt_len, static_lenb, static_len, stored_len,
|
||||||
last_lit, last_dist));
|
last_lit, last_dist));
|
||||||
@ -2271,8 +2272,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
|||||||
* and if the zip file can be seeked (to rewrite the local header),
|
* and if the zip file can be seeked (to rewrite the local header),
|
||||||
* the whole file is transformed into a stored file:
|
* the whole file is transformed into a stored file:
|
||||||
*/
|
*/
|
||||||
if (stored_len <= opt_lenb && eof && compressed_len == 0L
|
if (stored_len <= opt_lenb && eof && compressed_len == 0L && seekable()) {
|
||||||
&& seekable()) {
|
|
||||||
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
|
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
|
||||||
if (buf == (char *) 0)
|
if (buf == (char *) 0)
|
||||||
error_msg("block vanished");
|
error_msg("block vanished");
|
||||||
@ -2297,15 +2297,13 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
|||||||
|
|
||||||
} else if (static_lenb == opt_lenb) {
|
} else if (static_lenb == opt_lenb) {
|
||||||
send_bits((STATIC_TREES << 1) + eof, 3);
|
send_bits((STATIC_TREES << 1) + eof, 3);
|
||||||
compress_block((ct_data *) static_ltree,
|
compress_block((ct_data *) static_ltree, (ct_data *) static_dtree);
|
||||||
(ct_data *) static_dtree);
|
|
||||||
compressed_len += 3 + static_len;
|
compressed_len += 3 + static_len;
|
||||||
} else {
|
} else {
|
||||||
send_bits((DYN_TREES << 1) + eof, 3);
|
send_bits((DYN_TREES << 1) + eof, 3);
|
||||||
send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1,
|
send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1,
|
||||||
max_blindex + 1);
|
max_blindex + 1);
|
||||||
compress_block((ct_data *) dyn_ltree,
|
compress_block((ct_data *) dyn_ltree, (ct_data *) dyn_dtree);
|
||||||
(ct_data *) dyn_dtree);
|
|
||||||
compressed_len += 3 + opt_len;
|
compressed_len += 3 + opt_len;
|
||||||
}
|
}
|
||||||
Assert(compressed_len == bits_sent, "bad compressed size");
|
Assert(compressed_len == bits_sent, "bad compressed size");
|
||||||
@ -2363,8 +2361,7 @@ static int ct_tally(int dist, int lc)
|
|||||||
(ulg) dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]);
|
(ulg) dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]);
|
||||||
}
|
}
|
||||||
out_length >>= 3;
|
out_length >>= 3;
|
||||||
Trace(
|
Trace((stderr,
|
||||||
(stderr,
|
|
||||||
"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
|
"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
|
||||||
last_lit, last_dist, in_length, out_length,
|
last_lit, last_dist, in_length, out_length,
|
||||||
100L - out_length * 100L / in_length));
|
100L - out_length * 100L / in_length));
|
||||||
@ -2381,7 +2378,7 @@ static int ct_tally(int dist, int lc)
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Send the block data compressed using the given Huffman trees
|
* Send the block data compressed using the given Huffman trees
|
||||||
*/
|
*/
|
||||||
static void compress_block(ct_data *ltree, ct_data *dtree)
|
static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||||
{
|
{
|
||||||
unsigned dist; /* distance of matched string */
|
unsigned dist; /* distance of matched string */
|
||||||
int lc; /* match length or unmatched char (if dist == 0) */
|
int lc; /* match length or unmatched char (if dist == 0) */
|
||||||
@ -2464,7 +2461,7 @@ static long header_bytes; /* number of bytes in gzip header */
|
|||||||
static void put_long(ulg n)
|
static void put_long(ulg n)
|
||||||
{
|
{
|
||||||
put_short((n) & 0xffff);
|
put_short((n) & 0xffff);
|
||||||
put_short(((ulg)(n)) >> 16);
|
put_short(((ulg) (n)) >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* put_header_byte is used for the compressed output
|
/* put_header_byte is used for the compressed output
|
||||||
|
Reference in New Issue
Block a user