3 # html2man: Converts the NTP HTML documentation to man page format
5 # This file require the Perl HTML::TokeParser module:
6 # http://search.cpan.org/search?module=HTML::TokeParser
8 # Depending on where this is run from, you might need to modify $MANDIR below.
10 # Hacked together by Peter Boettcher <boettcher@ll.mit.edu>
11 # Last modified: <Mon Jan 28 17:24:38 2002 by pwb>
13 require HTML::TokeParser;
15 # use strict; # I can dream...
19 # HTML files to convert. Also include per-file info here:
20 # name of man page, man section, 'see also' section
22 'ntpd' => ['ntpd', 8, 'ntp.conf(5), ntpq(8), ntpdc(8)'],
23 'ntpq' => ['ntpq', 8, 'ntpd(8), ntpdc(8)'],
24 'ntpdate' => ['ntpdate', 8, 'ntpd(8)'],
25 'ntpdc' => ['ntpdc', 8, 'ntpd(8)'],
26 'ntptime' => ['ntpdtime', 8, 'ntpd(8), ntpdate(8)'],
27 'ntptrace' => ['ntptrace', 8, 'ntpd(8)'],
28 'keygen' => ['ntp-keygen', 8, 'ntpd(8), ntp_auth(5)'],
29 'confopt' => ['ntp.conf', 5, 'ntpd(8)'],
30 'authopt' => ['ntp_auth', 5, 'ntp.conf(5), ntpd(8)'],
31 'monopt' => ['ntp_mon', 5, 'ntp.conf(5)'],
32 'accopt' => ['ntp_acc', 5, 'ntp.conf(5)'],
33 'clockopt' => ['ntp_clock', 5, 'ntp.conf(5)'],
34 'miscopt' => ['ntp_misc', 5, 'ntp.conf(5)']);
36 # Disclaimer to go in SEE ALSO section of the man page
37 $seealso_disclaimer = 'These man pages are automatically hacked from the main NTP ' .
38 'documentation pages, which are maintained in HTML format. These files are ' .
39 'included in the NTP source distribution. If you installed NTP from a binary ' .
40 'package, or it came pre-installed on your system, chances are the documentation ' .
41 'was also included in the usual place for your system. The HTML files are more ' .
42 'correct and complete than these man pages, which are provided for your reference ' .
45 # Disclaimer to go right at the top
46 $top_disclaimer = 'This file was automatically generated from HTML source, and may be ' .
47 'incorrect. See the SEE ALSO section at the end of this file for more info';
50 mkdir "$MANDIR/man8", 0777;
51 mkdir "$MANDIR/man5", 0777;
53 # Do the actual processing
54 foreach $file (keys %manfiles) {
57 # End of main function
64 $fileinfo = $manfiles{$filename};
66 $p = HTML::TokeParser->new("$filename.html") || die "Can't open $filename.html: $!";
67 open(MANOUT, ">$MANDIR/man$fileinfo->[1]/$fileinfo->[0].$fileinfo->[1]")
68 || die "Can't open: $!";
71 $name = $p->get_text("/title");
72 $p->get_tag("hr"); # Skip past image and quote, hopefully
75 print MANOUT ".TH " . $fileinfo->[0] . " " . $fileinfo->[1] . "\n";
76 print MANOUT ".UC 4\n";
77 print MANOUT ".SH NAME\n";
78 $pat = $fileinfo->[0];
79 if ($name =~ /$pat/) {
81 # Add the manpage name, if not in the HTML title already
82 print MANOUT "$fileinfo->[0] - ";
84 print MANOUT "$name\n\n";
86 print MANOUT "$top_disclaimer\n";
88 # Now start scanning. We basically print everything after translating some tags.
89 # $token->[0] has "T", "S", "E" for Text, Start, End
90 # $token->[1] has the tag name, or text (for "T" case)
91 # Theres lots more in the world of tokens, but who cares?
92 while (my $token = $p->get_token) {
93 if($token->[0] eq "T") {
94 my $text = $token->[1];
97 $text =~ s/[\n ]*$/ /;
99 $text =~ s/ \;/ /g;
101 print MANOUT "$text";
104 if($token->[0] eq "S") {
105 if($token->[1] eq "h4") {
106 my $text = uc($p->get_trimmed_text("/h4"));
107 print MANOUT ".SH $text\n";
109 if($token->[1] eq "tt") {
110 push @fontstack, "tt";
113 if($token->[1] eq "i") {
114 push @fontstack, "i";
117 if($token->[1] eq "address") {
118 my $text = $p->get_trimmed_text("/address");
119 print MANOUT "\n.SH AUTHOR\n$text\n";
121 if($token->[1] eq "dt") {
123 print MANOUT "\n.RS $tmp\n";
126 if($token->[1] eq "dd") {
127 print MANOUT "\n.RS $deflevel\n";
130 if($token->[1] eq "dl") {
134 elsif($token->[0] eq "E") {
135 if($token->[1] eq "dd") {
136 print MANOUT "\n.RE\n";
139 if($token->[1] eq "tt") {
142 warn "Oops, mismatched font! Trying to continue\n";
144 if ($#fontstack < 0) { $fontswitch = "\\fR"; }
145 elsif ($fontstack[$#fontstack] eq "tt") { $fontswitch = "\\fB"; }
146 else { $fontswitch = "\\fI"; }
147 print MANOUT "$fontswitch";
149 if($token->[1] eq "i") {
152 warn "Oops, mismatched font! Trying to continue\n";
154 if ($#fontstack < 0) { $fontswitch = "\\fR"; }
155 elsif ($fontstack[$#fontstack] eq "tt") { $fontswitch = "\\fB"; }
156 else { $fontswitch = "\\fI"; }
157 print MANOUT "$fontswitch";
159 if($token->[1] eq "dl") {
162 if($token->[1] eq "dt") {
163 print MANOUT "\n.RE";
168 print MANOUT ".SH SEE ALSO\n\n";
169 print MANOUT "$fileinfo->[2]\n\n";
170 print MANOUT "$seealso_disclaimer\n";