blob: b1169899c19d0a7860e3da995e7f68a7812aac6a [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
Marc-André Lureauc9322ab2019-08-18 19:51:17 +040022if test -z "$1"; then
23 echo "Usage: $0 INPUTFILE..."
pbrookb2cd75b2008-10-11 18:23:22 +000024 exit 1
25fi
26
27for input; do
Stefan Weilbbd90802016-05-16 15:23:33 +020028 arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
pbrookb2cd75b2008-10-11 18:23:22 +000029
30 ${AWK:-awk} 'BEGIN { n = 0
Peter Maydell253785e2016-02-08 19:17:08 +000031 printf "#include \"qemu/osdep.h\"\n"
pbrookb2cd75b2008-10-11 18:23:22 +000032 print "static const char '$arrayname'[] = {"
33 for (i = 0; i < 255; i++)
34 _ord_[sprintf("%c", i)] = i
35 } {
36 split($0, line, "");
37 printf " "
38 for (i = 1; i <= length($0); i++) {
39 c = line[i]
40 if (c == "'\''") {
41 printf "'\''\\'\'''\'', "
42 } else if (c == "\\") {
43 printf "'\''\\\\'\'', "
44 } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
45 printf "'\''%s'\'', ", c
46 } else {
47 printf "'\''\\%03o'\'', ", _ord_[c]
48 }
49 if (i % 10 == 0)
50 printf "\n "
51 }
52 printf "'\''\\n'\'', \n"
53 } END {
54 print " 0 };"
Marc-André Lureauc9322ab2019-08-18 19:51:17 +040055 }' < $input
pbrookb2cd75b2008-10-11 18:23:22 +000056done
57
Marc-André Lureauc9322ab2019-08-18 19:51:17 +040058echo
59echo "const char *const xml_builtin[][2] = {"
pbrookb2cd75b2008-10-11 18:23:22 +000060
61for input; do
Stefan Weilbbd90802016-05-16 15:23:33 +020062 basename=$(echo $input | sed 's,.*/,,')
63 arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
Marc-André Lureauc9322ab2019-08-18 19:51:17 +040064 echo " { \"$basename\", $arrayname },"
pbrookb2cd75b2008-10-11 18:23:22 +000065done
66
Marc-André Lureauc9322ab2019-08-18 19:51:17 +040067echo " { (char *)0, (char *)0 }"
68echo "};"