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