feature_to_c.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 \"config.h\"\n"
  34. printf "#include \"qemu-common.h\"\n"
  35. printf "#include \"exec/gdbstub.h\"\n"
  36. print "static const char '$arrayname'[] = {"
  37. for (i = 0; i < 255; i++)
  38. _ord_[sprintf("%c", i)] = i
  39. } {
  40. split($0, line, "");
  41. printf " "
  42. for (i = 1; i <= length($0); i++) {
  43. c = line[i]
  44. if (c == "'\''") {
  45. printf "'\''\\'\'''\'', "
  46. } else if (c == "\\") {
  47. printf "'\''\\\\'\'', "
  48. } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
  49. printf "'\''%s'\'', ", c
  50. } else {
  51. printf "'\''\\%03o'\'', ", _ord_[c]
  52. }
  53. if (i % 10 == 0)
  54. printf "\n "
  55. }
  56. printf "'\''\\n'\'', \n"
  57. } END {
  58. print " 0 };"
  59. }' < $input >> $output
  60. done
  61. echo >> $output
  62. echo "const char *const xml_builtin[][2] = {" >> $output
  63. for input; do
  64. basename=`echo $input | sed 's,.*/,,'`
  65. arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
  66. echo " { \"$basename\", $arrayname }," >> $output
  67. done
  68. echo " { (char *)0, (char *)0 }" >> $output
  69. echo "};" >> $output