aboutsummaryrefslogtreecommitdiff
path: root/coreutils/tee.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /coreutils/tee.c
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'coreutils/tee.c')
-rw-r--r--coreutils/tee.c129
1 files changed, 64 insertions, 65 deletions
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 4c5c691c6..2f746f96d 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini tee implementation for busybox 3 * Mini tee implementation for busybox
3 * 4 *
@@ -25,102 +26,100 @@
25#include <stdio.h> 26#include <stdio.h>
26 27
27static const char tee_usage[] = 28static const char tee_usage[] =
28 "tee [OPTION]... [FILE]...\n\n" 29 "tee [OPTION]... [FILE]...\n\n"
29 "Copy standard input to each FILE, and also to standard output.\n\n" 30 "Copy standard input to each FILE, and also to standard output.\n\n"
30 "Options:\n" 31 "Options:\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
31 "\t-a\tappend to the given FILEs, do not overwrite\n"
32#if 0 32#if 0
33 "\t-i\tignore interrupt signals\n" 33 "\t-i\tignore interrupt signals\n"
34#endif 34#endif
35 ; 35;
36 36
37 37
38/* FileList _______________________________________________________________ */ 38/* FileList _______________________________________________________________ */
39 39
40#define FL_MAX 1024 40#define FL_MAX 1024
41static FILE *FileList[FL_MAX]; 41static FILE *FileList[FL_MAX];
42static int FL_end; 42static int FL_end;
43
44typedef void (FL_Function) (FILE * file, char c);
43 45
44typedef void (FL_Function)(FILE *file, char c);
45
46 46
47/* apply a function to everything in FileList */ 47/* apply a function to everything in FileList */
48static void 48static void FL_apply(FL_Function * f, char c)
49FL_apply(FL_Function *f, char c)
50{ 49{
51 int i; 50 int i;
52 for (i = 0; i <= FL_end; i++) { 51
53 f(FileList[i], c); 52 for (i = 0; i <= FL_end; i++) {
54 } 53 f(FileList[i], c);
54 }
55} 55}
56 56
57/* FL_Function for writing to files*/ 57/* FL_Function for writing to files*/
58static void 58static void tee_fwrite(FILE * file, char c)
59tee_fwrite(FILE *file, char c)
60{ 59{
61 fputc(c, file); 60 fputc(c, file);
62} 61}
63 62
64/* FL_Function for closing files */ 63/* FL_Function for closing files */
65static void 64static void tee_fclose(FILE * file, char c)
66tee_fclose(FILE *file, char c)
67{ 65{
68 fclose(file); 66 fclose(file);
69} 67}
70 68
71/* ________________________________________________________________________ */ 69/* ________________________________________________________________________ */
72 70
73/* BusyBoxed tee(1) */ 71/* BusyBoxed tee(1) */
74int 72int tee_main(int argc, char **argv)
75tee_main(int argc, char **argv)
76{ 73{
77 int i; 74 int i;
78 char c; 75 char c;
79 char opt; 76 char opt;
80 char opt_fopen[2] = "w"; 77 char opt_fopen[2] = "w";
81 FILE *file; 78 FILE *file;
82 79
83 /* parse argv[] */ 80 /* parse argv[] */
84 for (i = 1; i < argc; i++) { 81 for (i = 1; i < argc; i++) {
85 if (argv[i][0] == '-') { 82 if (argv[i][0] == '-') {
86 opt = argv[i][1]; 83 opt = argv[i][1];
87 switch (opt) { 84 switch (opt) {
88 case 'a': 85 case 'a':
89 opt_fopen[0] = 'a'; 86 opt_fopen[0] = 'a';
90 break; 87 break;
91#if 0 88#if 0
92 case 'i': 89 case 'i':
93 fprintf(stderr, "ignore interrupt not implemented\n"); 90 fprintf(stderr, "ignore interrupt not implemented\n");
94 break; 91 break;
95#endif 92#endif
96 default: 93 default:
97 usage(tee_usage); 94 usage(tee_usage);
98 } 95 }
99 } else { 96 } else {
100 break; 97 break;
98 }
101 } 99 }
102 } 100
103 101 /* init FILE pointers */
104 /* init FILE pointers */ 102 FL_end = 0;
105 FL_end = 0; 103 FileList[0] = stdout;
106 FileList[0] = stdout; 104 for (; i < argc; i++) {
107 for ( ; i < argc; i++) { 105 /* add a file to FileList */
108 /* add a file to FileList */ 106 file = fopen(argv[i], opt_fopen);
109 file = fopen(argv[i], opt_fopen); 107 if (!file) {
110 if (!file) { continue; } 108 continue;
111 if (FL_end < FL_MAX) { 109 }
112 FileList[++FL_end] = file; 110 if (FL_end < FL_MAX) {
111 FileList[++FL_end] = file;
112 }
113 } 113 }
114 }
115 114
116 /* read and redirect */ 115 /* read and redirect */
117 while ((c = (char) getchar()) && (!feof(stdin))) { 116 while ((c = (char) getchar()) && (!feof(stdin))) {
118 FL_apply(tee_fwrite, c); 117 FL_apply(tee_fwrite, c);
119 } 118 }
120 119
121 /* clean up */ 120 /* clean up */
122 FL_apply(tee_fclose, 0); 121 FL_apply(tee_fclose, 0);
123 exit(0); 122 exit(0);
124} 123}
125 124
126/* $Id: tee.c,v 1.5 2000/02/07 05:29:42 erik Exp $ */ 125/* $Id: tee.c,v 1.6 2000/02/08 19:58:47 erik Exp $ */