4 # Combine generated html page with GNU boilerplate.
13 die "Usage: $0 [--quiet] [--stdout]\n"
14 unless GetOptions \%opts, qw(quiet stdout) and !@ARGV;
18 # Fetch GNU boilerplate
20 my $url = 'http://www.gnu.org/server/standards/boilerplate-source.html';
22 open my $b, '-|', 'curl', '-sL', $url or die "curl: $!";
24 ($url) = $boilerplate =~ /<meta\s+http-equiv=["']?refresh["']?\s+
25 content=["']\d+;\s+url=["']?(http[^"'>]*)/xi;
30 s#\$Revision:\s+(\S+)\s+\$#$1#;
31 s#<!-- This is the template document.*?-->\s+##s;
32 s#<!-- Instructions for adapting.*?-->\s*(<!-- \d+\. .*?-->\s*)*##s;
33 s#<title>Baz\s+(- GNU Project)#<title>help2man $1#s;
34 s#<h2>GNU\sBaz</h2>.*(</div><!--\s+for\s+id="content")#%body%$1#s;
37 my ($header, $footer) = split /%body%/, $boilerplate;
38 die "can't parse boilerplate" unless $footer;
40 # Generate manual from texinfo
41 my $texi_tmp = File::Temp->new();
42 system 'makeinfo', '--html', '--no-number-sections', '--no-headers',
43 '--no-split', '--output=' . $texi_tmp->filename, 'help2man.texi';
45 my $gnu_standards = "http://www.gnu.org/prep/standards/standards.html";
46 my $body = <$texi_tmp>;
53 s#<a\s+href="standards\.html#<a href="$gnu_standards#g;
54 s#<a\s+href="\*manpages\*\.html\#perlre"
55 #<a href="http://perldoc.perl.org/perlre.html"#xg;
57 # Drop heading sizes by one, as h1 is quite loud.
58 s#<(/?)h(\d)\b#"<${1}h" . ($2 + 1)#ge;
72 $target =~ s/\.PL$// or die "$0: can't determine target name\n";
73 $tmp = "$target.tmp$$";
74 unlink $tmp or die "$0: can't unlink $tmp ($!)\n" if -e $tmp;
75 open OUT, ">$tmp" or die "$0: can't create $tmp ($!)\n";
78 print "Extracting $target (with GNU boilerplate)\n"
81 print OUT $header, $body, $footer;
83 # Fix output file permissions
84 unless ($opts{stdout})
87 rename $tmp, $target or die "$0: can't rename $tmp to $target ($!)\n";
88 chmod 0444, $target or warn "$0: can't change mode of $target ($!)\n";