Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/console-tools/setkeycodes.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1065 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /* vi: set sw=4 ts=4: */
2 /*
3 * setkeycodes
4 *
5 * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
6 *
7 * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org>
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include "busybox.h"
17
18
19 /* From <linux/kd.h> */
20 struct kbkeycode {
21 unsigned int scancode, keycode;
22 };
23 enum {
24 KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
25 };
26
27 extern int
28 setkeycodes_main(int argc, char** argv)
29 {
30 int fd, sc;
31 struct kbkeycode a;
32
33 if (argc % 2 != 1 || argc < 2) {
34 bb_show_usage();
35 }
36
37 fd = get_console_fd();
38
39 while (argc > 2) {
40 a.keycode = xatoul_range(argv[2], 0, 127);
41 a.scancode = sc = xstrtoul_range(argv[1], 16, 0, 255);
42 if (a.scancode > 127) {
43 a.scancode -= 0xe000;
44 a.scancode += 128;
45 }
46 if (ioctl(fd, KDSETKEYCODE, &a)) {
47 bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
48 }
49 argc -= 2;
50 argv += 2;
51 }
52 return EXIT_SUCCESS;
53 }