Add pancyrillic font
[platform/upstream/kbd.git] / src / setkeycodes.c
1 /*
2  * call: setkeycode scancode keycode ...
3  *  (where scancode is either xx or e0xx, given in hexadecimal,
4  *   and keycode is given in decimal)
5  *
6  * aeb, 941108, 2004-01-11
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12 #include <linux/kd.h>
13 #include "getfd.h"
14 #include "nls.h"
15 #include "version.h"
16
17 static void __attribute__ ((noreturn))
18 usage(char *s) {
19         fprintf(stderr, "setkeycode: %s\n", s);
20         fprintf(stderr, _(
21             "usage: setkeycode scancode keycode ...\n"
22             " (where scancode is either xx or e0xx, given in hexadecimal,\n"
23             "  and keycode is given in decimal)\n"));
24         exit(1);
25 }
26
27 int
28 main(int argc, char **argv) {
29         char *ep;
30         int fd;
31         struct kbkeycode a;
32
33         set_progname(argv[0]);
34
35         setlocale(LC_ALL, "");
36         bindtextdomain(PACKAGE_NAME, LOCALEDIR);
37         textdomain(PACKAGE_NAME);
38
39         if (argc == 2 && !strcmp(argv[1], "-V"))
40                 print_version_and_exit();
41
42         if (argc % 2 != 1)
43                 usage(_("even number of arguments expected"));
44         fd = getfd(NULL);
45
46         while (argc > 2) {
47                 a.keycode = atoi(argv[2]);
48                 a.scancode = strtol(argv[1], &ep, 16);
49                 if (*ep)
50                         usage(_("error reading scancode"));
51                 if (a.scancode >= 0xe000) {
52                         a.scancode -= 0xe000;
53                         a.scancode += 128;      /* some kernels needed +256 */
54                 }
55 #if 0
56                 /* Test is OK up to 2.5.31--later kernels have more keycodes */
57                 if (a.scancode > 255 || a.keycode > 127)
58                         usage(_("code outside bounds"));
59
60                 /* Both fields are unsigned int, so can be large;
61                    for current kernels the correct test might be
62                      (a.scancode > 255 || a.keycode > 239)
63                    but we can leave testing to the kernel. */
64 #endif
65                 if (ioctl(fd,KDSETKEYCODE,&a)) {
66                         perror("KDSETKEYCODE");
67                         fprintf(stderr,
68                                 _("failed to set scancode %x to keycode %d\n"),
69                                 a.scancode, a.keycode);
70                         exit(1);
71                 }
72                 argc -= 2;
73                 argv += 2;
74         }
75         return 0;
76 }