Make termios options process-wise instead of global. Write ps2 drivers, but keep translation between scancode set 2/3 to set 1 enabled.

This commit is contained in:
Enrico Fraccaroli
2022-01-07 18:09:02 +01:00
parent 2461d82431
commit ac9b627fad
22 changed files with 633 additions and 216 deletions
+1
View File
@@ -67,6 +67,7 @@ set(PROGRAMS
ipcs.c
sleep.c
man.c
edit.c
)
foreach(PROGRAM ${PROGRAMS})
# Prepare the program name.
+48
View File
@@ -0,0 +1,48 @@
#include <sys/unistd.h>
#include <termios.h>
#include <stdbool.h>
#include <debug.h>
#include <stdio.h>
#include <ctype.h>
#define CTRL_KEY(k) ((k)&0x1f)
static struct termios _original_termios, _termios;
static inline void die(const char *s)
{
printf("error: %s\n", s);
exit(1);
}
static inline void disable_raw_mode()
{
tcsetattr(STDIN_FILENO, 0, &_original_termios);
}
static inline void enable_raw_mode()
{
tcgetattr(STDIN_FILENO, &_original_termios);
_termios = _original_termios;
_termios.c_lflag &= ~(ICANON | ECHO | IEXTEN | ISIG);
tcsetattr(STDIN_FILENO, 0, &_termios);
}
int main(int argc, char *argv[])
{
enable_raw_mode();
int c;
do {
c = getchar();
if (iscntrl(c)) {
printf("%d\n", c);
} else {
printf("%d ('%c')\n", c, c);
}
} while (c != 'q');
disable_raw_mode();
return 0;
}