#!/usr/pkg/bin/perl
require "ctime.pl";
$sec = 8; # XXX
sub swallow {
my ($what) = @_;
while (<>) {
chomp;
return if /$what/i;
}
}
sub chew {
my ($match, $reset) = @_;
$_ = undef if $reset;
while (!(/$match/i)) {
chomp($_ .= " " . <>);
}
}
sub detag {
s/<[^>]+>//g;
}
sub dehtmlchar {
s/ / /g;
s/<//g;
}
($mday, $mon, $year) = (localtime(time))[3 .. 5];
$date = sprintf "%s %02d, %d", $ctime'MoY[$mon], $mday, $year + 1900;
swallow("
");
chomp($_ = <>);
detag;
($name, $descr) = split(' ', $_, 2);
$descr =~ s/^\s*-\s*//;
($NAME = $name) =~ tr/a-z/A-Z/;
print <", 1);
detag;
s/^\s*$name\s*//;
@args = split;
while ($_ = shift @args) {
next if /\[/;
s/^-//;
print ".Op Fl $_";
if (defined($args[0]) && $args[0] ne "]") {
print " Ar ", shift @args;
}
print "\n";
shift @args; # remove the "]"
}
while (<>) {
chomp;
next if length == 0;
if (/^/i) {
chew("
");
detag;
tr/a-z/A-Z/;
s/^\s+//;
dehtmlchar;
print ".Sh $_\n";
next;
}
if (//i) {
chew("");
detag;
s/^\s+//;
dehtmlchar;
print ".Sh AUTHOR\n$_\n";
next;
}
if (//i) {
print ".Bl -tag -width indent\n";
next;
}
if (m#
#i) {
print ".El\n";
next;
}
if (//i) {
chew("");
detag;
s/^\s*-//;
s/ / Ar /;
dehtmlchar;
print ".It Fl $_\n";
next;
}
if (/-/) {
# command line option
chew("");
s#-([^<]*)#\n.Fl $1\n#ig;
s###ig;
s#([^<]+)#\n.Ar $1\n#ig;
}
if (/");
chomp($_ .= " " . <>) if (/\1#\n.Xr \1 $sec\n#ig;
s#(.*?) + *page#\n.%T "$2"\npage in\n.Pa /usr/share/doc/ntp/$1\n#ig;
s#^
##g;
s#(.*?)#For\n.%T "$2"\n, refer to\n.Pa /usr/share/doc/ntp/$1 .\n.Pp\n#ig;
detag;
}
s#$name#\n.Nm\n#ig;
s#([^<]*)#\n.Pa $1\n#ig;
s#]*>([^<]*)#\n.Pa $1\n#ig;
s##.Pp\n.nf\n#ig;
s#
#\n.fi\n.Pp\n#ig;
s##\n.Pp\n#ig;
s#<(HR|DD)>##ig;
s#(BODY|HTML|DD)>##ig;
s#([^<]+)#\n.Ar $1\n#ig;
dehtmlchar;
s/^\s+//;
s/\n+\s*/\n/g;
s/\n.Nm\n([,\.:]) /\n.Nm "" $1\n/g;
s/\n\.(Pa|%T) (.*)\n([,\.:]) /\n.$1 $2 $3\n/g;
s/\n$//;
print $_, "\n" if length > 0;
}