loadkmap.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* 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. #include "libbb.h"
  10. #define BINARY_KEYMAP_MAGIC "bkeymap"
  11. /* From <linux/kd.h> */
  12. struct kbentry {
  13. unsigned char kb_table;
  14. unsigned char kb_index;
  15. unsigned short kb_value;
  16. };
  17. /* sets one entry in translation table */
  18. #define KDSKBENT 0x4B47
  19. /* From <linux/keyboard.h> */
  20. #define NR_KEYS 128
  21. #define MAX_NR_KEYMAPS 256
  22. int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  23. int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  24. {
  25. struct kbentry ke;
  26. int i, j, fd;
  27. uint16_t ibuff[NR_KEYS];
  28. /* const char *tty_name = CURRENT_TTY; */
  29. RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
  30. /* bb_warn_ignoring_args(argc >= 2); */
  31. fd = get_console_fd_or_die();
  32. /* or maybe:
  33. opt = getopt32(argv, "C:", &tty_name);
  34. fd = xopen(tty_name, O_NONBLOCK);
  35. */
  36. xread(STDIN_FILENO, flags, 7);
  37. if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
  38. bb_error_msg_and_die("not a valid binary keymap");
  39. xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
  40. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  41. if (flags[i] == 1) {
  42. xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
  43. for (j = 0; j < NR_KEYS; j++) {
  44. ke.kb_index = j;
  45. ke.kb_table = i;
  46. ke.kb_value = ibuff[j];
  47. ioctl(fd, KDSKBENT, &ke);
  48. }
  49. }
  50. }
  51. if (ENABLE_FEATURE_CLEAN_UP) {
  52. close(fd);
  53. RELEASE_CONFIG_BUFFER(flags);
  54. }
  55. return EXIT_SUCCESS;
  56. }