~ubuntu-manpage-repository-dev/ubuntu-manpage-repository/trunk

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
#!/usr/bin/perl

##############################################################################
# This is the Ubuntu manpage repository generator and interface.
# 
# Copyright (C) 2008 Canonical Ltd.
# 
# This code was originally written by Dustin Kirkland <kirkland@ubuntu.com>,
# based on a framework by Kees Cook <kees@ubuntu.com>.
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
# On Debian-based systems, the complete text of the GNU General Public
# License can be found in /usr/share/common-licenses/GPL-3
##############################################################################

use warnings;
use strict;
use CGI qw/escapeHTML/;

my @stdin = <STDIN>;
shift(@stdin);
shift(@stdin);
my $title = escapeHTML($stdin[1]);

for (my $i=0; $i<@stdin; $i++) {
	$stdin[$i] =~ s/</&lt;/g;
# The following line would ideally be used instead, however it seems
# to be too greedy with its escaping...
#	$stdin[$i] =~ escapeHTML($stdin[$i]);
	$stdin[$i] =~ s/^([A-Z].+)\n+/<\/pre><h3>$1<\/h3><pre>/g;
	$stdin[$i] =~ s/\s([^\s]+)\(([1-9])\)/ <a href=\"..\/man$2\/$1.$2.html\">$1($2)<\/a>/g;
	$stdin[$i] =~ s/\s[<]?([a-zA-Z]+):\/\/([^\s>]+)[>]?/ <a href=\"$1:\/\/$2\">$1:\/\/$2<\/a>/g;
	$stdin[$i] =~ s/\xe2\x94\xe2\x94\x82/|/g;		# pipe
	$stdin[$i] =~ s/\xe2\x80\xe2\x80\x98/&#8216;/g; 	# left quote
        $stdin[$i] =~ s/\xe2\x80\xe2\x80\x99/&#8217;/g;		# right quote
	if ($i>0 && $stdin[$i] =~ /^\s*<\/pre>/) {
		# Remove blank lines preceding a line starting with </pre>
		if ($stdin[$i-1] =~ /^\s*$/) {
			splice(@stdin, $i-1, 1);
			$i--;
		}
	}
}

my $pkg = $ARGV[0];
my $src_pkg = $ARGV[2];
my $bin_pkg = $pkg;
$bin_pkg =~ s/_.*$//g;
my $pkg_link = "https://launchpad.net/ubuntu/" . $ARGV[1] . "/+package/" . $bin_pkg;
my $bug_link = "https://bugs.launchpad.net/ubuntu/+source/" . $src_pkg . "/+filebug-advanced";

unshift(@stdin, '<!--#include virtual="/above2.html" -->Provided by: <a href="' . $pkg_link . '">' . $pkg . '</a> <a href="' . $bug_link . '" title="Report a bug in the content of this documentation"><img src="/img/bug.png" alt="bug" border=0></a><pre>');
unshift(@stdin, $title);
unshift(@stdin, '<!--#include virtual="/above1.html" -->');
push(@stdin, '</pre><!--#include virtual="/below.html" -->');

print("@stdin");