Rework per how I did things in version in 0.60.3 so it can

properly uncompress multiple files now.
 -Erik
This commit is contained in:
Eric Andersen 2002-04-13 09:10:34 +00:00
parent 114de55668
commit d75ac02a4f

View File

@ -68,27 +68,22 @@ static char *license_msg[] = {
extern int gunzip_main(int argc, char **argv)
{
FILE *in_file = stdin;
FILE *out_file = NULL;
int flags = 0;
int opt = 0;
int delete_old_file, file_count;
struct stat stat_buf;
char *if_name = NULL;
char *of_name = NULL;
char *delete_file_name = NULL;
FILE *in_file, *out_file;
char *if_name, *of_name, *delete_file_name;
const int gunzip_to_stdout = 1;
const int gunzip_force = 2;
const int gunzip_test = 4;
int flags = 0;
int opt = 0;
int delete_old_file = FALSE;
const int gunzip_verbose = 8;
/* if called as zcat */
if (strcmp(applet_name, "zcat") == 0)
flags |= gunzip_to_stdout;
while ((opt = getopt(argc, argv, "ctfhdq")) != -1) {
while ((opt = getopt(argc, argv, "ctfhdqv")) != -1) {
switch (opt) {
case 'c':
flags |= gunzip_to_stdout;
@ -99,6 +94,9 @@ extern int gunzip_main(int argc, char **argv)
case 't':
flags |= gunzip_test;
break;
case 'v':
flags |= gunzip_verbose;
break;
case 'd': /* Used to convert gzip to gunzip. */
break;
case 'q':
@ -110,14 +108,29 @@ extern int gunzip_main(int argc, char **argv)
}
}
file_count = argc - optind;
while (file_count==0 || optind < argc) {
in_file = stdin;
out_file = NULL;
if_name = NULL;
of_name = NULL;
delete_file_name = NULL;
delete_old_file = FALSE;
/* Set input filename and number */
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
flags |= gunzip_to_stdout;
/* Skip to the end */
optind = argc;
} else {
if_name = xstrdup(argv[optind]);
if_name = strdup(argv[optind]);
/* Open input file */
in_file = xfopen(if_name, "r");
if (flags & gunzip_verbose) {
fprintf(stderr, "%s:\t", if_name);
}
/* set the buffer size */
setvbuf(in_file, NULL, _IOFBF, 0x8000);
@ -163,6 +176,9 @@ extern int gunzip_main(int argc, char **argv)
if (unzip(in_file, out_file) == 0) {
/* Success, remove .gz file */
delete_file_name = if_name;
if (flags & gunzip_verbose) {
fprintf(stderr, "OK\n");
}
} else {
/* remove failed attempt */
delete_file_name = of_name;
@ -171,13 +187,16 @@ extern int gunzip_main(int argc, char **argv)
fclose(out_file);
fclose(in_file);
if (delete_old_file) {
if (delete_old_file == TRUE && !(flags & gunzip_test)) {
if (unlink(delete_file_name) < 0) {
error_msg_and_die("Couldnt remove %s", delete_file_name);
}
}
free(of_name);
optind++;
} /* while () */
return(EXIT_SUCCESS);
}