-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not depend on non-core Perl modules #361
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,14 @@ | |
use FindBin qw( $Bin ); | ||
|
||
use File::Path qw( mkpath ); | ||
use File::Slurp qw( edit_file read_file ); | ||
use File::Which qw( which ); | ||
|
||
sub main { | ||
my $target = shift || "$Bin/.."; | ||
|
||
my @translators = qw ( lowdown pandoc ); | ||
my $translator; | ||
foreach my $p (@translators) { | ||
if ( defined which($p) ) { | ||
if ( _which($p) ) { | ||
$translator = $p; | ||
last; | ||
} | ||
|
@@ -32,6 +30,14 @@ sub main { | |
_make_man( $translator, $target, 'mmdblookup', 1 ); | ||
} | ||
|
||
sub _which { | ||
my $program = shift; | ||
for my $path ( split /:/, $ENV{PATH} ) { | ||
return 1 if -x "$path/$program"; | ||
} | ||
return 0; | ||
} | ||
|
||
sub _make_man { | ||
my $translator = shift; | ||
my $target = shift; | ||
|
@@ -53,7 +59,7 @@ sub _make_man { | |
'-M', "section:$section", | ||
$input, | ||
'-o', $output, | ||
) == 0 or die "Failed to run pandoc: $!"; | ||
) == 0 or die "Failed to run pandoc: $?"; | ||
_pandoc_postprocess($output); | ||
} | ||
elsif ( $translator eq 'lowdown' ) { | ||
|
@@ -66,14 +72,21 @@ sub _make_man { | |
'-M', "section:$section", | ||
$input, | ||
'-o', $output, | ||
) == 0 or die "Failed to run lowdown: $!"; | ||
) == 0 or die "Failed to run lowdown: $?"; | ||
} | ||
} | ||
|
||
sub _make_lib_man_links { | ||
my $target = shift; | ||
|
||
my $header = read_file("$Bin/../include/maxminddb.h"); | ||
open my $header_fh, '<', "$Bin/../include/maxminddb.h" | ||
or die "Failed to open header file: $!"; | ||
my $header = do { local $/; <$header_fh> }; | ||
|
||
die "Error reading file header file: $!" unless defined $header; | ||
|
||
close $header_fh or die "Failed to close header file: $!"; | ||
|
||
for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) { | ||
open my $fh, '>', "$target/man/man3/$proto.3" | ||
or die "Failed to open file: $!"; | ||
|
@@ -88,13 +101,20 @@ sub _make_lib_man_links { | |
sub _pandoc_postprocess { | ||
my $file = shift; | ||
|
||
edit_file( | ||
sub { | ||
s/^\.IP\n\.nf/.IP "" 4\n.nf/gm; | ||
s/(Automatically generated by Pandoc)(.+)$/$1/m; | ||
}, | ||
$file, | ||
); | ||
open my $fh, '<', $file or die "Failed to open man file for reading: $!"; | ||
my @lines = <$fh>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, although it's less clear to me how to error check in this case. |
||
die "Error when reading man page: $!" if $!; | ||
|
||
close $fh or die "Failed to close file: $!"; | ||
|
||
for my $line (@lines) { | ||
$line =~ s/^\.IP\n\.nf/.IP "" 4\n.nf/gm; | ||
$line =~ s/(Automatically generated by Pandoc)(.+)$/$1/m; | ||
} | ||
|
||
open $fh, '>', $file or die "Failed to open file for writing: $!"; | ||
print $fh @lines or die "Failed to write to file: $!"; | ||
close $fh or die "Failed to close file: $!"; | ||
} | ||
|
||
main(shift); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to error check the read? I think I've used
if defined $header
in the past.