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