* gzip.h (local): Remove. All uses replaced by ‘static’. Previously, the source code was inconsistent about using ‘local’ vs ‘static’ even before the recent changes, and ‘local’ was more trouble than it was worth. --- bits.c | 2 +- deflate.c | 29 +++++++++-------- gzip.c | 66 ++++++++++++++++++++++----------------- gzip.h | 2 -- trees.c | 93 ++++++++++++++++++++++++++++--------------------------- unlzh.c | 67 ++++++++++++++++++++------------------- unpack.c | 30 +++++++++--------- 7 files changed, 154 insertions(+), 135 deletions(-)
diff --git a/bits.c b/bits.c index 0c4a6aa..23b65f9 100644 --- a/bits.c +++ b/bits.c @@ -76,7 +76,7 @@ * Local data used by the "bit string" routines. */ -local file_t zfile; /* output gzip file */ +static file_t zfile; /* output gzip file */ #ifndef IBM_Z_DFLTCC static diff --git a/deflate.c b/deflate.c index 1a47bc6..d95f454 100644 --- a/deflate.c +++ b/deflate.c @@ -176,7 +176,7 @@ long block_start; * negative when the window is moved backwards. */ -local unsigned ins_h; /* hash index of string to be inserted */ +static unsigned ins_h; /* hash index of string to be inserted */ #define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH) /* Number of bits by which ins_h and del_h must be shifted at each @@ -192,15 +192,15 @@ local unsigned ins_h; /* hash index of string to be inserted */ unsigned near strstart; /* start of string to insert */ unsigned near match_start; /* start of matching string */ -local int eofile; /* flag set at end of input file */ -local unsigned lookahead; /* number of valid bytes ahead in window */ +static int eofile; /* flag set at end of input file */ +static unsigned lookahead; /* number of valid bytes ahead in window */ unsigned max_chain_length; /* To speed up deflation, hash chains are never searched beyond this length. * A higher limit improves compression ratio but degrades the speed. */ -local unsigned int max_lazy_match; +static unsigned int max_lazy_match; /* Attempt to find a better match only when the current match is strictly * smaller than this value. This mechanism is used only for compression * levels >= 4. @@ -214,8 +214,8 @@ local unsigned int max_lazy_match; unsigned good_match; /* Use a faster search when the previous match is longer than this */ -local ulg rsync_sum; /* rolling sum of rsync window */ -local ulg rsync_chunk_end; /* next rsync sequence point */ +static ulg rsync_sum; /* rolling sum of rsync window */ +static ulg rsync_chunk_end; /* next rsync sequence point */ /* Values for max_lazy_match, good_match and max_chain_length, depending on * the desired pack level (0..9). The values given below have been tuned to @@ -243,7 +243,7 @@ typedef struct config { static_unless_ASMV int nice_match; #endif -local config configuration_table[10] = { +static config configuration_table[10] = { /* good lazy nice chain */ /* 0 */ {0, 0, 0, 0}, /* store only */ /* 1 */ {4, 4, 8, 4}, /* maximum speed, no lazy matches */ @@ -265,8 +265,8 @@ local config configuration_table[10] = { /* =========================================================================== * Prototypes for local functions. */ -local void fill_window (void); -local off_t deflate_fast (void); +static void fill_window (void); +static off_t deflate_fast (void); #ifdef ASMV int longest_match (IPos cur_match); @@ -274,7 +274,7 @@ local off_t deflate_fast (void); #endif #ifdef DEBUG -local void check_match (IPos start, IPos match, int length); +static void check_match (IPos start, IPos match, int length); #endif /* =========================================================================== @@ -528,7 +528,8 @@ check_match (IPos start, IPos match, int length) * file reads are performed for at least two bytes (required for the * translate_eol option). */ -local void fill_window() +static void +fill_window () { register unsigned n, m; unsigned more = (unsigned)(window_size - (ulg)lookahead - (ulg)strstart); @@ -584,7 +585,8 @@ local void fill_window() /* With an initial offset of START, advance rsync's rolling checksum by NUM bytes. */ -local void rsync_roll(unsigned int start, unsigned int num) +static void +rsync_roll (unsigned int start, unsigned int num) { unsigned i; @@ -630,7 +632,8 @@ local void rsync_roll(unsigned int start, unsigned int num) * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local off_t deflate_fast() +static off_t +deflate_fast () { IPos hash_head; /* head of the hash chain */ int flush = 0; /* set if current block must be flushed, 2=>and padded */ diff --git a/gzip.c b/gzip.c index fb1a089..fcf8e06 100644 --- a/gzip.c +++ b/gzip.c @@ -305,33 +305,33 @@ static const struct option longopts[] = /* local functions */ -_Noreturn local void try_help (void); -local void help (void); -local void license (void); -local void version (void); -local int input_eof (void); -local void treat_stdin (void); -local void treat_file (char *iname); -local int create_outfile (void); -local char *get_suffix (char *name); -local int open_input_file (char *iname, struct stat *sbuf); -local void discard_input_bytes (size_t nbytes, unsigned int flags); -local int make_ofname (void); -local void shorten_name (char *name); -local int get_method (int in); -local void do_list (int method); -local int check_ofname (void); -local void copy_stat (struct stat *ifstat); -local void install_signal_handlers (void); +_Noreturn static void try_help (void); +static void help (void); +static void license (void); +static void version (void); +static int input_eof (void); +static void treat_stdin (void); +static void treat_file (char *iname); +static int create_outfile (void); +static char *get_suffix (char *name); +static int open_input_file (char *iname, struct stat *sbuf); +static void discard_input_bytes (size_t nbytes, unsigned int flags); +static int make_ofname (void); +static void shorten_name (char *name); +static int get_method (int in); +static void do_list (int method); +static int check_ofname (void); +static void copy_stat (struct stat *ifstat); +static void install_signal_handlers (void); static void remove_output_file (bool); static void abort_gzip_signal (int); -_Noreturn local void do_exit (int exitcode); +_Noreturn static void do_exit (int exitcode); static void finish_out (void); int main (int argc, char **argv); static int (*work) (int infile, int outfile) = zip; /* function to call */ #if ! NO_DIR -local void treat_dir (int fd, char *dir); +static void treat_dir (int fd, char *dir); #endif #define strequ(s1, s2) (strcmp((s1),(s2)) == 0) @@ -345,7 +345,8 @@ try_help () } /* ======================================================================== */ -local void help() +static void +help () { static char const* const help_msg[] = { "Compress or uncompress FILEs (by default, compress FILES in-place).", @@ -394,7 +395,8 @@ local void help() } /* ======================================================================== */ -local void license() +static void +license () { char const *const *p = license_msg; @@ -403,14 +405,16 @@ local void license() } /* ======================================================================== */ -local void version() +static void +version () { license (); printf ("\n"); printf ("Written by Jean-loup Gailly.\n"); } -local void progerror (char const *string) +static void +progerror (char const *string) { int e = errno; fprintf (stderr, "%s: ", program_name); @@ -687,7 +691,7 @@ int main (int argc, char **argv) } /* Return nonzero when at end of file on input. */ -local int +static int input_eof () { if (!decompress || last_member) @@ -727,7 +731,8 @@ get_input_size_and_time () /* ======================================================================== * Compress or decompress stdin */ -local void treat_stdin() +static void +treat_stdin () { if (!force && !list && (presume_input_tty @@ -1091,7 +1096,8 @@ volatile_strcpy (char volatile *dst, char const volatile *src) * ofname has already been updated if there was an original name. * OUT assertions: ifd and ofd are closed in case of error. */ -local int create_outfile() +static int +create_outfile () { int name_shortened = 0; int flags = (O_WRONLY | O_CREAT | O_EXCL @@ -1382,7 +1388,8 @@ open_input_file (char *iname, struct stat *sbuf) * Generate ofname given ifname. Return OK, or WARNING if file must be skipped. * Sets save_orig_name to true if the file name has been truncated. */ -local int make_ofname() +static int +make_ofname () { char *suff; /* ofname z suffix */ @@ -1871,7 +1878,8 @@ shorten_name (char *name) * The compressed file already exists, so ask for confirmation. * Return ERROR if the file must be skipped. */ -local int check_ofname() +static int +check_ofname () { /* Ask permission to overwrite the existing file */ if (!force) { diff --git a/gzip.h b/gzip.h index 668d635..3334cd4 100644 --- a/gzip.h +++ b/gzip.h @@ -40,8 +40,6 @@ #include <string.h> #define memzero(s, n) memset ((voidp)(s), 0, (n)) -#define local static - typedef unsigned char uch; typedef unsigned short ush; typedef unsigned long ulg; diff --git a/trees.c b/trees.c index 14c6191..948c9aa 100644 --- a/trees.c +++ b/trees.c @@ -101,13 +101,13 @@ /* number of codes used to transfer the bit lengths */ -local int near extra_lbits[LENGTH_CODES] /* extra bits for each length code */ +static int near extra_lbits[LENGTH_CODES] /* extra bits for each length code */ = {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}; -local int near extra_dbits[D_CODES] /* extra bits for each distance code */ +static int near extra_dbits[D_CODES] /* extra bits for each distance code */ = {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}; -local int near extra_blbits[BL_CODES]/* extra bits for each bit length code */ +static int near extra_blbits[BL_CODES]/* extra bits for each bit length code */ = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; #define STORED_BLOCK 0 @@ -186,22 +186,22 @@ typedef struct ct_data { #define HEAP_SIZE (2*L_CODES+1) /* maximum heap size */ -local ct_data near dyn_ltree[HEAP_SIZE]; /* literal and length tree */ -local ct_data near dyn_dtree[2*D_CODES+1]; /* distance tree */ +static ct_data near dyn_ltree[HEAP_SIZE]; /* literal and length tree */ +static ct_data near dyn_dtree[2*D_CODES+1]; /* distance tree */ -local ct_data near static_ltree[L_CODES+2]; +static ct_data near static_ltree[L_CODES+2]; /* The static literal tree. Since the bit lengths are imposed, there is no * need for the L_CODES extra codes used during heap construction. However * The codes 286 and 287 are needed to build a canonical tree (see ct_init * below). */ -local ct_data near static_dtree[D_CODES]; +static ct_data near static_dtree[D_CODES]; /* The static distance tree. (Actually a trivial tree since all codes use * 5 bits.) */ -local ct_data near bl_tree[2*BL_CODES+1]; +static ct_data near bl_tree[2*BL_CODES+1]; /* Huffman tree for the bit lengths */ typedef struct tree_desc { @@ -214,48 +214,48 @@ typedef struct tree_desc { int max_code; /* largest code with non zero frequency */ } tree_desc; -local tree_desc near l_desc = +static tree_desc near l_desc = {dyn_ltree, static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS, 0}; -local tree_desc near d_desc = +static tree_desc near d_desc = {dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0}; -local tree_desc near bl_desc = +static tree_desc near bl_desc = {bl_tree, (ct_data near *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS, 0}; -local ush near bl_count[MAX_BITS+1]; +static ush near bl_count[MAX_BITS+1]; /* number of codes at each bit length for an optimal tree */ -local uch near bl_order[BL_CODES] +static uch near bl_order[BL_CODES] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; /* The lengths of the bit length codes are sent in order of decreasing * probability, to avoid transmitting the lengths for unused bit length codes. */ -local int near heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ -local int heap_len; /* number of elements in the heap */ -local int heap_max; /* element of largest frequency */ +static int near heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ +static int heap_len; /* number of elements in the heap */ +static int heap_max; /* element of largest frequency */ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. * The same heap array is used to build all trees. */ -local uch near depth[2*L_CODES+1]; +static uch near depth[2*L_CODES+1]; /* Depth of each subtree used as tie breaker for trees of equal frequency */ -local uch length_code[MAX_MATCH-MIN_MATCH+1]; +static uch length_code[MAX_MATCH-MIN_MATCH+1]; /* length code for each normalized match length (0 == MIN_MATCH) */ -local uch dist_code[512]; +static uch dist_code[512]; /* distance codes. The first 256 values correspond to the distances * 3 .. 258, the last 256 values correspond to the top 8 bits of * the 15 bit distances. */ -local int near base_length[LENGTH_CODES]; +static int near base_length[LENGTH_CODES]; /* First normalized length for each code (0 = MIN_MATCH) */ -local int near base_dist[D_CODES]; +static int near base_dist[D_CODES]; /* First normalized distance for each code (0 = distance of 1) */ #define l_buf inbuf @@ -263,27 +263,27 @@ local int near base_dist[D_CODES]; /* DECLARE(ush, d_buf, DIST_BUFSIZE); buffer for distances */ -local uch near flag_buf[(LIT_BUFSIZE/8)]; +static uch near flag_buf[(LIT_BUFSIZE/8)]; /* flag_buf is a bit array distinguishing literals from lengths in * l_buf, thus indicating the presence or absence of a distance. */ -local unsigned last_lit; /* running index in l_buf */ -local unsigned last_dist; /* running index in d_buf */ -local unsigned last_flags; /* running index in flag_buf */ -local uch flags; /* current flags not yet saved in flag_buf */ -local uch flag_bit; /* current bit used in flags */ +static unsigned last_lit; /* running index in l_buf */ +static unsigned last_dist; /* running index in d_buf */ +static unsigned last_flags; /* running index in flag_buf */ +static uch flags; /* current flags not yet saved in flag_buf */ +static uch flag_bit; /* current bit used in flags */ /* bits are filled in flags starting at bit 0 (least significant). * Note: these flags are overkill in the current code since we don't * take advantage of DIST_BUFSIZE == LIT_BUFSIZE. */ -local ulg opt_len; /* bit length of current block with optimal trees */ -local ulg static_len; /* bit length of current block with static trees */ +static ulg opt_len; /* bit length of current block with optimal trees */ +static ulg static_len; /* bit length of current block with static trees */ -local off_t compressed_len; /* total bit length of compressed file */ +static off_t compressed_len; /* total bit length of compressed file */ -local off_t input_len; /* total byte length of input file */ +static off_t input_len; /* total byte length of input file */ /* input_len is for debugging only since we can get it by other means. */ static ush *file_type; /* pointer to UNKNOWN, BINARY or ASCII */ @@ -300,17 +300,17 @@ extern unsigned near strstart; /* window offset of current string */ * Local (static) routines in this file. */ -local void init_block (void); -local void pqdownheap (ct_data near *tree, int k); -local void gen_bitlen (tree_desc near *desc); -local void gen_codes (ct_data near *tree, int max_code); -local void build_tree (tree_desc near *desc); -local void scan_tree (ct_data near *tree, int max_code); -local void send_tree (ct_data near *tree, int max_code); -local int build_bl_tree (void); -local void send_all_trees (int lcodes, int dcodes, int blcodes); -local void compress_block (ct_data near *ltree, ct_data near *dtree); -local void set_file_type (void); +static void init_block (void); +static void pqdownheap (ct_data near *tree, int k); +static void gen_bitlen (tree_desc near *desc); +static void gen_codes (ct_data near *tree, int max_code); +static void build_tree (tree_desc near *desc); +static void scan_tree (ct_data near *tree, int max_code); +static void send_tree (ct_data near *tree, int max_code); +static int build_bl_tree (void); +static void send_all_trees (int lcodes, int dcodes, int blcodes); +static void compress_block (ct_data near *ltree, ct_data near *dtree); +static void set_file_type (void); #ifndef DEBUG @@ -414,7 +414,8 @@ ct_init (ush *attr, int *methodp) /* =========================================================================== * Initialize a new block. */ -local void init_block() +static void +init_block () { int n; /* iterates over tree elements */ @@ -803,7 +804,8 @@ send_tree (ct_data near *tree, int max_code) * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree() +static int +build_bl_tree () { int max_blindex; /* index of last bit length code of non zero freq */ @@ -1080,7 +1082,8 @@ compress_block (ct_data near *ltree, ct_data near *dtree) * IN assertion: the fields freq of dyn_ltree are set and the total of all * frequencies does not exceed 64K (to fit in an int on 16 bit machines). */ -local void set_file_type() +static void +set_file_type () { int n = 0; unsigned ascii_freq = 0; diff --git a/unlzh.c b/unlzh.c index 0fb45e0..25c05e3 100644 --- a/unlzh.c +++ b/unlzh.c @@ -12,25 +12,24 @@ /* decode.c */ -local unsigned decode (unsigned count, uch buffer[]); -local void decode_start (void); +static unsigned decode (unsigned count, uch buffer[]); +static void decode_start (void); /* huf.c */ -local void huf_decode_start (void); -local unsigned decode_c (void); -local unsigned decode_p (void); -local void read_pt_len (int nn, int nbit, int i_special); -local void read_c_len (void); +static void huf_decode_start (void); +static unsigned decode_c (void); +static unsigned decode_p (void); +static void read_pt_len (int nn, int nbit, int i_special); +static void read_c_len (void); /* io.c */ -local void fillbuf (int n); -local unsigned getbits (int n); -local void init_getbits (void); +static void fillbuf (int n); +static unsigned getbits (int n); +static void init_getbits (void); /* maketbl.c */ -local void make_table (int nchar, uch bitlen[], - int tablebits, ush table[]); +static void make_table (int nchar, uch bitlen[], int tablebits, ush table[]); #define DICBIT 13 /* 12(-lh4-) or 13(-lh5-) */ @@ -67,25 +66,25 @@ local void make_table (int nchar, uch bitlen[], #define TBIT 5 /* smallest integer such that (1U << TBIT) > NT */ #define NPT (1 << TBIT) -/* local ush left[2 * NC - 1]; */ -/* local ush right[2 * NC - 1]; */ +/* static ush left[2 * NC - 1]; */ +/* static ush right[2 * NC - 1]; */ #define left prev #define right head #if NC > (1<<(BITS-2)) error cannot overlay left+right and prev #endif -/* local uch c_len[NC]; */ +/* static uch c_len[NC]; */ #define c_len outbuf #if NC > OUTBUFSIZ error cannot overlay c_len and outbuf #endif -local uch pt_len[NPT]; -local unsigned blocksize; -local ush pt_table[256]; +static uch pt_len[NPT]; +static unsigned blocksize; +static ush pt_table[256]; -/* local ush c_table[4096]; */ +/* static ush c_table[4096]; */ #define c_table d_buf #if (DIST_BUFSIZE-1) < 4095 error cannot overlay c_table and d_buf @@ -95,9 +94,9 @@ local ush pt_table[256]; io.c -- input/output ***********************************************************/ -local ush bitbuf; -local unsigned subbitbuf; -local int bitcount; +static ush bitbuf; +static unsigned subbitbuf; +static int bitcount; /* Shift bitbuf N bits left, read N bits. */ static void @@ -122,7 +121,8 @@ getbits (int n) return x; } -local void init_getbits() +static void +init_getbits () { bitbuf = 0; subbitbuf = 0; bitcount = 0; fillbuf(BITBUFSIZ); @@ -228,7 +228,8 @@ read_pt_len (int nn, int nbit, int i_special) } } -local void read_c_len() +static void +read_c_len () { int i, c, n; unsigned mask; @@ -263,7 +264,8 @@ local void read_c_len() } } -local unsigned decode_c() +static unsigned +decode_c () { unsigned j, mask; @@ -290,7 +292,8 @@ local unsigned decode_c() return j; } -local unsigned decode_p() +static unsigned +decode_p () { unsigned j, mask; @@ -308,7 +311,8 @@ local unsigned decode_p() return j; } -local void huf_decode_start() +static void +huf_decode_start () { init_getbits(); blocksize = 0; } @@ -317,10 +321,11 @@ local void huf_decode_start() decode.c ***********************************************************/ -local int j; /* remaining bytes to copy */ -local int done; /* set at end of input */ +static int j; /* remaining bytes to copy */ +static int done; /* set at end of input */ -local void decode_start() +static void +decode_start () { huf_decode_start(); j = 0; @@ -340,7 +345,7 @@ decode (unsigned count, uch buffer[]) before calling this function. */ { - local unsigned i; + static unsigned i; unsigned r, c; r = 0; diff --git a/unpack.c b/unpack.c index 2a87457..39ca75d 100644 --- a/unpack.c +++ b/unpack.c @@ -38,26 +38,26 @@ * Huffman tree. */ -local ulg orig_len; /* original uncompressed length */ -local int max_len; /* maximum bit length of Huffman codes */ +static ulg orig_len; /* original uncompressed length */ +static int max_len; /* maximum bit length of Huffman codes */ -local uch literal[LITERALS]; +static uch literal[LITERALS]; /* The literal bytes present in the Huffman tree. The EOB code is not * represented. */ -local int lit_base[MAX_BITLEN+1]; +static int lit_base[MAX_BITLEN+1]; /* All literals of a given bit length are contiguous in literal[] and * have contiguous codes. literal[code+lit_base[len]] is the literal * for a code of len bits. */ -local int leaves [MAX_BITLEN+1]; /* Number of leaves for each bit length */ -local int parents[MAX_BITLEN+1]; /* Number of parents for each bit length */ +static int leaves [MAX_BITLEN+1]; /* Number of leaves for each bit length */ +static int parents[MAX_BITLEN+1]; /* Number of parents for each bit length */ -local int peek_bits; /* Number of peek bits currently used */ +static int peek_bits; /* Number of peek bits currently used */ -/* local uch prefix_len[1 << MAX_PEEK]; */ +/* static uch prefix_len[1 << MAX_PEEK]; */ #define prefix_len outbuf /* For each bit pattern b of peek_bits bits, prefix_len[b] is the length * of the Huffman code starting with a prefix of b (upper bits), or 0 @@ -70,10 +70,10 @@ local int peek_bits; /* Number of peek bits currently used */ error cannot overlay prefix_len and outbuf #endif -local ulg bitbuf; +static ulg bitbuf; /* Bits are added on the low part of bitbuf and read from the high part. */ -local int valid; /* number of valid bits in bitbuf */ +static int valid; /* number of valid bits in bitbuf */ /* all bits above the last valid bit are always zero */ /* Read an input byte, reporting an error at EOF. */ @@ -104,13 +104,14 @@ read_byte () /* Local functions */ -local void read_tree (void); -local void build_tree (void); +static void read_tree (void); +static void build_tree (void); /* =========================================================================== * Read the Huffman tree. */ -local void read_tree() +static void +read_tree () { int len; /* bit length */ int base; /* base offset for a sequence of leaves */ @@ -167,7 +168,8 @@ local void read_tree() /* =========================================================================== * Build the Huffman tree and the prefix table. */ -local void build_tree() +static void +build_tree () { int nodes = 0; /* number of nodes (parents+leaves) at current bit length */ int len; /* current bit length */ -- 2.38.1