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