summaryrefslogtreecommitdiffstats
path: root/share/man/tools/line.c
diff options
context:
space:
mode:
Diffstat (limited to 'share/man/tools/line.c')
-rw-r--r--share/man/tools/line.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/share/man/tools/line.c b/share/man/tools/line.c
new file mode 100644
index 0000000..b395e1a
--- /dev/null
+++ b/share/man/tools/line.c
@@ -0,0 +1,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);
+}
OpenPOWER on IntegriCloud