"Fossies" - the Fresh Open Source Software Archive

Member "geoipupdate-4.3.0/dev-bin/make-man-pages.pl" (16 Apr 2020, 1192 Bytes) of package /linux/misc/geoipupdate-4.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "make-man-pages.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/env perl
    2 use strict;
    3 use warnings;
    4 
    5 use File::Temp qw( tempfile );
    6 
    7 sub main {
    8     my $build_dir = $ARGV[0] // 'build';
    9 
   10     _make_man(
   11         'geoipupdate',
   12         1,
   13         "$build_dir/geoipupdate.md",
   14         "$build_dir/geoipupdate.1",
   15     );
   16     _make_man(
   17         'GeoIP.conf',
   18         5,
   19         "$build_dir/GeoIP.conf.md",
   20         "$build_dir/GeoIP.conf.5",
   21     );
   22     return 1;
   23 }
   24 
   25 sub _make_man {
   26     my ( $name, $section, $input, $output ) = @_;
   27 
   28     my ( $fh, $tmp ) = tempfile();
   29     binmode $fh or die $!;
   30     print {$fh} "% $name($section)\n\n" or die $!;
   31     my $contents = _read($input);
   32     print {$fh} $contents or die $!;
   33     close $fh or die $!;
   34 
   35     system(
   36         'pandoc',
   37         '-s',
   38         '-f', 'markdown',
   39         '-t', 'man',
   40         $tmp,
   41         '-o', $output,
   42     ) == 0 or die 'pandoc failed';
   43 
   44     return;
   45 }
   46 
   47 sub _read {
   48     my ($file) = @_;
   49     open my $fh, '<', $file or die $!;
   50     binmode $fh or die $!;
   51     my $contents = '';
   52     while ( !eof($fh) ) {
   53         my $line = <$fh>;
   54         die 'error reading' unless defined $line;
   55         $contents .= $line;
   56     }
   57     close $fh or die $!;
   58     return $contents;
   59 }
   60 
   61 exit( main() ? 0 : 1 );