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

Last change on this file since 2142 was 1765, checked in by bruno, 12 years ago

Update to busybox 1.7.2

File size: 1.3 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 tarball for details.
8 *
9 */
10
11#include "libbb.h"
12
13#define BINARY_KEYMAP_MAGIC "bkeymap"
14
15/* From <linux/kd.h> */
16struct kbentry {
17    unsigned char kb_table;
18    unsigned char kb_index;
19    unsigned short kb_value;
20};
21/* sets one entry in translation table */
22#define KDSKBENT        0x4B47
23
24/* From <linux/keyboard.h> */
25#define NR_KEYS         128
26#define MAX_NR_KEYMAPS  256
27
28int loadkmap_main(int argc, char **argv);
29int loadkmap_main(int argc, char **argv)
30{
31    struct kbentry ke;
32    int i, j, fd;
33    uint16_t ibuff[NR_KEYS];
34    char flags[MAX_NR_KEYMAPS];
35    char buff[7];
36
37    if (argc != 1)
38        bb_show_usage();
39
40    fd = xopen(CURRENT_VC, O_RDWR);
41
42    xread(0, buff, 7);
43    if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
44        bb_error_msg_and_die("this is not a valid binary keymap");
45
46    xread(0, flags, MAX_NR_KEYMAPS);
47
48    for (i = 0; i < MAX_NR_KEYMAPS; i++) {
49        if (flags[i] == 1) {
50            xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
51            for (j = 0; j < NR_KEYS; j++) {
52                ke.kb_index = j;
53                ke.kb_table = i;
54                ke.kb_value = ibuff[j];
55                ioctl(fd, KDSKBENT, &ke);
56            }
57        }
58    }
59
60    if (ENABLE_FEATURE_CLEAN_UP) close(fd);
61    return 0;
62}
Note: See TracBrowser for help on using the repository browser.