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

Last change on this file was 3320, checked in by bruno, 5 years ago
  • Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in the move to 3.0
  • Property svn:eol-style set to native
File size: 1.7 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#include "libbb.h"
10
11#define BINARY_KEYMAP_MAGIC "bkeymap"
12
13/* From <linux/kd.h> */
14struct 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
26int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
27int loadkmap_main(int argc UNUSED_PARAM, char **argv)
28{
29    struct kbentry ke;
30    int i, j, fd;
31    uint16_t ibuff[NR_KEYS];
32/*  const char *tty_name = CURRENT_TTY; */
33    RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
34
35    /* 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/* bb_warn_ignoring_args(argv[1]); */
41    fd = get_console_fd_or_die();
42/* or maybe:
43    opt = getopt32(argv, "C:", &tty_name);
44    fd = xopen_nonblocking(tty_name);
45*/
46
47    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
51    xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
52
53    for (i = 0; i < MAX_NR_KEYMAPS; i++) {
54        if (flags[i] == 1) {
55            xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
56            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    if (ENABLE_FEATURE_CLEAN_UP) {
66        close(fd);
67        RELEASE_CONFIG_BUFFER(flags);
68    }
69    return EXIT_SUCCESS;
70}
Note: See TracBrowser for help on using the repository browser.