From b130f9f758b6404c6d0911a1c120937ae6ab47f8 Mon Sep 17 00:00:00 2001 From: Kang-Che Sung Date: Sun, 8 Jan 2017 14:28:34 +0800 Subject: Allow 'gzip -d' and 'bzip2 -d' without gunzip or bunzip2 Idea copied from the "ip" applet. Signed-off-by: Kang-Che Sung Signed-off-by: Denys Vlasenko --- archival/gzip.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'archival/gzip.c') diff --git a/archival/gzip.c b/archival/gzip.c index 9e0bee815..63bf76053 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -72,19 +72,29 @@ aa: 85.1% -- replaced with aa.gz //config: is 6. If levels 1-3 are specified, 4 is used. //config: If this option is not selected, -N options are ignored and -9 //config: is used. +//config: +//config:config FEATURE_GZIP_DECOMPRESS +//config: bool "Enable decompression" +//config: default y +//config: depends on GZIP || GUNZIP || ZCAT +//config: help +//config: Enable -d (--decompress) and -t (--test) options for gzip. +//config: This will be automatically selected if gunzip or zcat is +//config: enabled. //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_GZIP) += gzip.o //usage:#define gzip_trivial_usage -//usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." +//usage: "[-cf" IF_FEATURE_GZIP_DECOMPRESS("dt") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." //usage:#define gzip_full_usage "\n\n" //usage: "Compress FILEs (or stdin)\n" //usage: IF_FEATURE_GZIP_LEVELS( //usage: "\n -1..9 Compression level" //usage: ) -//usage: IF_GUNZIP( +//usage: IF_FEATURE_GZIP_DECOMPRESS( //usage: "\n -d Decompress" +//usage: "\n -t Test file integrity" //usage: ) //usage: "\n -c Write to stdout" //usage: "\n -f Force" @@ -2154,7 +2164,7 @@ static const char gzip_longopts[] ALIGN1 = "to-stdout\0" No_argument "c" "force\0" No_argument "f" "verbose\0" No_argument "v" -#if ENABLE_GUNZIP +#if ENABLE_FEATURE_GZIP_DECOMPRESS "decompress\0" No_argument "d" "uncompress\0" No_argument "d" "test\0" No_argument "t" @@ -2181,7 +2191,7 @@ static const char gzip_longopts[] ALIGN1 = */ int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -#if ENABLE_GUNZIP +#if ENABLE_FEATURE_GZIP_DECOMPRESS int gzip_main(int argc, char **argv) #else int gzip_main(int argc UNUSED_PARAM, char **argv) @@ -2211,13 +2221,13 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) applet_long_options = gzip_longopts; #endif /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ - opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789"); -#if ENABLE_GUNZIP /* gunzip_main may not be visible... */ + opt = getopt32(argv, "cfv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789"); +#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */ if (opt & 0x18) // -d and/or -t return gunzip_main(argc, argv); #endif #ifdef ENABLE_FEATURE_GZIP_LEVELS - opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */ + opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 7 : 5; /* drop cfv[dt]qn bits */ if (opt == 0) opt = 1 << 6; /* default: 6 */ opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ -- cgit v1.2.3