parse_linux_input.sh 2.1 KB

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