Commit b2cd75b00349ad0cc7eb47209d2a2b7b1d4b0bfc
1 parent
56aebc89
Add feature_to_c.sh.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5460 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
77 additions
and
0 deletions
feature_to_c.sh
0 → 100644
| 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 | |
| 20 | +# along with this program; if not, write to the Free Software | |
| 21 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 22 | +# Boston, MA 02110-1301, USA. | |
| 23 | + | |
| 24 | +output=$1 | |
| 25 | +shift | |
| 26 | + | |
| 27 | +if test -z "$output" || test -z "$1"; then | |
| 28 | + echo "Usage: $0 OUTPUTFILE INPUTFILE..." | |
| 29 | + exit 1 | |
| 30 | +fi | |
| 31 | + | |
| 32 | +if test -e "$output"; then | |
| 33 | + echo "Output file \"$output\" already exists; refusing to overwrite." | |
| 34 | + exit 1 | |
| 35 | +fi | |
| 36 | + | |
| 37 | +for input; do | |
| 38 | + arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` | |
| 39 | + | |
| 40 | + ${AWK:-awk} 'BEGIN { n = 0 | |
| 41 | + print "static const char '$arrayname'[] = {" | |
| 42 | + for (i = 0; i < 255; i++) | |
| 43 | + _ord_[sprintf("%c", i)] = i | |
| 44 | + } { | |
| 45 | + split($0, line, ""); | |
| 46 | + printf " " | |
| 47 | + for (i = 1; i <= length($0); i++) { | |
| 48 | + c = line[i] | |
| 49 | + if (c == "'\''") { | |
| 50 | + printf "'\''\\'\'''\'', " | |
| 51 | + } else if (c == "\\") { | |
| 52 | + printf "'\''\\\\'\'', " | |
| 53 | + } else if (_ord_[c] >= 32 && _ord_[c] < 127) { | |
| 54 | + printf "'\''%s'\'', ", c | |
| 55 | + } else { | |
| 56 | + printf "'\''\\%03o'\'', ", _ord_[c] | |
| 57 | + } | |
| 58 | + if (i % 10 == 0) | |
| 59 | + printf "\n " | |
| 60 | + } | |
| 61 | + printf "'\''\\n'\'', \n" | |
| 62 | + } END { | |
| 63 | + print " 0 };" | |
| 64 | + }' < $input >> $output | |
| 65 | +done | |
| 66 | + | |
| 67 | +echo >> $output | |
| 68 | +echo "const char *const xml_builtin[][2] = {" >> $output | |
| 69 | + | |
| 70 | +for input; do | |
| 71 | + basename=`echo $input | sed 's,.*/,,'` | |
| 72 | + arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'` | |
| 73 | + echo " { \"$basename\", $arrayname }," >> $output | |
| 74 | +done | |
| 75 | + | |
| 76 | +echo " { 0, 0 }" >> $output | |
| 77 | +echo "};" >> $output | ... | ... |