2009-05-20 14:24:39 +02:00
|
|
|
#! /bin/sh
|
2022-08-16 10:09:47 +02:00
|
|
|
# Convert manual page troff stdin to formatted .txt stdout.
|
2009-05-20 14:24:39 +02:00
|
|
|
|
2009-05-27 12:10:48 +02:00
|
|
|
# This file is in the public domain, so clarified as of
|
|
|
|
# 2009-05-17 by Arthur David Olson.
|
2009-05-20 14:24:39 +02:00
|
|
|
|
2022-08-16 10:09:47 +02:00
|
|
|
if (type nroff && type perl) >/dev/null 2>&1; then
|
2009-05-20 14:24:39 +02:00
|
|
|
|
2022-08-16 10:09:47 +02:00
|
|
|
# Tell groff not to emit SGR escape sequences (ANSI color escapes).
|
|
|
|
GROFF_NO_SGR=1
|
|
|
|
export GROFF_NO_SGR
|
|
|
|
|
|
|
|
echo ".am TH
|
2009-05-20 14:24:39 +02:00
|
|
|
.hy 0
|
|
|
|
.na
|
|
|
|
..
|
|
|
|
.rm }H
|
|
|
|
.rm }F" | nroff -man - ${1+"$@"} | perl -ne '
|
2022-08-16 10:09:47 +02:00
|
|
|
binmode STDIN, '\'':encoding(utf8)'\'';
|
|
|
|
binmode STDOUT, '\'':encoding(utf8)'\'';
|
2009-05-20 14:24:39 +02:00
|
|
|
chomp;
|
|
|
|
s/.\010//g;
|
|
|
|
s/\s*$//;
|
|
|
|
if (/^$/) {
|
|
|
|
$sawblank = 1;
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
if ($sawblank && $didprint) {
|
|
|
|
print "\n";
|
|
|
|
$sawblank = 0;
|
|
|
|
}
|
|
|
|
print "$_\n";
|
|
|
|
$didprint = 1;
|
|
|
|
}
|
2022-08-16 10:09:47 +02:00
|
|
|
'
|
|
|
|
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
|