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

version 1.5, 1998/05/02 21:29:02 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 612  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 622  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 660  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 678  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 ().

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


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