logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

eventnames.lua (3421B)


  1. local duplicates = {
  2. EV_VERSION=true,
  3. BTN_MISC=true,
  4. BTN_MOUSE=true,
  5. BTN_JOYSTICK=true,
  6. BTN_GAMEPAD=true,
  7. BTN_DIGI=true,
  8. BTN_WHEEL=true,
  9. BTN_TRIGGER_HAPPY=true,
  10. SW_MAX=true,
  11. REP_MAX=true,
  12. FF_STATUS_MAX=true,
  13. }
  14. local skip = {
  15. BTN=true,
  16. EV=true,
  17. INPUT_PROP=true,
  18. MT_TOOL=true,
  19. }
  20. local prefixes = {
  21. 'EV',
  22. 'REL',
  23. 'ABS',
  24. 'KEY',
  25. 'BTN',
  26. 'LED',
  27. 'SND',
  28. 'MSC',
  29. 'SW',
  30. 'FF',
  31. 'SYN',
  32. 'REP',
  33. 'INPUT_PROP',
  34. 'MT_TOOL',
  35. }
  36. local bits = {}
  37. for _, prefix in ipairs(prefixes) do
  38. bits[prefix] = {}
  39. end
  40. bits.EV.map = {}
  41. local function lookuptable(prefix)
  42. local entries = {}
  43. for _, name in ipairs(bits[prefix]) do
  44. table.insert(entries, name)
  45. end
  46. local max = prefix..'_MAX'
  47. if duplicates[max] then
  48. table.insert(entries, max)
  49. end
  50. table.sort(entries)
  51. for _, name in ipairs(entries) do
  52. io.write(string.format(' { .name = "%s", .value = %s },\n', name, name))
  53. end
  54. end
  55. for i = 1, #arg do
  56. for line in io.lines(arg[i]) do
  57. local name, value = line:match('^#define%s+([%w_]+)%s+(%dx?%x*)')
  58. value = tonumber(value)
  59. if name and not duplicates[name] then
  60. for prefix, b in pairs(bits) do
  61. if name:sub(1, #prefix + 1) == prefix..'_' then
  62. if b.map then
  63. b.map[value] = name
  64. b.map[name] = value
  65. end
  66. table.insert(b, name)
  67. end
  68. end
  69. end
  70. end
  71. end
  72. io.write[[
  73. /* THIS FILE IS GENERATED, DO NOT EDIT */
  74. #ifndef EVENT_NAMES_H
  75. #define EVENT_NAMES_H
  76. ]]
  77. for _, prefix in ipairs(prefixes) do
  78. if prefix ~= 'BTN' then
  79. io.write(string.format('static const char * const %s_map[%s_MAX + 1] = {\n', prefix:lower(), prefix))
  80. for _, name in ipairs(bits[prefix]) do
  81. io.write(string.format(' [%s] = "%s",\n', name, name))
  82. end
  83. if prefix == 'KEY' then
  84. for _, name in ipairs(bits.BTN) do
  85. io.write(string.format(' [%s] = "%s",\n', name, name))
  86. end
  87. end
  88. io.write[[
  89. };
  90. ]]
  91. end
  92. end
  93. for _, name in ipairs{'BTN_A', 'BTN_B', 'BTN_X', 'BTN_Y'} do
  94. table.insert(bits.BTN, name)
  95. end
  96. io.write[[
  97. static const char * const * const event_type_map[EV_MAX + 1] = {
  98. ]]
  99. for _, prefix in ipairs(prefixes) do
  100. if not skip[prefix] then
  101. print(string.format(' [EV_%s] = %s_map,', prefix, prefix:lower()))
  102. end
  103. end
  104. io.write[[
  105. };
  106. #if __clang__
  107. #pragma clang diagnostic push
  108. #pragma clang diagnostic ignored "-Winitializer-overrides"
  109. #elif __GNUC__
  110. #pragma GCC diagnostic push
  111. #pragma GCC diagnostic ignored "-Woverride-init"
  112. #endif
  113. static const int ev_max[EV_MAX + 1] = {
  114. ]]
  115. for i = 0, bits.EV.map.EV_MAX do
  116. local name = bits.EV.map[i]
  117. if name and bits[name:sub(4)] then
  118. io.write(string.format(' %s_MAX,\n', name:sub(4)))
  119. else
  120. io.write(' -1,\n')
  121. end
  122. end
  123. io.write[[
  124. };
  125. #if __clang__
  126. #pragma clang diagnostic pop /* "-Winitializer-overrides" */
  127. #elif __GNUC__
  128. #pragma GCC diagnostic pop /* "-Woverride-init" */
  129. #endif
  130. struct name_entry {
  131. const char *name;
  132. unsigned int value;
  133. };
  134. static const struct name_entry tool_type_names[] = {
  135. ]]
  136. lookuptable('MT_TOOL')
  137. io.write[[
  138. };
  139. static const struct name_entry ev_names[] = {
  140. ]]
  141. lookuptable('EV')
  142. io.write[[
  143. };
  144. static const struct name_entry code_names[] = {
  145. ]]
  146. lookuptable('ABS')
  147. lookuptable('BTN')
  148. lookuptable('FF')
  149. lookuptable('KEY')
  150. lookuptable('LED')
  151. lookuptable('MSC')
  152. lookuptable('REL')
  153. lookuptable('REP')
  154. lookuptable('SND')
  155. lookuptable('SW')
  156. lookuptable('SYN')
  157. io.write[[
  158. };
  159. static const struct name_entry prop_names[] = {
  160. ]]
  161. lookuptable('INPUT_PROP')
  162. io.write[[
  163. };
  164. #endif /* EVENT_NAMES_H */
  165. ]]