loadkmap.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. */
  10. #include "busybox.h"
  11. #define BINARY_KEYMAP_MAGIC "bkeymap"
  12. /* From <linux/kd.h> */
  13. struct kbentry {
  14. unsigned char kb_table;
  15. unsigned char kb_index;
  16. unsigned short kb_value;
  17. };
  18. /* sets one entry in translation table */
  19. #define KDSKBENT 0x4B47
  20. /* From <linux/keyboard.h> */
  21. #define NR_KEYS 128
  22. #define MAX_NR_KEYMAPS 256
  23. int loadkmap_main(int argc, char **argv)
  24. {
  25. struct kbentry ke;
  26. int i, j, fd;
  27. u_short ibuff[NR_KEYS];
  28. char flags[MAX_NR_KEYMAPS];
  29. char buff[7];
  30. if (argc != 1)
  31. bb_show_usage();
  32. fd = xopen(CURRENT_VC, O_RDWR);
  33. xread(0, buff, 7);
  34. if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
  35. bb_error_msg_and_die("this is not a valid binary keymap");
  36. xread(0, flags, MAX_NR_KEYMAPS);
  37. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  38. if (flags[i] == 1) {
  39. xread(0, ibuff, NR_KEYS * sizeof(u_short));
  40. for (j = 0; j < NR_KEYS; j++) {
  41. ke.kb_index = j;
  42. ke.kb_table = i;
  43. ke.kb_value = ibuff[j];
  44. ioctl(fd, KDSKBENT, &ke);
  45. }
  46. }
  47. }
  48. if (ENABLE_FEATURE_CLEAN_UP) close(fd);
  49. return 0;
  50. }