pbrook | b2cd75b | 2008-10-11 18:23:22 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Convert text files to compilable C arrays. |
| 4 | # |
| 5 | # Copyright (C) 2007 Free Software Foundation, Inc. |
| 6 | # |
| 7 | # This file is part of GDB. |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 2 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 20 | # along with this program; if not, see <http://www.gnu.org/licenses/>. |
pbrook | b2cd75b | 2008-10-11 18:23:22 +0000 | [diff] [blame] | 21 | |
| 22 | output=$1 |
| 23 | shift |
| 24 | |
| 25 | if test -z "$output" || test -z "$1"; then |
| 26 | echo "Usage: $0 OUTPUTFILE INPUTFILE..." |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | if test -e "$output"; then |
| 31 | echo "Output file \"$output\" already exists; refusing to overwrite." |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | for input; do |
| 36 | arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` |
| 37 | |
| 38 | ${AWK:-awk} 'BEGIN { n = 0 |
Blue Swirl | ba76a84 | 2011-01-23 11:43:25 +0000 | [diff] [blame] | 39 | printf "#include \"config.h\"\n" |
| 40 | printf "#include \"qemu-common.h\"\n" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 41 | printf "#include \"exec/gdbstub.h\"\n" |
pbrook | b2cd75b | 2008-10-11 18:23:22 +0000 | [diff] [blame] | 42 | print "static const char '$arrayname'[] = {" |
| 43 | for (i = 0; i < 255; i++) |
| 44 | _ord_[sprintf("%c", i)] = i |
| 45 | } { |
| 46 | split($0, line, ""); |
| 47 | printf " " |
| 48 | for (i = 1; i <= length($0); i++) { |
| 49 | c = line[i] |
| 50 | if (c == "'\''") { |
| 51 | printf "'\''\\'\'''\'', " |
| 52 | } else if (c == "\\") { |
| 53 | printf "'\''\\\\'\'', " |
| 54 | } else if (_ord_[c] >= 32 && _ord_[c] < 127) { |
| 55 | printf "'\''%s'\'', ", c |
| 56 | } else { |
| 57 | printf "'\''\\%03o'\'', ", _ord_[c] |
| 58 | } |
| 59 | if (i % 10 == 0) |
| 60 | printf "\n " |
| 61 | } |
| 62 | printf "'\''\\n'\'', \n" |
| 63 | } END { |
| 64 | print " 0 };" |
| 65 | }' < $input >> $output |
| 66 | done |
| 67 | |
| 68 | echo >> $output |
pbrook | b2cd75b | 2008-10-11 18:23:22 +0000 | [diff] [blame] | 69 | echo "const char *const xml_builtin[][2] = {" >> $output |
| 70 | |
| 71 | for input; do |
| 72 | basename=`echo $input | sed 's,.*/,,'` |
| 73 | arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` |
| 74 | echo " { \"$basename\", $arrayname }," >> $output |
| 75 | done |
| 76 | |
Blue Swirl | 660f11b | 2009-07-31 21:16:51 +0000 | [diff] [blame] | 77 | echo " { (char *)0, (char *)0 }" >> $output |
pbrook | b2cd75b | 2008-10-11 18:23:22 +0000 | [diff] [blame] | 78 | echo "};" >> $output |