2
0

feature_to_c.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. output=$1
  21. shift
  22. if test -z "$output" || test -z "$1"; then
  23. echo "Usage: $0 OUTPUTFILE INPUTFILE..."
  24. exit 1
  25. fi
  26. if test -e "$output"; then
  27. echo "Output file \"$output\" already exists; refusing to overwrite."
  28. exit 1
  29. fi
  30. for input; do
  31. arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
  32. ${AWK:-awk} 'BEGIN { n = 0
  33. printf "#include \"qemu/osdep.h\"\n"
  34. print "static const char '$arrayname'[] = {"
  35. for (i = 0; i < 255; i++)
  36. _ord_[sprintf("%c", i)] = i
  37. } {
  38. split($0, line, "");
  39. printf " "
  40. for (i = 1; i <= length($0); i++) {
  41. c = line[i]
  42. if (c == "'\''") {
  43. printf "'\''\\'\'''\'', "
  44. } else if (c == "\\") {
  45. printf "'\''\\\\'\'', "
  46. } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
  47. printf "'\''%s'\'', ", c
  48. } else {
  49. printf "'\''\\%03o'\'', ", _ord_[c]
  50. }
  51. if (i % 10 == 0)
  52. printf "\n "
  53. }
  54. printf "'\''\\n'\'', \n"
  55. } END {
  56. print " 0 };"
  57. }' < $input >> $output
  58. done
  59. echo >> $output
  60. echo "const char *const xml_builtin[][2] = {" >> $output
  61. for input; do
  62. basename=$(echo $input | sed 's,.*/,,')
  63. arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
  64. echo " { \"$basename\", $arrayname }," >> $output
  65. done
  66. echo " { (char *)0, (char *)0 }" >> $output
  67. echo "};" >> $output