2000-07-11 17:29:36 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini dumpkmap implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
|
|
|
*
|
2006-07-12 07:56:04 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2000-07-11 17:29:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
/* From <linux/kd.h> */
|
|
|
|
struct kbentry {
|
|
|
|
unsigned char kb_table;
|
|
|
|
unsigned char kb_index;
|
|
|
|
unsigned short kb_value;
|
|
|
|
};
|
2005-07-31 22:09:33 +00:00
|
|
|
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
/* From <linux/keyboard.h> */
|
2005-07-31 22:09:33 +00:00
|
|
|
#define NR_KEYS 128
|
|
|
|
#define MAX_NR_KEYMAPS 256
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2007-02-03 17:28:39 +00:00
|
|
|
int dumpkmap_main(int argc, char **argv);
|
2000-07-11 17:29:36 +00:00
|
|
|
int dumpkmap_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct kbentry ke;
|
|
|
|
int i, j, fd;
|
2007-02-03 17:28:39 +00:00
|
|
|
char flags[MAX_NR_KEYMAPS];
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2007-02-03 17:28:39 +00:00
|
|
|
if (argc >= 2 && argv[1][0] == '-')
|
2003-03-19 09:13:01 +00:00
|
|
|
bb_show_usage();
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2006-08-03 15:41:12 +00:00
|
|
|
fd = xopen(CURRENT_VC, O_RDWR);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2007-02-03 17:28:39 +00:00
|
|
|
write(1, "bkeymap", 7);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2005-07-31 22:06:38 +00:00
|
|
|
/* Here we want to set everything to 0 except for indexes:
|
|
|
|
* [0-2] [4-6] [8-10] [12] */
|
2005-07-31 20:51:58 +00:00
|
|
|
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
2005-07-31 22:06:38 +00:00
|
|
|
memset(flags, 0x01, 13);
|
|
|
|
flags[3] = flags[7] = flags[11] = 0;
|
2004-03-15 08:29:22 +00:00
|
|
|
|
2000-07-11 17:29:36 +00:00
|
|
|
/* dump flags */
|
2005-07-31 20:51:58 +00:00
|
|
|
write(1, flags, MAX_NR_KEYMAPS);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
|
|
|
if (flags[i] == 1) {
|
|
|
|
for (j = 0; j < NR_KEYS; j++) {
|
|
|
|
ke.kb_index = j;
|
|
|
|
ke.kb_table = i;
|
|
|
|
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
2005-07-30 09:29:10 +00:00
|
|
|
bb_perror_msg("ioctl failed with %s, %s, %p",
|
2005-07-30 09:24:49 +00:00
|
|
|
(char *)&ke.kb_index,
|
|
|
|
(char *)&ke.kb_table,
|
2005-07-30 09:29:10 +00:00
|
|
|
&ke.kb_value);
|
2005-07-30 09:24:49 +00:00
|
|
|
} else {
|
|
|
|
write(1, (void*)&ke.kb_value, 2);
|
|
|
|
}
|
2000-07-11 17:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(fd);
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-07-11 17:29:36 +00:00
|
|
|
}
|