diff options
author | Kang-Che Sung <explorer09@gmail.com> | 2017-01-08 09:28:34 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-09 11:03:31 +0300 |
commit | b130f9f758b6404c6d0911a1c120937ae6ab47f8 (patch) | |
tree | ce1502cfcfc67e7e9fb40b85d13488273aa82689 | |
parent | fb87d93d1e0a6760049fa88aadd1232b7e1545e7 (diff) |
Allow 'gzip -d' and 'bzip2 -d' without gunzip or bunzip2
Idea copied from the "ip" applet.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/bbunzip.c | 20 | ||||
-rw-r--r-- | archival/bzip2.c | 16 | ||||
-rw-r--r-- | archival/gzip.c | 24 |
3 files changed, 41 insertions, 19 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 0eff58713..12c82eba4 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -12,9 +12,9 @@ //kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o //kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o /* bzip2_main() too: */ -//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o +//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o /* gzip_main() too: */ -//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o +//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o /* Note: must be kept in sync with archival/lzop.c */ enum { @@ -197,7 +197,7 @@ int FAST_FUNC bbunpack(char **argv, } #if ENABLE_UNCOMPRESS \ - || ENABLE_BUNZIP2 || ENABLE_BZCAT \ + || ENABLE_FEATURE_BZIP2_DECOMPRESS \ || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \ || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ static @@ -295,6 +295,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //config:config GUNZIP //config: bool "gunzip" //config: default y +//config: select FEATURE_GZIP_DECOMPRESS //config: help //config: gunzip is used to decompress archives created by gzip. //config: You can use the `-t' option to test the integrity of @@ -303,6 +304,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //config:config ZCAT //config: bool "zcat" //config: default y +//config: select FEATURE_GZIP_DECOMPRESS //config: help //config: Alias to "gunzip -c". //config: @@ -315,9 +317,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) //applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) -//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o -//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o -#if ENABLE_GUNZIP || ENABLE_ZCAT +#if ENABLE_FEATURE_GZIP_DECOMPRESS static char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM) { @@ -385,7 +385,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); } -#endif +#endif /* FEATURE_GZIP_DECOMPRESS */ /* @@ -408,6 +408,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) //config:config BUNZIP2 //config: bool "bunzip2" //config: default y +//config: select FEATURE_BZIP2_DECOMPRESS //config: help //config: bunzip2 is a compression utility using the Burrows-Wheeler block //config: sorting text compression algorithm, and Huffman coding. Compression @@ -421,14 +422,13 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) //config:config BZCAT //config: bool "bzcat" //config: default y +//config: select FEATURE_BZIP2_DECOMPRESS //config: help //config: Alias to "bunzip2 -c". //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) //applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) -//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o -//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o -#if ENABLE_BUNZIP2 || ENABLE_BZCAT +#if ENABLE_FEATURE_BZIP2_DECOMPRESS int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int bunzip2_main(int argc UNUSED_PARAM, char **argv) { diff --git a/archival/bzip2.c b/archival/bzip2.c index 47fa29af3..7e38e78b3 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -19,6 +19,15 @@ //config: //config: Unless you have a specific application which requires bzip2, you //config: should probably say N here. +//config: +//config:config FEATURE_BZIP2_DECOMPRESS +//config: bool "Enable decompression" +//config: default y +//config: depends on BZIP2 || BUNZIP2 || BZCAT +//config: help +//config: Enable -d (--decompress) and -t (--test) options for bzip2. +//config: This will be automatically selected if bunzip2 or bzcat is +//config: enabled. //applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_BZIP2) += bzip2.o @@ -28,7 +37,10 @@ //usage:#define bzip2_full_usage "\n\n" //usage: "Compress FILEs (or stdin) with bzip2 algorithm\n" //usage: "\n -1..9 Compression level" +//usage: IF_FEATURE_BZIP2_DECOMPRESS( //usage: "\n -d Decompress" +//usage: "\n -t Test file integrity" +//usage: ) //usage: "\n -c Write to stdout" //usage: "\n -f Force" @@ -184,8 +196,8 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv) opt_complementary = "s2"; /* -s means -2 (compatibility) */ /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ - opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs"); -#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */ + opt = getopt32(argv, "cfv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"); +#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */ if (opt & 0x18) // -d and/or -t return bunzip2_main(argc, argv); opt >>= 5; 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] */ |