xref: /netbsd-src/share/man/tools/line.c (revision 3fe138c1461e710931a50b66f08982c5f52c371f)
1*3fe138c1Sperry /*	$NetBSD: line.c,v 1.2 1998/01/09 08:05:00 perry Exp $	*/
2*3fe138c1Sperry 
3a50e92eeSmrg /*	@(#)line.c	1.1	*/
4a50e92eeSmrg /*
5a50e92eeSmrg 	This program reads a single line from the standard input
6a50e92eeSmrg 	and writes it on the standard output. It is probably most useful
7a50e92eeSmrg 	in conjunction with the Bourne shell.
8a50e92eeSmrg */
9a50e92eeSmrg #define LSIZE 512
10a50e92eeSmrg int EOF;
11a50e92eeSmrg char nl = '\n';
main()12a50e92eeSmrg main()
13a50e92eeSmrg {
14a50e92eeSmrg 	register char c;
15a50e92eeSmrg 	char line[LSIZE];
16a50e92eeSmrg 	register char *linep, *linend;
17a50e92eeSmrg 
18a50e92eeSmrg EOF = 0;
19a50e92eeSmrg linep = line;
20a50e92eeSmrg linend = line + LSIZE;
21a50e92eeSmrg 
22a50e92eeSmrg while ((c = readc()) != nl)
23a50e92eeSmrg 	{
24a50e92eeSmrg 	if (linep == linend)
25a50e92eeSmrg 		{
26a50e92eeSmrg 		write (1, line, LSIZE);
27a50e92eeSmrg 		linep = line;
28a50e92eeSmrg 		}
29a50e92eeSmrg 	*linep++ = c;
30a50e92eeSmrg 	}
31a50e92eeSmrg write (1, line, linep-line);
32a50e92eeSmrg write(1,&nl,1);
33a50e92eeSmrg if (EOF == 1) exit(1);
34a50e92eeSmrg exit (0);
35a50e92eeSmrg }
readc()36a50e92eeSmrg readc()
37a50e92eeSmrg {
38a50e92eeSmrg 	char c;
39a50e92eeSmrg if (read (0, &c, 1) != 1) {
40a50e92eeSmrg 	EOF = 1;
41a50e92eeSmrg 	return(nl);
42a50e92eeSmrg 	}
43a50e92eeSmrg else
44a50e92eeSmrg 	return (c);
45a50e92eeSmrg }
46