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

Last change on this file was 3621, checked in by Bruno Cornec, 7 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
RevLine 
[821]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 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
[3232]9
10//usage:#define loadkmap_trivial_usage
11//usage: "< keymap"
12//usage:#define loadkmap_full_usage "\n\n"
[3621]13//usage: "Load a binary keyboard translation table from stdin"
14////usage: "\n"
15////usage: "\n -C TTY Affect TTY instead of /dev/tty"
[3232]16//usage:
17//usage:#define loadkmap_example_usage
18//usage: "$ loadkmap < /etc/i18n/lang-keymap\n"
19
[1765]20#include "libbb.h"
[821]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
[2725]37int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
38int loadkmap_main(int argc UNUSED_PARAM, char **argv)
[821]39{
40 struct kbentry ke;
41 int i, j, fd;
[1765]42 uint16_t ibuff[NR_KEYS];
[2725]43/* const char *tty_name = CURRENT_TTY; */
44 RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
[821]45
[2725]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])
[821]50 bb_show_usage();
[2725]51/* bb_warn_ignoring_args(argv[1]); */
[3621]52
[2725]53 fd = get_console_fd_or_die();
54/* or maybe:
55 opt = getopt32(argv, "C:", &tty_name);
56 fd = xopen_nonblocking(tty_name);
57*/
[821]58
[2725]59 xread(STDIN_FILENO, flags, 7);
[3621]60 if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
[2725]61 bb_error_msg_and_die("not a valid binary keymap");
[821]62
[2725]63 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
[821]64
65 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
[3621]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);
[821]84 }
85 }
86
[2725]87 if (ENABLE_FEATURE_CLEAN_UP) {
88 close(fd);
89 RELEASE_CONFIG_BUFFER(flags);
90 }
91 return EXIT_SUCCESS;
[821]92}
Note: See TracBrowser for help on using the repository browser.