xref: /freebsd/contrib/tzcode/workman.sh (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1#! /bin/sh
2# Convert manual page troff stdin to formatted .txt stdout.
3
4# This file is in the public domain, so clarified as of
5# 2009-05-17 by Arthur David Olson.
6
7if (type nroff && type perl) >/dev/null 2>&1; then
8
9  # Tell groff not to emit SGR escape sequences (ANSI color escapes).
10  export GROFF_NO_SGR=1
11
12  echo ".am TH
13.hy 0
14.na
15..
16.rm }H
17.rm }F" | nroff -man - ${1+"$@"} | perl -ne '
18	binmode STDIN, '\'':encoding(utf8)'\'';
19	binmode STDOUT, '\'':encoding(utf8)'\'';
20	chomp;
21	s/.\010//g;
22	s/\s*$//;
23	if (/^$/) {
24		$sawblank = 1;
25		next;
26	} else {
27		if ($sawblank && $didprint) {
28			print "\n";
29			$sawblank = 0;
30		}
31		print "$_\n";
32		$didprint = 1;
33	}
34  '
35elif (type mandoc && type col) >/dev/null 2>&1; then
36  mandoc -man -T ascii "$@" | col -bx
37else
38  echo >&2 "$0: please install nroff and perl, or mandoc and col"
39  exit 1
40fi
41