File: make-man-pages.pl

package info (click to toggle)
golang-github-maxmind-geoipupdate 6.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 376 kB
  • sloc: sh: 99; makefile: 57; perl: 51
file content (61 lines) | stat: -rwxr-xr-x 1,192 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl
use strict;
use warnings;

use File::Temp qw( tempfile );

sub main {
    my $build_dir = $ARGV[0] // 'build';

    _make_man(
        'geoipupdate',
        1,
        "$build_dir/geoipupdate.md",
        "$build_dir/geoipupdate.1",
    );
    _make_man(
        'GeoIP.conf',
        5,
        "$build_dir/GeoIP.conf.md",
        "$build_dir/GeoIP.conf.5",
    );
    return 1;
}

sub _make_man {
    my ( $name, $section, $input, $output ) = @_;

    my ( $fh, $tmp ) = tempfile();
    binmode $fh or die $!;
    print {$fh} "% $name($section)\n\n" or die $!;
    my $contents = _read($input);
    print {$fh} $contents or die $!;
    close $fh or die $!;

    system(
        'pandoc',
        '-s',
        '-f', 'markdown',
        '-t', 'man',
        $tmp,
        '-o', $output,
    ) == 0 or die 'pandoc failed';

    return;
}

sub _read {
    my ($file) = @_;
    open my $fh, '<', $file or die $!;
    binmode $fh or die $!;
    my $contents = '';
    while ( !eof($fh) ) {
        my $line = <$fh>;
        die 'error reading' unless defined $line;
        $contents .= $line;
    }
    close $fh or die $!;
    return $contents;
}

exit( main() ? 0 : 1 );