Improvements
This commit was SVN r22493.
Этот коммит содержится в:
родитель
3fdb9823cd
Коммит
21a4bc6af5
83
contrib/dist/make-html-man-pages.pl
поставляемый
83
contrib/dist/make-html-man-pages.pl
поставляемый
@ -2,8 +2,8 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2010 Cisco Systems, Inc.
|
# Copyright (c) 2010 Cisco Systems, Inc.
|
||||||
#
|
#
|
||||||
# Script to generate PHP-ized files of man pages generated by Open MPI
|
# Script to generate PHP-ized files of Open MPI tarball-installed man
|
||||||
# tarballs.
|
# pages.
|
||||||
#
|
#
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
@ -11,16 +11,16 @@ use File::Find;
|
|||||||
use File::Basename;
|
use File::Basename;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
|
|
||||||
my $topdir;
|
my $mandir;
|
||||||
my $version;
|
my $version;
|
||||||
|
|
||||||
# Read command line arguments
|
# Read command line arguments
|
||||||
while (@ARGV) {
|
while (@ARGV) {
|
||||||
my $a = $ARGV[0];
|
my $a = $ARGV[0];
|
||||||
if ($a eq "--topdir" && $#ARGV >= 1) {
|
if ($a eq "--mandir" && $#ARGV >= 1) {
|
||||||
shift @ARGV;
|
shift @ARGV;
|
||||||
$topdir = $ARGV[0];
|
$mandir = $ARGV[0];
|
||||||
print "Found topdir: $topdir\n";
|
print "Found mandir: $mandir\n";
|
||||||
shift @ARGV;
|
shift @ARGV;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ while (@ARGV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check that we have what we need
|
# Check that we have what we need
|
||||||
if (!defined($topdir) || !defined($version)) {
|
if (!defined($mandir) || !defined($version)) {
|
||||||
print "Usage: $0 --topdir dir --version version\n";
|
print "Usage: $0 --mandir dir --version version\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,15 +42,15 @@ if (!defined($topdir) || !defined($version)) {
|
|||||||
my @files;
|
my @files;
|
||||||
my $pwd = Cwd::cwd();
|
my $pwd = Cwd::cwd();
|
||||||
|
|
||||||
# Find all *.[0-9] files in the $topdir/share/man tree.
|
# Find all *.[0-9] files in the $mandir tree.
|
||||||
&File::Find::find(
|
&File::Find::find(
|
||||||
sub {
|
sub {
|
||||||
push(@files, $File::Find::name) if (-f $_ && $_ =~ /\.[1-9]$/);
|
push(@files, $File::Find::name) if (-f $_ && $_ =~ /\.[1-9]$/);
|
||||||
}, "$topdir/share/man");
|
}, $mandir);
|
||||||
|
|
||||||
# Must cd into the "man" directory because some of the man pages refer
|
# Must cd into the $mandir directory because some of the man pages
|
||||||
# to other man pages by "man/<filename>" relative path names.
|
# refer to other man pages by "man/<filename>" relative path names.
|
||||||
chdir("$topdir/share/man");
|
chdir($mandir);
|
||||||
|
|
||||||
my %dirs;
|
my %dirs;
|
||||||
my $outfiles;
|
my $outfiles;
|
||||||
@ -75,35 +75,54 @@ foreach my $file (@files) {
|
|||||||
if (! -d $outdir);
|
if (! -d $outdir);
|
||||||
|
|
||||||
print "Generating: $name ($section)\n";
|
print "Generating: $name ($section)\n";
|
||||||
|
|
||||||
|
# Run the groff command and send the output to the file
|
||||||
|
open(CMD, "groff -mandoc -T html $file|") || die("Can't open command");
|
||||||
|
my $text;
|
||||||
|
$text .= $_
|
||||||
|
while (<CMD>);
|
||||||
|
close(CMD);
|
||||||
|
|
||||||
|
# Post-process the text:
|
||||||
|
# Remove <head> ... </head>
|
||||||
|
# Remove <!doctype ...>
|
||||||
|
# Remove <meta ...>
|
||||||
|
# Remove <style ...> ... </style>
|
||||||
|
# Remove <title> ... </title>
|
||||||
|
# Remove <html> and </html>
|
||||||
|
# Remove <body> and </body>
|
||||||
|
|
||||||
|
$text =~ s/<head>.*<\/head>//is;
|
||||||
|
$text =~ s/<!doctype.*?>//is;
|
||||||
|
$text =~ s/<html>//i;
|
||||||
|
$text =~ s/<\/html>//i;
|
||||||
|
$text =~ s/<body>//i;
|
||||||
|
$text =~ s/<\/body>//i;
|
||||||
|
|
||||||
|
# Remove carriage returns, extra white space, and double blank
|
||||||
|
# lines
|
||||||
|
$text =~ s/\r//g;
|
||||||
|
$text =~ s/[ \t]+\n/\n/g;
|
||||||
|
$text =~ s/\n{3,}/\n\n/g;
|
||||||
|
|
||||||
|
# Now we're left with what we want. Output the PHP page.
|
||||||
|
|
||||||
|
# Write the output PHP file with our own header and footer,
|
||||||
|
# suitable for www.open-mpi.org.
|
||||||
unlink($outfile);
|
unlink($outfile);
|
||||||
open(FILE, ">$outfile") || die "Can't open $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
|
print FILE '<?php
|
||||||
$topdir = "../../..";
|
$topdir = "../../..";
|
||||||
$title = "' . "$name($section) man page (version $version)" . '";
|
$title = "' . "$name($section) man page (version $version)" . '";
|
||||||
|
|
||||||
include_once("$topdir/includes/header.inc");
|
include_once("$topdir/includes/header.inc");
|
||||||
?>
|
?>
|
||||||
';
|
<p> <a href="../">« Return to documentation listing</a></p>
|
||||||
|
' . $text . '
|
||||||
# Run the groff command and send the output to the file
|
<p> <a href="../">« Return to documentation listing</a></p>
|
||||||
open(CMD, "groff -mandoc -T html $file|") || die("Can't open command");
|
<?php
|
||||||
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");
|
include_once("$topdir/includes/footer.inc");
|
||||||
';
|
';
|
||||||
|
|
||||||
# Done with this file
|
|
||||||
close(FILE);
|
close(FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user