version 1.20, 2006/04/09 07:39:07
|
version 1.21, 2006/04/09 07:44:13
|
Line 617 void deprep_terminal ()
|
Line 617 void deprep_terminal ()
|
} |
} |
#endif /* NEW_TTY_DRIVER */ |
#endif /* NEW_TTY_DRIVER */ |
|
|
/* If a character is available to be read, then read it |
|
and stuff it into IBUFFER. Otherwise, just return. */ |
|
long pending = -1L; |
|
/* !! This is a bug: if key_avail(file1) is followed by getkey(file2), |
|
the getkey(file2) can return the character from file1. - anton */ |
|
|
|
/* Moreover, key_avail and getkey bypass the buffering of the FILE *, |
|
leading to unpleasant effects if KEY-FILE and KEY?-FILE are mixed |
|
with READ-FILE and READ-LINE */ |
|
|
|
long key_avail (FILE * stream) |
long key_avail (FILE * stream) |
{ |
{ |
int tty = fileno (stream); |
int tty = fileno (stream); |
int chars_avail = pending; |
fd_set selin; |
int result; |
static int now[2] = { 0 , 0 }; |
|
int res; |
|
|
if(!terminal_prepped && stream == stdin) |
if(!terminal_prepped && stream == stdin) |
prep_terminal(); |
prep_terminal(); |
|
|
#if defined(FIONREAD) && !defined(_WIN32) |
FD_ZERO(&selin); |
/* !! What is the point of this part? it does not affect |
FD_SET(tty, &selin); |
chars_avail, and "result" is never used - anton */ |
return select(1, &selin, NULL, NULL, now); |
if(isatty (tty)) { |
|
result = ioctl (tty, FIONREAD, &chars_avail); |
|
} |
|
#else |
|
{ |
|
fd_set selin; |
|
static int now[2] = { 0 , 0 }; |
|
int res; |
|
|
|
FD_ZERO(&selin); |
|
FD_SET(tty, &selin); |
|
chars_avail=select(1, &selin, NULL, NULL, now); |
|
} |
|
#endif |
|
|
|
if(chars_avail == -1L) { |
|
unsigned char inchar; |
|
|
|
fcntl(tty, F_SETFL, O_NDELAY); |
|
result = read(tty, &inchar, sizeof(char)); |
|
if(result == sizeof(char)) { |
|
chars_avail = 1; |
|
pending = (long)inchar; |
|
} else { |
|
chars_avail = 0; |
|
} |
|
fcntl(tty, F_SETFL, 0); |
|
} |
|
|
|
return chars_avail; |
|
} |
} |
|
|
/* Get a key from the buffer of characters to be read. |
/* Get a key from the buffer of characters to be read. |
Line 686 Cell getkey(FILE * stream)
|
Line 647 Cell getkey(FILE * stream)
|
if(!terminal_prepped) |
if(!terminal_prepped) |
prep_terminal(); |
prep_terminal(); |
|
|
while (pending < 0) |
while (1) |
{ |
{ |
result = read (fileno (stream), &c, sizeof (char)); |
result = read (fileno (stream), &c, sizeof (char)); |
|
|
Line 704 Cell getkey(FILE * stream)
|
Line 665 Cell getkey(FILE * stream)
|
if (errno != EINTR) |
if (errno != EINTR) |
return (EOF); |
return (EOF); |
} |
} |
|
|
/* otherwise there is a character pending; |
|
return it and delete pending char */ |
|
result = (Cell) pending; |
|
pending = -1L; |
|
|
|
return result; |
|
} |
} |
|
|
#ifdef TEST |
#ifdef TEST |