2
0

feature_to_c.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. # Convert text files to compilable C arrays.
  3. #
  4. # Copyright (C) 2007 Free Software Foundation, Inc.
  5. #
  6. # This file is part of GDB.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  20. if test -z "$1"; then
  21. echo "Usage: $0 INPUTFILE..."
  22. exit 1
  23. fi
  24. for input; do
  25. arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
  26. ${AWK:-awk} 'BEGIN { n = 0
  27. printf "#include \"qemu/osdep.h\"\n"
  28. print "static const char '$arrayname'[] = {"
  29. for (i = 0; i < 255; i++)
  30. _ord_[sprintf("%c", i)] = i
  31. } {
  32. split($0, line, "");
  33. printf " "
  34. for (i = 1; i <= length($0); i++) {
  35. c = line[i]
  36. if (c == "'\''") {
  37. printf "'\''\\'\'''\'', "
  38. } else if (c == "\\") {
  39. printf "'\''\\\\'\'', "
  40. } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
  41. printf "'\''%s'\'', ", c
  42. } else {
  43. printf "'\''\\%03o'\'', ", _ord_[c]
  44. }
  45. if (i % 10 == 0)
  46. printf "\n "
  47. }
  48. printf "'\''\\n'\'', \n"
  49. } END {
  50. print " 0 };"
  51. }' < $input
  52. done
  53. echo
  54. echo "const char *const xml_builtin[][2] = {"
  55. for input; do
  56. basename=$(echo $input | sed 's,.*/,,')
  57. arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
  58. echo " { \"$basename\", $arrayname },"
  59. done
  60. echo " { (char *)0, (char *)0 }"
  61. echo "};"