From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 5/5] [gdb/build] Cleanup gdb/features/feature_to_c.sh
Date: Thu, 13 Jun 2024 17:12:41 +0200 [thread overview]
Message-ID: <20240613151241.8144-5-tdevries@suse.de> (raw)
In-Reply-To: <20240613151241.8144-1-tdevries@suse.de>
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.
---
gdb/features/feature_to_c.awk | 30 +++++++++++++++++++
gdb/features/feature_to_c.sh | 56 ++++++++++++++---------------------
2 files changed, 52 insertions(+), 34 deletions(-)
create mode 100644 gdb/features/feature_to_c.awk
diff --git a/gdb/features/feature_to_c.awk b/gdb/features/feature_to_c.awk
new file mode 100644
index 00000000000..42b9900f206
--- /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 3159ec523a6..d5d3db7157f 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
--
2.35.3
next prev parent reply other threads:[~2024-06-13 15:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 15:12 [PATCH v2 1/5] [gdb/testsuite] Clean up gdb/contrib/expect-read1.sh Tom de Vries
2024-06-13 15:12 ` [PATCH v2 2/5] [gdb/testsuite] Clean up gdb/contrib/cc-with-tweaks.sh Tom de Vries
2024-06-13 15:12 ` [PATCH v2 3/5] [gdb/testsuite] Clean up formatting in gdb/contrib/cc-with-tweaks.sh Tom de Vries
2024-06-13 15:12 ` [PATCH v2 4/5] [gdb/testsuite] Clean up lib/dg-add-core-file-count.sh Tom de Vries
2024-06-13 15:12 ` Tom de Vries [this message]
2024-06-15 18:15 ` [PATCH v2 5/5] [gdb/build] Cleanup gdb/features/feature_to_c.sh Tom Tromey
2024-06-16 7:09 ` Tom de Vries
2024-06-14 18:32 ` [PATCH v2 1/5] [gdb/testsuite] Clean up gdb/contrib/expect-read1.sh Kevin Buettner
2024-06-15 6:11 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240613151241.8144-5-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).