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
|
#
# Should be called like
#
# perl mkhtmldoc.pl [FULLPATH_TO_SOURCE] [FULLPATH_TO_HTMLDIR]
#
# for example
#
# perl mkhtmldoc.pl `pwd`/blib/lib `pwd`/html
#
# reverted to use Pod::Html from normal perl distrib
# Christian
#
# (mod. by Tjl)
sub has_pod # does file contain HTML-able pod?
{
my $line; #mustn't clobber $_ during find
open(POD,shift) || return 0;
while ($line=<POD>) {return 1 if $line =~ /^=head/} # only a guess, avoids "=for nobody", etc.
return 0;
}
sub mkdir_p ($$$) {
return if -d $_[0];
my @a = split '/',$_[0];
pop @a;
if(!@a) {die "Couldn't create directory $_[2]"}
my $d = join '/',@a;
mkdir_p ($d, $_[1], $_[2]);
print "Creating directory $_[0]\n";
mkdir $_[0], $_[1] or die "Couldn't create directory $_[0]";
}
# start mkhtmldoc.pl
use File::Find;
use File::Basename;
use Pod::Html;
use Cwd;
$SIG{__DIE__} = sub {print Carp::longmess(@_); die;};
$back = getcwd;
$startdir = shift @ARGV; #$ARGV[0];
unless (defined $startdir) {
require PDL;
($startdir = $INC{'PDL.pm'}) =~ s/\.pm$//i;
umask 0022;
}
die "couldn't find directory '$startdir'" unless -d $startdir;
chdir $startdir or die "can't change to $startdir";
$startdir = getcwd; # Hack to get absolute pathname
chdir $back;
$htmldir = shift @ARGV; #$ARGV[1];
unless (defined $htmldir) {
$htmldir = "$startdir/HtmlDocs/PDL";
}
mkdir_p $htmldir, 0777, $htmldir;
chdir $htmldir or die "can't change to $htmldir";
$htmldir = getcwd; # Hack to get absolute pathname
chdir $back;
print "Put HTML $htmldir\n";
print "Scanning $startdir ... \n\n";
$sub = sub { if (($File::Find::name =~ /[.]pm$/ &&
$File::Find::name !~ /PP.pm/ &&
$File::Find::dir !~ m#/PP|/Gen#) or
$File::Find::name =~ /[.]pod$/) {
if (!&has_pod($File::Find::name)) {
printf STDERR "%-30s\n", $_ ."... skipped (no pod)";
return;
}
my $outdir = $File::Find::dir;
my $re = "\Q$startdir\E"; # ach: '+' in $outdir here!
# $outdir =~ s/$re/$htmldir/;
$outdir =~ s/$re//;
$outdir =~ /(^\/)?(.*)$/;
my $basename = basename($File::Find::name);
my $outfi;
if( $basename eq 'PDL.pm'){ # Special case for needed for PDL.pm file
$outfi = $basename; # since it is in a different location than the other
} # .pm and pod files.
else{
$outfi = $2.($2 =~ /^\s*$/ ? '' : '/').$basename;
$outfi =~ s|/|_|g;
}
# print "outdir = $outdir, making $outfi\n"; return;
# mkdir_p $outdir, 0777, $outdir;
my $file = $File::Find::name;
my $outfile = "$htmldir/$outfi";
$outfile =~ s/[.](pm|pod)$//;
$outfile .= ".html";
printf STDERR "%-30s\n", $_ ."... > $outfile";
chdir $htmldir; # reuse our pod caches
my $topPerlDir = $startdir;
# get Directory just above PDL for podroot arg
$topPerlDir = $1 if ($startdir =~ /^(.+?)\/PDL$/);
print "startdir: $startdir, podroot: $topPerlDir\n";
pod2html(
"--podpath=PDL:.",
"--podroot=$topPerlDir",
"--htmlroot=../../..",
"--libpods=perlfaq",
"--recurse",
"--infile=$file",
"--outfile=$outfile",
"--verbose");
chdir $File::Find::dir; # don't confuse File::Find
}
};
File::Find::find($sub,$startdir, "$startdir/../PDL.pm");
|