[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 15/17: m4/groff.m4 (GROFF_PAGE): Remove awk dependency.
From: |
G. Branden Robinson |
Subject: |
[groff] 15/17: m4/groff.m4 (GROFF_PAGE): Remove awk dependency. |
Date: |
Sat, 23 Jul 2022 12:40:46 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 1db8c0c1d2284be221635817f09878dd005cbfe1
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Jul 23 06:14:55 2022 -0500
m4/groff.m4 (GROFF_PAGE): Remove awk dependency.
* m4/groff.m4 (GROFF_PAGE): Macro used awk(1) without `AC_REQUIRE`-ing a
relevant macro or checking for its existence. Fortunately, sed is
powerful enough for our needs. Remove dependency on awk. Cope with
"search" directive in resolv.conf having multiple arguments. Match
"domain" directive in same file instead of "dom", which I cannot find
attested (this logic dates to 1991). Rename `dom` shell variable to
`domains` for clarity, since its multiplicity could be greater than 1.
---
ChangeLog | 11 +++++++++++
m4/groff.m4 | 40 ++++++++++++++++++++++++----------------
2 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 51c3fbae..be438bce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-07-22 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * m4/groff.m4 (GROFF_PAGE): Macro used awk(1) without
+ `AC_REQUIRE`-ing a relevant macro or checking for its existence.
+ Fortunately, sed is powerful enough for our needs. Remove
+ dependency on awk. Cope with "search" directive in resolv.conf
+ having multiple arguments. Match "domain" directive in same
+ file instead of "dom", which I cannot find attested (this logic
+ dates to 1991). Rename `dom` shell variable to `domains` for
+ clarity, since its multiplicity could be greater than 1.
+
2022-07-22 G. Branden Robinson <g.branden.robinson@gmail.com>
* m4/groff.m4 (GROFF_PAGE): Refactor: drop AC_DEFINE of
diff --git a/m4/groff.m4 b/m4/groff.m4
index 838a152d..9d5f3b57 100644
--- a/m4/groff.m4
+++ b/m4/groff.m4
@@ -862,7 +862,8 @@ AC_DEFUN([GROFF_PAGE],
groff_prefix=$prefix
test "$prefix" = NONE && groff_prefix=$ac_default_prefix
if test -z "$PAGE" && test -r /etc/papersize; then
- PAGE=`cat /etc/papersize | sed -e 's/^[ ]*#.*//g' | tr -d "\n" | awk '{
print $1 }'`
+ sedexpr='s/#.*//;s/[ \t]\+/ /;s/ \+$//;s/^ \+//;/^$/d;p'
+ PAGE=`sed -n "$sedexpr" /etc/papersize`
fi
if test -z "$PAGE"; then
descfile=
@@ -889,23 +890,30 @@ AC_DEFUN([GROFF_PAGE],
fi
if test -z "$PAGE"; then
- dom=`awk '([$]1 == "dom" || [$]1 == "search") { print [$]2; exit}' \
- /etc/resolv.conf 2>/dev/null`
- if test -z "$dom"; then
- dom=`(domainname) 2>/dev/null | tr -d '+'`
- if test -z "$dom" \
- || test "$dom" = '(none)'; then
- dom=`(hostname) 2>/dev/null | grep '\.'`
+ domains=
+ if test -r /etc/resolv.conf; then
+ sedexpr='s/#.*//;s/[ \t]\+/ /;s/ \+$//;s/^ \+//;/^$/d;
+/^\(domain\|search\)/!d;s/\(domain\|search\) //;p'
+ domains=`sed -n "$sedexpr" /etc/resolv.conf`
+ fi
+ if test -z "$domains"; then
+ domains=`(domainname) 2>/dev/null | tr -d '+'`
+ if test -z "$domains" \
+ || test "$domains" = '(none)'; then
+ domains=`(hostname) 2>/dev/null | grep '\.'`
fi
fi
- # If the top-level domain is two letters and it's not 'us' or 'ca'
- # then they probably use A4 paper.
- case "$dom" in
- [*.[Uu][Ss]|*.[Cc][Aa])]
- ;;
- [*.[A-Za-z][A-Za-z])]
- PAGE=A4 ;;
- esac
+ # resolv.conf's "search" directive might return multiple domains.
+ # If any top-level domain is two letters and it's not 'us' or 'ca',
+ # assume the system uses A4 paper.
+ for d in $domains; do
+ case "$d" in
+ [*.[Uu][Ss]|*.[Cc][Aa])]
+ ;;
+ [*.[A-Za-z][A-Za-z])]
+ PAGE=A4 ;;
+ esac
+ done
fi
test -n "$PAGE" || PAGE=letter
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 15/17: m4/groff.m4 (GROFF_PAGE): Remove awk dependency.,
G. Branden Robinson <=