Subject: patch to nex/nvi..
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Christos Zoulas <christos@deshaw.com>
List: current-users
Date: 02/27/1994 02:28:40
So than nex works without requiring access to /dev/tty.

[this is for version 1.01]

christos

*** gs.h.orig	Sun Jan  9 17:20:30 1994
--- gs.h	Sun Feb 27 02:15:48 1994
***************
*** 85,90 ****
--- 85,91 ----
  #define	G_SLEEPING	0x00800		/* Asleep (die on signal). */
  #define	G_SNAPSHOT	0x01000		/* Always snapshot files. */
  #define	G_TMP_INUSE	0x02000		/* Temporary buffer in use. */
+ #define	G_HAVETTY	0x04000		/* Do we have access to a tty */
  	u_int	 flags;
  };
  
*** main.c.orig	Wed Jan 12 01:36:14 1994
--- main.c	Sun Feb 27 02:12:12 1994
***************
*** 473,479 ****
  	 * other systems mess up characters typed after the quit command to
  	 * vi but before vi actually exits.
  	 */
! 	if (F_ISSET(gp, G_ISFROMTTY) &&
  	    tcsetattr(STDIN_FILENO, TCSADRAIN, &gp->original_termios))
  		err(1, "tcsetattr");
  	exit(eval);
--- 473,479 ----
  	 * other systems mess up characters typed after the quit command to
  	 * vi but before vi actually exits.
  	 */
! 	if (F_ISSET(gp, G_HAVETTY) && F_ISSET(gp, G_ISFROMTTY) &&
  	    tcsetattr(STDIN_FILENO, TCSADRAIN, &gp->original_termios))
  		err(1, "tcsetattr");
  	exit(eval);
***************
*** 517,530 ****
  	 * and term.c:term_init()) want values for special characters.
  	 */
  	if (F_ISSET(gp, G_ISFROMTTY)) {
! 		if (tcgetattr(STDIN_FILENO, &gp->original_termios))
  			err(1, "tcgetattr");
  	} else {
! 		if ((fd = open(_PATH_TTY, O_RDONLY, 0)) == -1)
! 			err(1, "%s", _PATH_TTY);
! 		if (tcgetattr(fd, &gp->original_termios))
! 			err(1, "tcgetattr");
! 		(void)close(fd);
  	}
  
  	return (gp);
--- 517,532 ----
  	 * and term.c:term_init()) want values for special characters.
  	 */
  	if (F_ISSET(gp, G_ISFROMTTY)) {
! 		if (tcgetattr(STDIN_FILENO, &gp->original_termios) == -1)
  			err(1, "tcgetattr");
+ 		F_SET(gp, G_HAVETTY);
  	} else {
! 		if ((fd = open(_PATH_TTY, O_RDONLY, 0)) != -1) {
! 			if (tcgetattr(fd, &gp->original_termios) == -1)
! 				err(1, "tcgetattr");
! 			(void)close(fd);
! 			F_SET(gp, G_HAVETTY);
! 		}
  	}
  
  	return (gp);
*** term.c.orig	Sat Jan  8 15:46:17 1994
--- term.c	Sun Feb 27 02:13:40 1994
***************
*** 145,151 ****
  
  	/* Set keys found in the termios structure. */
  #define	TERMSET(name, val) {						\
! 	if ((ch = gp->original_termios.c_cc[name]) != _POSIX_VDISABLE)	\
  		for (kp = keylist;; ++kp)				\
  			if (kp->value == (val)) {			\
  				kp->ch = ch;				\
--- 145,152 ----
  
  	/* Set keys found in the termios structure. */
  #define	TERMSET(name, val) {						\
! 	if (F_ISSET(gp, G_HAVETTY) && 					\
! 	    (ch = gp->original_termios.c_cc[name]) != _POSIX_VDISABLE)	\
  		for (kp = keylist;; ++kp)				\
  			if (kp->value == (val)) {			\
  				kp->ch = ch;				\
*** util.c.orig	Thu Dec 23 18:41:42 1993
--- util.c	Sun Feb 27 02:17:22 1994
***************
*** 499,504 ****
--- 499,507 ----
  {
  	speed_t v;
  
+ 	if (!F_ISSET(sp->gp, G_HAVETTY))
+ 		return (9600);
+ 
  	switch (v = cfgetospeed(&sp->gp->original_termios)) {
  	case B50:
  		return (50);
*** sex/sex_util.c.orig	Thu Dec 23 18:02:11 1993
--- sex/sex_util.c	Sun Feb 27 02:21:45 1994
***************
*** 77,83 ****
  	int rval;
  
  	/* Save ex/vi terminal settings, and restore the original ones. */
! 	if (F_ISSET(sp->gp, G_ISFROMTTY)) {
  		(void)tcgetattr(STDIN_FILENO, &t);
  		(void)tcsetattr(STDIN_FILENO,
  		    TCSADRAIN, &sp->gp->original_termios);
--- 77,83 ----
  	int rval;
  
  	/* Save ex/vi terminal settings, and restore the original ones. */
! 	if (F_ISSET(sp->gp, G_ISFROMTTY) && F_ISSET(sp->gp, G_HAVETTY)) {
  		(void)tcgetattr(STDIN_FILENO, &t);
  		(void)tcsetattr(STDIN_FILENO,
  		    TCSADRAIN, &sp->gp->original_termios);

------------------------------------------------------------------------------