3 # Combine generated html page with GNU boilerplate.
5 # Copyright (C) 2012 Free Software Foundation, Inc.
7 # Copying and distribution of this file, with or without modification,
8 # are permitted in any medium without royalty provided the copyright
9 # notice and this notice are preserved. This file is offered as-is,
10 # without any warranty.
12 # Written by Brendan O'Dea <bod@debian.org>
20 die "Usage: $0 [--quiet] [--stdout]\n"
21 unless GetOptions \%opts, qw(quiet stdout) and !@ARGV;
25 # Fetch GNU boilerplate
27 my $url = 'http://www.gnu.org/server/standards/boilerplate-source.html';
29 open my $b, '-|', 'curl', '-sL', $url or die "curl: $!";
31 ($url) = $boilerplate =~ /<meta\s+http-equiv=["']?refresh["']?\s+
32 content=["']\d+;\s+url=["']?(http[^"'>]*)/xi;
37 s#\$Revision:\s+(\S+)\s+\$#$1#;
38 s#<!-- This is the template document.*?-->\s+##s;
39 s#<!-- Instructions for adapting.*?-->\s*(<!-- \d+\. .*?-->\s*)*##s;
40 s#<title>Baz\s+(- GNU Project)#<title>help2man $1#s;
41 s#<h2>GNU\sBaz</h2>.*(</div><!--\s+for\s+id="content")#%body%$1#s;
44 my ($header, $footer) = split /%body%/, $boilerplate;
45 die "can't parse boilerplate" unless $footer;
47 # Generate manual from texinfo
48 my $texi_tmp = File::Temp->new();
49 system 'makeinfo', '--html', '--no-number-sections', '--no-headers',
50 '--no-split', '--output=' . $texi_tmp->filename, 'help2man.texi';
52 my $gnu_standards = "http://www.gnu.org/prep/standards/standards.html";
53 my $body = <$texi_tmp>;
60 s#<a\s+href="standards\.html#<a href="$gnu_standards#g;
61 s#<a\s+href="\*manpages\*\.html\#perlre"
62 #<a href="http://perldoc.perl.org/perlre.html"#xg;
64 # Drop heading sizes by one, as h1 is quite loud.
65 s#<(/?)h(\d)\b#"<${1}h" . ($2 + 1)#ge;
79 $target =~ s/\.PL$// or die "$0: can't determine target name\n";
80 $tmp = "$target.tmp$$";
81 unlink $tmp or die "$0: can't unlink $tmp ($!)\n" if -e $tmp;
82 open OUT, ">$tmp" or die "$0: can't create $tmp ($!)\n";
85 print "Extracting $target (with GNU boilerplate)\n"
88 print OUT $header, $body, $footer;
90 # Fix output file permissions
91 unless ($opts{stdout})
94 rename $tmp, $target or die "$0: can't rename $tmp to $target ($!)\n";
95 chmod 0444, $target or warn "$0: can't change mode of $target ($!)\n";