aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-06-15 08:10:44 +0200
committerTom de Vries <tdevries@suse.de>2024-06-15 08:10:44 +0200
commit97033da5070ba90ecc1ebb2a4659e129f17709bf (patch)
tree90bf6d89a7540ed90ee390957ffaaf56c83fdd9e
parent750fc33e4eb049a57cfd3594ee8e51677eb3368a (diff)
downloadgdb-97033da5070ba90ecc1ebb2a4659e129f17709bf.zip
gdb-97033da5070ba90ecc1ebb2a4659e129f17709bf.tar.gz
gdb-97033da5070ba90ecc1ebb2a4659e129f17709bf.tar.bz2
[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>
-rw-r--r--gdb/features/feature_to_c.awk30
-rwxr-xr-xgdb/features/feature_to_c.sh56
2 files changed, 52 insertions, 34 deletions
diff --git a/gdb/features/feature_to_c.awk b/gdb/features/feature_to_c.awk
new file mode 100644
index 0000000..42b9900
--- /dev/null
+++ b/gdb/features/feature_to_c.awk
@@ -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 };"
+}
diff --git a/gdb/features/feature_to_c.sh b/gdb/features/feature_to_c.sh
index 3159ec5..d5d3db7 100755
--- a/gdb/features/feature_to_c.sh
+++ b/gdb/features/feature_to_c.sh
@@ -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