File: createhtmlindex

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (189 lines) | stat: -rwxr-xr-x 5,249 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#! /usr/bin/env perl
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

use strict;

# Create an index of web pages for MPICH
#
# Default values
# Root for the pages
my $WWWRoot=`pwd`;
chop $WWWRoot;

# in case for out-of-tree build
my $srcdir = ".";

# End of line character (\r\n is DOS-friendly)
my $eol = "\r\n";
# Number of columns in table of names
my $TableCols = 3;
#
# Process arguments for any changes
foreach $a (@ARGV) {
    if ($a =~ /-?-wwwroot=(.*)/) {
	$WWWRoot = $1;
    }
    elsif ($a =~ /-?-srcdir=(.*)/) {
	$srcdir = $1;
    }
    elsif ($a =~ /-?help/) {
	print STDOUT "createhtmlindex [ -wwwroot=directory ]\n\n";
	print STDOUT "Build the www index pages for MPICH.\n";
	print STDOUT "This must be run in the root of an MPICH tree; it may\n";
        print STDOUT "be run in a VPATH directory after configuring.\n";
	exit 1;
    }
    else {
	print STDERR "Unknown argument $a\n";
	exit 1;
    }
}

# ---- Create the alias pages for large count functions ----
my $poly_aliases_lst = "$srcdir/src/binding/c/mansrc/poly_aliases.lst";
open In, $poly_aliases_lst or die "Failed to open $poly_aliases_lst\n";
while (<In>) {
    # e.g. MPI_Recv - MPI_Recv_c
    if (/^(MPI\w+) - (MPI\w+)/) {
        open Out, "> www/www3/$2.html" or die "Can't create www/www3/$2.html\n";
        print Out "<meta http-equiv=\"refresh\" content=\"0; url=$1.html\">\n";
        close Out;
    }
}
close In;

# ---- Create the main index ----
open( OUTFD, ">$WWWRoot/www/index.html" ) ||
    die "Cannot open $WWWRoot/www/index.html\n";

&AddHeader( "Man pages for MPI" );

print OUTFD "<H2>MPI Commands</H2>$eol";
&AddDirectoryContents( "www", "www1" );

print OUTFD "<H2>MPI Routines</H2>$eol";
&AddDirectoryContents( "www", "www3" );

print OUTFD "<H2>MPI Constants</H2>$eol";
&AddDirectoryConstants( "www", "www3/Constants.html" );

&AddTrailer( );

close( OUTFD );

# ---- Create the www1 index ----
open( OUTFD, ">$WWWRoot/www/www1/index.htm" ) ||
    die "Cannot open $WWWRoot/www/www1/index.htm\n";

&AddHeader( "Manpages for MPICH" );
&AddDirectoryContents( "www/www1", "." );
&AddTrailer( );
close( OUTFD );

# ---- Create the www3 index ----
open( OUTFD, ">$WWWRoot/www/www3/index.htm" ) ||
    die "Cannot open $WWWRoot/www/www3/index.htm\n";

&AddHeader( "Man pages for MPI Routines and Constants" );
&AddDirectoryContents( "www/www3", "." );
print OUTFD "<H2>MPI Routines</H2>$eol";
&AddDirectoryContents( "www/www3", "." );

print OUTFD "<H2>MPI Constants</H2>$eol";
&AddDirectoryConstants( "www/www3", "Constants.html" );

&AddTrailer( );
close( OUTFD );

0;
# ---------------------------------------------------------------------------
# Support routines.
# All write to OUTFD and use $eol for end-of-line
# ---------------------------------------------------------------------------
sub AddHeader {
    my $title = $_[0];
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    my $today = sprintf("%d/%d/%d", $mon + 1, $mday, $year + 1900);
    print OUTFD "<HTML>$eol<HEAD>$eol<TITLE>$title</TITLE>$eol";
    print OUTFD "<!-- This file generated by createhtmlindex on $today -->$eol";
    print OUTFD "</HEAD>$eol<BODY BGCOLOR=\"FFFFFF\">$eol";
    print OUTFD "<H1>$title</H1>$eol";
}

sub AddTrailer {
    print OUTFD "</BODY>$eol</HTML>$eol";
}

# Create a table of indexes for MPI Constants. Each link points to an
# anchor within Constants.html. We assume each anchor is in a expected
# format.
#
sub AddDirectoryConstants {
    my ($rootdir, $file) = @_;
    my %links;
    open In, "$rootdir/$file" or die "Can't open $rootdir/$file\n";
    while (<In>) {
        if (/<a name="(.+?)"><\/a>/) {
            $links{$1} = "$file#$1";
        }
    }
    MakeHTMLTable(\%links);
}

# Take all .htm and .html files and add them to the OUTFD file.
# This works in two steps:
# 1. Read the contents of the directory into the %links
# 2. Use the routine MakeHTMLTable to create a table with a given
# number of columns, adding the links within the columns
# Look in $1/$2 for files, but make links relative to $2
#
sub AddDirectoryContents {
    my ($rootdir, $dirname) = @_;

    my %links;
    opendir DIR, "$rootdir/$dirname";

    my $prefixname;
    if ($dirname ne ".") {
	$prefixname = "$dirname/";
    }
    while (my $filename = readdir DIR) {
	if ($filename =~ /(index|Constants)\.html?/) {
            next;
        } elsif ($filename =~ /(\w+)\.html?$/) {
            $links{$1} = "$prefixname$filename";
	}
    }
    closedir DIR;

    MakeHTMLTable(\%links);
}

# MakeHTMLTable takes an hash of items and turns them into a table with
# $TableCols columns.
#
sub MakeHTMLTable {
    my ($links) = @_;
    my @keys = sort keys %$links;
    my $nvals = @keys;

    my $nrows = int ( ($nvals + $TableCols - 1) / $TableCols );
    print OUTFD "<TABLE>$eol";
    for (my $j=0; $j<$nrows; $j++) {
	print OUTFD "<TR>";
	for (my $e=0; $e<$TableCols; $e++) {
	    my $linkname = $keys[$j + $e * $nrows];
	    my $filename = $links->{$linkname};
            my $line;
	    if ($filename) {
		$line = "<A HREF=\"$filename\">$linkname</A>";
	    }
	    print OUTFD "<TD>$line</TD>$eol";
	}
	print OUTFD "</TR>$eol";
    }
    print OUTFD "</TABLE>$eol";
}