[gdb/build] Cleanup gdb/features/feature_to_c.sh

Clean up script gdb/features/feature_to_c.sh by:
- fixing shellcheck warnings,
- moving an embedded awk script out of the file, reducing the amount of
  escaping in the awk script, making it more readable and maintainable, and
- adding emacs / vi settings for local tab size 2 (copied from ./ltmain.sh).

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
This commit is contained in:
Tom de Vries
2024-06-15 08:10:44 +02:00
parent 750fc33e4e
commit 97033da507
2 changed files with 52 additions and 34 deletions

View File

@@ -0,0 +1,30 @@
BEGIN { n = 0
printf "static const char %s[] = {\n", arrayname
for (i = 0; i < 255; i++)
_ord_[sprintf("%c", i)] = i
}
{
split($0, line, "");
printf " "
for (i = 1; i <= length($0); i++) {
c = line[i]
if (c == "'") {
printf "'\\''"
} else if (c == "\\") {
printf "'\\\\'"
} else if (_ord_[c] >= 32 && _ord_[c] < 127) {
printf "'%s'", c
} else {
printf "'\\%03o'", _ord_[c]
}
printf ", "
if (i % 10 == 0)
printf "\n "
}
printf "'\\n', \n"
}
END {
print " 0 };"
}

View File

@@ -32,47 +32,35 @@ if test -e "$output"; then
exit 1
fi
echo '#include "xml-builtin.h"' >> $output
echo '#include "xml-builtin.h"' >> "$output"
awk_script=$(echo "$0" | sed 's/\.sh$/.awk/')
for input; do
arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
arrayname=xml_feature_$(echo "$input" | sed 's,.*/,,; s/[-.]/_/g')
${AWK:-awk} 'BEGIN { n = 0
print "static const char '$arrayname'[] = {"
for (i = 0; i < 255; i++)
_ord_[sprintf("%c", i)] = i
} {
split($0, line, "");
printf " "
for (i = 1; i <= length($0); i++) {
c = line[i]
if (c == "'\''") {
printf "'\''\\'\'''\'', "
} else if (c == "\\") {
printf "'\''\\\\'\'', "
} else if (_ord_[c] >= 32 && _ord_[c] < 127) {
printf "'\''%s'\'', ", c
} else {
printf "'\''\\%03o'\'', ", _ord_[c]
}
if (i % 10 == 0)
printf "\n "
}
printf "'\''\\n'\'', \n"
} END {
print " 0 };"
}' < $input >> $output
${AWK:-awk} \
-v "arrayname=$arrayname" \
-f "$awk_script" \
< "$input" \
>> "$output"
done
echo >> $output
echo >> "$output"
echo "extern const char *const xml_builtin[][2] = {" >> $output
echo "extern const char *const xml_builtin[][2] = {" >> "$output"
for input; do
basename=`echo $input | sed 's,.*/,,'`
arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
echo " { \"$basename\", $arrayname }," >> $output
basename=$(echo "$input" | sed 's,.*/,,')
arrayname=xml_feature_$(echo "$input" | sed 's,.*/,,; s/[-.]/_/g')
echo " { \"$basename\", $arrayname }," >> "$output"
done
echo " { 0, 0 }" >> $output
echo "};" >> $output
echo " { 0, 0 }" >> "$output"
echo "};" >> "$output"
# Local Variables:
# mode:shell-script
# sh-indentation:2
# End:
# vi:sw=2