3 # Convert the HTML pages of the Administrator's Reference into POD man pages.
4 # This script was written by Chas Williams and Russ Allbery, based on work by
5 # Alf Wachsmann and Elizabeth Cassell. It just does a first pass; it's
6 # expected that the results will require further hand-editing.
11 my @ignore_tags = qw(meta head comment html body);
12 my @ignore_elements = qw(script style);
14 my %INLINES = ('b' => 'B<',
27 my %CDATA = ('dd' => 1,
36 # Global state of the conversion.
48 # Output some data. Accumulate this into $results so that we can do some
49 # post-filtering at the end.
51 my ($format, @args) = @_;
52 $result .= sprintf($format, @args);
55 # Handle a single element.
58 $buffer =~ s/^\s+\n/\n/m;
59 $buffer =~ s/\n+$/\n/g;
61 if ($lasttag eq "h2") {
64 $command =~ s/\(1\)>$//;
65 } elsif ($lasttag eq "strong") {
66 if ($buffer eq 'Related Information') {
71 if ($buffer eq 'PURPOSE') {
72 output "=head1 NAME\n\n%s - ", $command;
74 output "=head1 %s\n\n", $buffer;
76 } elsif ($lasttag eq "h5") {
77 output "=head2 %s\n\n", $buffer;
78 } elsif ($lasttag eq "h6") {
79 output "=head3 %s\n\n", $buffer;
80 } elsif ($lasttag eq "p") {
82 output "%s\n\n", $buffer if $buffer ne "";
83 } elsif ($lasttag eq "pre") {
85 output "%s\n\n", $buffer if $buffer ne "";
86 } elsif ($lasttag eq "ul" || $lasttag eq "dl") {
88 } elsif ($lasttag eq "li") {
89 output "=item *\n\n%s\n\n", $buffer;
90 } elsif ($lasttag eq "dt") {
91 output "=item %s\n\n", $buffer;
92 } elsif ($lasttag eq "dd") {
93 output "%s\n", $buffer;
94 } elsif ($lasttag eq "/ul" || $lasttag eq "/dl") {
98 printf ">>>%s:%s<<<", $lasttag, $buffer;
105 # Handle a single tag.
112 $output = 1 if ($tag eq "h2");
113 $output = 0 if ($tag eq "hr");
115 if (defined $INLINES{$tag}) {
116 if (defined $open && $open eq $tag) {
117 printf STDERR "duplicate tag <%s>\n", $tag;
126 &text(sprintf "%s", $INLINES{$tag});
131 $cdata = 1 if defined $CDATA{$tag};
137 # Do text conversion, mostly undoing SGML escapes.
147 s/\n$//g if defined $open; # in inline seq, remove \n
148 s/L<(\S+) (\S+\(1\))>/L<${1}_${2}>/g;
149 $buffer = $buffer . $_;
153 my $file = shift @ARGV;
155 my $p = HTML::Parser->new(api_version => 3,
156 start_h => [\&tag, "self, text, tag, attr"],
157 end_h => [\&tag, "self, text, tag, attr"],
158 process_h => ["", ""],
159 comment_h => ["", ""],
160 declaration_h => ["", ""],
161 default_h => [\&text, "text"],
163 ignore_tags => \@ignore_tags,
164 ignore_elements => \@ignore_elements,
167 $p->parse_file($file) || die "Can't open file: $!\n";
169 # Fix up a few last things.
170 $result =~ s/L<(\S+) (\S+\(1\))>/L<${1}_${2}>/g;
171 $result =~ s/^(L<[^>]+>)\n\n(?=L<)/$1,\n/mg;
172 $result =~ s/^(\s+.*)B<([^>]+)>/$1$2/mg;
174 # Append a stock copyright statement.
178 IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved.
180 This documentation is covered by the IBM Public License Version 1.0. It was
181 converted from HTML to POD by software written by Chas Williams and Russ
182 Allbery, based on work by Alf Wachsmann and Elizabeth Cassell.
185 # Output the results.