Debian Codegraph @

imake/mkhtmlindex.pl

raw
1 #!/usr/bin/perl
2 #
3 # Copyright © 2000,2001 by VA Linux Systems, Inc.
4 #
5 # Generate index files for HTML man pages.
6 #
7 # Author: David Dawes <[email protected]>
8 #
9
10 #
11 # Best viewed with tabs set to 4
12 #
13
14 if ($#ARGV ne 0) {
15 print STDERR "Usage: mkhtmlindex.pl htmlmandir\n";
16 exit 1;
17 }
18
19 $dir = $ARGV[0];
20
21 if (! -d $dir) {
22 print STDERR "$dir is not a directory\n";
23 exit 1;
24 }
25
26 @vollist = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "o", "l", "n", "p");
27
28 $indexprefix = "manindex";
29
30 foreach $vol (@vollist) {
31 $empty = "yes";
32 $indexname="$dir/$indexprefix$vol.html";
33
34 # print "Processing volume $vol\n";
35
36 open(mindex, ">$indexname") || die "Can't create $indexname";
37 opendir(dir, "$dir") || die "Can't open $dir";
38
39 print mindex <<EOF;
40 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
41 <HTML>
42 <HEAD>
43 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
44 <TITLE>X.Org Manual pages: Section $vol</TITLE>
45 </HEAD>
46 <BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red">
47
48 <H1>X.Org Manual pages: Section $vol</H1>
49 <P>
50 <UL>
51 EOF
52
53 foreach $file (sort readdir dir) {
54 if ($file =~ "\.$vol\.html") {
55 open(file, "<$dir/$file") || die "Can't open $dir/$file";
56 while (<file>) {
57 chop;
58 if (/^<[hH]2>/) {
59 if (! /<\/[hH]2>$/) {
60 while (<file> && ! /<\/[hH]2>$/) {
61 ;
62 }
63 }
64 $heading = "";
65 while (<file>) {
66 if (/^<[hH]2>/) {
67 last;
68 }
69 $heading = "$heading" . "$_";
70 }
71 if ($heading) {
72 undef $empty;
73 $heading =~ s/--/-/;
74 ($name, $descr) = split(/-/, $heading, 2);
75 $file =~ /(.*)\.$vol\.html/;
76 $fname = $1;
77 $descr =~ s/<[pP]>//g;
78 print mindex
79 "<LI><A href=\"$file\">$fname</A> - $descr</LI>";
80 }
81 last;
82 }
83 }
84 close file;
85 }
86 }
87
88 print mindex <<EOF;
89 </UL>
90 <P>
91 </BODY>
92 </HTML>
93 EOF
94
95 close mindex;
96 closedir dir;
97 if (defined $empty) {
98 # print "Removing empty $indexname\n";
99 unlink $indexname;
100 }
101 }