--- gforth/engine/io.c 1997/08/22 19:23:20 1.4 +++ gforth/engine/io.c 1998/10/18 23:16:52 1.7 @@ -26,16 +26,22 @@ */ #include "config.h" +#include +#include #include #if defined(apollo) || defined(_WIN32) #define _POSIX_VERSION #endif +#if !defined(Solaris) && defined(sun) && defined(__svr4__) +#define Solaris +typedef unsigned int uint32_t; +#endif + #include #include #include -#include #if !defined(apollo) && !defined(MSDOS) #include #endif @@ -85,12 +91,15 @@ #endif /* !_POSIX_VERSION */ /* Posix systems use termios and the Posix signal functions. */ -#if defined (_POSIX_VERSION) +#if defined (_POSIX_VERSION) || defined (NeXT) # if !defined (TERMIOS_MISSING) # undef NEW_TTY_DRIVER # define TERMIOS_TTY_DRIVER # include # endif /* !TERMIOS_MISSING */ +#endif /* _POSIX_VERSION || NeXT */ + +#if defined (_POSIX_VERSION) # define HAVE_POSIX_SIGNALS # if !defined (O_NDELAY) # define O_NDELAY O_NONBLOCK /* Posix-style non-blocking i/o */ @@ -107,7 +116,7 @@ special character is disabled and to disable certain special characters. Posix systems should set to 0, USG systems to -1. */ #if !defined (NEW_TTY_DRIVER) && !defined (_POSIX_VDISABLE) -# if defined (_POSIX_VERSION) +# if defined (_POSIX_VERSION) || defined (NeXT) # define _POSIX_VDISABLE 0 # else /* !_POSIX_VERSION */ # define _POSIX_VDISABLE -1 @@ -609,8 +618,7 @@ void deprep_terminal () long pending = -1L; -long key_avail (stream) - FILE *stream; +long key_avail (FILE * stream) { int tty = fileno (stream); int chars_avail = pending; @@ -619,33 +627,34 @@ long key_avail (stream) if(!terminal_prepped) prep_terminal(); #ifndef _WIN32 - result = ioctl (tty, FIONREAD, &chars_avail); + 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); + 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); + + 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; } @@ -657,8 +666,7 @@ long key_avail (stream) /* When compiling and running in the `Posix' environment, Ultrix does not restart system calls, so this needs to do it. */ -unsigned char getkey(stream) - FILE *stream; +unsigned char getkey(FILE * stream) { int result; unsigned char c; @@ -974,7 +982,7 @@ void install_signal_handlers (void) signal (sigs_to_ignore [i], SIG_IGN); */ for (i = 0; i < DIM (sigs_to_throw); i++) - signal (sigs_to_throw [i], signal_throw); + signal (sigs_to_throw [i], die_on_signal ? graceful_exit : signal_throw); for (i = 0; i < DIM (sigs_to_quit); i++) signal (sigs_to_quit [i], graceful_exit); #ifdef SIGCONT