parse_linux_input.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. OUTPUT=$1
  3. shift
  4. INPUTS=("$@")
  5. types=""
  6. keys=""
  7. rels=""
  8. syns=""
  9. abss=""
  10. sws=""
  11. mscs=""
  12. leds=""
  13. reps=""
  14. snds=""
  15. ffstatuss=""
  16. while read LINE; do
  17. tab=$'\t'
  18. space="[ ${tab}]"
  19. regex="^#define ((EV|SYN|KEY|BTN|REL|ABS|SW|MSC|LED|REP|SND|FF_STATUS)_([A-Z0-9_]+))${space}"
  20. if [[ $LINE =~ $regex ]]; then
  21. name=${BASH_REMATCH[1]}
  22. type=${BASH_REMATCH[2]}
  23. nameonly=${BASH_REMATCH[3]}
  24. [[ $nameonly = "MAX" || $nameonly = "CNT" ]] && continue
  25. if [[ $type = "EV" ]]; then
  26. if [[ $name != "EV_VERSION" ]]; then
  27. types="${types} [${name}] = \"${name}\",
  28. "
  29. fi
  30. elif [[ $type = "SYN" ]]; then
  31. syns="${syns} [${name}] = \"${name}\",
  32. "
  33. elif [[ $type = "KEY" ]] || [[ $type = "BTN" ]]; then
  34. if [[ $name != "KEY_MIN_INTERESTING" ]]; then
  35. keys="${keys} [${name}] = \"${name}\",
  36. "
  37. fi
  38. elif [[ $type = "REL" ]]; then
  39. rels="${rels} [${name}] = \"${name}\",
  40. "
  41. elif [[ $type = "ABS" ]]; then
  42. abss="${abss} [${name}] = \"${name}\",
  43. "
  44. elif [[ $type = "SW" ]]; then
  45. sws="${sws} [${name}] = \"${name}\",
  46. "
  47. elif [[ $type = "MSC" ]]; then
  48. mscs="${mscs} [${name}] = \"${name}\",
  49. "
  50. elif [[ $type = "LED" ]]; then
  51. leds="${leds} [${name}] = \"${name}\",
  52. "
  53. elif [[ $type = "REP" ]]; then
  54. reps="${reps} [${name}] = \"${name}\",
  55. "
  56. elif [[ $type = "SND" ]]; then
  57. snds="${snds} [${name}] = \"${name}\",
  58. "
  59. elif [[ $type = "FF_STATUS" ]]; then
  60. ffstatuss="${ffstatuss} [${name}] = \"${name}\",
  61. "
  62. fi
  63. fi
  64. done < <(cat "${INPUTS[@]}")
  65. (
  66. echo "
  67. static const char *type_names[] = {
  68. ${types}};
  69. static const char *syn_names[] = {
  70. ${syns}};
  71. static const char *key_names[] = {
  72. ${keys}};
  73. static const char *rel_names[] = {
  74. ${rels}};
  75. static const char *abs_names[] = {
  76. ${abss}};
  77. static const char *sw_names[] = {
  78. ${sws}};
  79. static const char *msc_names[] = {
  80. ${mscs}};
  81. static const char *led_names[] = {
  82. ${leds}};
  83. static const char *rep_names[] = {
  84. ${reps}};
  85. static const char *snd_names[] = {
  86. ${snds}};
  87. static const char *ffstatus_names[] = {
  88. ${ffstatuss}};
  89. "
  90. ) >"${OUTPUT}"