2 * Mini tee implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by John Beppu <beppu@lineo.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 static const char tee_usage[] =
28 "tee [OPTION]... [FILE]...\n\n"
29 "Copy standard input to each FILE, and also to standard output.\n\n"
31 "\t-a\tappend to the given FILEs, do not overwrite\n"
33 "\t-i\tignore interrupt signals\n"
38 /* FileList _______________________________________________________________ */
41 static FILE *FileList[FL_MAX];
44 typedef void (FL_Function)(FILE *file, char c);
47 /* apply a function to everything in FileList */
49 FL_apply(FL_Function *f, char c)
52 for (i = 0; i <= FL_end; i++) {
57 /* FL_Function for writing to files*/
59 tee_fwrite(FILE *file, char c)
64 /* FL_Function for closing files */
66 tee_fclose(FILE *file, char c)
71 /* ________________________________________________________________________ */
73 /* BusyBoxed tee(1) */
75 tee_main(int argc, char **argv)
80 char opt_fopen[2] = "w";
84 for (i = 1; i < argc; i++) {
85 if (argv[i][0] == '-') {
93 fprintf(stderr, "ignore interrupt not implemented\n");
104 /* init FILE pointers */
106 FileList[0] = stdout;
107 for ( ; i < argc; i++) {
108 /* add a file to FileList */
109 file = fopen(argv[i], opt_fopen);
110 if (!file) { continue; }
111 if (FL_end < FL_MAX) {
112 FileList[++FL_end] = file;
116 /* read and redirect */
117 while ((c = (char) getchar()) && (!feof(stdin))) {
118 FL_apply(tee_fwrite, c);
122 FL_apply(tee_fclose, 0);
126 /* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */