eval 'exec perl -Ssw $0 "$@"' if 0; # Usage $0 manpage # Parse my man page formats. die "Usage: $0 [ manpage ] \n" unless $#ARGV <= 0; $firstSH = 1; $inDL = 0; warn "Doing $ARGV[0]\n"; open(STDIN, "$ARGV[0]") if ($#ARGV == 0); while (<>) { next if (/^\.\\"/); if (/^\.TH\s/) { # .TH BW_MEM_CP 8 "$Date$" "(c)1994 Larry McVoy" "LMBENCH" split; print "$_[1]($_[2]) - LMBENCH man page\n"; print "

$_[1]($_[2]) - LMBENCH man page


\n"; next; } if (/^\.SH\s/) { s/.SH\s+//; s/"//g; chop; print "\n" unless $firstSH; $firstSH = 0; print "\n" if $inDL; $inDL = 0; print "

$_

\n"; next; } next if &fontfont; if (/^\.LP\s/ || /^\.PP/) { s/..P\s+//; chop; print "

\n"; next; } if (/^\.TP/) { # treat as a DT list $_ = <>; &html; chop; print "

\n" if ($inDL); print "
"; print unless &fontfont; print "

\n"; $inDL = 1; next; } if (/^\.IP/) { # treat as a DT list s/^\.IP\s*//; chop; s/"//; s/".*//; &html; print "
\n" if ($inDL); print "
$_

\n"; $inDL = 1; next; } if (/^\.sp/) { print "
\n
\n"; next; } next if (/^\.in/ || /^\.ps/); # skip this stuff. if (/^\.br/) { print "
\n"; next; } if (/^\.nf/ || /^\.DS/) { # starting a display print "
\n";
		while (<>) {
			last if /^\.fi/;
			last if /^\.DE/;
			next if /^\./;
			&html;
			print "\t$_";	# XXX - a screwy way of indenting
		}
		print "
\n"; next; } if (/^\.ft C[WB]/) { local($pre) = 0; print "\n"; while (<>) { last if /^\.ft\s*$/; if (/^\.nf/) { $pre = 1; print "
\n";
				next;
			}
			if ($pre && /^\.fi/) {
				print "
\n"; $pre = 0; next; } next if /^\.br/; &html; print; } print "
\n"; next; } if (/\\f\(C[WB]/) { &html; s/\\f\(C[WB]//; while (!/\\f/) { &html; print; $_ = <>; } s/\\fP/<\/CODE>/; print; next; } if (/\\fB/) { &html; s/\\fB//; while (!/\\f/) { print; $_ = <>; &html; } s/\\fP/<\/STRONG>/; print; next; } if (/\\fI/) { &html; s/\\fB//; while (!/\\f/) { print; $_ = <>; &html; } s/\\fP/<\/EM>/; print; next; } if (/^\.ti/) { # one line display print "
\n";
		$_ = <>;
		&html;
		print;
		print "
\n"; next; } if (/^\.de\s+/) { s/^\.de\s+//; warn "$ARGV[0]: Ignoring definition: $_"; while (<>) { last if /^\.\./; } next; } # Warn about unimplemented troff/man commands if (/^\./) { chop; warn "$ARGV[0] unimp: \"$_\"\n"; next; } if (/\\f/) { warn "$ARGV[0]: missed font: \"$_\"\n"; } # Catchall for all the weirdball things I do. s/^\\\&\.\\\|\.\\\|\./.../; s/\\-/-/; &html; print; } exit 0; sub html { # HTML things that I've encountered. s/"/"/g; s//>/g; } sub fontfont { if (/^\.BI\s/) { s/.BI\s+//; chop; split; print "$_[0]$_[1]\n"; return 1; } if (/^\.IB\s/) { s/.IB\s+//; chop; split; print "$_[0]$_[1]\n"; return 1; } if (/^\.IR\s/) { s/.IR\s+//; chop; split; print "$_[0]$_[1]\n"; return 1; } if (/^\.BR\s/) { s/.BR\s+//; chop; split; print "$_[0]$_[1]\n"; return 1; } if (/^\.B\s/) { s/.B\s+//; chop; print "$_\n"; return 1; } if (/^\.I\s/) { s/.I\s+//; chop; print "$_\n"; return 1; } return 0; }