]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/build] Cleanup gdb/features/feature_to_c.sh
authorTom de Vries <tdevries@suse.de>
Sat, 15 Jun 2024 06:10:44 +0000 (08:10 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 15 Jun 2024 06:10:44 +0000 (08:10 +0200)
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>
gdb/features/feature_to_c.awk [new file with mode: 0644]
gdb/features/feature_to_c.sh

diff --git a/gdb/features/feature_to_c.awk b/gdb/features/feature_to_c.awk
new file mode 100644 (file)
index 0000000..42b9900
--- /dev/null
@@ -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 };"
+}
index 3159ec523a659e3c0c22412ecab4852c9b286154..d5d3db7157f8236b173d910d0a8f5148e6b3866b 100755 (executable)
@@ -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