DEVEL15-man-page-net-info-fixes-20070619
[openafs.git] / doc / man-pages / generate-html
1 #!/usr/bin/perl -w
2 package OpenAFS::HTML;
3
4 use strict;
5 use vars qw(@ISA);
6
7 use Pod::Simple::Search;
8 @ISA = qw(Pod::Simple::HTML);
9
10 sub do_man_link {
11     my ($self, $token) = @_;
12     my $page = $token->attr ('to');
13     my ($name, $section) = ($page =~ /^([^\(]+)\((\d+)\)$/);
14     return unless $name;
15     my @url = ('..', $section, $name);
16     return join ('/', map { $self->pagepath_url_escape ($_) } @url)
17         . $Pod::Simple::HTML::HTML_EXTENSION;
18 }
19
20 # Underscore isn't allowed in man page names in Pod::Simple 3.04, so links
21 # like L<fs_setacl(8)> show up as POD links.  Discover that case and dispatch
22 # everything else to the standard do_pod_link implementation.
23 sub do_pod_link {
24     my ($self, $token) = @_;
25     my $target = $token->attr ('to');
26     if ($target && $target =~ /^([^\s\(]+)\((\d+)\)$/) {
27         return $self->do_man_link ($token);
28     } else {
29         return $self->SUPER::do_pod_link ($token);
30     }
31 }
32
33 sub VERSION () { '1.1' }
34
35 $Pod::Simple::HTML::Tagmap{'item-bullet'} = '<li><p>';
36 $Pod::Simple::HTML::Tagmap{'/item-bullet'} = '</p></li>';
37 $Pod::Simple::HTML::Tagmap{'item-number'} = '<li><p>';
38 $Pod::Simple::HTML::Tagmap{'/item-number'} = '</p></li>';
39
40 package main;
41
42 use strict;
43
44 use File::Copy;
45 use Pod::Simple::HTMLBatch;
46
47 our $HEADER = <<'EOH';
48 <html>
49 <head>
50   <title>OpenAFS Reference Manual</title>
51   <link rel="stylesheet" title="style" type="text/css" href="style.css" media="all">
52 </head>
53 <body class='contentspage'>
54 <h1>OpenAFS Reference Manual</h1>
55 EOH
56
57 our %HEADINGS = (1 => 'User Commands',
58                  5 => 'Configuration and Data Files',
59                  8 => 'Administrator Commands');
60
61 # Scan all of the POD files and build a list of section, name, and short
62 # description, returning that as an array.
63 sub scan_names {
64     my @index;
65     for my $dir (qw(pod1 pod5 pod8)) {
66         my $section = $dir;
67         $section =~ s/^pod//;
68         opendir (D, $dir) or die "Cannot open $dir: $!\n";
69         for my $file (sort grep { !/^\./ && !/CVS/ } readdir D) {
70             open (F, "$dir/$file") or die "Cannot open $dir/$file: $!\n";
71             my ($name, $desc);
72             local $_;
73             while (<F>) {
74                 last if /^=head1/ && !/^=head1\s+NAME\b/;
75                 next unless /\s+-\s+/;
76                 ($name, $desc) = split (/\s+-\s+/, $_, 2);
77             }
78             unless ($name) {
79                 warn "$dir/$file: cannot find NAME section, skipping\n";
80             }
81             my $page = $file;
82             $page =~ s/\.pod$//;
83             push (@index, [ $section, $name, $page, $desc ]);
84         }
85         closedir D;
86     }
87     return @index;
88 }
89
90 unless (-d 'html') {
91     mkdir ('html', 0755) or die "Cannot create html directory: $!\n";
92 }
93 for my $dir (qw(pod1 pod5 pod8)) {
94     my $section = $dir;
95     $section =~ s/^pod//;
96     mkdir ("html/$section", 0755) unless -d "html/$section";
97
98     my $conv = Pod::Simple::HTMLBatch->new;
99     $conv->verbose (0);
100     $conv->index (undef);
101     $conv->contents_file (undef);
102     $conv->add_css ('../style.css', 1);
103     $conv->css_flurry (0);
104     $conv->javascript_flurry (0);
105     $conv->html_render_class ('OpenAFS::HTML');
106     $conv->batch_convert ($dir, "html/$section");
107 }
108 copy ('style.css', 'html/style.css') or die "Cannot copy style.css: $!\n";
109
110 open (INDEX, '> html/index.html')
111     or die "Cannot create html/index.html: $!\n";
112 print INDEX $HEADER;
113 print INDEX "<table>\n";
114 my @index = scan_names;
115 my $current;
116 for my $entry (@index) {
117     my ($section, $name, $page, $desc) = @$entry;
118     for ($name, $desc) {
119         s/&/&gt;/g;
120         s/</&lt;/g;
121         s/>/&gt;/g;
122     }
123     if (!$current || $section != $current) {
124         print INDEX qq(<tr><td>&nbsp;</td></tr>\n);
125         print INDEX qq(<tr class="heading"><th colspan="2">);
126         print INDEX qq($HEADINGS{$section}</th></tr>\n);
127         $current = $section;
128     }
129     print INDEX qq(<tr><td><a href="$section/$page.html">$name</a></td>);
130     print INDEX qq(<td>$desc</td></tr>\n);
131 }
132 print INDEX "</table>\n</body>\n</html>\n";