[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Mini dumpkmap implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 8 | *
|
---|
| 9 | */
|
---|
[2725] | 10 | /* no options, no getopt */
|
---|
[821] | 11 |
|
---|
[3232] | 12 | //usage:#define dumpkmap_trivial_usage
|
---|
| 13 | //usage: "> keymap"
|
---|
| 14 | //usage:#define dumpkmap_full_usage "\n\n"
|
---|
| 15 | //usage: "Print a binary keyboard translation table to stdout"
|
---|
| 16 | //usage:
|
---|
| 17 | //usage:#define dumpkmap_example_usage
|
---|
| 18 | //usage: "$ dumpkmap > keymap\n"
|
---|
| 19 |
|
---|
[1765] | 20 | #include "libbb.h"
|
---|
[3621] | 21 | #include "common_bufsiz.h"
|
---|
[821] | 22 |
|
---|
| 23 | /* From <linux/kd.h> */
|
---|
| 24 | struct kbentry {
|
---|
| 25 | unsigned char kb_table;
|
---|
| 26 | unsigned char kb_index;
|
---|
| 27 | unsigned short kb_value;
|
---|
| 28 | };
|
---|
| 29 | #define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
---|
| 30 |
|
---|
| 31 | /* From <linux/keyboard.h> */
|
---|
| 32 | #define NR_KEYS 128
|
---|
| 33 | #define MAX_NR_KEYMAPS 256
|
---|
| 34 |
|
---|
[2725] | 35 | int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 36 | int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
---|
[821] | 37 | {
|
---|
| 38 | struct kbentry ke;
|
---|
| 39 | int i, j, fd;
|
---|
[3621] | 40 | #define flags bb_common_bufsiz1
|
---|
| 41 | setup_common_bufsiz();
|
---|
[821] | 42 |
|
---|
[2725] | 43 | /* When user accidentally runs "dumpkmap FILE"
|
---|
| 44 | * instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
---|
[3621] | 45 | * Let's prevent it:
|
---|
| 46 | */
|
---|
[2725] | 47 | if (argv[1])
|
---|
[821] | 48 | bb_show_usage();
|
---|
[2725] | 49 | /* bb_warn_ignoring_args(argv[1]);*/
|
---|
[821] | 50 |
|
---|
[2725] | 51 | fd = get_console_fd_or_die();
|
---|
[821] | 52 |
|
---|
[3621] | 53 | #if 0
|
---|
[2725] | 54 | write(STDOUT_FILENO, "bkeymap", 7);
|
---|
[821] | 55 | /* Here we want to set everything to 0 except for indexes:
|
---|
[3621] | 56 | * [0-2] [4-6] [8-10] [12]
|
---|
| 57 | */
|
---|
| 58 | /*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */
|
---|
[821] | 59 | memset(flags, 0x01, 13);
|
---|
| 60 | flags[3] = flags[7] = flags[11] = 0;
|
---|
| 61 | /* dump flags */
|
---|
[2725] | 62 | write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
---|
[3621] | 63 | #define flags7 flags
|
---|
| 64 | #else
|
---|
| 65 | /* Same effect */
|
---|
| 66 | /* 0 1 2 3 4 5 6 7 8 9 a b c=12 */
|
---|
| 67 | memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1",
|
---|
| 68 | /* Can use sizeof, or sizeof-1. sizeof is even, using that */
|
---|
| 69 | /****/ sizeof("bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1")
|
---|
| 70 | );
|
---|
| 71 | write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS);
|
---|
| 72 | #define flags7 (flags + 7)
|
---|
| 73 | #endif
|
---|
[821] | 74 |
|
---|
[3621] | 75 | for (i = 0; i < 13; i++) {
|
---|
| 76 | if (flags7[i]) {
|
---|
[821] | 77 | for (j = 0; j < NR_KEYS; j++) {
|
---|
| 78 | ke.kb_index = j;
|
---|
| 79 | ke.kb_table = i;
|
---|
[1765] | 80 | if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
---|
[3621] | 81 | "ioctl(KDGKBENT{%d,%d}) failed",
|
---|
| 82 | j, i)
|
---|
[1765] | 83 | ) {
|
---|
[3621] | 84 | write(STDOUT_FILENO, &ke.kb_value, 2);
|
---|
[821] | 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
[2725] | 89 | if (ENABLE_FEATURE_CLEAN_UP) {
|
---|
| 90 | close(fd);
|
---|
| 91 | }
|
---|
[821] | 92 | return EXIT_SUCCESS;
|
---|
| 93 | }
|
---|