*
*/
+#include "internal.h"
#include <stdio.h>
-#include <stdlib.h>
+
+static const char tee_usage[] =
+ "tee [OPTION]... [FILE]...\n\n"
+ "Copy standard input to each FILE, and also to standard output.\n\n"
+ "Options:\n"
+ "\t-a\tappend to the given FILEs, do not overwrite\n"
+#if 0
+ "\t-i\tignore interrupt signals\n"
+#endif
+ ;
+
/* FileList _______________________________________________________________ */
typedef void (FL_Function)(FILE *file, char c);
-/* initialize FileList */
-static void
-FL_init()
-{
- FL_end = 0;
- FileList[0] = stdout;
-}
-
-/* add a file to FileList */
-static int
-FL_add(const char *filename, char *opt_open)
-{
- FILE *file;
-
- file = fopen(filename, opt_open);
- if (!file) { return 0; };
- if (FL_end < FL_MAX) {
- FileList[++FL_end] = file;
- }
- return 1;
-}
/* apply a function to everything in FileList */
static void
}
}
-/* ________________________________________________________________________ */
-
/* FL_Function for writing to files*/
static void
tee_fwrite(FILE *file, char c)
fclose(file);
}
-/* help message */
-static void
-tee_usage()
-{
- fprintf (
- stdout,
- "%s\n%s\n%s\n%s\n%s\n",
- "Usage: tee [OPTION]... [FILE]...",
- "Copy standard input to each FILE, and also to standard output.\n",
- " -a, append to the given FILEs, do not overwrite",
- " -i, ignore interrupt signals",
- " -h, this help message"
- );
- exit(1);
-}
+/* ________________________________________________________________________ */
/* BusyBoxed tee(1) */
int
char c;
char opt;
char opt_fopen[2] = "w";
+ FILE *file;
/* parse argv[] */
for (i = 1; i < argc; i++) {
case 'a':
opt_fopen[0] = 'a';
break;
+#if 0
case 'i':
- fprintf(stderr, "ingore interrupt not implemented\n");
- break;
- case 'h':
- tee_usage();
+ fprintf(stderr, "ignore interrupt not implemented\n");
break;
+#endif
default:
- fprintf(stderr, "tee: invalid option -- %c\n", opt);
- tee_usage();
+ usage(tee_usage);
}
} else {
break;
}
/* init FILE pointers */
- FL_init();
+ FL_end = 0;
+ FileList[0] = stdout;
for ( ; i < argc; i++) {
- FL_add(argv[i], opt_fopen);
+ /* add a file to FileList */
+ file = fopen(argv[i], opt_fopen);
+ if (!file) { continue; }
+ if (FL_end < FL_MAX) {
+ FileList[++FL_end] = file;
+ }
}
/* read and redirect */
exit(0);
}
-/* $Id: tee.c,v 1.2 1999/12/10 06:45:42 andersen Exp $ */
+/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */