--- gforth/engine/io.c 2006/04/09 08:04:22 1.22 +++ gforth/engine/io.c 2008/11/01 22:19:30 1.34 @@ -1,12 +1,12 @@ /* direct key io driver - Copyright (C) 1995,1996,1997,1998,1999,2002,2003 Free Software Foundation, Inc. + Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006,2007,2008 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 + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + along with this program; if not, see http://www.gnu.org/licenses/. The following is stolen from the readline library for bash */ @@ -475,6 +474,7 @@ void prep_terminal () } /* added by MdG */ setlocale(LC_ALL, ""); + setlocale(LC_NUMERIC, "C"); /* Try to keep this function from being INTerrupted. We can do it on POSIX and systems with BSD-like signal handling. */ @@ -621,8 +621,7 @@ long key_avail (FILE * stream) { int tty = fileno (stream); fd_set selin; - static int now[2] = { 0 , 0 }; - int res; + static struct timeval now = { 0 , 0 }; setvbuf(stream, NULL, _IONBF, 0); if(!terminal_prepped && stream == stdin) @@ -630,7 +629,7 @@ long key_avail (FILE * stream) FD_ZERO(&selin); FD_SET(tty, &selin); - return select(1, &selin, NULL, NULL, now); + return select(1, &selin, NULL, NULL, &now); } /* Get a key from the buffer of characters to be read. @@ -645,13 +644,26 @@ Cell getkey(FILE * stream) Cell result; unsigned char c; + setvbuf(stream, NULL, _IONBF, 0); if(!terminal_prepped && stream == stdin) prep_terminal(); result = fread(&c, sizeof(c), 1, stream); - return result==0 ? EOF : c; + return result==0 ? (errno == EINTR ? 12 : 4) : c; +} + +#ifdef STANDALONE +void emit_char(char x) +{ + putc(x, stdout); } +void type_chars(char *addr, unsigned int l) +{ + fwrite(addr, l, 1, stdout); +} +#endif + #ifdef TEST #include