--- gforth/Attic/io.c 1996/01/25 16:45:52 1.14 +++ gforth/Attic/io.c 1997/03/04 22:09:54 1.20 @@ -28,7 +28,7 @@ #include "config.h" #include -#ifdef apollo +#if defined(apollo) || defined(_WIN32) #define _POSIX_VERSION #endif @@ -36,7 +36,7 @@ #include #include #include -#ifndef apollo +#if !defined(apollo) && !defined(MSDOS) #include #endif #include @@ -45,6 +45,7 @@ #include "forth.h" #include "io.h" +#ifndef MSDOS #if defined (__GNUC__) # define alloca __builtin_alloca #else @@ -70,7 +71,7 @@ /* System V machines use termio. */ #if !defined (_POSIX_VERSION) -# if defined (USG) || defined (hpux) || defined (Xenix) || defined (sgi) || defined (DGUX) || defined (ultrix) || defined (Solaris) +# if defined (USG) || defined (hpux) || defined (Xenix) || defined (sgi) || defined (DGUX) || defined (ultrix) || defined (Solaris) || defined(_WIN32) # undef NEW_TTY_DRIVER # define TERMIO_TTY_DRIVER # include @@ -111,7 +112,7 @@ #endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */ #include -extern int errno; +/* extern int errno; */ #if defined (SHELL) # include @@ -283,6 +284,11 @@ void prep_terminal () if (terminal_prepped) return; + if (!isatty(tty)) { /* added by MdG */ + terminal_prepped = 1; /* added by MdG */ + return; /* added by MdG */ + } /* added by MdG */ + oldmask = sigblock (sigmask (SIGINT)); /* We always get the latest tty values. Maybe stty changed them. */ @@ -389,6 +395,12 @@ void deprep_terminal () if (!terminal_prepped) return; +/* Added by MdG */ + if (!isatty(tty)) { + terminal_prepped = 0; + return; + } + oldmask = sigblock (sigmask (SIGINT)); the_ttybuff.sg_flags = original_tty_flags; @@ -443,6 +455,11 @@ void prep_terminal () if (terminal_prepped) return; + if (!isatty(tty)) { /* added by MdG */ + terminal_prepped = 1; /* added by MdG */ + return; /* added by MdG */ + } /* added by MdG */ + /* Try to keep this function from being INTerrupted. We can do it on POSIX and systems with BSD-like signal handling. */ #if defined (HAVE_POSIX_SIGNALS) @@ -547,6 +564,12 @@ void deprep_terminal () if (!terminal_prepped) return; +/* Added by MdG */ + if (!isatty(tty)) { + terminal_prepped = 0; + return; + } + #if defined (HAVE_POSIX_SIGNALS) sigemptyset (&set); sigemptyset (&oset); @@ -592,8 +615,18 @@ long key_avail (stream) if(!terminal_prepped) prep_terminal(); -#if defined (FIONREAD) +#ifndef _WIN32 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) @@ -693,7 +726,7 @@ int main() puts(""); } #endif - +#endif /* MSDOS */ /* signal handling adapted from pfe by Dirk Zoller (Copylefted) - anton */ @@ -717,7 +750,9 @@ signal_throw(int sig) } *p, throwtable[] = { { SIGINT, -28 }, { SIGFPE, -55 }, +#ifdef SIGBUS { SIGBUS, -23 }, +#endif { SIGSEGV, -9 }, }; signal(sig,signal_throw); @@ -729,15 +764,22 @@ signal_throw(int sig) longjmp(throw_jmp_buf,code); /* or use siglongjmp ? */ } +UCell cols=80; +#if defined(MSDOS) || defined (_WIN32) +UCell rows=25; +#else +UCell rows=24; +#endif + +#ifdef SIGCONT static void termprep (int sig) { signal(sig,termprep); terminal_prepped=0; } +#endif -UCell rows=24; -UCell cols=80; - +#ifdef SIGWINCH void get_winsize() { #ifdef TIOCGWINSZ @@ -770,6 +812,7 @@ static void change_winsize(int sig) get_winsize(); #endif } +#endif void install_signal_handlers (void) {