mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
gzip: getopt_ulflags'isation
This commit is contained in:
parent
27ee7ba95e
commit
01e88f0339
@ -1122,44 +1122,36 @@ typedef struct dirent dir_type;
|
|||||||
/* ======================================================================== */
|
/* ======================================================================== */
|
||||||
int gzip_main(int argc, char **argv)
|
int gzip_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
enum {
|
||||||
|
OPT_tostdout = 0x1,
|
||||||
|
OPT_force = 0x2,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned long opt;
|
||||||
int result;
|
int result;
|
||||||
int inFileNum;
|
int inFileNum;
|
||||||
int outFileNum;
|
int outFileNum;
|
||||||
struct stat statBuf;
|
struct stat statBuf;
|
||||||
char *delFileName;
|
char *delFileName;
|
||||||
int tostdout = 0;
|
|
||||||
int force = 0;
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "cf123456789dq")) != -1) {
|
opt = bb_getopt_ulflags(argc, argv, "cf123456789q" USE_GUNZIP("d"));
|
||||||
switch (opt) {
|
//if (opt & 0x1) // -c
|
||||||
case 'c':
|
//if (opt & 0x2) // -f
|
||||||
tostdout = 1;
|
/* Ignore 1-9 (compression level) options */
|
||||||
break;
|
//if (opt & 0x4) // -1
|
||||||
case 'f':
|
//if (opt & 0x8) // -2
|
||||||
force = 1;
|
//if (opt & 0x10) // -3
|
||||||
break;
|
//if (opt & 0x20) // -4
|
||||||
/* Ignore 1-9 (compression level) options */
|
//if (opt & 0x40) // -5
|
||||||
case '1':
|
//if (opt & 0x80) // -6
|
||||||
case '2':
|
//if (opt & 0x100) // -7
|
||||||
case '3':
|
//if (opt & 0x200) // -8
|
||||||
case '4':
|
//if (opt & 0x400) // -9
|
||||||
case '5':
|
//if (opt & 0x800) // -q
|
||||||
case '6':
|
if (ENABLE_GUNZIP && (opt & 0x1000)) { // -d
|
||||||
case '7':
|
/* FIXME: bb_getopt_ulflags should not depend on optind */
|
||||||
case '8':
|
optind = 1;
|
||||||
case '9':
|
return gunzip_main(argc, argv);
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
break;
|
|
||||||
#ifdef CONFIG_GUNZIP
|
|
||||||
case 'd':
|
|
||||||
optind = 1;
|
|
||||||
return gunzip_main(argc, argv);
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
@ -1211,7 +1203,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
bb_perror_msg_and_die("%s", argv[i]);
|
bb_perror_msg_and_die("%s", argv[i]);
|
||||||
time_stamp = statBuf.st_ctime;
|
time_stamp = statBuf.st_ctime;
|
||||||
|
|
||||||
if (!tostdout) {
|
if (!(opt & OPT_tostdout)) {
|
||||||
path = xasprintf("%s.gz", argv[i]);
|
path = xasprintf("%s.gz", argv[i]);
|
||||||
|
|
||||||
/* Open output file */
|
/* Open output file */
|
||||||
@ -1233,7 +1225,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
outFileNum = STDOUT_FILENO;
|
outFileNum = STDOUT_FILENO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == NULL && isatty(outFileNum) && force == 0) {
|
if (path == NULL && isatty(outFileNum) && !(opt & OPT_force)) {
|
||||||
bb_error_msg
|
bb_error_msg
|
||||||
("compressed data not written to a terminal. Use -f to force compression.");
|
("compressed data not written to a terminal. Use -f to force compression.");
|
||||||
free(path);
|
free(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user