diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-12-10 08:25:07 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-12-10 08:25:07 +0000 |
commit | 2cb55077e2f65f17dbc8933eec47760bcc2a6ba1 (patch) | |
tree | a788718415ded192938d7c7a3661d0cab8cd8afe /coreutils/tee.c | |
parent | c5ff0165adac767d37103baa875c2f86bb43c0e1 (diff) | |
download | busybox-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.c | 60 |
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 | ||
27 | static const char tee_usage[] = | 27 | static 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 | ||
40 | typedef void (FL_Function)(FILE *file, char c); | 44 | typedef void (FL_Function)(FILE *file, char c); |
41 | 45 | ||
42 | /* initialize FileList */ | ||
43 | static void | ||
44 | FL_init() | ||
45 | { | ||
46 | FL_end = 0; | ||
47 | FileList[0] = stdout; | ||
48 | } | ||
49 | |||
50 | /* add a file to FileList */ | ||
51 | static int | ||
52 | FL_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 */ |
65 | static void | 48 | static 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*/ |
77 | static void | 58 | static void |
78 | tee_fwrite(FILE *file, char c) | 59 | tee_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) */ |
91 | int | 74 | int |
92 | tee_main(int argc, char **argv) | 75 | tee_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 $ */ |