makemapdata.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* makemapdata.c
  3. * originally written by: Kirk Reiser.
  4. *
  5. ** Copyright (C) 2002 Kirk Reiser.
  6. * Copyright (C) 2003 David Borowski.
  7. */
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <libgen.h>
  11. #include <string.h>
  12. #include <linux/version.h>
  13. #include <ctype.h>
  14. #include "utils.h"
  15. static char buffer[256];
  16. static int get_define(void)
  17. {
  18. char *c;
  19. while (fgets(buffer, sizeof(buffer)-1, infile)) {
  20. lc++;
  21. if (strncmp(buffer, "#define", 7))
  22. continue;
  23. c = buffer + 7;
  24. while (*c == ' ' || *c == '\t')
  25. c++;
  26. def_name = c;
  27. while (*c && *c != ' ' && *c != '\t' && *c != '\n')
  28. c++;
  29. if (!*c || *c == '\n')
  30. continue;
  31. *c++ = '\0';
  32. while (*c == ' ' || *c == '\t' || *c == '(')
  33. c++;
  34. def_val = c;
  35. while (*c && *c != '\n' && *c != ')')
  36. c++;
  37. *c++ = '\0';
  38. return 1;
  39. }
  40. fclose(infile);
  41. infile = 0;
  42. return 0;
  43. }
  44. int
  45. main(int argc, char *argv[])
  46. {
  47. int value, i;
  48. struct st_key *this;
  49. const char *dir_name;
  50. char *cp;
  51. dir_name = getenv("TOPDIR");
  52. if (!dir_name)
  53. dir_name = ".";
  54. bzero(key_table, sizeof(key_table));
  55. add_key("shift", 1, is_shift);
  56. add_key("altgr", 2, is_shift);
  57. add_key("ctrl", 4, is_shift);
  58. add_key("alt", 8, is_shift);
  59. add_key("spk", 16, is_shift);
  60. add_key("double", 32, is_shift);
  61. open_input(dir_name, "include/linux/input.h");
  62. while (get_define()) {
  63. if (strncmp(def_name, "KEY_", 4))
  64. continue;
  65. value = atoi(def_val);
  66. if (value > 0 && value < MAXKEYVAL)
  67. add_key(def_name, value, is_input);
  68. }
  69. open_input(dir_name, "include/uapi/linux/input-event-codes.h");
  70. while (get_define()) {
  71. if (strncmp(def_name, "KEY_", 4))
  72. continue;
  73. value = atoi(def_val);
  74. if (value > 0 && value < MAXKEYVAL)
  75. add_key(def_name, value, is_input);
  76. }
  77. open_input(dir_name, "drivers/accessibility/speakup/spk_priv_keyinfo.h");
  78. while (get_define()) {
  79. if (strlen(def_val) > 5) {
  80. //if (def_val[0] == '(')
  81. // def_val++;
  82. cp = strchr(def_val, '+');
  83. if (!cp)
  84. continue;
  85. if (cp[-1] == ' ')
  86. cp[-1] = '\0';
  87. *cp++ = '\0';
  88. this = find_key(def_val);
  89. while (*cp == ' ')
  90. cp++;
  91. if (!this || *cp < '0' || *cp > '9')
  92. continue;
  93. value = this->value+atoi(cp);
  94. } else if (!strncmp(def_val, "0x", 2))
  95. sscanf(def_val+2, "%x", &value);
  96. else if (*def_val >= '0' && *def_val <= '9')
  97. value = atoi(def_val);
  98. else
  99. continue;
  100. add_key(def_name, value, is_spk);
  101. }
  102. printf("struct st_key_init init_key_data[] = {\n");
  103. for (i = 0; i < HASHSIZE; i++) {
  104. this = &key_table[i];
  105. if (!this->name)
  106. continue;
  107. do {
  108. printf("\t{ \"%s\", %d, %d, },\n", this->name, this->value, this->shift);
  109. this = this->next;
  110. } while (this);
  111. }
  112. printf("\t{ \".\", 0, 0 }\n};\n");
  113. exit(0);
  114. }