aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>1999-12-10 05:27:16 +0000
committerJohn Beppu <beppu@lbox.org>1999-12-10 05:27:16 +0000
commit059f152a7a2d1796cf93d1a79f33055d38b94f2a (patch)
treef099ca4df6d8a137af037e0bfd6976d06a627e66
parent29fcc90f3e0ebd8b4d4d5f1a96741f982baa38f1 (diff)
downloadbusybox-w32-059f152a7a2d1796cf93d1a79f33055d38b94f2a.tar.gz
busybox-w32-059f152a7a2d1796cf93d1a79f33055d38b94f2a.tar.bz2
busybox-w32-059f152a7a2d1796cf93d1a79f33055d38b94f2a.zip
Implemented tee(1).
-rw-r--r--Changelog1
-rw-r--r--applets/busybox.c3
-rw-r--r--busybox.c3
-rw-r--r--busybox.def.h3
-rw-r--r--coreutils/tee.c147
-rw-r--r--internal.h1
-rw-r--r--tee.c147
7 files changed, 304 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index edaa34c24..3694a2ffb 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@
16 which blocked reboots. 16 which blocked reboots.
17 * Added a prelinary du implementation. Some parameter parsing 17 * Added a prelinary du implementation. Some parameter parsing
18 stuff still needs to be added. -beppu 18 stuff still needs to be added. -beppu
19 * Implemented tee -beppu
19 20
20 -Erik Andrsen 21 -Erik Andrsen
21 22
diff --git a/applets/busybox.c b/applets/busybox.c
index c050acc9c..4ac907665 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -182,6 +182,9 @@ static const struct Applet applets[] = {
182#ifdef BB_TAR //bin 182#ifdef BB_TAR //bin
183 {"tar", tar_main}, 183 {"tar", tar_main},
184#endif 184#endif
185#ifdef BB_TEE //bin
186 {"tee", tee_main},
187#endif
185#ifdef BB_TOUCH //usr/bin 188#ifdef BB_TOUCH //usr/bin
186 {"touch", touch_main}, 189 {"touch", touch_main},
187#endif 190#endif
diff --git a/busybox.c b/busybox.c
index c050acc9c..4ac907665 100644
--- a/busybox.c
+++ b/busybox.c
@@ -182,6 +182,9 @@ static const struct Applet applets[] = {
182#ifdef BB_TAR //bin 182#ifdef BB_TAR //bin
183 {"tar", tar_main}, 183 {"tar", tar_main},
184#endif 184#endif
185#ifdef BB_TEE //bin
186 {"tee", tee_main},
187#endif
185#ifdef BB_TOUCH //usr/bin 188#ifdef BB_TOUCH //usr/bin
186 {"touch", touch_main}, 189 {"touch", touch_main},
187#endif 190#endif
diff --git a/busybox.def.h b/busybox.def.h
index efab4941c..cd3447f15 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -59,8 +59,9 @@
59#define BB_SWAPONOFF 59#define BB_SWAPONOFF
60#define BB_SYNC 60#define BB_SYNC
61#define BB_SYSLOGD 61#define BB_SYSLOGD
62#define BB_TAR
63#define BB_TAIL 62#define BB_TAIL
63#define BB_TAR
64#define BB_TEE
64#define BB_TOUCH 65#define BB_TOUCH
65#define BB_TRUE_FALSE 66#define BB_TRUE_FALSE
66#define BB_UMOUNT 67#define BB_UMOUNT
diff --git a/coreutils/tee.c b/coreutils/tee.c
new file mode 100644
index 000000000..fe444fcc4
--- /dev/null
+++ b/coreutils/tee.c
@@ -0,0 +1,147 @@
1/*
2 * Mini tee implementation for busybox
3 *
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by John Beppu <beppu@line.com>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26
27/* FileList _______________________________________________________________ */
28
29#define FL_MAX 1024
30static FILE *FileList[FL_MAX];
31static int FL_end;
32
33typedef void (FL_Function)(FILE *file, char c);
34
35/* initialize FileList */
36static void
37FL_init()
38{
39 FL_end = 0;
40 FileList[0] = stdout;
41}
42
43/* add a file to FileList */
44static int
45FL_add(const char *filename, char *opt_open)
46{
47 FILE *file;
48
49 file = fopen(filename, opt_open);
50 if (!file) { return 0; };
51 if (FL_end < FL_MAX) {
52 FileList[++FL_end] = file;
53 }
54 return 1;
55}
56
57/* apply a function to everything in FileList */
58static void
59FL_apply(FL_Function *f, char c)
60{
61 int i;
62 for (i = 0; i <= FL_end; i++) {
63 f(FileList[i], c);
64 }
65}
66
67/* ________________________________________________________________________ */
68
69/* FL_Function for writing to files*/
70static void
71tee_fwrite(FILE *file, char c)
72{
73 fputc(c, file);
74}
75
76/* FL_Function for closing files */
77static void
78tee_fclose(FILE *file, char c)
79{
80 fclose(file);
81}
82
83/* help message */
84static void
85tee_usage()
86{
87 fprintf (
88 stdout,
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"
95 );
96 exit(1);
97}
98
99/* BusyBoxed tee(1) */
100int
101tee_main(int argc, char **argv)
102{
103 int i;
104 char c;
105 char opt;
106 char opt_fopen[2] = "w";
107
108 /* parse argv[] */
109 for (i = 1; i < argc; i++) {
110 if (argv[i][0] == '-') {
111 opt = argv[i][1];
112 switch (opt) {
113 case 'a':
114 opt_fopen[0] = 'a';
115 break;
116 case 'i':
117 fprintf(stderr, "ingore interrupt not implemented\n");
118 break;
119 case 'h':
120 tee_usage();
121 break;
122 default:
123 fprintf(stderr, "tee: invalid option -- %c\n", opt);
124 tee_usage();
125 }
126 } else {
127 break;
128 }
129 }
130
131 /* init FILE pointers */
132 FL_init();
133 for ( ; i < argc; i++) {
134 FL_add(argv[i], opt_fopen);
135 }
136
137 /* read and redirect */
138 while ((c = (char) getchar()) && (!feof(stdin))) {
139 FL_apply(tee_fwrite, c);
140 }
141
142 /* clean up */
143 FL_apply(tee_fclose, 0);
144 exit(0);
145}
146
147/* $Id: tee.c,v 1.1 1999/12/10 05:27:16 beppu Exp $ */
diff --git a/internal.h b/internal.h
index de13bb202..4bde46612 100644
--- a/internal.h
+++ b/internal.h
@@ -112,6 +112,7 @@ extern int syslogd_main(int argc, char **argv);
112extern int logger_main(int argc, char **argv); 112extern int logger_main(int argc, char **argv);
113extern int tar_main(int argc, char** argv); 113extern int tar_main(int argc, char** argv);
114extern int tail_main(int argc, char** argv); 114extern int tail_main(int argc, char** argv);
115extern int tee_main(int argc, char** argv);
115extern int touch_main(int argc, char** argv); 116extern int touch_main(int argc, char** argv);
116extern int tput_main(int argc, char** argv); 117extern int tput_main(int argc, char** argv);
117extern int true_main(int argc, char** argv); 118extern int true_main(int argc, char** argv);
diff --git a/tee.c b/tee.c
new file mode 100644
index 000000000..fe444fcc4
--- /dev/null
+++ b/tee.c
@@ -0,0 +1,147 @@
1/*
2 * Mini tee implementation for busybox
3 *
4 *
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by John Beppu <beppu@line.com>
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26
27/* FileList _______________________________________________________________ */
28
29#define FL_MAX 1024
30static FILE *FileList[FL_MAX];
31static int FL_end;
32
33typedef void (FL_Function)(FILE *file, char c);
34
35/* initialize FileList */
36static void
37FL_init()
38{
39 FL_end = 0;
40 FileList[0] = stdout;
41}
42
43/* add a file to FileList */
44static int
45FL_add(const char *filename, char *opt_open)
46{
47 FILE *file;
48
49 file = fopen(filename, opt_open);
50 if (!file) { return 0; };
51 if (FL_end < FL_MAX) {
52 FileList[++FL_end] = file;
53 }
54 return 1;
55}
56
57/* apply a function to everything in FileList */
58static void
59FL_apply(FL_Function *f, char c)
60{
61 int i;
62 for (i = 0; i <= FL_end; i++) {
63 f(FileList[i], c);
64 }
65}
66
67/* ________________________________________________________________________ */
68
69/* FL_Function for writing to files*/
70static void
71tee_fwrite(FILE *file, char c)
72{
73 fputc(c, file);
74}
75
76/* FL_Function for closing files */
77static void
78tee_fclose(FILE *file, char c)
79{
80 fclose(file);
81}
82
83/* help message */
84static void
85tee_usage()
86{
87 fprintf (
88 stdout,
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"
95 );
96 exit(1);
97}
98
99/* BusyBoxed tee(1) */
100int
101tee_main(int argc, char **argv)
102{
103 int i;
104 char c;
105 char opt;
106 char opt_fopen[2] = "w";
107
108 /* parse argv[] */
109 for (i = 1; i < argc; i++) {
110 if (argv[i][0] == '-') {
111 opt = argv[i][1];
112 switch (opt) {
113 case 'a':
114 opt_fopen[0] = 'a';
115 break;
116 case 'i':
117 fprintf(stderr, "ingore interrupt not implemented\n");
118 break;
119 case 'h':
120 tee_usage();
121 break;
122 default:
123 fprintf(stderr, "tee: invalid option -- %c\n", opt);
124 tee_usage();
125 }
126 } else {
127 break;
128 }
129 }
130
131 /* init FILE pointers */
132 FL_init();
133 for ( ; i < argc; i++) {
134 FL_add(argv[i], opt_fopen);
135 }
136
137 /* read and redirect */
138 while ((c = (char) getchar()) && (!feof(stdin))) {
139 FL_apply(tee_fwrite, c);
140 }
141
142 /* clean up */
143 FL_apply(tee_fclose, 0);
144 exit(0);
145}
146
147/* $Id: tee.c,v 1.1 1999/12/10 05:27:16 beppu Exp $ */