Fix zcat/gunzip when reading from stdin

This commit is contained in:
Glenn L McGrath 2001-04-18 13:34:09 +00:00
parent 2771d1a574
commit bcfeb2ac44
2 changed files with 56 additions and 52 deletions

View File

@ -60,9 +60,6 @@ static char *license_msg[] = {
}; };
#endif #endif
//#include <sys/types.h>
//#include <sys/wait.h>
//#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -93,37 +90,42 @@ extern int gunzip_main(int argc, char **argv)
/* if called as zcat */ /* if called as zcat */
if (strcmp(applet_name, "zcat") == 0) { if (strcmp(applet_name, "zcat") == 0) {
if (argc != 2) { if (argc > 2) {
show_usage(); show_usage();
} }
optind = 1; else if (argc == 2) {
flags |= (gunzip_force | gunzip_to_stdout); /* a filename was specified */
flags |= (gunzip_to_stdout | gunzip_force);
optind = 1;
} else {
/* read from stdin, this gets caught below as argv[optind] will be NULL */
optind = argc;
}
} else { } else {
/* workout flags as regular gunzip */ /* workout flags as regular gunzip */
/* set default flags */ while ((opt = getopt(argc, argv, "ctfh")) != -1) {
if (argc == 1) { switch (opt) {
flags |= (gunzip_from_stdin | gunzip_to_stdout); case 'c':
} else { flags |= gunzip_to_stdout;
/* Parse any options */ break;
while ((opt = getopt(argc, argv, "ctfh")) != -1) { case 'f':
switch (opt) { flags |= gunzip_force;
case 'c': break;
flags |= gunzip_to_stdout; case 't':
break; flags |= gunzip_test;
case 'f': break;
flags |= gunzip_force; case 'h':
break; default:
case 't': show_usage(); /* exit's inside usage */
flags |= gunzip_test;
break;
case 'h':
default:
show_usage(); /* exit's inside usage */
}
} }
} }
} }
/* no filename specified so it must be reading from stdin to stdout */
if (argv[optind] == NULL) {
flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
}
/* Set input filename and number */ /* Set input filename and number */
if (flags & gunzip_from_stdin) { if (flags & gunzip_from_stdin) {
in_file = stdin; in_file = stdin;

View File

@ -60,9 +60,6 @@ static char *license_msg[] = {
}; };
#endif #endif
//#include <sys/types.h>
//#include <sys/wait.h>
//#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -93,37 +90,42 @@ extern int gunzip_main(int argc, char **argv)
/* if called as zcat */ /* if called as zcat */
if (strcmp(applet_name, "zcat") == 0) { if (strcmp(applet_name, "zcat") == 0) {
if (argc != 2) { if (argc > 2) {
show_usage(); show_usage();
} }
optind = 1; else if (argc == 2) {
flags |= (gunzip_force | gunzip_to_stdout); /* a filename was specified */
flags |= (gunzip_to_stdout | gunzip_force);
optind = 1;
} else {
/* read from stdin, this gets caught below as argv[optind] will be NULL */
optind = argc;
}
} else { } else {
/* workout flags as regular gunzip */ /* workout flags as regular gunzip */
/* set default flags */ while ((opt = getopt(argc, argv, "ctfh")) != -1) {
if (argc == 1) { switch (opt) {
flags |= (gunzip_from_stdin | gunzip_to_stdout); case 'c':
} else { flags |= gunzip_to_stdout;
/* Parse any options */ break;
while ((opt = getopt(argc, argv, "ctfh")) != -1) { case 'f':
switch (opt) { flags |= gunzip_force;
case 'c': break;
flags |= gunzip_to_stdout; case 't':
break; flags |= gunzip_test;
case 'f': break;
flags |= gunzip_force; case 'h':
break; default:
case 't': show_usage(); /* exit's inside usage */
flags |= gunzip_test;
break;
case 'h':
default:
show_usage(); /* exit's inside usage */
}
} }
} }
} }
/* no filename specified so it must be reading from stdin to stdout */
if (argv[optind] == NULL) {
flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
}
/* Set input filename and number */ /* Set input filename and number */
if (flags & gunzip_from_stdin) { if (flags & gunzip_from_stdin) {
in_file = stdin; in_file = stdin;