aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-11-18 14:20:25 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-11-18 14:20:25 +0000
commitfff11f1ab7ec7cc67087231361f3bde8ecff115f (patch)
treeef99119582637a44a5a065ac235f6999c85083d8
parentfedce06b7fa53989df8a7994dcd2b24ed5ccf51a (diff)
downloadbusybox-w32-fff11f1ab7ec7cc67087231361f3bde8ecff115f.tar.gz
busybox-w32-fff11f1ab7ec7cc67087231361f3bde8ecff115f.tar.bz2
busybox-w32-fff11f1ab7ec7cc67087231361f3bde8ecff115f.zip
bzcat and bunzip -c support from Thomas Lundquist
-rw-r--r--archival/bunzip2.c38
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h8
3 files changed, 44 insertions, 5 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index da9808e82..290681dd3 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -1,4 +1,5 @@
1/* Modified for busybox by Glenn McGrath <bug1@optushome.com.au> */ 1/* Modified for busybox by Glenn McGrath <bug1@optushome.com.au> */
2/* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> */
2/*-- 3/*--
3 This file is a part of bzip2 and/or libbzip2, a program and 4 This file is a part of bzip2 and/or libbzip2, a program and
4 library for lossless, block-sorting data compression. 5 library for lossless, block-sorting data compression.
@@ -56,6 +57,7 @@
56#include <stdlib.h> 57#include <stdlib.h>
57#include <stdio.h> 58#include <stdio.h>
58#include <string.h> 59#include <string.h>
60#include <getopt.h>
59#include <busybox.h> 61#include <busybox.h>
60 62
61//#define TRUE 1 63//#define TRUE 1
@@ -2316,15 +2318,38 @@ errhandler_io:
2316 2318
2317int bunzip2_main(int argc, char **argv) 2319int bunzip2_main(int argc, char **argv)
2318{ 2320{
2321 const int bunzip_to_stdout = 1;
2322 int flags = 0;
2323 int opt = 0;
2324
2319 FILE *src_stream; 2325 FILE *src_stream;
2320 FILE *dst_stream; 2326 FILE *dst_stream;
2321 char *save_name; 2327 char *save_name;
2322 char *save_name_ptr; 2328 char *save_name_ptr;
2323 if (argc != 2) { 2329
2330 /* if called as bzcat */
2331 if (strcmp(applet_name, "bzcat") == 0)
2332 flags |= bunzip_to_stdout;
2333
2334 while ((opt = getopt(argc, argv, "ch")) != -1) {
2335 switch (opt) {
2336 case 'c':
2337 flags |= bunzip_to_stdout;
2338 break;
2339 case 'h':
2340 default:
2341 show_usage(); /* exit's inside usage */
2342 }
2343 }
2344
2345 save_name = xstrdup(argv[optind]);
2346
2347 if (save_name == NULL) {
2324 show_usage(); 2348 show_usage();
2325 } 2349 }
2326 src_stream = xfopen(argv[1], "r"); 2350
2327 save_name = xstrdup(argv[1]); 2351 src_stream = xfopen(argv[optind], "r");
2352
2328 save_name_ptr = strrchr(save_name, '.'); 2353 save_name_ptr = strrchr(save_name, '.');
2329 if (save_name_ptr == NULL) { 2354 if (save_name_ptr == NULL) {
2330 return(FALSE); 2355 return(FALSE);
@@ -2333,7 +2358,12 @@ int bunzip2_main(int argc, char **argv)
2333 error_msg("Invalid extension, expected .bz2"); 2358 error_msg("Invalid extension, expected .bz2");
2334 } 2359 }
2335 *save_name_ptr = '\0'; 2360 *save_name_ptr = '\0';
2336 dst_stream = xfopen(save_name, "w"); 2361
2362 if (flags & bunzip_to_stdout) {
2363 dst_stream = stdout;
2364 } else {
2365 dst_stream = xfopen(save_name, "w");
2366 }
2337 uncompressStream(src_stream, dst_stream); 2367 uncompressStream(src_stream, dst_stream);
2338 2368
2339 return(TRUE); 2369 return(TRUE);
diff --git a/include/applets.h b/include/applets.h
index ea196cb66..aa112c30b 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -68,6 +68,9 @@
68 APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN) 68 APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN)
69#endif 69#endif
70 APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN) 70 APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
71#ifdef CONFIG_BUNZIP2
72 APPLET(bzcat, bunzip2_main, _BB_DIR_USR_BIN)
73#endif
71#ifdef CONFIG_CAT 74#ifdef CONFIG_CAT
72 APPLET(cat, cat_main, _BB_DIR_BIN) 75 APPLET(cat, cat_main, _BB_DIR_BIN)
73#endif 76#endif
diff --git a/include/usage.h b/include/usage.h
index 12d5e1ed5..df1c18ec7 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -52,11 +52,17 @@
52 "bar" 52 "bar"
53 53
54#define bunzip2_trivial_usage \ 54#define bunzip2_trivial_usage \
55 "FILE" 55 "[-c] FILE"
56#define bunzip2_full_usage \ 56#define bunzip2_full_usage \
57 "Uncompress FILE to current directory, stripping its .bz2 extension.\n"\ 57 "Uncompress FILE to current directory, stripping its .bz2 extension.\n"\
58 " -c output to stdout\n"\
58 " -k is assumed" 59 " -k is assumed"
59 60
61#define bzcat_trivial_usage \
62 "FILE"
63#define bzcat_full_usage \
64 "Uncompress to stdout."
65
60#define cat_trivial_usage \ 66#define cat_trivial_usage \
61 "[FILE]..." 67 "[FILE]..."
62#define cat_full_usage \ 68#define cat_full_usage \