Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/console-tools/loadkmap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 1557 byte(s)
-updated to busybox-1.13.4
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     int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
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     RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
34 niro 532
35 niro 816 /* bb_warn_ignoring_args(argc >= 2); */
36     fd = get_console_fd_or_die();
37     /* or maybe:
38     opt = getopt32(argv, "C:", &tty_name);
39     fd = xopen(tty_name, O_NONBLOCK);
40     */
41 niro 532
42 niro 816 xread(STDIN_FILENO, flags, 7);
43     if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
44     bb_error_msg_and_die("not a valid binary keymap");
45 niro 532
46 niro 816 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
47 niro 532
48     for (i = 0; i < MAX_NR_KEYMAPS; i++) {
49     if (flags[i] == 1) {
50 niro 816 xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
51 niro 532 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 niro 816 if (ENABLE_FEATURE_CLEAN_UP) {
61     close(fd);
62     RELEASE_CONFIG_BUFFER(flags);
63     }
64     return EXIT_SUCCESS;
65 niro 532 }