]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/features/feature_to_c.sh
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / features / feature_to_c.sh
CommitLineData
108546a0
DJ
1#!/bin/sh
2
3# Convert text files to compilable C arrays.
4#
1d506c26 5# Copyright (C) 2007-2024 Free Software Foundation, Inc.
108546a0
DJ
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
50efebf8 11# the Free Software Foundation; either version 3 of the License, or
108546a0
DJ
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
50efebf8 20# along with this program. If not, see <http://www.gnu.org/licenses/>.
108546a0 21
73519cce 22if test -z "$1" || test -z "$2"; then
108546a0
DJ
23 echo "Usage: $0 OUTPUTFILE INPUTFILE..."
24 exit 1
25fi
26
73519cce
SM
27output=$1
28shift
29
108546a0
DJ
30if test -e "$output"; then
31 echo "Output file \"$output\" already exists; refusing to overwrite."
32 exit 1
33fi
34
fec4e896
CB
35echo '#include "xml-builtin.h"' >> $output
36
108546a0
DJ
37for 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) {
fe5dedf4 54 printf "'\''%s'\'', ", c
108546a0
DJ
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
65done
66
67echo >> $output
7cf99fb1 68
ddb6d633 69echo "extern const char *const xml_builtin[][2] = {" >> $output
108546a0
DJ
70
71for input; do
72 basename=`echo $input | sed 's,.*/,,'`
73 arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
74 echo " { \"$basename\", $arrayname }," >> $output
75done
76
77echo " { 0, 0 }" >> $output
78echo "};" >> $output