LIFE: tty_char() fix
Jon S. Stumpf
jss at rochester.UUCP
Thu Feb 21 09:06:25 AEST 1985
: 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
More information about the Comp.sources.bugs
mailing list