parse_linux_input.sh 2.0 KB

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