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 /* FileList _______________________________________________________________ */
30 static FILE *FileList[FL_MAX];
33 typedef void (FL_Function)(FILE *file, char c);
35 /* initialize FileList */
43 /* add a file to FileList */
45 FL_add(const char *filename, char *opt_open)
49 file = fopen(filename, opt_open);
50 if (!file) { return 0; };
51 if (FL_end < FL_MAX) {
52 FileList[++FL_end] = file;
57 /* apply a function to everything in FileList */
59 FL_apply(FL_Function *f, char c)
62 for (i = 0; i <= FL_end; i++) {
67 /* ________________________________________________________________________ */
69 /* FL_Function for writing to files*/
71 tee_fwrite(FILE *file, char c)
76 /* FL_Function for closing files */
78 tee_fclose(FILE *file, char c)
89 "%s\n%s\n%s\n%s\n%s\n",
90 "Usage: tee [OPTION]... [FILE]...",
91 "Copy standard input to each FILE, and also to standard output.\n",
92 " -a, append to the given FILEs, do not overwrite",
93 " -i, ignore interrupt signals",
94 " -h, this help message"
99 /* BusyBoxed tee(1) */
101 tee_main(int argc, char **argv)
106 char opt_fopen[2] = "w";
109 for (i = 1; i < argc; i++) {
110 if (argv[i][0] == '-') {
117 fprintf(stderr, "ingore interrupt not implemented\n");
123 fprintf(stderr, "tee: invalid option -- %c\n", opt);
131 /* init FILE pointers */
133 for ( ; i < argc; i++) {
134 FL_add(argv[i], opt_fopen);
137 /* read and redirect */
138 while ((c = (char) getchar()) && (!feof(stdin))) {
139 FL_apply(tee_fwrite, c);
143 FL_apply(tee_fclose, 0);
147 /* $Id: tee.c,v 1.2 1999/12/10 06:45:42 andersen Exp $ */