| 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | #include <ctype.h> |
| 4 | #include <unistd.h> |
| 5 | #include <termios.h> |
| 6 | |
| 7 | static struct termios term; |
| 8 | |
| 9 | static void newtermio() |
| 10 | { |
| 11 | struct termios newterm; |
| 12 | tcgetattr(0, &term); |
| 13 | newterm=term; |
| 14 | newterm.c_lflag&=~(ECHO|ICANON); |
| 15 | newterm.c_cc[VMIN]=1; |
| 16 | newterm.c_cc[VTIME]=0; |
| 17 | tcsetattr(0, TCSANOW, &newterm); |
| 18 | } |
| 19 | |
| 20 | static void restoretermio() |
| 21 | { |
| 22 | tcsetattr(0, TCSANOW, &term); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void main() |
| 27 | { |
| 28 | int endOfInput = 0; |
| 29 | char ch; |
| 30 | |
| 31 | while (!endOfInput) { |
| 32 | fflush(stdout); |
| 33 | if (read(0, &ch, 1) != 1) { |
| 34 | return; |
| 35 | } |
| 36 | printf("%d %x '%c'\n", (int)ch, (int)ch, ch); |
| 37 | } |
| 38 | return; |
| 39 | } |