[net.sources.bugs] LIFE: tty_char

jss@rochester.UUCP (Jon S. Stumpf) (02/21/85)

: Munch Munch Munch o^o(:. .:..

	Below is a fix to life's lower level input routine, tty_char().  On
    a Vax, the original code did not produce runtime errors, but on a Sun, on
    any input, the error message "Unknown command" would appear.  This was due
    the code with the '/*?*/' marker at the beginning of the line.  Apparent-
    ly, read() was putting the value in the high byte where it was told, &ch.
    By changing the type of ch to an unsigned char (or char for that matter)
    should do the trick for anyone else having problems.

	All lines that have been changed are preceded by a /*!*/ marker.
    The original code starts at line 75 in io.c which is the line below
    FIXED CODE BEGINS HERE.

				Jon S. Stumpf
				University of Rochester
				{allegra|decvax|seismo}rochester!jss

------------------------FIXED CODE BEGINS HERE------------------------------
/*
 * Read next character from the terminal if it is ready.  If nothing is
 * going on we will wait for it anyway, to prevent excessive runtimes.
 * We set the interactive flag to indicate we are talking to user.
 */
tty_char()
{
/*!*/	long		n;			/* char count */
/*!*/	unsigned char	ch;			/* char to return */

	interact = 1;
	if ((dowait == 0) && (redraw || update || (genleft > 0))) {
		if ((ioctl(STDIN, FIONREAD, &n) == 0) && (n <= 0)) {
			scaneof();		/* no char available now */
		}
	}
	do {
		if (stop) return('\0');		/* stop will be seen later */
		errno = 0;
/*?*/		n = read(STDIN, &ch, 1);	/* read one char */
	} while ((n < 0) && (errno == EINTR));
	if (n <= 0) {
		return(-1);			/* error or end of file */
	}
	if (errorstring) {			/* disable error message */
		errorstring = NULL;
		update = 1;
	}
/*!*/	return((int) (ch & 0x7f));
}

-- 

Jon S. Stumpf @ U. of Rochester
{allegra|decvax|seismo}!rochester!jss