5 |
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es> |
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es> |
6 |
* |
* |
7 |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
|
* |
|
8 |
*/ |
*/ |
9 |
|
#include "libbb.h" |
|
#include "busybox.h" |
|
10 |
|
|
11 |
#define BINARY_KEYMAP_MAGIC "bkeymap" |
#define BINARY_KEYMAP_MAGIC "bkeymap" |
12 |
|
|
23 |
#define NR_KEYS 128 |
#define NR_KEYS 128 |
24 |
#define MAX_NR_KEYMAPS 256 |
#define MAX_NR_KEYMAPS 256 |
25 |
|
|
26 |
int loadkmap_main(int argc, char **argv) |
int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
27 |
|
int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
28 |
{ |
{ |
29 |
struct kbentry ke; |
struct kbentry ke; |
30 |
int i, j, fd; |
int i, j, fd; |
31 |
uint16_t ibuff[NR_KEYS]; |
uint16_t ibuff[NR_KEYS]; |
32 |
char flags[MAX_NR_KEYMAPS]; |
/* const char *tty_name = CURRENT_TTY; */ |
33 |
char buff[7]; |
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS); |
|
|
|
|
if (argc != 1) |
|
|
bb_show_usage(); |
|
34 |
|
|
35 |
fd = xopen(CURRENT_VC, O_RDWR); |
/* 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 |
|
|
42 |
|
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 |
|
|
46 |
xread(0, buff, 7); |
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); |
|
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) |
|
|
bb_error_msg_and_die("this is not a valid binary keymap"); |
|
|
|
|
|
xread(0, flags, MAX_NR_KEYMAPS); |
|
47 |
|
|
48 |
for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
49 |
if (flags[i] == 1) { |
if (flags[i] == 1) { |
50 |
xread(0, ibuff, NR_KEYS * sizeof(uint16_t)); |
xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); |
51 |
for (j = 0; j < NR_KEYS; j++) { |
for (j = 0; j < NR_KEYS; j++) { |
52 |
ke.kb_index = j; |
ke.kb_index = j; |
53 |
ke.kb_table = i; |
ke.kb_table = i; |
57 |
} |
} |
58 |
} |
} |
59 |
|
|
60 |
if (ENABLE_FEATURE_CLEAN_UP) close(fd); |
if (ENABLE_FEATURE_CLEAN_UP) { |
61 |
return 0; |
close(fd); |
62 |
|
RELEASE_CONFIG_BUFFER(flags); |
63 |
|
} |
64 |
|
return EXIT_SUCCESS; |
65 |
} |
} |