From d7f86ac32edd627900004a62c28df4fed9eb07ec Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 10 Aug 2022 23:50:57 -0700
Subject: [PROPOSED] Port .txt generation to macOS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Be able to build man pages on macOS, which has mandoc not nroff.
Although mandoc has some minor glitches compared to nroff,
it’s good enough.  This follows up on a suggestion by Guy Harris in:
https://mm.icann.org/pipermail/tz/2022-August/031786.html
* time2posix.3: Insert \& to convince groff to not double-space
afterwards, so that it doesn’t disagree with mandoc.
* tzselect.8, zic.8: Use \& instead of \" because mandoc
mishandles the latter.  Don’t use a 5-deep nested .if on one line,
as mandoc mishandles it.
* workman.sh: If nroff and perl are not both available,
then use mandoc and col if they are both available,
else report an error.
---
 time2posix.3 |  2 +-
 tzselect.8   |  6 ++++--
 workman.sh   | 18 +++++++++++++-----
 zic.8        |  6 ++++--
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/time2posix.3 b/time2posix.3
index 2ea7edc4..1fcdf9e5 100644
--- a/time2posix.3
+++ b/time2posix.3
@@ -37,7 +37,7 @@ however,
 no such adjustment is needed and
 time_t values continue to increase over leap events
 (as a true
-.q "seconds since..."
+.q "seconds since...\&"
 value).
 This means that these values will differ from those required by POSIX
 by the net number of leap seconds inserted since the Epoch.
diff --git a/tzselect.8 b/tzselect.8
index 85496593..1a5ce110 100644
--- a/tzselect.8
+++ b/tzselect.8
@@ -7,12 +7,14 @@ tzselect \- select a timezone
 .ds d " degrees
 .ds m " minutes
 .ds s " seconds
-.ds _ " \"
-.if t .if \n(.g .if c \(de .if c \(fm .if c \(sd \{\
+.ds _ " \&
+.if t \{\
+. if \n(.g .if c \(de .if c \(fm .if c \(sd \{\
 .  ds d \(de
 .  ds m \(fm
 .  ds s \(sd
 .  ds _ \|
+. \}
 .\}
 .B tzselect
 [
diff --git a/workman.sh b/workman.sh
index 8fb18a43..6e2da3a8 100644
--- a/workman.sh
+++ b/workman.sh
@@ -4,11 +4,13 @@
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 
-# Tell groff not to emit SGR escape sequences (ANSI color escapes).
-GROFF_NO_SGR=1
-export GROFF_NO_SGR
+if (type nroff && type perl) >/dev/null 2>&1; then
 
-echo ".am TH
+  # Tell groff not to emit SGR escape sequences (ANSI color escapes).
+  GROFF_NO_SGR=1
+  export GROFF_NO_SGR
+
+  echo ".am TH
 .hy 0
 .na
 ..
@@ -30,4 +32,10 @@ echo ".am TH
 		print "$_\n";
 		$didprint = 1;
 	}
-'
+  '
+elif (type mandoc && type col) >/dev/null 2>&1; then
+  mandoc -man -T ascii "$@" | col -bx
+else
+  echo >&2 "$0: please install nroff and perl, or mandoc and col"
+  exit 1
+fi
diff --git a/zic.8 b/zic.8
index 772ee89c..e46d0ab0 100644
--- a/zic.8
+++ b/zic.8
@@ -31,12 +31,14 @@ zic \- timezone compiler
 .ds d " degrees
 .ds m " minutes
 .ds s " seconds
-.ds _ " \"
-.if t .if \n(.g .if c \(de .if c \(fm .if c \(sd \{\
+.ds _ " \&
+.if t \{\
+. if \n(.g .if c \(de .if c \(fm .if c \(sd \{\
 .  ds d \(de
 .  ds m \(fm
 .  ds s \(sd
 .  ds _ \|
+. \}
 .\}
 The
 .B zic
-- 
2.34.1

