1
2
3
4
5
6
7
8
9
10
11#include "libbb.h"
12#include <linux/kd.h>
13
14int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
16{
17 enum {
18 SCANCODE = (1 << 0),
19 ASCII = (1 << 1),
20 MEDIUMRAW = (1 << 2),
21 UNICODE = (1 << 3),
22 };
23 int fd;
24 unsigned opt;
25 const char *tty_name = CURRENT_TTY;
26
27 opt = getopt32(argv, "sakuC:", &tty_name);
28 fd = xopen_nonblocking(tty_name);
29 opt &= 0xf;
30
31 if (!opt) {
32 const char *mode = "unknown";
33 int m;
34
35 xioctl(fd, KDGKBMODE, &m);
36 if (m == K_RAW)
37 mode = "raw (scancode)";
38 else if (m == K_XLATE)
39 mode = "default (ASCII)";
40 else if (m == K_MEDIUMRAW)
41 mode = "mediumraw (keycode)";
42 else if (m == K_UNICODE)
43 mode = "Unicode (UTF-8)";
44 printf("The keyboard is in %s mode\n", mode);
45 } else {
46
47 opt = opt & UNICODE ? 3 : opt >> 1;
48
49 xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
50 }
51
52 if (ENABLE_FEATURE_CLEAN_UP)
53 close(fd);
54 return EXIT_SUCCESS;
55}
56