source: MondoRescue/branches/3.3/mindi-busybox/console-tools/loadkmap.c@ 3901

Last change on this file since 3901 was 3621, checked in by Bruno Cornec, 10 years ago

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

File size: 2.4 KB
Line 
1/* 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 source tree.
8 */
9
10//usage:#define loadkmap_trivial_usage
11//usage: "< keymap"
12//usage:#define loadkmap_full_usage "\n\n"
13//usage: "Load a binary keyboard translation table from stdin"
14////usage: "\n"
15////usage: "\n -C TTY Affect TTY instead of /dev/tty"
16//usage:
17//usage:#define loadkmap_example_usage
18//usage: "$ loadkmap < /etc/i18n/lang-keymap\n"
19
20#include "libbb.h"
21
22#define BINARY_KEYMAP_MAGIC "bkeymap"
23
24/* From <linux/kd.h> */
25struct kbentry {
26 unsigned char kb_table;
27 unsigned char kb_index;
28 unsigned short kb_value;
29};
30/* sets one entry in translation table */
31#define KDSKBENT 0x4B47
32
33/* From <linux/keyboard.h> */
34#define NR_KEYS 128
35#define MAX_NR_KEYMAPS 256
36
37int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38int loadkmap_main(int argc UNUSED_PARAM, char **argv)
39{
40 struct kbentry ke;
41 int i, j, fd;
42 uint16_t ibuff[NR_KEYS];
43/* const char *tty_name = CURRENT_TTY; */
44 RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
45
46 /* When user accidentally runs "loadkmap FILE"
47 * instead of "loadkmap <FILE", we end up waiting for input from tty.
48 * Let's prevent it: */
49 if (argv[1])
50 bb_show_usage();
51/* bb_warn_ignoring_args(argv[1]); */
52
53 fd = get_console_fd_or_die();
54/* or maybe:
55 opt = getopt32(argv, "C:", &tty_name);
56 fd = xopen_nonblocking(tty_name);
57*/
58
59 xread(STDIN_FILENO, flags, 7);
60 if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
61 bb_error_msg_and_die("not a valid binary keymap");
62
63 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
64
65 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
66 if (flags[i] != 1)
67 continue;
68 xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
69 for (j = 0; j < NR_KEYS; j++) {
70 ke.kb_index = j;
71 ke.kb_table = i;
72 ke.kb_value = ibuff[j];
73 /*
74 * Note: table[idx:0] can contain special value
75 * K_ALLOCATED (marks allocated tables in kernel).
76 * dumpkmap saves the value as-is; but attempts
77 * to load it here fail, since it isn't a valid
78 * key value: it is K(KT_SPEC,126) == 2<<8 + 126,
79 * whereas last valid KT_SPEC is
80 * K_BARENUMLOCK == K(KT_SPEC,19).
81 * So far we just ignore these errors:
82 */
83 ioctl(fd, KDSKBENT, &ke);
84 }
85 }
86
87 if (ENABLE_FEATURE_CLEAN_UP) {
88 close(fd);
89 RELEASE_CONFIG_BUFFER(flags);
90 }
91 return EXIT_SUCCESS;
92}
Note: See TracBrowser for help on using the repository browser.