1
1

First cut at a script to automatically make PHP-ized man pages from an OMPI

tarball script suitable for putting on www.open-mpi.org.

This commit was SVN r22485.
Этот коммит содержится в:
Jeff Squyres 2010-01-26 03:45:12 +00:00
родитель 9efd8cfedc
Коммит 3fdb9823cd

158
contrib/dist/make-html-man-pages.pl поставляемый Исполняемый файл
Просмотреть файл

@ -0,0 +1,158 @@
#!/usr/bin/env perl
#
# Copyright (c) 2010 Cisco Systems, Inc.
#
# Script to generate PHP-ized files of man pages generated by Open MPI
# tarballs.
#
use strict;
use File::Find;
use File::Basename;
use Cwd;
my $topdir;
my $version;
# Read command line arguments
while (@ARGV) {
my $a = $ARGV[0];
if ($a eq "--topdir" && $#ARGV >= 1) {
shift @ARGV;
$topdir = $ARGV[0];
print "Found topdir: $topdir\n";
shift @ARGV;
}
elsif ($a eq "--version" && $#ARGV >= 1) {
shift @ARGV;
$version = $ARGV[0];
print "Found version: $version\n";
shift @ARGV;
}
}
# Check that we have what we need
if (!defined($topdir) || !defined($version)) {
print "Usage: $0 --topdir dir --version version\n";
exit(1);
}
# Setup
my @files;
my $pwd = Cwd::cwd();
# Find all *.[0-9] files in the $topdir/share/man tree.
&File::Find::find(
sub {
push(@files, $File::Find::name) if (-f $_ && $_ =~ /\.[1-9]$/);
}, "$topdir/share/man");
# Must cd into the "man" directory because some of the man pages refer
# to other man pages by "man/<filename>" relative path names.
chdir("$topdir/share/man");
my %dirs;
my $outfiles;
# Generate a PHP file for each man page.
foreach my $file (@files) {
my $b = basename($file);
$b =~ m/(.*)\.([0-9])$/;
my $name = $1;
my $section = $2;
my $outfile = "$pwd/man$section/$b.php";
my $outdir = dirname($outfile);
$dirs{$outdir} = "";
push(@{$outfiles->{$section}}, {
name => $name,
file => "man$section/$b.php",
});
mkdir($outdir)
if (! -d $outdir);
print "Generating: $name ($section)\n";
unlink($outfile);
open(FILE, ">$outfile") || die "Can't open $outfile";
# Write a PHP header that is suitable for the pages on
# www.open-mpi.org
print FILE '<?php
$topdir = "../../..";
$title = "' . "$name($section) man page (version $version)" . '";
include_once("$topdir/includes/header.inc");
?>
';
# Run the groff command and send the output to the file
open(CMD, "groff -mandoc -T html $file|") || die("Can't open command");
while (<CMD>) {
last
if ($_ =~ /<\/body>/ || $_ =~ /<\/html>/);
print FILE $_;
}
close(CMD);
# Write a PHP footer that is suitable for the pages on
# www.open-mpi.org
print FILE '<?php
include_once("$topdir/includes/footer.inc");
';
# Done with this file
close(FILE);
}
# Now write out an index.php file in each subdir
foreach my $dir (keys(%dirs)) {
print "Writing index file in $dir...\n";
open(FILE, ">$dir/index.php") || die "Can't open $dir/index.php";
print FILE '<?php header("Location: ..");
';
close(FILE);
}
# Now write out a top-level data-<version>.inc file
my $file = "$pwd/data-$version.inc";
print "Writing $file...\n";
open(FILE, ">$file") || die "Can't open $file";
print FILE '<?php
$version = "' . $version . '";
';
foreach my $section (sort(keys(%{$outfiles}))) {
print FILE '$files[] = "' . $section . '";
$files_' . $section . ' = array(';
my $first = 1;
my @f;
# The hash isn't sorted, so build up an array of just the
# filenames
foreach my $file (@{$outfiles->{$section}}) {
push(@f, $file->{name});
}
# Now output the sorted filenames
foreach my $file (sort(@f)) {
print FILE ", "
if (!$first);
$first = 0;
print FILE '"' . $file . '"';
}
print FILE ");\n\n";
}
close(FILE);
# Print the top-level engine file for this version (it will use the
# data-<version>.inc file).
open(FILE, ">index.php") || die "Can't open index.php";
print FILE '<?php
$topdir = "../..";
include_once("data-' . $version . '.inc");
include_once("../engine.inc");
';
close(FILE);