summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorG. Branden Robinson <g.branden.robinson@gmail.com>2022-07-23 06:14:55 -0500
committerG. Branden Robinson <g.branden.robinson@gmail.com>2022-07-23 06:14:55 -0500
commit1db8c0c1d2284be221635817f09878dd005cbfe1 (patch)
tree11122bcc0b805843f1f0b246e751b968608b7aca /m4
parent5fe7fa6c13f4cf9864150287cb438b76fd0d935d (diff)
downloadgroff-git-1db8c0c1d2284be221635817f09878dd005cbfe1.tar.gz
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.
Diffstat (limited to 'm4')
-rw-r--r--m4/groff.m440
1 files changed, 24 insertions, 16 deletions
diff --git a/m4/groff.m4 b/m4/groff.m4
index 838a152d9..9d5f3b573 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