--- gforth/engine/io.c 2002/03/13 17:09:09 1.14 +++ gforth/engine/io.c 2006/04/09 07:39:07 1.20 @@ -1,6 +1,6 @@ /* direct key io driver - Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc. + Copyright (C) 1995,1996,1997,1998,1999,2002,2003 Free Software Foundation, Inc. This file is part of Gforth. @@ -26,6 +26,7 @@ */ #include "config.h" +#include "forth.h" #include #include #include @@ -51,7 +52,6 @@ typedef unsigned int uint32_t; #include #endif #include -#include "forth.h" #include "io.h" #ifndef MSDOS @@ -447,6 +447,8 @@ void deprep_terminal () #define VTIME VEOL #endif +#include + void prep_terminal () { int tty = fileno (stdin); @@ -472,6 +474,8 @@ void prep_terminal () return; /* added by MdG */ } /* added by MdG */ + setlocale(LC_ALL, ""); + /* Try to keep this function from being INTerrupted. We can do it on POSIX and systems with BSD-like signal handling. */ #if defined (HAVE_POSIX_SIGNALS) @@ -615,8 +619,13 @@ void deprep_terminal () /* If a character is available to be read, then read it and stuff it into IBUFFER. Otherwise, just return. */ - long pending = -1L; +/* !! This is a bug: if key_avail(file1) is followed by getkey(file2), + the getkey(file2) can return the character from file1. - anton */ + +/* Moreover, key_avail and getkey bypass the buffering of the FILE *, + leading to unpleasant effects if KEY-FILE and KEY?-FILE are mixed + with READ-FILE and READ-LINE */ long key_avail (FILE * stream) { @@ -624,9 +633,12 @@ long key_avail (FILE * stream) int chars_avail = pending; int result; - if(!terminal_prepped) prep_terminal(); + if(!terminal_prepped && stream == stdin) + prep_terminal(); #if defined(FIONREAD) && !defined(_WIN32) + /* !! What is the point of this part? it does not affect + chars_avail, and "result" is never used - anton */ if(isatty (tty)) { result = ioctl (tty, FIONREAD, &chars_avail); }