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