From: Scott Schwartz <[email-masked]>
Date: Sun, 25 Dec 1994 16:47:13 -0500

Hi gang,
  I've made some changes to Matty's 9term v1.6.2 which I thought
I'd share.  The changes are:

	* Fix the Xrm stuff to not poke around inside the display structure,
	  so that it will work with X11R6.

	* Export the (correct) DISPLAY variable to the shell, like xterm does.

	* Under SUNOS, make utmp entries using ttyslot, like xterm and others do.

	* Don't put null host fields in utmp, even for local displays.

	* The tcdrain fix(?) that someone else posted.

-- Scott

*** 1.1	1994/12/13 04:33:24
--- display.c	1994/12/20 23:37:44
***************
*** 29,40 ****
  
  #include "9term.h"
  
- #ifdef __alpha
- #	define XRDB	(((_XPrivDisplay)_dpy)->db)
- #else
- #	define XRDB	(_dpy->db)
- #endif
- 
  extern	Display	*_dpy;
  extern	Widget	_toplevel;
  
--- 29,34 ----
***************
*** 136,142 ****
  
  	sprintf(str1, "%s.%s", resource, rname);
  	sprintf(str2, "%s.%s", class, cname);
! 	if (XrmGetResource(XRDB, str1, str2, &str_type, &value) == True) {
  		strncpy(result, value.addr, (int)value.size);
  		return result;
  	}
--- 130,138 ----
  
  	sprintf(str1, "%s.%s", resource, rname);
  	sprintf(str2, "%s.%s", class, cname);
! 	if (XrmGetResource(
! 			XrmGetDatabase(_dpy),
! 			str1, str2, &str_type, &value) == True) {
  		strncpy(result, value.addr, (int)value.size);
  		return result;
  	}
***************
*** 209,214 ****
--- 205,211 ----
  void
  init_display(int *argc, char **argv, char **shargv, char *resource)
  {
+ 	XrmDatabase	rdb;
  	XrmDatabase	cmd;
  	char		**cp;
  	char		id[512];
***************
*** 225,231 ****
  	xtbinit(0, resource, argc, argv, fallbacks);
  
  		/* we're still not done with the command line */
! 	XrmMergeDatabases(cmd, &XRDB);
  #ifdef DEBUG_X
  	XSynchronize(_dpy, True);
  	XSetErrorHandler(abort);
--- 222,229 ----
  	xtbinit(0, resource, argc, argv, fallbacks);
  
  		/* we're still not done with the command line */
! 	rdb = XrmGetDatabase(_dpy);
! 	XrmMergeDatabases(cmd, &rdb);
  #ifdef DEBUG_X
  	XSynchronize(_dpy, True);
  	XSetErrorHandler(abort);
***************
*** 233,238 ****
--- 231,238 ----
  		/* export window id to environment */
  	sprintf(id, "%d", XtWindow(_toplevel));
  	setenv("WINDOWID", id, 1);
+ 		/* make the display env var match the actual display */
+ 	setenv("DISPLAY", XDisplayString(_dpy), 1);
  
  		/* register mouse and keyboard events */
  	einit(Ekeyboard | Emouse);
*** 1.1	1994/12/13 20:51:08
--- pty.c	1994/12/25 21:31:13
***************
*** 409,414 ****
--- 409,415 ----
  				;
  #if !defined(PCKT) && !defined(REMOTE)
  		/* reinstate echo mode, if we disabled it above */
+ 	tcdrain (comm_fd);
  	if (echo) {
  		ttmode.c_lflag |= ECHO;
  		IOSETATTR(slave_fd, &ttmode);
***************
*** 573,583 ****
--- 574,586 ----
  	char *user, *display, *cp;
  	struct utmp utmp;
  	int fd;
+ 	int save_fd;
  
  	user = getuser();
  	fd = open("/etc/utmp", O_RDWR);
  	if (fd < 0)
  		return;
+ #ifndef SUNOS
  	/*
  	 * search for existing entry or add a new entry
  	 * to the end of the file if one is not found.
***************
*** 590,607 ****
--- 593,632 ----
  		}
  		slot++;
  	}
+ #else /* SUNOS */
+ 	/* XXX - ttyslot assumes that fd 0 is already attached to the 
+ 	   9term pty, so we jump thru some hoops to make it so, and
+ 	   then put it back.  Since we don't use stdin, we could probably
+ 	   leave off the last bit. */
+ #undef dup
+ 	save_fd = dup (0);
+ 	if (save_fd < 0)
+ 	    goto done;
+         dup2 (slave_fd, 0);
+ 	slot = ttyslot ();
+ 	dup2 (save_fd, 0);
+ 	close (save_fd);
+ 	if (slot <= 0)
+ 	    goto done;
+ 	
+ 	lseek (fd, slot*sizeof(utmp), SEEK_SET);	
+ #endif /* SUNOS */
+ 
  		/* build the entry and write it */
  	strncpy(utmp.ut_line, ttyname, sizeof(utmp.ut_line));
  	strncpy(utmp.ut_name, user, sizeof(utmp.ut_name));
  	display = getenv("DISPLAY");
  	if (display) {
+ /*
  		cp = strchr(display, ':');
  		if (cp)
  			*cp = 0;
+ */
  		strncpy(utmp.ut_host, display, sizeof(utmp.ut_host));
  	}
  	time(&utmp.ut_time);
  	write(fd, &utmp, sizeof(utmp));
+ done:
  	close(fd);
  }