]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/extman.perl
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / Documentation / extman.perl
1 #!/usr/bin/perl -w
2 # Copyright (C) 2019-2020 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
5 use strict;
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';
10 my @args;
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
15 push @args, $manpage;
16
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
20 $ENV{PAGER} = 'cat';
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";
25
26 # touch -r $(man -w $section $manpage) output.txt
27 if (-f \*STDOUT) {
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";
31         # 9 - mtime
32         utime($st[9], $st[9], \*STDOUT) or die "utime(STDOUT) failed: $!\n";
33 }