2 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # prints a manpage to stdout
6 my $xapmsg = 'See https://xapian.org/ for more information on Xapian';
7 my $usage = "$0 /path/to/manpage.SECTION.txt";
8 my $manpage = shift or die $usage;
9 my $MAN = $ENV{MAN} || 'man';
11 $manpage = (split('/', $manpage))[-1];
12 $manpage =~ s/\.txt\z//;
13 $manpage =~ s/\A\.//; # no leading dot (see Documentation/include.mk)
14 $manpage =~ s/\.(\d+.*)\z// and push @args, $1; # section
17 # don't use UTF-8 characters which readers may not have fonts for
18 $ENV{LC_ALL} = $ENV{LANG} = 'C';
19 $ENV{COLUMNS} = '76'; # same as pod2text default
21 my $cmd = join(' ', $MAN, @args);
22 system($MAN, @args) and die "$cmd failed: $!\n";
23 $manpage =~ /\A(?:copydatabase|xapian-compact)\z/ and
24 print "\n\n", $xapmsg, "\n";
26 # touch -r $(man -w $section $manpage) output.txt
28 open(my $fh, '-|', $MAN, '-w', @args) or die "$MAN -w broken?: $!\n";
29 chomp(my $path = <$fh>);
30 my @st = stat($path) or die "stat($path) failed: $!\n";
32 utime($st[9], $st[9], \*STDOUT) or die "utime(STDOUT) failed: $!\n";