forked from Imagelibrary/binutils-gdb
[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:
30
gdb/features/feature_to_c.awk
Normal file
30
gdb/features/feature_to_c.awk
Normal 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 };"
|
||||||
|
}
|
||||||
@@ -32,47 +32,35 @@ if test -e "$output"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo '#include "xml-builtin.h"' >> $output
|
echo '#include "xml-builtin.h"' >> "$output"
|
||||||
|
|
||||||
|
awk_script=$(echo "$0" | sed 's/\.sh$/.awk/')
|
||||||
|
|
||||||
for input; do
|
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
|
${AWK:-awk} \
|
||||||
print "static const char '$arrayname'[] = {"
|
-v "arrayname=$arrayname" \
|
||||||
for (i = 0; i < 255; i++)
|
-f "$awk_script" \
|
||||||
_ord_[sprintf("%c", i)] = i
|
< "$input" \
|
||||||
} {
|
>> "$output"
|
||||||
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
|
|
||||||
done
|
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
|
for input; do
|
||||||
basename=`echo $input | sed 's,.*/,,'`
|
basename=$(echo "$input" | sed 's,.*/,,')
|
||||||
arrayname=xml_feature_`echo $input | sed 's,.*/,,; s/[-.]/_/g'`
|
arrayname=xml_feature_$(echo "$input" | sed 's,.*/,,; s/[-.]/_/g')
|
||||||
echo " { \"$basename\", $arrayname }," >> $output
|
echo " { \"$basename\", $arrayname }," >> "$output"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo " { 0, 0 }" >> $output
|
echo " { 0, 0 }" >> "$output"
|
||||||
echo "};" >> $output
|
echo "};" >> "$output"
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode:shell-script
|
||||||
|
# sh-indentation:2
|
||||||
|
# End:
|
||||||
|
# vi:sw=2
|
||||||
|
|||||||
Reference in New Issue
Block a user