Diff for /gforth/engine/io.c between versions 1.4 and 1.9

version 1.4, 1997/08/22 19:23:20 version 1.9, 1999/01/21 20:09:13
Line 1 Line 1
 /* direct key io driver; signal handler  /* direct key io driver; signal handler
   
   Copyright (C) 1995 Free Software Foundation, Inc.    Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
   
   This file is part of Gforth.    This file is part of Gforth.
   
Line 26 Line 26
 */  */
   
 #include "config.h"  #include "config.h"
   #include <sys/time.h>
   #include <sys/types.h>
 #include <unistd.h>  #include <unistd.h>
   
 #if defined(apollo) || defined(_WIN32)  #if defined(apollo) || defined(_WIN32)
 #define _POSIX_VERSION  #define _POSIX_VERSION
 #endif  #endif
   
   #if !defined(Solaris) && defined(sun) && defined(__svr4__)
   #define Solaris
   typedef unsigned int uint32_t;
   #endif
   
 #include <stdio.h>  #include <stdio.h>
 #include <signal.h>  #include <signal.h>
 #include <string.h>  #include <string.h>
 #include <sys/types.h>  
 #if !defined(apollo) && !defined(MSDOS)  #if !defined(apollo) && !defined(MSDOS)
 #include <sys/ioctl.h>  #include <sys/ioctl.h>
 #endif  #endif
Line 85 Line 91
 #endif /* !_POSIX_VERSION */  #endif /* !_POSIX_VERSION */
   
 /* Posix systems use termios and the Posix signal functions. */  /* Posix systems use termios and the Posix signal functions. */
 #if defined (_POSIX_VERSION)  #if defined (_POSIX_VERSION) || defined (NeXT)
 #  if !defined (TERMIOS_MISSING)  #  if !defined (TERMIOS_MISSING)
 #    undef NEW_TTY_DRIVER  #    undef NEW_TTY_DRIVER
 #    define TERMIOS_TTY_DRIVER  #    define TERMIOS_TTY_DRIVER
 #    include <termios.h>  #    include <termios.h>
 #  endif /* !TERMIOS_MISSING */  #  endif /* !TERMIOS_MISSING */
   #endif /* _POSIX_VERSION || NeXT */
   
   #if defined (_POSIX_VERSION)
 #  define HAVE_POSIX_SIGNALS  #  define HAVE_POSIX_SIGNALS
 #  if !defined (O_NDELAY)  #  if !defined (O_NDELAY)
 #    define O_NDELAY O_NONBLOCK /* Posix-style non-blocking i/o */  #    define O_NDELAY O_NONBLOCK /* Posix-style non-blocking i/o */
Line 107 Line 116
    special character is disabled and to disable certain special     special character is disabled and to disable certain special
    characters.  Posix systems should set to 0, USG systems to -1. */     characters.  Posix systems should set to 0, USG systems to -1. */
 #if !defined (NEW_TTY_DRIVER) && !defined (_POSIX_VDISABLE)  #if !defined (NEW_TTY_DRIVER) && !defined (_POSIX_VDISABLE)
 #  if defined (_POSIX_VERSION)  #  if defined (_POSIX_VERSION) || defined (NeXT)
 #    define _POSIX_VDISABLE 0  #    define _POSIX_VDISABLE 0
 #  else /* !_POSIX_VERSION */  #  else /* !_POSIX_VERSION */
 #    define _POSIX_VDISABLE -1  #    define _POSIX_VDISABLE -1
Line 609  void deprep_terminal () Line 618  void deprep_terminal ()
   
 long pending = -1L;  long pending = -1L;
   
 long key_avail (stream)  long key_avail (FILE * stream)
         FILE *stream;  
 {  {
   int tty = fileno (stream);    int tty = fileno (stream);
   int chars_avail = pending;    int chars_avail = pending;
Line 619  long key_avail (stream) Line 627  long key_avail (stream)
   if(!terminal_prepped)  prep_terminal();    if(!terminal_prepped)  prep_terminal();
   
 #ifndef _WIN32  #ifndef _WIN32
   result = ioctl (tty, FIONREAD, &chars_avail);    if(isatty (tty)) {
       result = ioctl (tty, FIONREAD, &chars_avail);
     }
 #else  #else
   {    {
      fd_set selin;      fd_set selin;
      static int now[2] = { 0 , 0 };      static int now[2] = { 0 , 0 };
      int res;      int res;
       
      FD_ZERO(&selin);      FD_ZERO(&selin);
      FD_SET(tty, &selin);      FD_SET(tty, &selin);
      chars_avail=select(1, &selin, NULL, NULL, now);      chars_avail=select(1, &selin, NULL, NULL, now);
   }    }
 #endif  #endif
     
   if(chars_avail == -1L)    if(chars_avail == -1L) {
     {  unsigned char inchar;      unsigned char inchar;
       
        fcntl(tty, F_SETFL, O_NDELAY);      fcntl(tty, F_SETFL, O_NDELAY);
        result = read(tty, &inchar, sizeof(char));      result = read(tty, &inchar, sizeof(char));
        if(result == sizeof(char))      if(result == sizeof(char)) {
        {        chars_avail = 1;
          chars_avail = 1;        pending = (long)inchar;
          pending = (long)inchar;      } else {
        }        chars_avail = 0;
        else  
          chars_avail = 0;  
        fcntl(tty, F_SETFL, 0);  
     }      }
       fcntl(tty, F_SETFL, 0);
     }
   
   return chars_avail;    return chars_avail;
 }  }
Line 657  long key_avail (stream) Line 666  long key_avail (stream)
 /* When compiling and running in the `Posix' environment, Ultrix does  /* When compiling and running in the `Posix' environment, Ultrix does
    not restart system calls, so this needs to do it. */     not restart system calls, so this needs to do it. */
   
 unsigned char getkey(stream)  unsigned getkey(FILE * stream)
      FILE *stream;  
 {  {
   int result;    int result;
   unsigned char c;    unsigned char c;
Line 675  unsigned char getkey(stream) Line 683  unsigned char getkey(stream)
       /* If zero characters are returned, then the file that we are        /* If zero characters are returned, then the file that we are
          reading from is empty!  Return EOF in that case. */           reading from is empty!  Return EOF in that case. */
       if (result == 0)        if (result == 0)
         return CTRL('D');          return (EOF);
   
       /* If the error that we received was SIGINT, then try again,        /* If the error that we received was SIGINT, then try again,
          this is simply an interrupted system call to read ().           this is simply an interrupted system call to read ().
Line 974  void install_signal_handlers (void) Line 982  void install_signal_handlers (void)
     signal (sigs_to_ignore [i], SIG_IGN);      signal (sigs_to_ignore [i], SIG_IGN);
 */  */
   for (i = 0; i < DIM (sigs_to_throw); i++)    for (i = 0; i < DIM (sigs_to_throw); i++)
     signal (sigs_to_throw [i], signal_throw);      signal (sigs_to_throw [i], die_on_signal ? graceful_exit : 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);
 #ifdef SIGCONT  #ifdef SIGCONT

Removed from v.1.4  
changed lines
  Added in v.1.9


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