Diff for /gforth/engine/io.c between versions 1.6 and 1.7

version 1.6, 1998/10/15 09:47:45 version 1.7, 1998/10/18 23:16:52
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)
Line 40  typedef unsigned int uint32_t; Line 42  typedef unsigned int uint32_t;
 #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 617  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 627  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 665  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 char getkey(FILE * stream)
      FILE *stream;  
 {  {
   int result;    int result;
   unsigned char c;    unsigned char c;

Removed from v.1.6  
changed lines
  Added in v.1.7


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