gdb/features/feature_to_c.sh - gdb

  1. #!/bin/sh

  2. # Convert text files to compilable C arrays.
  3. #
  4. # Copyright (C) 2007-2015 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 3 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.       print "static const char '$arrayname'[] = {"
  34.       for (i = 0; i < 255; i++)
  35.         _ord_[sprintf("%c", i)] = i
  36.     } {
  37.       split($0, line, "");
  38.       printf "  "
  39.       for (i = 1; i <= length($0); i++) {
  40.         c = line[i]
  41.         if (c == "'\''") {
  42.           printf "'\''\\'\'''\'', "
  43.         } else if (c == "\\") {
  44.           printf "'\''\\\\'\'', "
  45.         } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
  46.           printf "'\''%s'\'', ", c
  47.         } else {
  48.           printf "'\''\\%03o'\'', ", _ord_[c]
  49.         }
  50.         if (i % 10 == 0)
  51.           printf "\n   "
  52.       }
  53.       printf "'\''\\n'\'', \n"
  54.     } END {
  55.       print "  0 };"
  56.     }' < $input >> $output
  57. done

  58. echo >> $output
  59. echo "const char *const xml_builtin[][2] = {" >> $output

  60. for input; do
  61.   basename=`echo $input | sed 's,.*/,,'`
  62.   arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
  63.   echo "  { \"$basename\", $arrayname }," >> $output
  64. done

  65. echo "  { 0, 0 }" >> $output
  66. echo "};" >> $output