I wrote:
> Right, but stealing these small snippets from NetBSD wasn't very hard,
> see patch below.

Here's a better patch, including stty.  If there are no objects, I'll
commit this.

/assar
Index: bin/stty/modes.c
===================================================================
RCS file: /home/ncvs/src/bin/stty/modes.c,v
retrieving revision 1.8
diff -u -w -r1.8 modes.c
--- bin/stty/modes.c    1999/08/27 23:15:41     1.8
+++ bin/stty/modes.c    2000/12/29 22:47:29
@@ -191,10 +191,16 @@
        { "-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 },
 };
 
Index: bin/stty/print.c
===================================================================
RCS file: /home/ncvs/src/bin/stty/print.c,v
retrieving revision 1.14
diff -u -w -r1.14 print.c
--- bin/stty/print.c    2000/04/30 17:04:25     1.14
+++ bin/stty/print.c    2000/12/29 22:47:29
@@ -148,7 +148,10 @@
        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;
Index: bin/stty/stty.1
===================================================================
RCS file: /home/ncvs/src/bin/stty/stty.1,v
retrieving revision 1.18
diff -u -w -r1.18 stty.1
--- bin/stty/stty.1     2000/11/28 19:48:06     1.18
+++ bin/stty/stty.1     2000/12/29 22:47:29
@@ -237,8 +237,18 @@
 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
Index: share/man/man4/termios.4
===================================================================
RCS file: /home/ncvs/src/share/man/man4/termios.4,v
retrieving revision 1.17
diff -u -w -r1.17 termios.4
--- share/man/man4/termios.4    2000/11/22 16:10:59     1.17
+++ share/man/man4/termios.4    2000/12/29 22:48:23
@@ -991,6 +991,8 @@
 /* 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
@@ -998,6 +1000,10 @@
 .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
@@ -1010,6 +1016,10 @@
 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).
@@ -1020,6 +1030,15 @@
 .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
Index: sys/kern/tty.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/tty.c,v
retrieving revision 1.142
diff -u -w -r1.142 tty.c
--- sys/kern/tty.c      2000/12/08 21:50:36     1.142
+++ sys/kern/tty.c      2000/12/29 22:48:54
@@ -663,9 +663,16 @@
        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))
@@ -680,6 +687,9 @@
        case CONTROL:
                break;
        case NEWLINE:
+               if (ISSET(tp->t_oflag, ONLCR | ONLRET))
+                       col = 0;
+               break;
        case RETURN:
                col = 0;
                break;
Index: sys/sys/termios.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/termios.h,v
retrieving revision 1.14
diff -u -w -r1.14 termios.h
--- sys/sys/termios.h   2000/11/28 20:03:23     1.14
+++ sys/sys/termios.h   2000/12/29 22:49:10
@@ -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 */
 
 /*

Reply via email to