version 1.21, 2006/04/09 07:44:13
|
version 1.31, 2007/12/31 17:34:59
|
Line 1
|
Line 1
|
/* direct key io driver |
/* 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 Free Software Foundation, Inc. |
|
|
This file is part of Gforth. |
This file is part of Gforth. |
|
|
Line 475 void prep_terminal ()
|
Line 475 void prep_terminal ()
|
} /* added by MdG */ |
} /* added by MdG */ |
|
|
setlocale(LC_ALL, ""); |
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. */ |
Line 621 long key_avail (FILE * stream)
|
Line 622 long key_avail (FILE * stream)
|
{ |
{ |
int tty = fileno (stream); |
int tty = fileno (stream); |
fd_set selin; |
fd_set selin; |
static int now[2] = { 0 , 0 }; |
static struct timespec now = { 0 , 0 }; |
int res; |
int res; |
|
|
|
setvbuf(stream, NULL, _IONBF, 0); |
if(!terminal_prepped && stream == stdin) |
if(!terminal_prepped && stream == stdin) |
prep_terminal(); |
prep_terminal(); |
|
|
FD_ZERO(&selin); |
FD_ZERO(&selin); |
FD_SET(tty, &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. |
/* Get a key from the buffer of characters to be read. |
Line 644 Cell getkey(FILE * stream)
|
Line 646 Cell getkey(FILE * stream)
|
Cell result; |
Cell result; |
unsigned char c; |
unsigned char c; |
|
|
if(!terminal_prepped) |
setvbuf(stream, NULL, _IONBF, 0); |
|
if(!terminal_prepped && stream == stdin) |
prep_terminal(); |
prep_terminal(); |
|
|
while (1) |
result = fread(&c, sizeof(c), 1, stream); |
{ |
return result==0 ? (errno == EINTR ? 12 : 4) : c; |
result = read (fileno (stream), &c, sizeof (char)); |
} |
|
|
if (result == sizeof (char)) |
#ifdef STANDALONE |
return /* (c == 0x7F ? 0x08 :*/ c /*)*/; |
void emit_char(char x) |
|
{ |
|
putc(x, stdout); |
|
} |
|
|
/* If zero characters are returned, then the file that we are |
void type_chars(char *addr, unsigned int l) |
reading from is empty! Return EOF in that case. */ |
{ |
if (result == 0) |
fwrite(addr, l, 1, stdout); |
return (EOF); |
|
|
|
/* If the error that we received was SIGINT, then try again, |
|
this is simply an interrupted system call to read (). |
|
Otherwise, some error ocurred, also signifying EOF. */ |
|
if (errno != EINTR) |
|
return (EOF); |
|
} |
|
} |
} |
|
#endif |
|
|
#ifdef TEST |
#ifdef TEST |
|
|