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