version 1.12, 1995/12/26 17:35:36
|
version 1.18, 1996/10/06 22:24:17
|
Line 36
|
Line 36
|
#include <signal.h> |
#include <signal.h> |
#include <string.h> |
#include <string.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#ifndef apollo |
#if !defined(apollo) && !defined(MSDOS) |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#endif |
#endif |
#include <fcntl.h> |
#include <fcntl.h> |
Line 45
|
Line 45
|
#include "forth.h" |
#include "forth.h" |
#include "io.h" |
#include "io.h" |
|
|
|
#ifndef MSDOS |
#if defined (__GNUC__) |
#if defined (__GNUC__) |
# define alloca __builtin_alloca |
# define alloca __builtin_alloca |
#else |
#else |
Line 70
|
Line 71
|
|
|
/* System V machines use termio. */ |
/* System V machines use termio. */ |
#if !defined (_POSIX_VERSION) |
#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 |
# undef NEW_TTY_DRIVER |
# define TERMIO_TTY_DRIVER |
# define TERMIO_TTY_DRIVER |
# include <termio.h> |
# include <termio.h> |
Line 111
|
Line 112
|
#endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */ |
#endif /* !NEW_TTY_DRIVER && !_POSIX_VDISABLE */ |
|
|
#include <errno.h> |
#include <errno.h> |
extern int errno; |
/* extern int errno; */ |
|
|
#if defined (SHELL) |
#if defined (SHELL) |
# include <posixstat.h> |
# include <posixstat.h> |
Line 183 static int eof_char = CTRL ('D');
|
Line 184 static int eof_char = CTRL ('D');
|
/* **************************************************************** */ |
/* **************************************************************** */ |
|
|
/* Non-zero means that the terminal is in a prepped state. */ |
/* 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) |
#if defined (NEW_TTY_DRIVER) |
|
|
Line 283 void prep_terminal ()
|
Line 284 void prep_terminal ()
|
if (terminal_prepped) |
if (terminal_prepped) |
return; |
return; |
|
|
|
if (!isatty(tty)) { /* added by MdG */ |
|
terminal_prepped = 1; /* added by MdG */ |
|
return; /* added by MdG */ |
|
} /* added by MdG */ |
|
|
oldmask = sigblock (sigmask (SIGINT)); |
oldmask = sigblock (sigmask (SIGINT)); |
|
|
/* We always get the latest tty values. Maybe stty changed them. */ |
/* We always get the latest tty values. Maybe stty changed them. */ |
Line 389 void deprep_terminal ()
|
Line 395 void deprep_terminal ()
|
if (!terminal_prepped) |
if (!terminal_prepped) |
return; |
return; |
|
|
|
/* Added by MdG */ |
|
if (!isatty(tty)) { |
|
terminal_prepped = 0; |
|
return; |
|
} |
|
|
oldmask = sigblock (sigmask (SIGINT)); |
oldmask = sigblock (sigmask (SIGINT)); |
|
|
the_ttybuff.sg_flags = original_tty_flags; |
the_ttybuff.sg_flags = original_tty_flags; |
Line 443 void prep_terminal ()
|
Line 455 void prep_terminal ()
|
if (terminal_prepped) |
if (terminal_prepped) |
return; |
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 |
/* Try to keep this function from being INTerrupted. We can do it |
on POSIX and systems with BSD-like signal handling. */ |
on POSIX and systems with BSD-like signal handling. */ |
#if defined (HAVE_POSIX_SIGNALS) |
#if defined (HAVE_POSIX_SIGNALS) |
Line 547 void deprep_terminal ()
|
Line 564 void deprep_terminal ()
|
if (!terminal_prepped) |
if (!terminal_prepped) |
return; |
return; |
|
|
|
/* Added by MdG */ |
|
if (!isatty(tty)) { |
|
terminal_prepped = 0; |
|
return; |
|
} |
|
|
#if defined (HAVE_POSIX_SIGNALS) |
#if defined (HAVE_POSIX_SIGNALS) |
sigemptyset (&set); |
sigemptyset (&set); |
sigemptyset (&oset); |
sigemptyset (&oset); |
Line 693 int main()
|
Line 716 int main()
|
puts(""); |
puts(""); |
} |
} |
#endif |
#endif |
|
#endif /* MSDOS */ |
|
|
/* signal handling adapted from pfe by Dirk Zoller (Copylefted) - anton */ |
/* signal handling adapted from pfe by Dirk Zoller (Copylefted) - anton */ |
|
|
Line 717 signal_throw(int sig)
|
Line 740 signal_throw(int sig)
|
} *p, throwtable[] = { |
} *p, throwtable[] = { |
{ SIGINT, -28 }, |
{ SIGINT, -28 }, |
{ SIGFPE, -55 }, |
{ SIGFPE, -55 }, |
|
#ifdef SIGBUS |
{ SIGBUS, -23 }, |
{ SIGBUS, -23 }, |
|
#endif |
{ SIGSEGV, -9 }, |
{ SIGSEGV, -9 }, |
}; |
}; |
signal(sig,signal_throw); |
signal(sig,signal_throw); |
Line 729 signal_throw(int sig)
|
Line 754 signal_throw(int sig)
|
longjmp(throw_jmp_buf,code); /* or use siglongjmp ? */ |
longjmp(throw_jmp_buf,code); /* or use siglongjmp ? */ |
} |
} |
|
|
static void |
UCell cols=80; |
termprep (int sig) |
#if defined(MSDOS) || defined (_WIN32) |
|
UCell rows=25; |
|
#else |
|
UCell rows=24; |
|
#endif |
|
|
|
#ifdef SIGCONT |
|
static void termprep (int sig) |
{ |
{ |
terminal_prepped=0; |
|
signal(sig,termprep); |
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 |
|
} |
|
|
|
static void change_winsize(int sig) |
|
{ |
|
signal(sig,change_winsize); |
|
#ifdef TIOCGWINSZ |
|
get_winsize(); |
|
#endif |
} |
} |
|
#endif |
|
|
void |
void install_signal_handlers (void) |
install_signal_handlers (void) |
|
{ |
{ |
|
|
#if 0 |
#if 0 |
Line 801 install_signal_handlers (void)
|
Line 868 install_signal_handlers (void)
|
#ifdef SIGTTOU |
#ifdef SIGTTOU |
SIGTTOU, |
SIGTTOU, |
#endif |
#endif |
#ifdef SIGWINCH |
|
SIGWINCH, |
|
#endif |
|
#ifdef SIGSTKFLT |
#ifdef SIGSTKFLT |
SIGSTKFLT, |
SIGSTKFLT, |
#endif |
#endif |
Line 838 install_signal_handlers (void)
|
Line 902 install_signal_handlers (void)
|
#ifdef SIGALRM |
#ifdef SIGALRM |
SIGALRM, |
SIGALRM, |
#endif |
#endif |
|
#ifdef SIGPIPE |
|
SIGPIPE, |
|
#endif |
#ifdef SIGPOLL |
#ifdef SIGPOLL |
SIGPOLL, |
SIGPOLL, |
#endif |
#endif |
Line 879 install_signal_handlers (void)
|
Line 946 install_signal_handlers (void)
|
#ifdef SIGABRT |
#ifdef SIGABRT |
SIGABRT, |
SIGABRT, |
#endif |
#endif |
#ifdef SIGPIPE |
|
SIGPIPE, |
|
#endif |
|
#ifdef SIGTERM |
#ifdef SIGTERM |
SIGTERM, |
SIGTERM, |
#endif |
#endif |
Line 889 install_signal_handlers (void)
|
Line 953 install_signal_handlers (void)
|
SIGXCPU, |
SIGXCPU, |
#endif |
#endif |
}; |
}; |
static short sigs_to_termprep [] = { |
|
#ifdef SIGCONT |
|
SIGCONT, |
|
#endif |
|
}; |
|
int i; |
int i; |
|
|
#define DIM(X) (sizeof (X) / sizeof *(X)) |
#define DIM(X) (sizeof (X) / sizeof *(X)) |
Line 905 install_signal_handlers (void)
|
Line 964 install_signal_handlers (void)
|
signal (sigs_to_throw [i], signal_throw); |
signal (sigs_to_throw [i], signal_throw); |
for (i = 0; i < DIM (sigs_to_quit); i++) |
for (i = 0; i < DIM (sigs_to_quit); i++) |
signal (sigs_to_quit [i], graceful_exit); |
signal (sigs_to_quit [i], graceful_exit); |
for (i = 0; i < DIM (sigs_to_termprep); i++) |
#ifdef SIGCONT |
signal (sigs_to_termprep [i], termprep); |
signal (SIGCONT, termprep); |
|
#endif |
|
#ifdef SIGWINCH |
|
signal (SIGWINCH, change_winsize); |
|
#endif |
} |
} |
/* end signal handling */ |
/* end signal handling */ |