blob: c8ce9b88f6d910632f8112f49c47324bb7724a21 [file] [log] [blame]
pbrookb2cd75b2008-10-11 18:23:22 +00001#!/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 Swirl8167ee82009-07-16 20:47:01 +000020# along with this program; if not, see <http://www.gnu.org/licenses/>.
pbrookb2cd75b2008-10-11 18:23:22 +000021
22output=$1
23shift
24
25if test -z "$output" || test -z "$1"; then
26 echo "Usage: $0 OUTPUTFILE INPUTFILE..."
27 exit 1
28fi
29
30if test -e "$output"; then
31 echo "Output file \"$output\" already exists; refusing to overwrite."
32 exit 1
33fi
34
35for input; do
Stefan Weilbbd90802016-05-16 15:23:33 +020036 arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
pbrookb2cd75b2008-10-11 18:23:22 +000037
38 ${AWK:-awk} 'BEGIN { n = 0
Peter Maydell253785e2016-02-08 19:17:08 +000039 printf "#include \"qemu/osdep.h\"\n"
pbrookb2cd75b2008-10-11 18:23:22 +000040 print "static const char '$arrayname'[] = {"
41 for (i = 0; i < 255; i++)
42 _ord_[sprintf("%c", i)] = i
43 } {
44 split($0, line, "");
45 printf " "
46 for (i = 1; i <= length($0); i++) {
47 c = line[i]
48 if (c == "'\''") {
49 printf "'\''\\'\'''\'', "
50 } else if (c == "\\") {
51 printf "'\''\\\\'\'', "
52 } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
53 printf "'\''%s'\'', ", c
54 } else {
55 printf "'\''\\%03o'\'', ", _ord_[c]
56 }
57 if (i % 10 == 0)
58 printf "\n "
59 }
60 printf "'\''\\n'\'', \n"
61 } END {
62 print " 0 };"
63 }' < $input >> $output
64done
65
66echo >> $output
pbrookb2cd75b2008-10-11 18:23:22 +000067echo "const char *const xml_builtin[][2] = {" >> $output
68
69for input; do
Stefan Weilbbd90802016-05-16 15:23:33 +020070 basename=$(echo $input | sed 's,.*/,,')
71 arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
pbrookb2cd75b2008-10-11 18:23:22 +000072 echo " { \"$basename\", $arrayname }," >> $output
73done
74
Blue Swirl660f11b2009-07-31 21:16:51 +000075echo " { (char *)0, (char *)0 }" >> $output
pbrookb2cd75b2008-10-11 18:23:22 +000076echo "};" >> $output