loadkmap.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <errno.h>
  23. #include <fcntl.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <sys/ioctl.h>
  29. #include "busybox.h"
  30. #define BINARY_KEYMAP_MAGIC "bkeymap"
  31. /* From <linux/kd.h> */
  32. struct kbentry {
  33. unsigned char kb_table;
  34. unsigned char kb_index;
  35. unsigned short kb_value;
  36. };
  37. /* sets one entry in translation table */
  38. #define KDSKBENT 0x4B47
  39. /* From <linux/keyboard.h> */
  40. #define NR_KEYS 128
  41. #define MAX_NR_KEYMAPS 256
  42. int loadkmap_main(int argc, char **argv)
  43. {
  44. struct kbentry ke;
  45. int i, j, fd;
  46. u_short ibuff[NR_KEYS];
  47. char flags[MAX_NR_KEYMAPS];
  48. char buff[7];
  49. if (argc != 1)
  50. bb_show_usage();
  51. fd = bb_xopen(CURRENT_VC, O_RDWR);
  52. if ((bb_full_read(0, buff, 7) != 7) || (strncmp(buff, BINARY_KEYMAP_MAGIC, 7) != 0))
  53. bb_error_msg_and_die("This is not a valid binary keymap.");
  54. if (bb_full_read(0, flags, MAX_NR_KEYMAPS) != MAX_NR_KEYMAPS)
  55. bb_perror_msg_and_die("Error reading keymap flags");
  56. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  57. if (flags[i] == 1) {
  58. bb_full_read(0, ibuff, NR_KEYS * sizeof(u_short));
  59. for (j = 0; j < NR_KEYS; j++) {
  60. ke.kb_index = j;
  61. ke.kb_table = i;
  62. ke.kb_value = ibuff[j];
  63. ioctl(fd, KDSKBENT, &ke);
  64. }
  65. }
  66. }
  67. /* Don't bother to close files. Exit does that
  68. * automagically, so we can save a few bytes */
  69. /* close(fd); */
  70. return EXIT_SUCCESS;
  71. }