/usr/lib/perl5/PDL/Doc/mkhtmldoc.pl is in pdl 1:2.007-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | #
# 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)
use File::Find;
use File::Basename;
use File::Basename;
use Getopt::Std;
use Pod::Html;
use Cwd;
use IO::File; # for hack_links()
$opt_v = 0;
$opt_s = '';
getopts('vs:');
my $verbose = $opt_v;
my ($strip_path,$add_path) = split(/,/,$opt_s);
##############################################################
## Subroutines
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 @dirs = File::Spec->splitdir($_[0]);
my @dirs = split '/', $_[0];
pop @dirs;
if(!@dirs) {die "Couldn't create directory $_[2]"}
# my $dir = File::Spec->catdir( @dirs );
my $dir = join '/', @dirs;
mkdir_p ($dir, $_[1], $_[2]);
print "Creating directory $_[0]\n" if $verbose;
mkdir $_[0], $_[1] or die "Couldn't create directory $_[0]";
}
# Replace PDL/...|PDL/... with PDL/...
# as Pod::Html v1.01 (perlv 5.005_03 )
# doesn't seem to be able to handle
# L<PDL::PDL|PDL::PDL> correctly
#
# (not necessary for perl 5.6.0)
#
sub hack_html ($) {
my $infile = shift;
my $outfile = "${infile}.n";
my $ifh = new IO::File "<$infile"
or die "ERROR: Unable to read from <$infile>\n";
my $ofh = new IO::File ">$outfile"
or die "ERROR: Unable to write to <$outfile>\n";
# assume that links do not break across a line
while ( <$ifh> ) {
# fix the links
s{PDL/([^|]+)\|PDL/\1}{PDL/$1}g;
# fix the text of the link
s{PDL::([^|]+)\|PDL::\1}{PDL::$1}g;
# now fix any links for scripts
s{/([^|]+)\|PDL/\1}{/PDL/$1}g;
s{([^|]+)\|PDL::\1}{$1}g;
print $ofh $_;
}
$ifh->close;
$ofh->close;
rename $outfile, $infile
or die "ERROR: Unable to rename $outfile\n";
}
sub fix_pdl_dot_html ($) {
##Links to PDL.html sensibly try to go up one too many directories
##(e.g., to "../PDL.html" instead of "PDL.html"). This hopefully
##fixes that. Shamelessly ripped off hack_html() above.
my $infile = shift;
my $outfile = "${infile}.n";
my $ifh = new IO::File "<$infile"
or die "ERROR: Unable to read from <$infile>\n";
my $ofh = new IO::File ">$outfile"
or die "ERROR: Unable to write to <$outfile>\n";
# assume that links do not break across a line
while ( <$ifh> ) {
# fix the links
s{\.\.\/PDL\.html}{PDL.html}g;
print $ofh $_;
}
$ifh->close;
$ofh->close;
rename $outfile, $infile
or die "ERROR: Unable to rename $outfile\n";
}
sub fix_html_path ($) {
my $infile = shift;
my $outfile = "${infile}.n";
my $ifh = new IO::File "<$infile"
or die "ERROR: Unable to read from <$infile>\n";
my $ofh = new IO::File ">$outfile"
or die "ERROR: Unable to write to <$outfile>\n";
# assume that links do not break across a line
while ( <$ifh> ) {
# fix the links
s{a href="$strip_path}{a href="$add_path}g;
print $ofh $_;
}
$ifh->close;
$ofh->close;
rename $outfile, $infile
or die "ERROR: Unable to rename $outfile\n";
}
sub fix_pp_inline ($) {
my $infile = shift;
my $outfile = "${infile}.n";
my $ifh = new IO::File "<$infile"
or die "ERROR Unable to read from <$infile>\n";
my $ofh = new IO::File ">$outfile"
or die "ERROR: Unable to write to <$outfile>\n";
# assume that links do not break across a line
while ( <$ifh> ) {
#fix the links
s|a href="../Inline/Pdlpp.html"|a href="./PP-Inline.html"|g;
print $ofh $_;
}
$ifh->close;
$ofh->close;
rename $outfile, $infile
or die "ERROR: Unable to rename $outfile\n";
}
##############################################################
## Code
$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];
#$htmldir = File::Spec->catdir( $startdir, "HtmlDocs", "PDL" )
$htmldir = "${startdir}/HtmlDocs/PDL"
unless defined $htmldir;
mkdir_p $htmldir, 0777, $htmldir;
chdir $htmldir or die "can't change to $htmldir";
$htmldir = getcwd; # Hack to get absolute pathname
chdir $back;
#my $updir = File::Spec->updir;
print "Making HTML docs...\n\n";
print "Put HTML $htmldir\n" if $verbose;
print "Scanning $startdir ... \n\n" if $verbose;
$sub = sub {
return unless $File::Find::name =~ /[.]pod$/ or
($File::Find::name =~ /[.]pm$/ and
$File::Find::name !~ /PP.pm/ and
$File::Find::dir !~ m{/PP|/Gen});
# if (($File::Find::name =~ /[.]pm$/ and
# $File::Find::name !~ /PP.pm/ and
# $File::Find::dir !~ m#/PP|/Gen#) or
# $File::Find::name =~ /[.]pod$/) {
if (!&has_pod($File::Find::name)) {
printf STDERR "%-30s\n", $_ ."... skipped (no pod)"
if $verbose;
return;
}
my $re = "\Q$startdir\E"; # ach: '+' in $outdir here!
my $outdir = $File::Find::dir;
# $outdir =~ s/$re/$htmldir/;
$outdir =~ s/$re//;
$outdir =~ /(^\/)?(.*)$/;
my $basename = basename($File::Find::name);
my $outfi;
# Special case for needed for PDL.pm file since it is in a
# different location than the other .pm and pod files.
if( $basename eq 'PDL.pm'){
$outfi = $basename;
} else {
$outfi = $2.($2 =~ /^\s*$/ ? '' : '/').$basename;
#
# with the following substitution, everything gets stored in the same directory -
# so PDL/Graphics/LUT -> PDL_Graphics_LUT for example
#
#$outfi =~ s|/|_|g;
}
# create the output directory, if required
if ( $outdir ne "" ) {
# $outdir = File::Spec->catdir( $htmldir, $outdir );
$outdir = "${htmldir}/${outdir}";
mkdir_p $outdir, 0777, $outdir;
}
# print "outdir = $outdir, making $outfi\n"; return;
# mkdir_p $outdir, 0777, $outdir;
my $file = $File::Find::name;
# my $outfile = File::Spec->catfile( $htmldir, $outfi );
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" if $verbose;
# instead of having htmlroot="../../.."
# (or even File::Spec->catdir( $updir, $updir, $updir ) )
# calculate it from the known location of the
# file we're creating
my $htmlrootdir = $htmldir;
$htmlrootdir =~ s|PDL$||;
my $verbopts = $verbose ? "--verbose" : "--quiet";
if($] > 5.015) {
# With perl 5.15.x (for some value of x) and later, '--libpods' is invalid
# and hence needs to be removed.
# Beginning with 5.15.x, the generated PDL html docs are a little different
# (missing some underlining of headings and some <b></b> tagging), though
# this appears to have nothing to do with the removal of --libpods. Rather,
# it seems to be the result of some other change to pod2html. Perhaps this
# can be addressed over time. SIS 23-Feb-2012
pod2html("--podpath=.",
"--podroot=$topPerlDir",
"--htmldir=$htmlrootdir",
"--recurse",
"--infile=$file",
"--outfile=$outfile",
$verbopts,
);
}
else {
# Cut out "PDL" from the podpath as it crashes the podscan(!) - It doesn't
# seem to help either -- it looks for cached docs in .../HtmlDocs/pdl/PDL,
# which is silly. I left this note because pod paths are pretty arcane to
# me. CED 11-Mar-2009
# pod2html("--podpath=PDL:.",
pod2html("--podpath=.",
"--podroot=$topPerlDir",
"--htmldir=$htmlrootdir",
"--libpods=perlfaq",
"--recurse",
"--infile=$file",
"--outfile=$outfile",
$verbopts,
);
}
hack_html( $outfile ) if $] < 5.006;
fix_pdl_dot_html( $outfile);
fix_html_path( $outfile);
fix_pp_inline( $outfile);
chdir $File::Find::dir; # don't confuse File::Find
};
#File::Find::find($sub,$startdir,File::Spec->catdir( $startdir, $updir, "PDL.pm"));
File::Find::find( $sub, $startdir, "${startdir}/../PDL.pm" );
## End
|