Add pancyrillic font
[platform/upstream/kbd.git] / src / getkeycodes.c
1 /*
2  * call: getkeycodes
3  *
4  * aeb, 941108
5  */
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include <linux/kd.h>
12 #include "getfd.h"
13 #include "nls.h"
14 #include "version.h"
15
16 static void __attribute__ ((noreturn))
17 usage(void) {
18     fprintf(stderr, _("usage: getkeycodes\n"));
19     exit(1);
20 }
21
22 int
23 main(int argc, char **argv) {
24         int fd;
25         unsigned int sc, sc0;
26         struct kbkeycode a;
27
28         set_progname(argv[0]);
29
30         setlocale(LC_ALL, "");
31         bindtextdomain(PACKAGE_NAME, LOCALEDIR);
32         textdomain(PACKAGE_NAME);
33
34         if (argc == 2 && !strcmp(argv[1], "-V"))
35                 print_version_and_exit();
36
37         if (argc != 1)
38                 usage();
39         fd = getfd(NULL);
40
41         /* Old kernels don't support changing scancodes below SC_LIM. */
42         a.scancode = 0;
43         a.keycode = 0;
44         if (ioctl(fd, KDGETKEYCODE, &a)) {
45                 sc0 = 89;
46         } else
47         for (sc0 = 1; sc0 <= 88; sc0++) {
48                 a.scancode = sc0;
49                 a.keycode = 0;
50                 if (ioctl(fd, KDGETKEYCODE, &a) || a.keycode != sc0)
51                         break;
52         }
53
54         printf(_("Plain scancodes xx (hex) versus keycodes (dec)\n"));
55
56         if (sc0 == 89) {
57                 printf(_("0 is an error; "
58                          "for 1-88 (0x01-0x58) scancode equals keycode\n"));
59         } else if (sc0 > 1) {
60                 printf(_("for 1-%d (0x01-0x%02x) scancode equals keycode\n"),
61                        sc0 - 1, sc0 - 1);
62         }
63
64         for (sc = (sc0 & ~7); sc < 256; sc++) {
65                 if (sc == 128)
66                         printf(_("\n\nEscaped scancodes e0 xx (hex)\n"));
67                 if (sc % 8 == 0) {
68                         if (sc < 128)
69                                 printf("\n 0x%02x: ", sc);
70                         else
71                                 printf("\ne0 %02x: ", sc-128);
72                 }
73
74                 if (sc < sc0) {
75                         printf(" %3d", sc);
76                         continue;
77                 }
78
79                 a.scancode = sc;
80                 a.keycode = 0;
81                 if (ioctl(fd, KDGETKEYCODE, &a) == 0) {
82                         printf(" %3d", a.keycode);
83                         continue;
84                 }
85                 if (errno == EINVAL) {
86                         printf("   -");
87                         continue;
88                 }
89                 perror("KDGETKEYCODE");
90                 fprintf(stderr,
91                         _("failed to get keycode for scancode 0x%x\n"), sc);
92                 exit(1);
93         }
94         printf("\n");
95         return 0;
96 }