xref: /original-bsd/usr.bin/learn/lrntee/lrntee.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1986, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)lrntee.c	8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17 
18 main()
19 {
20 	int f;
21 	char c;
22 
23 	f = creat(".ocopy", 0666);
24 	while (read(0, &c, 1) == 1) {
25 		write (1, &c, 1);
26 		put(c, f);
27 	}
28 	fl(f);
29 	close(f);
30 }
31 
32 static char ln[512];
33 char *p = ln;
34 put(c, f)
35 {
36 	*p++ = c;
37 	if (c == '\n') {
38 		fl(f);
39 		p=ln;
40 	}
41 }
42 fl(f)
43 {
44 	register char *s;
45 
46 	s = ln;
47 	while (*s == '%' && *(s+1) == ' ')
48 		s += 2;
49 	write(f, s, p-s);
50 }
51