Line | |
---|
1 | /* loadkeys - load national keyboard map Author: Marcus Hampel
|
---|
2 | */
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <sys/ioctl.h>
|
---|
5 | #include <minix/keymap.h>
|
---|
6 | #include <fcntl.h>
|
---|
7 | #include <unistd.h>
|
---|
8 | #include <stdlib.h>
|
---|
9 | #include <string.h>
|
---|
10 | #include <errno.h>
|
---|
11 |
|
---|
12 | #if __minix_vmd
|
---|
13 | #define KBD_DEVICE "/dev/kbd"
|
---|
14 | #else
|
---|
15 | #define KBD_DEVICE "/dev/console"
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | u16_t keymap[NR_SCAN_CODES * MAP_COLS];
|
---|
19 | u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1];
|
---|
20 |
|
---|
21 |
|
---|
22 | void tell(char *s)
|
---|
23 | {
|
---|
24 | write(2, s, strlen(s));
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | void fatal(char *say)
|
---|
29 | {
|
---|
30 | int err = errno;
|
---|
31 | tell("loadkeys: ");
|
---|
32 | if (say != NULL) {
|
---|
33 | tell(say);
|
---|
34 | tell(": ");
|
---|
35 | }
|
---|
36 | tell(strerror(err));
|
---|
37 | tell("\n");
|
---|
38 | exit(1);
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | void usage(void)
|
---|
43 | {
|
---|
44 | tell("Usage: loadkeys mapfile\n");
|
---|
45 | exit(1);
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | int main(int argc, char *argv[])
|
---|
50 | {
|
---|
51 | u8_t *cm;
|
---|
52 | u16_t *km;
|
---|
53 | int fd, n, fb;
|
---|
54 |
|
---|
55 | if (argc != 2)
|
---|
56 | usage();
|
---|
57 |
|
---|
58 | if ((fd = open(argv[1], O_RDONLY)) < 0) fatal(argv[1]);
|
---|
59 |
|
---|
60 | if (read(fd, comprmap, sizeof(comprmap)) < 0) fatal(argv[1]);
|
---|
61 |
|
---|
62 | if (memcmp(comprmap, KEY_MAGIC, 4) != 0) {
|
---|
63 | tell("loadkeys: ");
|
---|
64 | tell(argv[1]);
|
---|
65 | tell(": not a keymap file\n");
|
---|
66 | exit(1);
|
---|
67 | }
|
---|
68 | close(fd);
|
---|
69 |
|
---|
70 | /* Decompress the keymap data. */
|
---|
71 | cm = comprmap + 4;
|
---|
72 | n = 8;
|
---|
73 | for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) {
|
---|
74 | if (n == 8) {
|
---|
75 | /* Need a new flag byte. */
|
---|
76 | fb = *cm++;
|
---|
77 | n = 0;
|
---|
78 | }
|
---|
79 | *km = *cm++; /* Low byte. */
|
---|
80 | if (fb & (1 << n)) {
|
---|
81 | *km |= (*cm++ << 8); /* One of the few special keys. */
|
---|
82 | }
|
---|
83 | n++;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if ((fd = open(KBD_DEVICE, O_WRONLY)) < 0) fatal(KBD_DEVICE);
|
---|
87 |
|
---|
88 | if (ioctl(fd, KIOCSMAP, keymap) < 0) fatal(KBD_DEVICE);
|
---|
89 |
|
---|
90 | return 0;
|
---|
91 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.