bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/8] maint: declare many variables to be static


From: Jim Meyering
Subject: [PATCH 5/8] maint: declare many variables to be static
Date: Fri, 13 May 2011 12:13:47 +0200

From: Jim Meyering <address@hidden>

* deflate.c: Likewise.
* gzip.c: Likewise.
* gzip.h: Likewise.
* inflate.c: Likewise.
* trees.c: Likewise.
* unzip.c: Likewise.
* util.c: Likewise.
---
 deflate.c |   12 +++++-----
 gzip.c    |   66 ++++++++++++++++++++++++++++++------------------------------
 gzip.h    |    1 -
 inflate.c |   12 +++++-----
 trees.c   |    4 +-
 unzip.c   |    7 ++---
 util.c    |    4 +-
 7 files changed, 52 insertions(+), 54 deletions(-)

diff --git a/deflate.c b/deflate.c
index 09a1434..461fdda 100644
--- a/deflate.c
+++ b/deflate.c
@@ -161,7 +161,7 @@ typedef unsigned IPos;
 /* DECLARE(Pos, head, 1<<HASH_BITS); */
 /* Heads of the hash chains or NIL. */

-ulg window_size = (ulg)2*WSIZE;
+static ulg window_size = (ulg)2*WSIZE;
 /* window size, 2*WSIZE except for MMAP or BIG_MEM, where it is the
  * input file length plus MIN_LOOKAHEAD.
  */
@@ -180,17 +180,17 @@ local unsigned ins_h;  /* hash index of string to be 
inserted */
  *   H_SHIFT * MIN_MATCH >= HASH_BITS
  */

-unsigned int near prev_length;
+static unsigned int near prev_length;
 /* Length of the best match at previous step. Matches not greater than this
  * are discarded. This is used in the lazy match evaluation.
  */

       unsigned near strstart;      /* start of string to insert */
-      unsigned near match_start;   /* start of matching string */
+local 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 */

-unsigned near max_chain_length;
+static 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.
  */
@@ -209,7 +209,7 @@ local unsigned int max_lazy_match;
 local int compr_level;
 /* compression level (1..9) */

-unsigned near good_match;
+static unsigned good_match;
 /* Use a faster search when the previous match is longer than this */


