summaryrefslogtreecommitdiff
path: root/Build/mdwn2man
blob: 171218db035b5f441fff320cdadd53cd0e92f741 (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
57
58
#!/usr/bin/env perl
# Warning: hack

my $prog=shift;
$prog=~s/\.\d+$//;
$prog=~s/man\///;
my $section=shift;

print ".TH $prog $section\n";

while (<>) {
	s{(\\?)\[\[([^\s\|\]]+)(\|[^\s\]]+)?\]\]}{$1 ? "[[$2]]" : $2}eg;
	s/\`([^\`]*)\`/\\fB$1\\fP/g;
	s/\`//g;
	s/^\s*\./\\&./g;
	if (/^#\s/) {
		s/^#\s/.SH /;
		<>; # blank;
	}
	s/^[ \n]+//;
	s/^\t/ /;
	s/-/\\-/g;
	s/git\\-annex/git-annex/g;
	s/^Warning:.*//g;
	s/^$/.PP\n/;
	s/^\*\s+(.*)/.IP "$1"/;
	next if $_ eq ".PP\n" && $skippara;
	if (/^.IP /) {
		$inlist=1;
		$spippara=0;
	}
	elsif (/^.SH/) {
		$skippara=0;
		$inlist=0;
	}
	elsif (/^\./) {
		$skippara=1;
	}
	else {
		$skippara=0;
	}
	if ($inlist && $_ eq ".PP\n") {
		$_=".IP\n";
	}

	if ($inNAME) {
		# make lexgrog happy
		s/^git-annex (\w)/git-annex-$1/;
	}
	if ($_ eq ".SH NAME\n") {
		$inNAME=1;
	}
	else {
		$inNAME=0;
	}

	print $_;
}