[BusyBox] Adding pseudo-applet.

Thomas Lundquist lists at zelow.no
Sun Nov 18 05:30:29 UTC 2001


I'll call it that at least.

I've added output to stdout ( -c option) for bunzip2 but since gunzip
had zcat I decided to nick that (code and idea) from gunzip aswell.

so, I did as it was done with zcat and added to applets.h and usage.h
the same way as zcat and gunzip.

but now I get:

$ ./busybox bzcat
busybox: applet not found

$ ./busybox 
busybox: applet not found

$ strings busybox | grep bzcat
bzcat
bzcat

anyone been experiencing this before and can give me a hint?
I guess I've forgotten something, somewhere but grepping for
"zcat" hasn't given me any hints either.

I've attached the three diffs (I hope cvs diff is a good enough diff)


Thomas.
-------------- next part --------------
Index: include/applets.h
===================================================================
RCS file: /var/cvs/busybox/include/applets.h,v
retrieving revision 1.49
diff -u -r1.49 applets.h
--- include/applets.h	2001/11/02 11:39:45	1.49
+++ include/applets.h	2001/11/18 12:25:28
@@ -67,6 +67,9 @@
 #ifdef CONFIG_BUNZIP2
 	APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN)
 #endif
+#ifdef CONFIG_BUNZIP2
+	APPLET(bzcat, bunzip2_main, _BB_DIR_USR_BIN)
+#endif
 	APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
 #ifdef CONFIG_CAT
 	APPLET(cat, cat_main, _BB_DIR_BIN)
-------------- next part --------------
Index: archival/bunzip2.c
===================================================================
RCS file: /var/cvs/busybox/archival/bunzip2.c,v
retrieving revision 1.2
diff -u -r1.2 bunzip2.c
--- archival/bunzip2.c	2001/11/12 16:57:15	1.2
+++ archival/bunzip2.c	2001/11/18 12:25:03
@@ -1,4 +1,5 @@
 /* Modified for busybox by Glenn McGrath <bug1 at optushome.com.au> */
+/* Added support output to stdout by Thomas Lundquist <thomasez at zelow.no> */ 
 /*--
   This file is a part of bzip2 and/or libbzip2, a program and
   library for lossless, block-sorting data compression.
@@ -56,6 +57,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <getopt.h>
 #include <busybox.h>
 
 //#define TRUE 1
@@ -2316,15 +2318,38 @@
 
 int bunzip2_main(int argc, char **argv)
 {
+	const int bunzip_to_stdout = 1;
+	int flags = 0;
+	int opt = 0;
+
 	FILE *src_stream;
 	FILE *dst_stream;
 	char *save_name;
 	char *save_name_ptr;
-	if (argc != 2) {
+
+	/* if called as bzcat */
+	if (strcmp(applet_name, "bzcat") == 0)
+		flags |= bunzip_to_stdout;
+
+	while ((opt = getopt(argc, argv, "ch")) != -1) {
+		switch (opt) {
+		case 'c':
+			flags |= bunzip_to_stdout;
+			break;
+		case 'h':
+		default:
+			show_usage(); /* exit's inside usage */
+		}
+	}
+
+	save_name = xstrdup(argv[optind]);
+		
+	if (save_name == NULL) {
 		show_usage();
 	}
-	src_stream = xfopen(argv[1], "r");
-	save_name = xstrdup(argv[1]);
+
+	src_stream = xfopen(argv[optind], "r");
+
 	save_name_ptr = strrchr(save_name, '.');
 	if (save_name_ptr == NULL) {
 		return(FALSE);
@@ -2333,7 +2358,12 @@
 		error_msg("Invalid extension, expected .bz2");
 	}
 	*save_name_ptr = '\0';	
-	dst_stream = xfopen(save_name, "w");
+
+	if (flags & bunzip_to_stdout) {
+		dst_stream = stdout;
+	} else {
+		dst_stream = xfopen(save_name, "w");
+	}
 	uncompressStream(src_stream, dst_stream);
 
 	return(TRUE);
-------------- next part --------------
Index: include/usage.h
===================================================================
RCS file: /var/cvs/busybox/include/usage.h,v
retrieving revision 1.71
diff -u -r1.71 usage.h
--- include/usage.h	2001/11/02 11:39:45	1.71
+++ include/usage.h	2001/11/18 12:25:49
@@ -52,10 +52,16 @@
 	"bar"
 
 #define bunzip2_trivial_usage \
-	"FILE"
+	"[-c] FILE"
 #define bunzip2_full_usage \
 	"Uncompress FILE to current directory, stripping its .bz2 extension.\n"\
+	" -c output to stdout\n"\
 	" -k is assumed" 
+
+#define bzcat_trivial_usage \
+	"FILE"
+#define bzcat_full_usage \
+	"Uncompress to stdout."
 
 #define cat_trivial_usage \
 	"[FILE]..."


More information about the busybox mailing list