--- gforth/Attic/io.c 1995/10/16 18:33:10 1.10 +++ gforth/Attic/io.c 1996/09/19 22:17:32 1.16 @@ -1,12 +1,31 @@ -/* direct key io driver +/* direct key io driver; signal handler - The following is stolen from the readline library for bash + Copyright (C) 1995 Free Software Foundation, Inc. + + This file is part of Gforth. + + Gforth is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + The following is stolen from the readline library for bash */ /* Use -D_POSIX_VERSION for POSIX systems. */ +#include "config.h" #include #ifdef apollo @@ -26,6 +45,7 @@ #include "forth.h" #include "io.h" +#ifndef MSDOS #if defined (__GNUC__) # define alloca __builtin_alloca #else @@ -92,7 +112,7 @@ #endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */ #include -extern int errno; +/* extern int errno; */ #if defined (SHELL) # include @@ -164,7 +184,7 @@ static int eof_char = CTRL ('D'); /* **************************************************************** */ /* Non-zero means that the terminal is in a prepped state. */ -static int terminal_prepped = 0; +int terminal_prepped = 0; #if defined (NEW_TTY_DRIVER) @@ -264,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. */ @@ -370,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; @@ -424,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) @@ -528,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); @@ -674,7 +716,7 @@ int main() puts(""); } #endif - +#endif /* MSDOS */ /* signal handling adapted from pfe by Dirk Zoller (Copylefted) - anton */ @@ -698,7 +740,9 @@ signal_throw(int sig) } *p, throwtable[] = { { SIGINT, -28 }, { SIGFPE, -55 }, +#ifdef SIGBUS { SIGBUS, -23 }, +#endif { SIGSEGV, -9 }, }; signal(sig,signal_throw); @@ -710,15 +754,57 @@ signal_throw(int sig) longjmp(throw_jmp_buf,code); /* or use siglongjmp ? */ } -static void -termprep (int sig) +UCell cols=80; +#ifdef MSDOS +UCell rows=25; +#else +UCell rows=24; +#endif + +#ifdef SIGCONT +static void termprep (int sig) { - terminal_prepped=0; signal(sig,termprep); + terminal_prepped=0; +} +#endif + +#ifdef SIGWINCH +void get_winsize() +{ +#ifdef TIOCGWINSZ + struct winsize size; + + if (ioctl (1, TIOCGWINSZ, (char *) &size) >= 0) { + rows = size.ws_row; + cols = size.ws_col; + } +#else + char *s, *ends; + unsigned long ul; + if (s=getenv("LINES")) { + rows=atoi(s); + if (rows==0) + rows=24; + } + if (s=getenv("COLUMNS")) { + rows=atoi(s); + if (rows==0) + cols=80; + } +#endif } -void -install_signal_handlers (void) +static void change_winsize(int sig) +{ + signal(sig,change_winsize); +#ifdef TIOCGWINSZ + get_winsize(); +#endif +} +#endif + +void install_signal_handlers (void) { #if 0 @@ -782,9 +868,6 @@ install_signal_handlers (void) #ifdef SIGTTOU SIGTTOU, #endif -#ifdef SIGWINCH - SIGWINCH, -#endif #ifdef SIGSTKFLT SIGSTKFLT, #endif @@ -819,6 +902,9 @@ install_signal_handlers (void) #ifdef SIGALRM SIGALRM, #endif +#ifdef SIGPIPE + SIGPIPE, +#endif #ifdef SIGPOLL SIGPOLL, #endif @@ -860,9 +946,6 @@ install_signal_handlers (void) #ifdef SIGABRT SIGABRT, #endif -#ifdef SIGPIPE - SIGPIPE, -#endif #ifdef SIGTERM SIGTERM, #endif @@ -870,11 +953,6 @@ install_signal_handlers (void) SIGXCPU, #endif }; - static short sigs_to_termprep [] = { -#ifdef SIGCONT - SIGCONT, -#endif - }; int i; #define DIM(X) (sizeof (X) / sizeof *(X)) @@ -886,7 +964,11 @@ install_signal_handlers (void) signal (sigs_to_throw [i], signal_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); +#ifdef SIGCONT + signal (SIGCONT, termprep); +#endif +#ifdef SIGWINCH + signal (SIGWINCH, change_winsize); +#endif } /* end signal handling */