xref: /csrg-svn/usr.bin/learn/NOTUSED/tee.c (revision 62052)
148269Sbostic /*-
2*62052Sbostic  * Copyright (c) 1983, 1993
3*62052Sbostic  *	The Regents of the University of California.  All rights reserved.
448269Sbostic  *
548269Sbostic  * %sccs.include.proprietary.c%
648269Sbostic  */
748269Sbostic 
811266Smckusick #ifndef lint
9*62052Sbostic static char sccsid[] = "@(#)tee.c	8.1 (Berkeley) 06/06/93";
1048269Sbostic #endif /* not lint */
1111266Smckusick 
1211266Smckusick #include <stdio.h>
main()1311266Smckusick main()
1411266Smckusick {
1511266Smckusick 	int f, c;
1611266Smckusick 
1711266Smckusick 	f = creat(".ocopy", 0666);
1811266Smckusick 	while (read(0, &c, 1) == 1) {
1911266Smckusick 		write (1, &c, 1);
2011266Smckusick 		put(c, f);
2111266Smckusick 	}
2211266Smckusick 	fl(f);
2311266Smckusick 	close(f);
2411266Smckusick }
2511266Smckusick 
2611266Smckusick static char ln[BUFSIZ];
2711266Smckusick char *p = ln;
put(c,f)2811266Smckusick put(c, f)
2911266Smckusick {
3011266Smckusick 	*p++ = c;
3111266Smckusick 	if (c == '\n') {
3211266Smckusick 		fl(f);
3311266Smckusick 		p=ln;
3411266Smckusick 	}
3511266Smckusick }
fl(f)3611266Smckusick fl(f)
3711266Smckusick {
3811266Smckusick 	register char *s;
3911266Smckusick 
4011266Smckusick 	s = ln;
4111266Smckusick 	while (*s == '$' && *(s+1) == ' ')
4211266Smckusick 		s += 2;
4311266Smckusick 	write(f, s, p-s);
4411266Smckusick }
45