summaryrefslogtreecommitdiff
path: root/coreutils/tee.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-12-10 08:25:07 +0000
committerEric Andersen <andersen@codepoet.org>1999-12-10 08:25:07 +0000
commit2cb55077e2f65f17dbc8933eec47760bcc2a6ba1 (patch)
treea788718415ded192938d7c7a3661d0cab8cd8afe /coreutils/tee.c
parentc5ff0165adac767d37103baa875c2f86bb43c0e1 (diff)
downloadbusybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.tar.gz
busybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.tar.bz2
busybox-w32-2cb55077e2f65f17dbc8933eec47760bcc2a6ba1.zip
Added poweroff (and adjusted init to use it). Inlined function
calls to code only called once in tee. Made BB_KLOGD and option. -Erik
Diffstat (limited to 'coreutils/tee.c')
-rw-r--r--coreutils/tee.c60
1 files changed, 24 insertions, 36 deletions
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 45128b568..8d1ca6efd 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -25,11 +25,15 @@
25#include <stdio.h> 25#include <stdio.h>
26 26
27static const char tee_usage[] = 27static const char tee_usage[] =
28"Usage: tee [OPTION]... [FILE]...\n" 28 "tee [OPTION]... [FILE]...\n\n"
29"Copy standard input to each FILE, and also to standard output.\n\n" 29 "Copy standard input to each FILE, and also to standard output.\n\n"
30" -a, append to the given FILEs, do not overwrite\n" 30 "Options:\n"
31" -i, ignore interrupt signals\n" 31 "\t-a\tappend to the given FILEs, do not overwrite\n"
32" -h, this help message\n"; 32#if 0
33 "\t-i\tignore interrupt signals\n"
34#endif
35 ;
36
33 37
34/* FileList _______________________________________________________________ */ 38/* FileList _______________________________________________________________ */
35 39
@@ -39,27 +43,6 @@ static int FL_end;
39 43
40typedef void (FL_Function)(FILE *file, char c); 44typedef void (FL_Function)(FILE *file, char c);
41 45
42/* initialize FileList */
43static void
44FL_init()
45{
46 FL_end = 0;
47 FileList[0] = stdout;
48}
49
50/* add a file to FileList */
51static int
52FL_add(const char *filename, char *opt_open)
53{
54 FILE *file;
55
56 file = fopen(filename, opt_open);
57 if (!file) { return 0; };
58 if (FL_end < FL_MAX) {
59 FileList[++FL_end] = file;
60 }
61 return 1;
62}
63 46
64/* apply a function to everything in FileList */ 47/* apply a function to everything in FileList */
65static void 48static void
@@ -71,8 +54,6 @@ FL_apply(FL_Function *f, char c)
71 } 54 }
72} 55}
73 56
74/* ________________________________________________________________________ */
75
76/* FL_Function for writing to files*/ 57/* FL_Function for writing to files*/
77static void 58static void
78tee_fwrite(FILE *file, char c) 59tee_fwrite(FILE *file, char c)
@@ -87,6 +68,8 @@ tee_fclose(FILE *file, char c)
87 fclose(file); 68 fclose(file);
88} 69}
89 70
71/* ________________________________________________________________________ */
72
90/* BusyBoxed tee(1) */ 73/* BusyBoxed tee(1) */
91int 74int
92tee_main(int argc, char **argv) 75tee_main(int argc, char **argv)
@@ -95,6 +78,7 @@ tee_main(int argc, char **argv)
95 char c; 78 char c;
96 char opt; 79 char opt;
97 char opt_fopen[2] = "w"; 80 char opt_fopen[2] = "w";
81 FILE *file;
98 82
99 /* parse argv[] */ 83 /* parse argv[] */
100 for (i = 1; i < argc; i++) { 84 for (i = 1; i < argc; i++) {
@@ -104,14 +88,12 @@ tee_main(int argc, char **argv)
104 case 'a': 88 case 'a':
105 opt_fopen[0] = 'a'; 89 opt_fopen[0] = 'a';
106 break; 90 break;
91#if 0
107 case 'i': 92 case 'i':
108 fprintf(stderr, "ingore interrupt not implemented\n"); 93 fprintf(stderr, "ignore interrupt not implemented\n");
109 break;
110 case 'h':
111 usage(tee_usage);
112 break; 94 break;
95#endif
113 default: 96 default:
114 fprintf(stderr, "tee: invalid option -- %c\n", opt);
115 usage(tee_usage); 97 usage(tee_usage);
116 } 98 }
117 } else { 99 } else {
@@ -120,9 +102,15 @@ tee_main(int argc, char **argv)
120 } 102 }
121 103
122 /* init FILE pointers */ 104 /* init FILE pointers */
123 FL_init(); 105 FL_end = 0;
106 FileList[0] = stdout;
124 for ( ; i < argc; i++) { 107 for ( ; i < argc; i++) {
125 FL_add(argv[i], opt_fopen); 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;
113 }
126 } 114 }
127 115
128 /* read and redirect */ 116 /* read and redirect */
@@ -135,4 +123,4 @@ tee_main(int argc, char **argv)
135 exit(0); 123 exit(0);
136} 124}
137 125
138/* $Id: tee.c,v 1.3 1999/12/10 07:41:03 beppu Exp $ */ 126/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */