diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-11-11 01:36:55 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-11-11 01:36:55 +0000 |
commit | c296b54827d102bd020845da904773d861552788 (patch) | |
tree | 7d7ce5d8f44a63d6e260df4a27bd2fdde03d7ddd | |
parent | d73dc5b07390fb90e7f605871c993a28eedf1d46 (diff) |
Stuf
-rw-r--r-- | archival/gzip.c | 37 | ||||
-rw-r--r-- | gzip.c | 37 | ||||
-rw-r--r-- | zcat.c | 4 |
3 files changed, 52 insertions, 26 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index de794febb..c36270647 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -11,7 +11,12 @@ #error you need zcat to have gzip support! #endif -static const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n"; +static const char gzip_usage[] = + "gzip [OPTION]... [FILE]...\n\n" + "Compress FILEs with maximum compression.\n\n" + "Options:\n" + "\t-c\tWrite output on standard output\n"; + /* gzip.h -- common declarations for all gzip modules * Copyright (C) 1992-1993 Jean-loup Gailly. @@ -210,7 +215,6 @@ extern int exit_code; /* program exit code */ extern int verbose; /* be verbose (-v) */ extern int quiet; /* be quiet (-q) */ extern int test; /* check .z file integrity */ -extern int to_stdout; /* output to stdout (-c) */ extern int save_orig_name; /* set if original name must be saved */ #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0)) @@ -1726,8 +1730,8 @@ DECLARE(uch, window, 2L*WSIZE); /* local variables */ 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 tostdout = 0; /* uncompress to stdout (-c) */ 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 foreground; /* set if program run in foreground */ @@ -1767,8 +1771,22 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */ // int main (argc, argv) // int argc; // char **argv; -int gzip_main(int argc, char * * argv) +int gzip_main(int argc, char ** argv) { + + /* Parse any options */ + while (--argc > 0 && **(++argv) == '-') { + while (*(++(*argv))) { + switch (**argv) { + case 'c': + tostdout = 1; + break; + default: + usage(gzip_usage); + } + } + } + foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; if (foreground) { (void) signal (SIGINT, (sig_type)abort_gzip); @@ -1787,8 +1805,6 @@ int gzip_main(int argc, char * * argv) strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1); z_len = strlen(z_suffix); - to_stdout = 1; - /* Allocate all global buffers (for DYN_ALLOC option) */ ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA); ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA); @@ -1802,7 +1818,7 @@ int gzip_main(int argc, char * * argv) #endif /* And get to work */ - treat_stdin(); + treat_stdin(); do_exit(exit_code); return exit_code; /* just to avoid lint warning */ } @@ -1812,7 +1828,7 @@ int gzip_main(int argc, char * * argv) */ local void treat_stdin() { - SET_BINARY_MODE(fileno(stdout)); + SET_BINARY_MODE(fileno(stdout)); strcpy(ifname, "stdin"); strcpy(ofname, "stdout"); @@ -1822,12 +1838,11 @@ local void treat_stdin() ifile_size = -1L; /* convention for unknown size */ clear_bufs(); /* clear input and output buffers */ - to_stdout = 1; part_nb = 0; /* Actually do the compression/decompression. Loop over zipped members. */ - if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; + if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; } /* ======================================================================== @@ -2941,8 +2956,6 @@ local void set_file_type() extern int errno; #endif -extern ulg crc_32_tab[]; /* crc table, defined below */ - /* =========================================================================== * Copy input to output unchanged: zcat == cat with --force. * IN assertion: insize bytes have already been read in inbuf. @@ -11,7 +11,12 @@ #error you need zcat to have gzip support! #endif -static const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n"; +static const char gzip_usage[] = + "gzip [OPTION]... [FILE]...\n\n" + "Compress FILEs with maximum compression.\n\n" + "Options:\n" + "\t-c\tWrite output on standard output\n"; + /* gzip.h -- common declarations for all gzip modules * Copyright (C) 1992-1993 Jean-loup Gailly. @@ -210,7 +215,6 @@ extern int exit_code; /* program exit code */ extern int verbose; /* be verbose (-v) */ extern int quiet; /* be quiet (-q) */ extern int test; /* check .z file integrity */ -extern int to_stdout; /* output to stdout (-c) */ extern int save_orig_name; /* set if original name must be saved */ #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0)) @@ -1726,8 +1730,8 @@ DECLARE(uch, window, 2L*WSIZE); /* local variables */ 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 tostdout = 0; /* uncompress to stdout (-c) */ 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 foreground; /* set if program run in foreground */ @@ -1767,8 +1771,22 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */ // int main (argc, argv) // int argc; // char **argv; -int gzip_main(int argc, char * * argv) +int gzip_main(int argc, char ** argv) { + + /* Parse any options */ + while (--argc > 0 && **(++argv) == '-') { + while (*(++(*argv))) { + switch (**argv) { + case 'c': + tostdout = 1; + break; + default: + usage(gzip_usage); + } + } + } + foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; if (foreground) { (void) signal (SIGINT, (sig_type)abort_gzip); @@ -1787,8 +1805,6 @@ int gzip_main(int argc, char * * argv) strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1); z_len = strlen(z_suffix); - to_stdout = 1; - /* Allocate all global buffers (for DYN_ALLOC option) */ ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA); ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA); @@ -1802,7 +1818,7 @@ int gzip_main(int argc, char * * argv) #endif /* And get to work */ - treat_stdin(); + treat_stdin(); do_exit(exit_code); return exit_code; /* just to avoid lint warning */ } @@ -1812,7 +1828,7 @@ int gzip_main(int argc, char * * argv) */ local void treat_stdin() { - SET_BINARY_MODE(fileno(stdout)); + SET_BINARY_MODE(fileno(stdout)); strcpy(ifname, "stdin"); strcpy(ofname, "stdout"); @@ -1822,12 +1838,11 @@ local void treat_stdin() ifile_size = -1L; /* convention for unknown size */ clear_bufs(); /* clear input and output buffers */ - to_stdout = 1; part_nb = 0; /* Actually do the compression/decompression. Loop over zipped members. */ - if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; + if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; } /* ======================================================================== @@ -2941,8 +2956,6 @@ local void set_file_type() extern int errno; #endif -extern ulg crc_32_tab[]; /* crc table, defined below */ - /* =========================================================================== * Copy input to output unchanged: zcat == cat with --force. * IN assertion: insize bytes have already been read in inbuf. @@ -1025,7 +1025,7 @@ int unzip(in, out) extern int errno; #endif -const ulg crc_32_tab[]; /* crc table, defined below */ +static const ulg crc_32_tab[]; /* crc table, defined below */ /* =========================================================================== * Run a set of bytes through the crc shift register. If s is a NULL @@ -1239,7 +1239,7 @@ voidp xmalloc (size) /* ======================================================================== * Table of CRC-32's of all single-byte values (made by makecrc.c) */ -const 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, |