Annotation of /trunk/mkinitrd-magellan/busybox/console-tools/loadkmap.c
Parent Directory | Revision Log
Revision 1123 -
(hide annotations)
(download)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1720 byte(s)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1720 byte(s)
-updated to busybox-1.17.1
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Mini loadkmap implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | niro | 816 | #include "libbb.h" |
10 | niro | 532 | |
11 | #define BINARY_KEYMAP_MAGIC "bkeymap" | ||
12 | |||
13 | /* From <linux/kd.h> */ | ||
14 | struct kbentry { | ||
15 | unsigned char kb_table; | ||
16 | unsigned char kb_index; | ||
17 | unsigned short kb_value; | ||
18 | }; | ||
19 | /* sets one entry in translation table */ | ||
20 | #define KDSKBENT 0x4B47 | ||
21 | |||
22 | /* From <linux/keyboard.h> */ | ||
23 | #define NR_KEYS 128 | ||
24 | #define MAX_NR_KEYMAPS 256 | ||
25 | |||
26 | niro | 816 | int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
27 | niro | 1123 | int loadkmap_main(int argc UNUSED_PARAM, char **argv) |
28 | niro | 532 | { |
29 | struct kbentry ke; | ||
30 | int i, j, fd; | ||
31 | uint16_t ibuff[NR_KEYS]; | ||
32 | niro | 816 | /* const char *tty_name = CURRENT_TTY; */ |
33 | niro | 984 | RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS); |
34 | niro | 532 | |
35 | niro | 1123 | /* When user accidentally runs "loadkmap FILE" |
36 | * instead of "loadkmap <FILE", we end up waiting for input from tty. | ||
37 | * Let's prevent it: */ | ||
38 | if (argv[1]) | ||
39 | bb_show_usage(); | ||
40 | niro | 984 | /* bb_warn_ignoring_args(argv[1]); */ |
41 | niro | 816 | fd = get_console_fd_or_die(); |
42 | /* or maybe: | ||
43 | opt = getopt32(argv, "C:", &tty_name); | ||
44 | niro | 984 | fd = xopen_nonblocking(tty_name); |
45 | niro | 816 | */ |
46 | niro | 532 | |
47 | niro | 816 | xread(STDIN_FILENO, flags, 7); |
48 | if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7)) | ||
49 | bb_error_msg_and_die("not a valid binary keymap"); | ||
50 | niro | 532 | |
51 | niro | 816 | xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); |
52 | niro | 532 | |
53 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | ||
54 | if (flags[i] == 1) { | ||
55 | niro | 816 | xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); |
56 | niro | 532 | for (j = 0; j < NR_KEYS; j++) { |
57 | ke.kb_index = j; | ||
58 | ke.kb_table = i; | ||
59 | ke.kb_value = ibuff[j]; | ||
60 | ioctl(fd, KDSKBENT, &ke); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | niro | 816 | if (ENABLE_FEATURE_CLEAN_UP) { |
66 | close(fd); | ||
67 | RELEASE_CONFIG_BUFFER(flags); | ||
68 | } | ||
69 | return EXIT_SUCCESS; | ||
70 | niro | 532 | } |