[comp.sources.bugs] Rn patch to preserve typeahead when entering and leaving.

jef@ace.ee.lbl.gov (Jef Poskanzer) (02/02/89)

Rn's -T flag supposedly preserves typeahead.  However, even if it is set,
typeahead still gets discarded when entering or leaving CBREAK mode.
This is because rn changes tty modes using the obsolete stty(3) interface,
which at least on my system is implemented with an ioctl(TIOCSETP).

The appended patch changes all the stty's into ioctl(TIOCSETN)'s.  The
only difference between TIOCSETP and TIOCSETN is that TIOCSETN preserves
typeahead when possible.

Perhaps a better fix would be to change stty(3) to use TIOCSETN...
---
Jef

            Jef Poskanzer   jef@helios.ee.lbl.gov   ...well!pokey
     "Any sufficiently advanced bug is indistinguishable from a feature."
                              -- Rich Kulawiec

*** /tmp/,RCSt1a07149	Wed Feb  1 11:52:58 1989
--- term.h	Tue Jan 31 22:16:13 1989
***************
*** 88,94 ****
  #ifdef TERMIO
  
  #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
! #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,stty(_tty_ch,&_tty))
  #define echo()	 ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  #define nl()	 ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
--- 92,98 ----
  #ifdef TERMIO
  
  #define crmode() ((bizarre=1),_tty.c_lflag &=~ICANON,_tty.c_cc[VMIN] = 1,ioctl(_tty_ch,TCSETAF,&_tty))
! #define nocrmode() ((bizarre=1),_tty.c_lflag |= ICANON,_tty.c_cc[VEOF] = CEOF,ioctl(_tty_ch,TIOCSETN,&_tty))
  #define echo()	 ((bizarre=1),_tty.c_lflag |= ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  #define noecho() ((bizarre=1),_tty.c_lflag &=~ECHO, ioctl(_tty_ch, TCSETA, &_tty))
  #define nl()	 ((bizarre=1),_tty.c_iflag |= ICRNL,_tty.c_oflag |= ONLCR,ioctl(_tty_ch, TCSETAW, &_tty))
***************
*** 99,114 ****
  
  #else
  
! #define raw()	 ((bizarre=1),_tty.sg_flags|=RAW, stty(_tty_ch,&_tty))
! #define noraw()	 ((bizarre=1),_tty.sg_flags&=~RAW,stty(_tty_ch,&_tty))
! #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, stty(_tty_ch,&_tty))
! #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,stty(_tty_ch,&_tty))
! #define echo()	 ((bizarre=1),_tty.sg_flags |= ECHO, stty(_tty_ch, &_tty))
! #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, stty(_tty_ch, &_tty))
! #define nl()	 ((bizarre=1),_tty.sg_flags |= CRMOD,stty(_tty_ch, &_tty))
! #define nonl()	 ((bizarre=1),_tty.sg_flags &= ~CRMOD, stty(_tty_ch, &_tty))
! #define	savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
! #define	resetty() ((bizarre=0),_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))
  #ifdef LFLUSHO
  #ifndef lint
  EXT int lflusho INIT(LFLUSHO);
--- 103,118 ----
  
  #else
  
! #define raw()	 ((bizarre=1),_tty.sg_flags|=RAW, ioctl(_tty_ch,TIOCSETN,&_tty))
! #define noraw()	 ((bizarre=1),_tty.sg_flags&=~RAW,ioctl(_tty_ch,TIOCSETN,&_tty))
! #define crmode() ((bizarre=1),_tty.sg_flags |= CBREAK, ioctl(_tty_ch,TIOCSETN,&_tty))
! #define nocrmode() ((bizarre=1),_tty.sg_flags &= ~CBREAK,ioctl(_tty_ch,TIOCSETN,&_tty))
! #define echo()	 ((bizarre=1),_tty.sg_flags |= ECHO, ioctl(_tty_ch,TIOCSETN,&_tty))
! #define noecho() ((bizarre=1),_tty.sg_flags &= ~ECHO, ioctl(_tty_ch,TIOCSETN,&_tty))
! #define nl()	 ((bizarre=1),_tty.sg_flags |= CRMOD,ioctl(_tty_ch,TIOCSETN,&_tty))
! #define nonl()	 ((bizarre=1),_tty.sg_flags &= ~CRMOD, ioctl(_tty_ch,TIOCSETN,&_tty))
! #define	savetty() (ioctl(_tty_ch, TIOCGETP, &_tty), _res_flg = _tty.sg_flags)
! #define	resetty() ((bizarre=0),_tty.sg_flags = _res_flg, ioctl(_tty_ch,TIOCSETN,&_tty))
  #ifdef LFLUSHO
  #ifndef lint
  EXT int lflusho INIT(LFLUSHO);