summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorassar <assar@FreeBSD.org>2001-03-04 06:04:50 +0000
committerassar <assar@FreeBSD.org>2001-03-04 06:04:50 +0000
commitc78c138f0f1e0db42115c306e06a6c59f6d5b4bc (patch)
treea8c2687c4b1bd822502b1894633d12e6b935cec7
parent35583224c700ea795d0000e00b57a46e7f96d2fb (diff)
downloadFreeBSD-src-c78c138f0f1e0db42115c306e06a6c59f6d5b4bc.zip
FreeBSD-src-c78c138f0f1e0db42115c306e06a6c59f6d5b4bc.tar.gz
implement OCRNL, ONOCR, and ONLRET
Obtained from: NetBSD
-rw-r--r--bin/stty/modes.c6
-rw-r--r--bin/stty/print.c3
-rw-r--r--bin/stty/stty.110
-rw-r--r--share/man/man4/termios.419
-rw-r--r--sys/kern/tty.c12
-rw-r--r--sys/sys/termios.h3
6 files changed, 52 insertions, 1 deletions
diff --git a/bin/stty/modes.c b/bin/stty/modes.c
index b1f333e..f724a537 100644
--- a/bin/stty/modes.c
+++ b/bin/stty/modes.c
@@ -191,10 +191,16 @@ struct modes omodes[] = {
{ "-litout", OPOST, 0 },
{ "onlcr", ONLCR, 0 },
{ "-onlcr", 0, ONLCR },
+ { "ocrnl", OCRNL, 0 },
+ { "-ocrnl", 0, OCRNL },
{ "tabs", 0, OXTABS }, /* "preserve" tabs */
{ "-tabs", OXTABS, 0 },
{ "oxtabs", OXTABS, 0 },
{ "-oxtabs", 0, OXTABS },
+ { "onocr", ONOCR, 0 },
+ { "-onocr", 0, ONOCR },
+ { "onlret", ONLRET, 0 },
+ { "-onlret", 0, ONLRET },
{ NULL },
};
diff --git a/bin/stty/print.c b/bin/stty/print.c
index a0149c2..364b95b 100644
--- a/bin/stty/print.c
+++ b/bin/stty/print.c
@@ -148,7 +148,10 @@ print(tp, wp, ldisc, fmt)
binit("oflags");
put("-opost", OPOST, 1);
put("-onlcr", ONLCR, 1);
+ put("-ocrnl", OCRNL, 0);
put("-oxtabs", OXTABS, 1);
+ put("-onocr", OXTABS, 0);
+ put("-onlret", OXTABS, 0);
/* control flags (hardware state) */
tmp = tp->c_cflag;
diff --git a/bin/stty/stty.1 b/bin/stty/stty.1
index bf0bcf6..3720fbd 100644
--- a/bin/stty/stty.1
+++ b/bin/stty/stty.1
@@ -237,8 +237,18 @@ Map (do not map)
to
.Dv CR-NL
on output.
+.It Cm ocrnl Pq Fl ocrnl
+Map (do not map)
+.Dv CR
+to
+.Dv NL
+on output.
.It Cm oxtabs Pq Fl oxtabs
Expand (do not expand) tabs to spaces on output.
+.It Cm onocr Pq Fl onocr
+Do not (do) output CRs at column zero.
+.It Cm onlret Pq Fl onlret
+On the terminal NL performs (does not perform) the CR function.
.El
.Ss Local Modes:
.Pp
diff --git a/share/man/man4/termios.4 b/share/man/man4/termios.4
index 773ee24..3d8a534 100644
--- a/share/man/man4/termios.4
+++ b/share/man/man4/termios.4
@@ -994,6 +994,8 @@ and are composed of the following masks:
/* map NL to CR-NL (ala
.Dv CRMOD )
*/
+.It Dv OCRNL
+/* map CR to NL */
.It Dv OXTABS
/* expand tabs to spaces */
.It Dv ONOEOT
@@ -1001,6 +1003,10 @@ and are composed of the following masks:
.Dv EOT Ns 's
.Ql \&^D
on output) */
+.It Dv ONOCR
+/* do not transmit CRs on column 0 */
+.It Dv ONLRET
+/* on the termianl NL performs the CR function */
.El
.Pp
If
@@ -1013,6 +1019,10 @@ If
is set, newlines are translated to carriage return, linefeeds.
.Pp
If
+.Dv OCRNL
+is set, carriage returns are translated to newlines.
+.Pp
+If
.Dv OXTABS
is set, tabs are expanded to the appropriate number of
spaces (assuming 8 column tab stops).
@@ -1023,6 +1033,15 @@ is set,
.Tn ASCII
.Dv EOT Ns 's
are discarded on output.
+.Pp
+If
+.Dv ONOCR
+is set, no CR character is transmitted when at column 0 (first position).
+.Pp
+If
+.Dv ONLRET
+is set, the NL character is assumed to do the carriage-return function;
+the column pointer will be set to 0.
.Ss Control Modes
Values of the
.Fa c_cflag
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 1bc30ca..a7ba12d 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -667,9 +667,16 @@ ttyoutput(c, tp)
if (c == '\n' && ISSET(tp->t_oflag, ONLCR)) {
tk_nout++;
tp->t_outcc++;
- if (putc('\r', &tp->t_outq))
+ if (!ISSET(tp->t_lflag, FLUSHO) && putc('\r', &tp->t_outq))
return (c);
}
+ /* If OCRNL is set, translate "\r" into "\n". */
+ else if (c == '\r' && ISSET(tp->t_oflag, OCRNL))
+ c = '\n';
+ /* If ONOCR is set, don't transmit CRs when on column 0. */
+ else if (c == '\r' && ISSET(tp->t_oflag, ONOCR) && tp->t_column == 0)
+ return (-1);
+
tk_nout++;
tp->t_outcc++;
if (!ISSET(tp->t_lflag, FLUSHO) && putc(c, &tp->t_outq))
@@ -684,6 +691,9 @@ ttyoutput(c, tp)
case CONTROL:
break;
case NEWLINE:
+ if (ISSET(tp->t_oflag, ONLCR | ONLRET))
+ col = 0;
+ break;
case RETURN:
col = 0;
break;
diff --git a/sys/sys/termios.h b/sys/sys/termios.h
index 6111fc3..7e7643f 100644
--- a/sys/sys/termios.h
+++ b/sys/sys/termios.h
@@ -112,6 +112,9 @@
#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
#define OXTABS 0x00000004 /* expand tabs to spaces */
#define ONOEOT 0x00000008 /* discard EOT's (^D) on output) */
+#define OCRNL 0x00000010 /* map CR to NL on output */
+#define ONOCR 0x00000020 /* no CR output at column 0 */
+#define ONLRET 0x00000040 /* NL performs CR function */
#endif /*_POSIX_SOURCE */
/*
OpenPOWER on IntegriCloud