2020-02-11 01:01:21 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
2020-02-18 22:31:23 +00:00
|
|
|
#include <wctype.h>
|
2020-02-11 01:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct termios orig_termios;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
disableRawMode()
|
|
|
|
{
|
|
|
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
enableRawMode()
|
|
|
|
{
|
|
|
|
tcgetattr(STDIN_FILENO, &orig_termios);
|
|
|
|
atexit(disableRawMode);
|
|
|
|
|
|
|
|
struct termios raw = orig_termios;
|
|
|
|
raw.c_lflag &= ~(ECHO | ICANON);
|
|
|
|
|
|
|
|
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
enableRawMode();
|
|
|
|
|
2020-02-18 22:31:23 +00:00
|
|
|
wchar_t c;
|
|
|
|
while (read(STDIN_FILENO, &c, sizeof(c)) > 0 && c != 'q') {
|
|
|
|
if (iswcntrl(c)) {
|
2020-02-11 01:01:21 +00:00
|
|
|
printf("$%02x\n", c);
|
|
|
|
} else {
|
2020-02-18 22:31:23 +00:00
|
|
|
printf("$%02x ('%lc')\n", c, c);
|
2020-02-11 01:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 22:31:23 +00:00
|
|
|
perror("read");
|
2020-02-11 01:01:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|