2 /***************************************************************
\r
3 ** I/O subsystem for PForth based on 'C'
\r
6 ** Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
\r
8 ** The pForth software code is dedicated to the public domain,
\r
9 ** and any third party may reproduce, distribute and modify
\r
10 ** the pForth software code or any derivative works thereof
\r
11 ** without any compensation or license. The pForth software
\r
12 ** code is provided on an "as is" basis without any warranty
\r
13 ** of any kind, including, without limitation, the implied
\r
14 ** warranties of merchantability and fitness for a particular
\r
15 ** purpose and their equivalents under the laws of any jurisdiction.
\r
17 ****************************************************************
\r
18 ** 941004 PLB Extracted IO calls from pforth_main.c
\r
19 ***************************************************************/
\r
21 #include "../pf_all.h"
\r
24 /* Configure console so that characters are not buffered.
\r
25 * This allows KEY to work and also HISTORY.ON
\r
26 * Thanks to Ralf Baechle and David Feuer for contributing this.
\r
31 #include <sys/int_types.h> /* Needed on Solaris for uint32_t in termio.h */
\r
33 #include <termios.h>
\r
34 #include <sys/poll.h>
\r
38 static struct termios save_termios;
\r
39 static int stdin_is_tty;
\r
41 /* Default portable terminal I/O. */
\r
42 int sdTerminalOut( char c )
\r
46 /* We don't need to echo because getchar() echos. */
\r
47 int sdTerminalEcho( char c )
\r
52 int sdTerminalIn( void )
\r
57 int sdTerminalFlush( void )
\r
62 return fflush(PF_STDOUT);
\r
66 /****************************************************/
\r
67 int sdQueryTerminal( void )
\r
72 pfd.events = stdin_fd;
\r
73 return poll( &pfd, 1, 0 );
\r
76 /****************************************************/
\r
77 void sdTerminalInit(void)
\r
79 struct termios term;
\r
81 stdin_is_tty = isatty(stdin_fd);
\r
85 /* Get current terminal attributes and save them so we can restore them. */
\r
86 tcgetattr(stdin_fd, &term);
\r
87 save_termios = term;
\r
89 /* ICANON says to wait upon read until a character is received,
\r
90 * and then to return it immediately (or soon enough....)
\r
91 * ECHOCTL says not to echo backspaces and other control chars as ^H */
\r
92 term.c_lflag &= ~( ECHO | ECHONL | ECHOCTL | ICANON );
\r
93 term.c_cc[VTIME] = 0;
\r
94 term.c_cc[VMIN] = 1;
\r
95 tcsetattr(stdin_fd, TCSANOW, &term);
\r
98 /****************************************************/
\r
99 void sdTerminalTerm(void)
\r
104 tcsetattr(stdin_fd, TCSANOW, &save_termios);
\r