aboutsummaryrefslogtreecommitdiff
path: root/gzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzip.c')
-rw-r--r--gzip.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/gzip.c b/gzip.c
index de794febb..c36270647 100644
--- a/gzip.c
+++ b/gzip.c
@@ -11,7 +11,12 @@
11#error you need zcat to have gzip support! 11#error you need zcat to have gzip support!
12#endif 12#endif
13 13
14static const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n"; 14static const char gzip_usage[] =
15 "gzip [OPTION]... [FILE]...\n\n"
16 "Compress FILEs with maximum compression.\n\n"
17 "Options:\n"
18 "\t-c\tWrite output on standard output\n";
19
15 20
16/* gzip.h -- common declarations for all gzip modules 21/* gzip.h -- common declarations for all gzip modules
17 * Copyright (C) 1992-1993 Jean-loup Gailly. 22 * Copyright (C) 1992-1993 Jean-loup Gailly.
@@ -210,7 +215,6 @@ extern int exit_code; /* program exit code */
210extern int verbose; /* be verbose (-v) */ 215extern int verbose; /* be verbose (-v) */
211extern int quiet; /* be quiet (-q) */ 216extern int quiet; /* be quiet (-q) */
212extern int test; /* check .z file integrity */ 217extern int test; /* check .z file integrity */
213extern int to_stdout; /* output to stdout (-c) */
214extern int save_orig_name; /* set if original name must be saved */ 218extern int save_orig_name; /* set if original name must be saved */
215 219
216#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0)) 220#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
@@ -1726,8 +1730,8 @@ DECLARE(uch, window, 2L*WSIZE);
1726 /* local variables */ 1730 /* local variables */
1727 1731
1728int ascii = 0; /* convert end-of-lines to local OS conventions */ 1732int ascii = 0; /* convert end-of-lines to local OS conventions */
1729int to_stdout = 0; /* output to stdout (-c) */
1730int decompress = 0; /* decompress (-d) */ 1733int decompress = 0; /* decompress (-d) */
1734int tostdout = 0; /* uncompress to stdout (-c) */
1731int no_name = -1; /* don't save or restore the original file name */ 1735int no_name = -1; /* don't save or restore the original file name */
1732int no_time = -1; /* don't save or restore the original file time */ 1736int no_time = -1; /* don't save or restore the original file time */
1733int foreground; /* set if program run in foreground */ 1737int foreground; /* set if program run in foreground */
@@ -1767,8 +1771,22 @@ static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
1767// int main (argc, argv) 1771// int main (argc, argv)
1768// int argc; 1772// int argc;
1769// char **argv; 1773// char **argv;
1770int gzip_main(int argc, char * * argv) 1774int gzip_main(int argc, char ** argv)
1771{ 1775{
1776
1777 /* Parse any options */
1778 while (--argc > 0 && **(++argv) == '-') {
1779 while (*(++(*argv))) {
1780 switch (**argv) {
1781 case 'c':
1782 tostdout = 1;
1783 break;
1784 default:
1785 usage(gzip_usage);
1786 }
1787 }
1788 }
1789
1772 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; 1790 foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
1773 if (foreground) { 1791 if (foreground) {
1774 (void) signal (SIGINT, (sig_type)abort_gzip); 1792 (void) signal (SIGINT, (sig_type)abort_gzip);
@@ -1787,8 +1805,6 @@ int gzip_main(int argc, char * * argv)
1787 strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1); 1805 strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
1788 z_len = strlen(z_suffix); 1806 z_len = strlen(z_suffix);
1789 1807
1790 to_stdout = 1;
1791
1792 /* Allocate all global buffers (for DYN_ALLOC option) */ 1808 /* Allocate all global buffers (for DYN_ALLOC option) */
1793 ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA); 1809 ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
1794 ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA); 1810 ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
@@ -1802,7 +1818,7 @@ int gzip_main(int argc, char * * argv)
1802#endif 1818#endif
1803 1819
1804 /* And get to work */ 1820 /* And get to work */
1805 treat_stdin(); 1821 treat_stdin();
1806 do_exit(exit_code); 1822 do_exit(exit_code);
1807 return exit_code; /* just to avoid lint warning */ 1823 return exit_code; /* just to avoid lint warning */
1808} 1824}
@@ -1812,7 +1828,7 @@ int gzip_main(int argc, char * * argv)
1812 */ 1828 */
1813local void treat_stdin() 1829local void treat_stdin()
1814{ 1830{
1815 SET_BINARY_MODE(fileno(stdout)); 1831 SET_BINARY_MODE(fileno(stdout));
1816 strcpy(ifname, "stdin"); 1832 strcpy(ifname, "stdin");
1817 strcpy(ofname, "stdout"); 1833 strcpy(ofname, "stdout");
1818 1834
@@ -1822,12 +1838,11 @@ local void treat_stdin()
1822 ifile_size = -1L; /* convention for unknown size */ 1838 ifile_size = -1L; /* convention for unknown size */
1823 1839
1824 clear_bufs(); /* clear input and output buffers */ 1840 clear_bufs(); /* clear input and output buffers */
1825 to_stdout = 1;
1826 part_nb = 0; 1841 part_nb = 0;
1827 1842
1828 /* Actually do the compression/decompression. Loop over zipped members. 1843 /* Actually do the compression/decompression. Loop over zipped members.
1829 */ 1844 */
1830 if ((*work)(fileno(stdin), fileno(stdout)) != OK) return; 1845 if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
1831} 1846}
1832 1847
1833/* ======================================================================== 1848/* ========================================================================
@@ -2941,8 +2956,6 @@ local void set_file_type()
2941 extern int errno; 2956 extern int errno;
2942#endif 2957#endif
2943 2958
2944extern ulg crc_32_tab[]; /* crc table, defined below */
2945
2946/* =========================================================================== 2959/* ===========================================================================
2947 * Copy input to output unchanged: zcat == cat with --force. 2960 * Copy input to output unchanged: zcat == cat with --force.
2948 * IN assertion: insize bytes have already been read in inbuf. 2961 * IN assertion: insize bytes have already been read in inbuf.