--- gforth/Attic/io.c 1994/07/08 15:00:45 1.4 +++ gforth/Attic/io.c 1995/09/06 21:00:19 1.9 @@ -3,18 +3,20 @@ The following is stolen from the readline library for bash */ -/* Use -DDOMAINOS for Apollo Domain-OS. +/* Use -D_POSIX_VERSION for POSIX systems. */ -#ifdef DOMAINOS +#include + +#ifdef apollo #define _POSIX_VERSION #endif #include #include #include -#ifndef DOMAINOS +#ifndef apollo #include #endif #include @@ -31,15 +33,15 @@ # endif #endif -#if defined (HAVE_UNISTD_H) -# include -#endif - #define NEW_TTY_DRIVER #define HAVE_BSD_SIGNALS -#ifndef DOMAINOS +/* +#ifndef apollo #define USE_XON_XOFF #endif +*/ + +#define HANDLE_SIGNALS /* Some USG machines have BSD signal handling (sigblock, sigsetmask, etc.) */ #if defined (USG) && !defined (hpux) @@ -48,7 +50,7 @@ /* System V machines use termio. */ #if !defined (_POSIX_VERSION) -# if defined (USG) || defined (hpux) || defined (Xenix) || defined (sgi) || defined (DGUX) || defined (ultrix) +# if defined (USG) || defined (hpux) || defined (Xenix) || defined (sgi) || defined (DGUX) || defined (ultrix) || defined (Solaris) # undef NEW_TTY_DRIVER # define TERMIO_TTY_DRIVER # include @@ -104,7 +106,7 @@ extern int errno; # endif /* USGr3 */ #endif /* USG && hpux */ -#if (defined (_POSIX_VERSION) || defined (USGr3)) && !defined(DOMAINOS) +#if (defined (_POSIX_VERSION) || defined (USGr3)) && !defined(apollo) # include # define direct dirent # if defined (_POSIX_VERSION) @@ -568,6 +570,8 @@ long key_avail (stream) long chars_avail = pending; int result; + if(!terminal_prepped) prep_terminal(); + #if defined (FIONREAD) result = ioctl (tty, FIONREAD, &chars_avail); #endif @@ -603,6 +607,8 @@ unsigned char getkey(stream) int result; unsigned char c; + if(!terminal_prepped) prep_terminal(); + while (pending < 0) { result = read (fileno (stream), &c, sizeof (char)); @@ -613,7 +619,7 @@ unsigned char getkey(stream) /* If zero characters are returned, then the file that we are reading from is empty! Return EOF in that case. */ if (result == 0) - return (0); + return CTRL('D'); /* If the error that we received was SIGINT, then try again, this is simply an interrupted system call to read (). @@ -740,6 +746,13 @@ signal_throw(int sig) longjmp(throw_jmp_buf,throw_codes[sig-1]); /* or use siglongjmp ? */ } +static void +termprep (int sig) +{ + terminal_prepped=0; + signal(sig,termprep); +} + void install_signal_handlers (void) { @@ -751,10 +764,12 @@ install_signal_handlers (void) SIGALRM, SIGBUS #define SIGS_TO_QUIT SIGHUP, SIGQUIT, SIGABRT, SIGPIPE, \ SIGTERM +#define SIGS_TO_TERMPREP SIGCONT static short sigs_to_ignore [] = { SIGS_TO_IGNORE }; static short sigs_to_abort [] = { SIGS_TO_ABORT }; static short sigs_to_quit [] = { SIGS_TO_QUIT }; + static short sigs_to_termprep [] = { SIGS_TO_TERMPREP }; int i; #define DIM(X) (sizeof (X) / sizeof *(X)) @@ -765,5 +780,7 @@ install_signal_handlers (void) signal (sigs_to_abort [i], signal_throw); /* !! change to throw */ for (i = 0; i < DIM (sigs_to_quit); i++) signal (sigs_to_quit [i], graceful_exit); + for (i = 0; i < DIM (sigs_to_termprep); i++) + signal (sigs_to_termprep [i], termprep); } /* end signal handling */