summaryrefslogtreecommitdiff
path: root/debian/installman
blob: 9384e4fb8d2d6b6cb9753cbd207c9527729645e3 (plain)
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
#!/usr/bin/perl -w
use strict;
use IO::File;

my $pkg    = shift;
my $outdir = "debian/$pkg/usr/share/man/man1";
my $USD    = "/usr/share/doc";
system("mkdir", "-p", $outdir) && die "Couldn't create $outdir";

foreach my $x (@ARGV ? @ARGV : <debian/$pkg/usr/bin/*>) {
    my $full_x = $x;
    $x =~ s:.*/::;
    my $xin = $x;
# gone as of 6.1.20040616
#     if ($x eq 'fastamerge') {
# 	$xin = 'fmerge'; # renamed in Debian per #155791
#     }
    if (-l $full_x) {
	symlink readlink($full_x) . ".1", "$outdir/$x.1";
	next;
    }
    foreach my $dir ('doc/man', 'debian/man') {
	if (-f "$dir/$xin.1") {
	    my $in  = new IO::File("<$dir/$xin.1")
		or die "Couldn't open $dir/$xin.1: $!";
	    my $out = new IO::File(">$outdir/$x.1")
		or die "Couldn't open $outdir/$x.1: $!";
	    while (<$in>) {
		# s/fmerge/fastamerge/g;
		# s/FMERGE/FASTAMERGE/g;
	        s:(\w+)/README:README.$1:g;
		while (/^(.*)(?<!\S)(README\.\w+|\w+\.txt|\w+\.html?)(.*)$/) {
		    my ($pre, $main, $post) = ($1, $2, $3);
		    my @matches = <debian/*$USD/*/$main>;
		    if (!@matches) {
			warn "[$x] $USD/*/$main not found in any package";
		    } elsif (@matches > 1) {
			warn "[$x] $USD/*/$main found in multiple packages";
		    } else {
			my $m = $matches[0];
			$m .= '.gz' if ((-s $m) > 4096  &&  $m !~ /\.html?$/);
			$m =~ s:^debian/[^/]*::;
			print $out $pre . $m;
		    }
		    # Consider just the remaining text next time,
		    # and make sure it ends with exactly one newline.
		    chomp $post;
		    $_ = "$post\n";
		}
		print $out $_;
	    }
	    last;
	}
    }
    -f "$outdir/$x.1" || warn "Unable to find a man page for $x";
}