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', @NTPD_MS@, 'ntp.conf(5), ntpq(@NTPQ_MS@), ntpdc(@NTPDC_MS@)'],
23 'ntpq' => ['ntpq', @NTPQ_MS@, 'ntp_decode(5), ntpd(@NTPD_MS@), ntpdc(@NTPDC_MS@)'],
24 'ntpdate' => ['ntpdate', @NTPDATE_MS@, 'ntpd(@NTPD_MS@)'],
25 'ntpdc' => ['ntpdc', @NTPDC_MS@, 'ntpd(@NTPD_MS@)'],
26 'ntptime' => ['ntptime', @NTPTIME_MS@, 'ntpd(@NTPD_MS@), ntpdate(@NTPDATE_MS@)'],
27 'ntptrace' => ['ntptrace', @NTPTRACE_MS@, 'ntpd(@NTPD_MS@)'],
28 'ntp-wait' => ['ntp-wait', @NTP_WAIT_MS@, 'ntpd(@NTPD_MS@)'],
29 'keygen' => ['ntp-keygen', @NTP_KEYGEN_MS@, 'ntpd(@NTPD_MS@), ntp_auth(5)'],
30 'tickadj' => ['tickadj', @TICKADJ_MS@, 'ntpd(@NTPD_MS@)'],
31 'confopt' => ['ntp.conf', 5, 'ntpd(@NTPD_MS@), ntp_auth(5), ntp_mon(5), ntp_acc(5), ntp_clock(5), ntp_misc(5)'],
32 'authopt' => ['ntp_auth', 5, 'ntp.conf(5), ntpd(@NTPD_MS@)'],
33 'monopt' => ['ntp_mon', 5, 'ntp.conf(5), ntp_decode(5)'],
34 'accopt' => ['ntp_acc', 5, 'ntp.conf(5)'],
35 'clockopt' => ['ntp_clock', 5, 'ntp.conf(5)'],
36 'decode' => ['ntp_decode', 5, 'ntpq(@NTPQ_MS@), ntp_mon(5)'],
37 'miscopt' => ['ntp_misc', 5, 'ntp.conf(5)']);
43 'decode' => 'l l l l.',
44 'authopt' => 'c c c c c c.'
47 # Disclaimer to go in SEE ALSO section of the man page
48 $seealso_disclaimer = "The official HTML documentation.\n\n" .
49 "This file was automatically generated from HTML source.\n";
52 mkdir "$MANDIR/man8", 0777;
53 mkdir "$MANDIR/man5", 0777;
55 # Do the actual processing
56 foreach $file (keys %manfiles) {
59 # End of main function
66 $fileinfo = $manfiles{$filename};
68 $p = HTML::TokeParser->new("$filename.html") || die "Can't open $filename.html: $!";
69 $fileout = "$MANDIR/man$fileinfo->[1]/$fileinfo->[0].$fileinfo->[1]";
70 open(MANOUT, ">$fileout")
71 || die "Can't open: $!";
74 $name = $p->get_text("/title");
75 $p->get_tag("hr"); # Skip past image and quote, hopefully
78 print MANOUT ".TH " . $fileinfo->[0] . " " . $fileinfo->[1] . "\n";
79 print MANOUT ".SH NAME\n";
80 $pat = $fileinfo->[0];
81 if ($name =~ /$pat/) {
83 # Add the manpage name, if not in the HTML title already
84 print MANOUT "$fileinfo->[0] - ";
86 print MANOUT "$name\n.SH \\ \n\n";
93 # Now start scanning. We basically print everything after translating some tags.
94 # $token->[0] has "T", "S", "E" for Text, Start, End
95 # $token->[1] has the tag name, or text (for "T" case)
96 # Theres lots more in the world of tokens, but who cares?
97 while (my $token = $p->get_token) {
98 if($token->[0] eq "T") {
99 my $text = $token->[1];
102 $text =~ s/^[\n\t ]*//;
104 $text =~ s/^[\n\t ][\n\t ]+$//;
105 $text =~ s/[\n\t ]+/ /g;
106 $text =~ s/ \;/ /g;
107 $text =~ s/>\;/>/g;
108 $text =~ s/<\;/</g;
109 $text =~ s/"\;/"/g;
110 $text =~ s/&\;/&/g;
111 $text =~ s/^\./\\[char46]/;
113 print MANOUT "$text";
116 if($token->[0] eq "S") {
117 if($token->[1] eq "h4") {
118 my $text = uc($p->get_trimmed_text("/h4"));
119 # ignore these sections in ntpd.html
120 if ($filename eq "ntpd" &&
121 ($text eq "CONFIGURATION OPTIONS")) {
124 open(MANOUT, ">/dev/null");
128 open(MANOUT, ">>$fileout");
130 print MANOUT "\n\n.SH $text\n";
132 if($token->[1] eq "tt") {
133 push @fontstack, "tt";
136 if($token->[1] eq "i") {
137 push @fontstack, "i";
140 if($token->[1] eq "address") {
141 my $text = $p->get_trimmed_text("/address");
142 print MANOUT "\n.SH AUTHOR\n$text\n";
144 if($token->[1] eq "dt" || $token->[1] eq "br" && $deflevel > 0) {
145 print MANOUT "\n.TP 8\n";
148 if($token->[1] eq "dd") {
152 if($token->[1] eq "dl") {
155 print MANOUT "\n.RS ", $deflevel > 1 ? 8 : 0;
158 if($token->[1] eq "p") {
161 if($token->[1] eq "pre") {
162 print MANOUT "\n.nf";
165 if($token->[1] eq "table") {
166 print MANOUT "\n.TS\n";
167 print MANOUT "expand allbox tab(%);\n";
168 print MANOUT $table_headers{$filename};
171 if($token->[1] eq "td") {
172 if ($first_td == 0) {
178 elsif($token->[0] eq "E") {
179 if($token->[1] eq "h4") {
182 if($token->[1] eq "tt") {
185 warn "Oops, mismatched font! Trying to continue\n";
187 if ($#fontstack < 0) { $fontswitch = "\\fR"; }
188 elsif ($fontstack[$#fontstack] eq "tt") { $fontswitch = "\\fB"; }
189 else { $fontswitch = "\\fI"; }
190 print MANOUT "$fontswitch";
192 if($token->[1] eq "i") {
195 warn "Oops, mismatched font! Trying to continue\n";
197 if ($#fontstack < 0) { $fontswitch = "\\fR"; }
198 elsif ($fontstack[$#fontstack] eq "tt") { $fontswitch = "\\fB"; }
199 else { $fontswitch = "\\fI"; }
200 print MANOUT "$fontswitch";
202 if($token->[1] eq "dl") {
204 print MANOUT "\n.RE";
209 if($token->[1] eq "p") {
213 if($token->[1] eq "pre") {
214 print MANOUT "\n.fi";
217 if($token->[1] eq "table") {
218 print MANOUT ".TE\n";
220 if($token->[1] eq "tr") {
228 open(MANOUT, ">>$fileout");
230 print MANOUT "\n.SH SEE ALSO\n\n";
231 print MANOUT "$fileinfo->[2]\n\n";
232 print MANOUT "$seealso_disclaimer\n";