Diff for /gforth/Attic/io.c between versions 1.10 and 1.19

version 1.10, 1995/10/16 18:33:10 version 1.19, 1997/02/16 20:51:08
Line 1 Line 1
 /*      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.     Use -D_POSIX_VERSION for POSIX systems.
 */  */
   
   #include "config.h"
 #include <unistd.h>  #include <unistd.h>
   
 #ifdef apollo  #if defined(apollo) || defined(_WIN32)
 #define _POSIX_VERSION  #define _POSIX_VERSION
 #endif  #endif
   
Line 17 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 26 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 51 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 92 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 164  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 264  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 370  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 424  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 528  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 674  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 698  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 710  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
   
 void  #ifdef SIGWINCH
 install_signal_handlers (void)  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 install_signal_handlers (void)
 {  {
   
 #if 0  #if 0
Line 782  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 819  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 860  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 870  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 886  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 */

Removed from v.1.10  
changed lines
  Added in v.1.19


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>