2 * Unix test code that puts the terminal into raw mode, then echos typed
3 * characters to stdout. Derived from sample code in the Stevens book, posted
4 * online at http://www.lafn.org/~dave/linux/terminalIO.html.
11 #include "FormatChar.h"
13 static struct termios save_termios;
14 static int term_saved;
21 if (tcgetattr(fd, &save_termios) < 0) /* get the original state */
26 /* echo off, canonical mode off, extended input
27 processing off, signal chars off */
28 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
30 /* no SIGINT on BREAK, CR-to-NL off, input parity
31 check off, don't strip the 8th bit on input,
32 ouput flow control off */
33 buf.c_iflag &= ~(BRKINT | ICRNL | ISTRIP | IXON);
35 /* clear size bits, parity checking off */
36 buf.c_cflag &= ~(CSIZE | PARENB);
41 /* output processing off */
42 buf.c_oflag &= ~(OPOST);
44 buf.c_cc[VMIN] = 1; /* 1 byte at a time */
45 buf.c_cc[VTIME] = 0; /* no timer on input */
47 if (tcsetattr(fd, TCSAFLUSH, &buf) < 0)
56 /* set it to normal! */
60 if (tcsetattr(fd, TCSAFLUSH, &save_termios) < 0)
75 int actual = read(0, &ch, 1);
83 if (ch == 3) // Ctrl-C