aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKang-Che Sung <explorer09@gmail.com>2017-01-08 14:28:34 +0800
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-09 09:03:31 +0100
commitb130f9f758b6404c6d0911a1c120937ae6ab47f8 (patch)
treece1502cfcfc67e7e9fb40b85d13488273aa82689
parentfb87d93d1e0a6760049fa88aadd1232b7e1545e7 (diff)
downloadbusybox-w32-b130f9f758b6404c6d0911a1c120937ae6ab47f8.tar.gz
busybox-w32-b130f9f758b6404c6d0911a1c120937ae6ab47f8.tar.bz2
busybox-w32-b130f9f758b6404c6d0911a1c120937ae6ab47f8.zip
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.c20
-rw-r--r--archival/bzip2.c16
-rw-r--r--archival/gzip.c24
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 @@
12//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o 12//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
13//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o 13//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
14/* bzip2_main() too: */ 14/* bzip2_main() too: */
15//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o 15//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o
16/* gzip_main() too: */ 16/* gzip_main() too: */
17//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o 17//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o
18 18
19/* Note: must be kept in sync with archival/lzop.c */ 19/* Note: must be kept in sync with archival/lzop.c */
20enum { 20enum {
@@ -197,7 +197,7 @@ int FAST_FUNC bbunpack(char **argv,
197} 197}
198 198
199#if ENABLE_UNCOMPRESS \ 199#if ENABLE_UNCOMPRESS \
200 || ENABLE_BUNZIP2 || ENABLE_BZCAT \ 200 || ENABLE_FEATURE_BZIP2_DECOMPRESS \
201 || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \ 201 || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
202 || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ 202 || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
203static 203static
@@ -295,6 +295,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
295//config:config GUNZIP 295//config:config GUNZIP
296//config: bool "gunzip" 296//config: bool "gunzip"
297//config: default y 297//config: default y
298//config: select FEATURE_GZIP_DECOMPRESS
298//config: help 299//config: help
299//config: gunzip is used to decompress archives created by gzip. 300//config: gunzip is used to decompress archives created by gzip.
300//config: You can use the `-t' option to test the integrity of 301//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)
303//config:config ZCAT 304//config:config ZCAT
304//config: bool "zcat" 305//config: bool "zcat"
305//config: default y 306//config: default y
307//config: select FEATURE_GZIP_DECOMPRESS
306//config: help 308//config: help
307//config: Alias to "gunzip -c". 309//config: Alias to "gunzip -c".
308//config: 310//config:
@@ -315,9 +317,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
315 317
316//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) 318//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
317//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) 319//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
318//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o 320#if ENABLE_FEATURE_GZIP_DECOMPRESS
319//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
320#if ENABLE_GUNZIP || ENABLE_ZCAT
321static 321static
322char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM) 322char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
323{ 323{
@@ -385,7 +385,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
385 385
386 return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL); 386 return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
387} 387}
388#endif 388#endif /* FEATURE_GZIP_DECOMPRESS */
389 389
390 390
391/* 391/*
@@ -408,6 +408,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
408//config:config BUNZIP2 408//config:config BUNZIP2
409//config: bool "bunzip2" 409//config: bool "bunzip2"
410//config: default y 410//config: default y
411//config: select FEATURE_BZIP2_DECOMPRESS
411//config: help 412//config: help
412//config: bunzip2 is a compression utility using the Burrows-Wheeler block 413//config: bunzip2 is a compression utility using the Burrows-Wheeler block
413//config: sorting text compression algorithm, and Huffman coding. Compression 414//config: sorting text compression algorithm, and Huffman coding. Compression
@@ -421,14 +422,13 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
421//config:config BZCAT 422//config:config BZCAT
422//config: bool "bzcat" 423//config: bool "bzcat"
423//config: default y 424//config: default y
425//config: select FEATURE_BZIP2_DECOMPRESS
424//config: help 426//config: help
425//config: Alias to "bunzip2 -c". 427//config: Alias to "bunzip2 -c".
426 428
427//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) 429//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
428//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) 430//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
429//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o 431#if ENABLE_FEATURE_BZIP2_DECOMPRESS
430//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
431#if ENABLE_BUNZIP2 || ENABLE_BZCAT
432int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 432int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
433int bunzip2_main(int argc UNUSED_PARAM, char **argv) 433int bunzip2_main(int argc UNUSED_PARAM, char **argv)
434{ 434{
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 @@
19//config: 19//config:
20//config: Unless you have a specific application which requires bzip2, you 20//config: Unless you have a specific application which requires bzip2, you
21//config: should probably say N here. 21//config: should probably say N here.
22//config:
23//config:config FEATURE_BZIP2_DECOMPRESS
24//config: bool "Enable decompression"
25//config: default y
26//config: depends on BZIP2 || BUNZIP2 || BZCAT
27//config: help
28//config: Enable -d (--decompress) and -t (--test) options for bzip2.
29//config: This will be automatically selected if bunzip2 or bzcat is
30//config: enabled.
22 31
23//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) 32//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
24//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o 33//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
@@ -28,7 +37,10 @@
28//usage:#define bzip2_full_usage "\n\n" 37//usage:#define bzip2_full_usage "\n\n"
29//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n" 38//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
30//usage: "\n -1..9 Compression level" 39//usage: "\n -1..9 Compression level"
40//usage: IF_FEATURE_BZIP2_DECOMPRESS(
31//usage: "\n -d Decompress" 41//usage: "\n -d Decompress"
42//usage: "\n -t Test file integrity"
43//usage: )
32//usage: "\n -c Write to stdout" 44//usage: "\n -c Write to stdout"
33//usage: "\n -f Force" 45//usage: "\n -f Force"
34 46
@@ -184,8 +196,8 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
184 196
185 opt_complementary = "s2"; /* -s means -2 (compatibility) */ 197 opt_complementary = "s2"; /* -s means -2 (compatibility) */
186 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 198 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
187 opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs"); 199 opt = getopt32(argv, "cfv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs");
188#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */ 200#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
189 if (opt & 0x18) // -d and/or -t 201 if (opt & 0x18) // -d and/or -t
190 return bunzip2_main(argc, argv); 202 return bunzip2_main(argc, argv);
191 opt >>= 5; 203 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
72//config: is 6. If levels 1-3 are specified, 4 is used. 72//config: is 6. If levels 1-3 are specified, 4 is used.
73//config: If this option is not selected, -N options are ignored and -9 73//config: If this option is not selected, -N options are ignored and -9
74//config: is used. 74//config: is used.
75//config:
76//config:config FEATURE_GZIP_DECOMPRESS
77//config: bool "Enable decompression"
78//config: default y
79//config: depends on GZIP || GUNZIP || ZCAT
80//config: help
81//config: Enable -d (--decompress) and -t (--test) options for gzip.
82//config: This will be automatically selected if gunzip or zcat is
83//config: enabled.
75 84
76//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) 85//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
77//kbuild:lib-$(CONFIG_GZIP) += gzip.o 86//kbuild:lib-$(CONFIG_GZIP) += gzip.o
78 87
79//usage:#define gzip_trivial_usage 88//usage:#define gzip_trivial_usage
80//usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." 89//usage: "[-cf" IF_FEATURE_GZIP_DECOMPRESS("dt") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
81//usage:#define gzip_full_usage "\n\n" 90//usage:#define gzip_full_usage "\n\n"
82//usage: "Compress FILEs (or stdin)\n" 91//usage: "Compress FILEs (or stdin)\n"
83//usage: IF_FEATURE_GZIP_LEVELS( 92//usage: IF_FEATURE_GZIP_LEVELS(
84//usage: "\n -1..9 Compression level" 93//usage: "\n -1..9 Compression level"
85//usage: ) 94//usage: )
86//usage: IF_GUNZIP( 95//usage: IF_FEATURE_GZIP_DECOMPRESS(
87//usage: "\n -d Decompress" 96//usage: "\n -d Decompress"
97//usage: "\n -t Test file integrity"
88//usage: ) 98//usage: )
89//usage: "\n -c Write to stdout" 99//usage: "\n -c Write to stdout"
90//usage: "\n -f Force" 100//usage: "\n -f Force"
@@ -2154,7 +2164,7 @@ static const char gzip_longopts[] ALIGN1 =
2154 "to-stdout\0" No_argument "c" 2164 "to-stdout\0" No_argument "c"
2155 "force\0" No_argument "f" 2165 "force\0" No_argument "f"
2156 "verbose\0" No_argument "v" 2166 "verbose\0" No_argument "v"
2157#if ENABLE_GUNZIP 2167#if ENABLE_FEATURE_GZIP_DECOMPRESS
2158 "decompress\0" No_argument "d" 2168 "decompress\0" No_argument "d"
2159 "uncompress\0" No_argument "d" 2169 "uncompress\0" No_argument "d"
2160 "test\0" No_argument "t" 2170 "test\0" No_argument "t"
@@ -2181,7 +2191,7 @@ static const char gzip_longopts[] ALIGN1 =
2181 */ 2191 */
2182 2192
2183int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 2193int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
2184#if ENABLE_GUNZIP 2194#if ENABLE_FEATURE_GZIP_DECOMPRESS
2185int gzip_main(int argc, char **argv) 2195int gzip_main(int argc, char **argv)
2186#else 2196#else
2187int gzip_main(int argc UNUSED_PARAM, char **argv) 2197int gzip_main(int argc UNUSED_PARAM, char **argv)
@@ -2211,13 +2221,13 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2211 applet_long_options = gzip_longopts; 2221 applet_long_options = gzip_longopts;
2212#endif 2222#endif
2213 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2223 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
2214 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789"); 2224 opt = getopt32(argv, "cfv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
2215#if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2225#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
2216 if (opt & 0x18) // -d and/or -t 2226 if (opt & 0x18) // -d and/or -t
2217 return gunzip_main(argc, argv); 2227 return gunzip_main(argc, argv);
2218#endif 2228#endif
2219#ifdef ENABLE_FEATURE_GZIP_LEVELS 2229#ifdef ENABLE_FEATURE_GZIP_LEVELS
2220 opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */ 2230 opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 7 : 5; /* drop cfv[dt]qn bits */
2221 if (opt == 0) 2231 if (opt == 0)
2222 opt = 1 << 6; /* default: 6 */ 2232 opt = 1 << 6; /* default: 6 */
2223 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ 2233 opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */