aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Bachmeyer <jcb@gnu.org>2021-04-16 16:29:55 -0500
committerJacob Bachmeyer <jcb@gnu.org>2021-04-16 16:29:55 -0500
commite2fa0bcf54e2bb05106be1ce22a73de4f7381444 (patch)
tree8dea1ce726813750eff294b2321e3d3994e3d732
parent84c903914b49e5051f116b7a1512ee6d962d71bc (diff)
Revise help system in dejagnu launcher to use Awk
-rw-r--r--ChangeLog4
-rwxr-xr-xdejagnu18
2 files changed, 10 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index c3249bc..b5f5504 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,10 @@
* dejagnu: Use shell "case" pattern match instead of non-portable
"grep -q" to determine if "awk" is GNU Awk.
+ * dejagnu: Use Awk instead of non-portable "grep -q" to verify
+ that a file contains a help message. Also use Awk to extract help
+ messages from files, instead of a complex dynamic sed(1) program.
+
2021-04-15 Jacob Bachmeyer <jcb@gnu.org>
PR47382
diff --git a/dejagnu b/dejagnu
index 57767b1..d323a62 100755
--- a/dejagnu
+++ b/dejagnu
@@ -418,21 +418,15 @@ if $want_help ; then
echo ERROR: file "'$help_file'" is not readable
exit 2
fi
- if grep -q '#help' "$help_file" \
- && grep -q '#end' "$help_file"; then : ; else
+ if awk '/#help$/ { pfxlen = length($0) - 4 }
+ pfxlen && substr($0, pfxlen) == "#end" { exit 1 }
+ ' "$help_file" ; then
echo ERROR: file "'$help_file'" does not contain a help message
exit 2
fi
- help_prefix_pat=`grep '#help' "$help_file" \
- | sed -e 's/#help.*$//' -e '1q' | tr '[:print:][:blank:]' .`
- if expr "$verbose" \> 1 > /dev/null ; then
- echo Extracting help from "'$help_file'" with prefix "'$help_prefix_pat'"
- fi
- sed -n < "$help_file" \
- -e '1,/#help/d' \
- -e '/^'"$help_prefix_pat"'#end/q' \
- -e 's/^'"$help_prefix_pat"'//;p'
- exit 0
+ exec awk '/#help$/ { pfxlen = length($0) - 4 }
+ pfxlen && substr($0, pfxlen) == "#end" { exit 0 }
+ pfxlen { print substr($0, pfxlen) }' "$help_file"
fi
if test -z "$command" ; then