10SN/A#! /bin/sh 2157SN/A# Convert manual page troff stdin to formatted .txt stdout. 30SN/A 40SN/A# This file is in the public domain, so clarified as of 50SN/A# 2009-05-17 by Arthur David Olson. 60SN/A 7157SN/Aif (type nroff && type perl) >/dev/null 2>&1; then 80SN/A 9157SN/A # Tell groff not to emit SGR escape sequences (ANSI color escapes). 100SN/A GROFF_NO_SGR=1 110SN/A export GROFF_NO_SGR 120SN/A 130SN/A echo ".am TH 140SN/A.hy 0 150SN/A.na 160SN/A.. 170SN/A.rm }H 180SN/A.rm }F" | nroff -man - ${1+"$@"} | perl -ne ' 190SN/A binmode STDIN, '\'':encoding(utf8)'\''; 200SN/A binmode STDOUT, '\'':encoding(utf8)'\''; 21157SN/A chomp; 22157SN/A s/.\010//g; 23157SN/A s/\s*$//; 240SN/A if (/^$/) { 250SN/A $sawblank = 1; 260SN/A next; 270SN/A } else { 280SN/A if ($sawblank && $didprint) { 290SN/A print "\n"; 300SN/A $sawblank = 0; 310SN/A } 320SN/A print "$_\n"; 330SN/A $didprint = 1; 340SN/A } 350SN/A ' 360SN/Aelif (type mandoc && type col) >/dev/null 2>&1; then 370SN/A mandoc -man -T ascii "$@" | col -bx 380SN/Aelse 390SN/A echo >&2 "$0: please install nroff and perl, or mandoc and col" 400SN/A exit 1 410SN/Afi 420SN/A