@@ -229,7 +229,7 @@ typedef struct config {
 #ifdef  FULL_SEARCH
 # define nice_match MAX_MATCH
 #else
-  int near nice_match; /* Stop searching when current match exceeds this */
+  static int nice_match; /* Stop searching when current match exceeds this */
 #endif

 local config configuration_table[10] = {
diff --git a/gzip.c b/gzip.c
index 4739dbe..6164438 100644
--- a/gzip.c
+++ b/gzip.c
@@ -29,7 +29,7 @@
  */

 static char const *const license_msg[] = {
-"Copyright (C) 2007, 2010 Free Software Foundation, Inc.",
+"Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.",
 "Copyright (C) 1993 Jean-loup Gailly.",
 "This is free software.  You may redistribute copies of it under the terms of",
 "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.",
@@ -170,33 +170,33 @@ DECLARE(uch, window, 2L*WSIZE);
    is deliberately not documented, and only for testing.  */
 static bool presume_input_tty;

-int ascii = 0;        /* convert end-of-lines to local OS conventions */
-int to_stdout = 0;    /* output to stdout (-c) */
-int decompress = 0;   /* decompress (-d) */
-int force = 0;        /* don't ask questions, compress links (-f) */
-int no_name = -1;     /* don't save or restore the original file name */
-int no_time = -1;     /* don't save or restore the original file time */
-int recursive = 0;    /* recurse through directories (-r) */
-int list = 0;         /* list the file contents (-l) */
-int verbose = 0;      /* be verbose (-v) */
-int quiet = 0;        /* be very quiet (-q) */
-int do_lzw = 0;       /* generate output compatible with old compress (-Z) */
-int test = 0;         /* test .gz file integrity */
-int foreground = 0;   /* set if program run in foreground */
-char *program_name;   /* program name */
-int maxbits = BITS;   /* max bits per code for LZW */
-int method = DEFLATED;/* compression method */
-int level = 6;        /* compression level */
-int exit_code = OK;   /* program exit code */
-int save_orig_name;   /* set if original name must be saved */
-int last_member;      /* set for .zip and .Z files */
-int part_nb;          /* number of parts in .gz file */
-struct timespec time_stamp; /* original time stamp (modification time) */
-off_t ifile_size;      /* input file size, -1 for devices (debug only) */
-char *env;            /* contents of GZIP env variable */
-char **args = NULL;   /* argv pointer if GZIP env variable defined */
-char const *z_suffix; /* default suffix (can be set with --suffix) */
-size_t z_len;         /* strlen(z_suffix) */
+static int ascii = 0;        /* convert end-of-lines to local OS conventions */
+       int to_stdout = 0;    /* output to stdout (-c) */
+static int decompress = 0;   /* decompress (-d) */
+static int force = 0;        /* don't ask questions, compress links (-f) */
+static int no_name = -1;     /* don't save or restore the original file name */
+static int no_time = -1;     /* don't save or restore the original file time */
+static int recursive = 0;    /* recurse through directories (-r) */
+static int list = 0;         /* list the file contents (-l) */
+       int verbose = 0;      /* be verbose (-v) */
+       int quiet = 0;        /* be very quiet (-q) */
+static int do_lzw = 0;       /* generate output compatible with old compress 
(-Z) */
+       int test = 0;         /* test .gz file integrity */
+static int foreground = 0;   /* set if program run in foreground */
+       char *program_name;   /* program name */
+       int maxbits = BITS;   /* max bits per code for LZW */
+       int method = DEFLATED;/* compression method */
+       int level = 6;        /* compression level */
+       int exit_code = OK;   /* program exit code */
+       int save_orig_name;   /* set if original name must be saved */
+static int last_member;      /* set for .zip and .Z files */
+static int part_nb;          /* number of parts in .gz file */
+       struct timespec time_stamp; /* original time stamp (modification time) 
*/
+       off_t ifile_size;      /* input file size, -1 for devices (debug only) 
*/
+static char *env;            /* contents of GZIP env variable */
+static char **args = NULL;   /* argv pointer if GZIP env variable defined */
+static char const *z_suffix; /* default suffix (can be set with --suffix) */
+static size_t z_len;         /* strlen(z_suffix) */

 /* The set of signals that are caught.  */
 static sigset_t caught_signals;
@@ -211,11 +211,11 @@ static int volatile remove_ofname_fd = -1;

 off_t bytes_in;             /* number of input bytes */
 off_t bytes_out;            /* number of output bytes */
-off_t total_in;                    /* input bytes for all files */
-off_t total_out;           /* output bytes for all files */
+static off_t total_in;      /* input bytes for all files */
+static off_t total_out;            /* output bytes for all files */
 char ifname[MAX_PATH_LEN]; /* input file name */
 char ofname[MAX_PATH_LEN]; /* output file name */
-struct stat istat;         /* status for input file */
+static struct stat istat;         /* status for input file */
 int  ifd;                  /* input file descriptor */
 int  ofd;                  /* output file descriptor */
 unsigned insize;           /* valid bytes in inbuf */
@@ -249,7 +249,7 @@ enum
   PRESUME_INPUT_TTY_OPTION = CHAR_MAX + 1
 };

-struct option longopts[] =
+static const struct option longopts[] =
 {
  /* { name  has_arg  *flag  val } */
     {"ascii",      0, 0, 'a'}, /* ascii text mode */
@@ -306,7 +306,7 @@ local void remove_output_file (void);
 local RETSIGTYPE abort_gzip_signal (int);
 local void do_exit      (int exitcode) ATTRIBUTE_NORETURN;
       int main          (int argc, char **argv);
-int (*work) (int infile, int outfile) = zip; /* function to call */
+static int (*work) (int infile, int outfile) = zip; /* function to call */

 #if ! NO_DIR
 local void treat_dir    (int fd, char *dir);
diff --git a/gzip.h b/gzip.h
index 5f6791b..568ffb0 100644
--- a/gzip.h
+++ b/gzip.h
@@ -196,7 +196,6 @@ typedef int file_t;     /* Do not use stdio */
  * distances are limited to MAX_DIST instead of WSIZE.
  */

-extern int decrypt;        /* flag to turn on decryption */
 extern int exit_code;      /* program exit code */
 extern int verbose;        /* be verbose (-v) */
 extern int quiet;          /* be quiet (-q) */
diff --git a/inflate.c b/inflate.c
index d7dbebe..2ca5a5e 100644
--- a/inflate.c
+++ b/inflate.c
@@ -208,10 +208,10 @@ static ush cpdext[] = {         /* Extra bits for 
distance codes */
    the stream.
  */

-ulg bb;                         /* bit buffer */
-unsigned bk;                    /* bits in bit buffer */
+static ulg bb;                         /* bit buffer */
+static unsigned bk;                    /* bits in bit buffer */

-ush mask_bits[] = {
+static ush mask_bits[] = {
     0x0000,
     0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
     0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
@@ -263,8 +263,8 @@ ush mask_bits[] = {
  */


-int lbits = 9;          /* bits in base literal/length lookup table */
-int dbits = 6;          /* bits in base distance lookup table */
+static int lbits = 9;   /* bits in base literal/length lookup table */
+static int dbits = 6;   /* bits in base distance lookup table */


 /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */
@@ -272,7 +272,7 @@ int dbits = 6;          /* bits in base distance lookup 
table */
 #define N_MAX 288       /* maximum number of codes in any set */


-unsigned hufts;         /* track memory usage */
+static unsigned hufts;  /* track memory usage */


 static int
diff --git a/trees.c b/trees.c
index d94f237..bdc1986 100644
--- a/trees.c
+++ b/trees.c
@@ -286,8 +286,8 @@ local off_t compressed_len; /* total bit length of 
compressed file */
 local off_t input_len;      /* total byte length of input file */
 /* input_len is for debugging only since we can get it by other means. */

-ush *file_type;        /* pointer to UNKNOWN, BINARY or ASCII */
-int *file_method;      /* pointer to DEFLATE or STORE */
+static ush *file_type;        /* pointer to UNKNOWN, BINARY or ASCII */
+static int *file_method;      /* pointer to DEFLATE or STORE */

 #ifdef DEBUG
 extern off_t bits_sent;  /* bit length of the compressed data */
diff --git a/unzip.c b/unzip.c
index 302194c..1c1d782 100644
--- a/unzip.c
+++ b/unzip.c
@@ -51,10 +51,9 @@

 /* Globals */

-int decrypt;        /* flag to turn on decryption */
-char *key;          /* not used--needed to link crypt.c */
-int pkzip = 0;      /* set for a pkzip file */
-int ext_header = 0; /* set if extended local header */
+static int decrypt;        /* flag to turn on decryption */
+static int pkzip = 0;      /* set for a pkzip file */
+static int ext_header = 0; /* set if extended local header */

 /* ===========================================================================
  * Check zip file and advance inptr to the start of the compressed data.
diff --git a/util.c b/util.c
index 58e0092..723b448 100644
--- a/util.c
+++ b/util.c
@@ -39,7 +39,7 @@

 static int write_buffer (int, voidp, unsigned int);

-extern ulg crc_32_tab[];   /* crc table, defined below */
+static const ulg crc_32_tab[];   /* crc table, defined below */

 /* ===========================================================================
  * Copy input to output unchanged: zcat == cat with --force.
@@ -438,7 +438,7 @@ void fprint_off(file, offset, width)
 /* ========================================================================
  * Table of CRC-32's of all single-byte values (made by makecrc.c)
  */
-ulg crc_32_tab[] = {
+static const ulg crc_32_tab[] = {
   0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
   0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
   0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-- 
1.7.5.1.398.g86d1d




reply via email to

[Prev in Thread] Current Thread [Next in Thread]