Diff for /gforth/engine/io.c between versions 1.39 and 1.44

version 1.39, 2009/12/31 15:32:36 version 1.44, 2012/07/22 22:24:50
Line 1 Line 1
 /* direct key io driver  /* direct key io driver
   
   Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006,2007,2008,2009 Free Software Foundation, Inc.    Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
   
   This file is part of Gforth.    This file is part of Gforth.
   
Line 55  typedef unsigned int uint32_t; Line 55  typedef unsigned int uint32_t;
 #include "io.h"  #include "io.h"
   
 #ifndef MSDOS  #ifndef MSDOS
   #include <poll.h>
 #if defined (__GNUC__)  #if defined (__GNUC__)
 #  define alloca __builtin_alloca  #  define alloca __builtin_alloca
 #else  #else
Line 447  void deprep_terminal () Line 448  void deprep_terminal ()
 #define VTIME VEOL  #define VTIME VEOL
 #endif  #endif
   
 #include <locale.h>  
   
 void prep_terminal ()  void prep_terminal ()
 {  {
   int tty = fileno (stdin);    int tty = fileno (stdin);
Line 474  void prep_terminal () Line 473  void prep_terminal ()
     return;      /* added by MdG */      return;      /* added by MdG */
   }      /* added by MdG */    }      /* added by MdG */
         
   setlocale(LC_ALL, "");  
   setlocale(LC_NUMERIC, "C");  
   
   /* 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 668  int gf_ungottenc(FILE *stream) Line 664  int gf_ungottenc(FILE *stream)
 long key_avail (FILE *stream)  long key_avail (FILE *stream)
 {  {
   int tty = fileno (stream);    int tty = fileno (stream);
   fd_set selin;    struct pollfd fds = { tty, POLLIN, 0 };
   static struct timeval now = { 0 , 0 };  
   int chars_avail;    int chars_avail;
   
   if (gf_ungottenc(stream))    if (gf_ungottenc(stream))
Line 678  long key_avail (FILE *stream) Line 673  long key_avail (FILE *stream)
   if(!terminal_prepped && stream == stdin)    if(!terminal_prepped && stream == stdin)
     prep_terminal();      prep_terminal();
   
   FD_ZERO(&selin);  #if defined(FIONREAD) && !defined(_WIN32)
   FD_SET(tty, &selin);    if(isatty (tty)) {
   chars_avail = select(1, &selin, NULL, NULL, &now);      int result = ioctl (tty, FIONREAD, &chars_avail);
     } else
   #endif
     {
       chars_avail = poll(&fds, 1, 0);
     }
   #ifndef __ANDROID__
   if (chars_avail > 0) {    if (chars_avail > 0) {
     /* getc won't block */      /* getc won't block */
     int c = getc(stream);      int c = getc(stream);
Line 688  long key_avail (FILE *stream) Line 689  long key_avail (FILE *stream)
       return 0;        return 0;
     gf_ungetc(c, stream);      gf_ungetc(c, stream);
   }    }
   #endif
   return (chars_avail == -1) ? 0 : chars_avail;    return (chars_avail == -1) ? 0 : chars_avail;
 }  }
   

Removed from v.1.39  
changed lines
  Added in v.1.44


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