Subject: Re: standards/3434: OCRNL not defined in termios.h
To: None <mcr@sandelman.ottawa.on.ca>
From: Klaus Klein <kleink@layla.inka.de>
List: netbsd-bugs
Date: 04/02/1997 02:18:03
On Tue, 1 Apr 1997 15:21:19 -0500 (EST),
 Michael Richardson <mcr@sandelman.ottawa.on.ca> wrote:

> 	I don't know if this is POSIX or not, this this patch makes 
> 	compiling them just work.

Actually it's X/Open.

> *** /usr/include/termios.h      Wed Apr 10 07:38:17 1996
> --- /w/netbsd/src/sys/sys/termios.h     Tue Apr  1 15:16:14 1997
> ***************
> *** 112,117 ****
> --- 112,118 ----
>   #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 outp
> ut) */
> + #define OCRNL           0x00000000      /* not available */
>   #endif  /*_POSIX_SOURCE */

Ew. "So what happens if an application really relies on this?"
I'd suggest we implement the real thing, then.


-klaus



Index: src/share/man/man4/termios.4
===================================================================
RCS file: /cvsroot/netbsd/src/share/man/man4/termios.4,v
retrieving revision 1.1.1.3
diff -b -c -r1.1.1.3 termios.4
*** termios.4	1997/03/14 16:16:49	1.1.1.3
--- termios.4	1997/04/02 00:14:42
***************
*** 973,978 ****
--- 973,980 ----
  /* 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
***************
*** 990,995 ****
--- 992,1001 ----
  If
  .Dv ONLCR
  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
Index: src/sys/kern/tty.c
===================================================================
RCS file: /cvsroot/netbsd/src/sys/kern/tty.c,v
retrieving revision 1.1.1.1.2.9
diff -b -c -r1.1.1.1.2.9 tty.c
*** tty.c	1997/04/01 19:40:50	1.1.1.1.2.9
--- tty.c	1997/04/02 00:14:42
***************
*** 608,613 ****
--- 608,619 ----
  		if (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';
+ 
  	tk_nout++;
  	tp->t_outcc++;
  	if (!ISSET(tp->t_lflag, FLUSHO) && putc(c, &tp->t_outq))
***************
*** 622,627 ****
--- 628,636 ----
  	case CONTROL:
  		break;
  	case NEWLINE:
+ 		if(ISSET(tp->t_oflag, OCRNL))
+ 			col = 0;
+ 		break;
  	case RETURN:
  		col = 0;
  		break;
Index: src/sys/sys/termios.h
===================================================================
RCS file: /cvsroot/netbsd/src/sys/sys/termios.h,v
retrieving revision 1.1.1.1.2.1
diff -b -c -r1.1.1.1.2.1 termios.h
*** termios.h	1997/02/03 09:49:08	1.1.1.1.2.1
--- termios.h	1997/04/02 00:14:42
***************
*** 112,117 ****
--- 112,118 ----
  #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 */
  #endif  /*_POSIX_SOURCE */
  
  /*
Index: src/bin/stty/modes.c
===================================================================
RCS file: /cvsroot/netbsd/src/bin/stty/modes.c,v
retrieving revision 1.1.1.1
diff -b -c -r1.1.1.1 modes.c
*** modes.c	1996/12/20 13:14:33	1.1.1.1
--- modes.c	1997/04/02 00:14:42
***************
*** 185,190 ****
--- 185,192 ----
  	{ "-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 },
Index: src/bin/stty/print.c
===================================================================
RCS file: /cvsroot/netbsd/src/bin/stty/print.c,v
retrieving revision 1.1.1.1
diff -b -c -r1.1.1.1 print.c
*** print.c	1996/12/20 13:14:33	1.1.1.1
--- print.c	1997/04/02 00:14:42
***************
*** 148,153 ****
--- 148,154 ----
  	binit("oflags");
  	put("-opost", OPOST, 1);
  	put("-onlcr", ONLCR, 1);
+ 	put("-ocrnl", OCRNL, 0);
  	put("-oxtabs", OXTABS, 1);
  
  	/* control flags (hardware state) */
Index: src/bin/stty/stty.1
===================================================================
RCS file: /cvsroot/netbsd/src/bin/stty/stty.1,v
retrieving revision 1.1.1.2
diff -b -c -r1.1.1.2 stty.1
*** stty.1	1997/03/14 15:48:29	1.1.1.2
--- stty.1	1997/04/02 00:14:42
***************
*** 240,245 ****
--- 240,251 ----
  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.
  .El