File: createhtmlindex

package info (click to toggle)
mpich 3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 131,836 kB
  • sloc: ansic: 975,868; cpp: 57,437; f90: 53,762; perl: 19,562; xml: 12,464; sh: 12,303; fortran: 7,875; makefile: 7,078; ruby: 126; java: 100; python: 98; lisp: 19; php: 8; sed: 4
file content (205 lines) | stat: -rwxr-xr-x 5,427 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#! /usr/bin/env perl
# -*- mode: perl; -*-
#
# Create an index of web pages for MPICH
#
# Default values
# Root for the pages
$WWWRoot=`pwd`;
chop $WWWRoot;
# Base address (installation address)
# $URLBase = "http://";
# End of line character (\r\n is DOS-friendly)
$eol = "\r\n";
# Number of colums in table of names
$TableCols = 3;
#
# Process arguments for any changes
foreach $_ (@ARGV) {
    if (/-?(-[^=]*)=(.*)/) {
	$argname = $1;
	$argval  = $2;
    }
    else {
	$argname = $1;
	$argval  = "";
    }
    if ($argname =~ /-wwwroot/) {
	$WWWRoot = $argval;
    }
    elsif ($argname =~ /-urlbase/) {
	$URLBase = $argval;
    }
    elsif ($argname eq "-help") {
	print STDOUT "createhtmlindex [ -wwwroot=directory ] [ -urlbase=base ]\n";
	print STDOUT "Build the www index pages for MPICH.";
	print STDOUT "This must be run in the root of an MPICH tree; it may\n
be run in a VPATH directory after configuring.\n";
	exit 1;
    }
    else {
	print STDERR "Unknown argument $_\n";
	exit 1;
    }
}

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

&AddHeader( "Web pages for MPI" );

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

print OUTFD "<H2>MPI Routines and Constants</H2>$eol";
if (-f "www/www3/mpi.cit") {
    &createRedirects("www/www3", "mpi.cit");
}
else {
    print STDERR "Could not find mapping file\n";
}
&AddDirectoryContents( "www", "www3" );

#print OUTFD "<H2>MPE Routines</H2>$eol";
#&AddDirectoryContents( "www", "www4" );

&AddTrailer( );

close( OUTFD );

# Create the sectional indices
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 );

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

&AddHeader( "Web pages for MPI Routines and Constants" );
&AddDirectoryContents( "www/www3", "." );
&AddTrailer( );
close( OUTFD );

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

# &AddHeader( "Web pages for MPE Routines" );
# &AddDirectoryContents( "www/www4", "." );
# &AddTrailer( );
# close( OUTFD );


0;
# ---------------------------------------------------------------------------
# Support routines.
# All write to OUTFD and use $eol for end-of-line
# ---------------------------------------------------------------------------
sub AddHeader {
    my $title = $_[0];
    print OUTFD "<HTML>$eol<HEAD>$eol<TITLE>$title</TITLE>$eol";
    print OUTFD "<!-- This file generated by createhtmlindex on $date -->$eol";
    print OUTFD "</HEAD>$eol<BODY BGCOLOR=\"FFFFFF\">$eol";
    print OUTFD "<H1>$title</H1>$eol";
}

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

# For the items (mostly MPI constants) that are within a single web page,
# create a redirect page for them.  This allows us to point to a location
# on the page, rather than just a page which is what a file link would
# accomplish
sub createRedirects {
    $rootdir = $_[0];
    $mapfile = $_[1];
    open( MAPFD, "<$rootdir/$mapfile" ) || die "Cannot open map file $mapfile\n";
    while (<MAPFD>) {
	@fields = split(/\+/);
	$name = $fields[1];
	$url  = $fields[8];
	if ($url =~ /(.*)\/([^\/]*)\.([HTMLhtml]*)#(.*)/) {
	    $rooturl  = $1;
	    $basefile = $2;
	    $ext      = $3;
	    $anchor   = $4;
	    if ($basefile ne $anchor) {
		open(RFD, ">$rootdir/$anchor.htm") || die "Cannot open redirect file $anchor.htm\n";
		print RFD "<html><head><meta http-equiv=\"refresh\" content=\"0; url=$basefile.$ext#$anchor\" /></head></html>\n";
		close RFD;
	    }
	}
	else {
	    print STDERR "Could not decode $url\n";
	}

    }
    close MAPFD;
}

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

    # 1 Read the files
    @HTMLFiles = ();
    opendir DIR, "$rootdir/$dirname";
    if ($dirname eq ".") {
	$prefixname = "";
    }
    else {
	$prefixname = "$dirname/";
    }
    while ($filename = readdir DIR) {
	if ($filename =~ /index\.html?/) { next; }
	if ($filename =~ /.*\.html?$/) {
	    $HTMLFiles[$#HTMLFiles+1] = "$prefixname$filename";
	}
    }
    closedir DIR;

    @HTMLFiles = sort( @HTMLFiles );

    # Format the table
    &MakeHTMLTable;
}
# MakeHTMLTable takes an array of items and turns them into a table with
# $TableCols columns.
#
sub MakeHTMLTable {
    my $nvals = $#HTMLFiles;

    my $nrows = int ( ($nvals + $TableCols - 1) / $TableCols );
    print OUTFD "<TABLE>$eol";
    for ($j=0; $j<$nrows; $j++) {
	print OUTFD "<TR>";
	for ($e=0; $e<$TableCols; $e++) {
	    $filename = $HTMLFiles[$j + $e * $nrows];
	    $linkname = $filename;
	    $linkname =~ s/\.html?//;
	    $linkname =~ s/.*\///;
	    if ($filename ne "") {
		$line = "<A HREF=\"$filename\">$linkname</A>";
	    }
	    else {
		$line = "";
	    }
	    print OUTFD "<TD>$line</TD>$eol";
	}
	print OUTFD "</TR>$eol";
    }
    print OUTFD "</TABLE>$eol";
}