#! /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 "
MPI Commands
$eol";
&AddDirectoryContents( "www", "www1" );
print OUTFD "MPI Routines and Constants
$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 "MPE Routines
$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 "$eol$eol$title$eol";
print OUTFD "$eol";
print OUTFD "$eol$eol";
print OUTFD "$title
$eol";
}
sub AddTrailer {
print OUTFD "$eol$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 () {
@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 "\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 "$eol";
for ($j=0; $j<$nrows; $j++) {
print OUTFD "";
for ($e=0; $e<$TableCols; $e++) {
$filename = $HTMLFiles[$j + $e * $nrows];
$linkname = $filename;
$linkname =~ s/\.html?//;
$linkname =~ s/.*\///;
if ($filename ne "") {
$line = "$linkname";
}
else {
$line = "";
}
print OUTFD "$line | $eol";
}
print OUTFD "
$eol";
}
print OUTFD "
$eol";
}