Skip to content

Commit a09fa4b

Browse files
committed
Do not depend on non-core Perl modules
1 parent fff8dae commit a09fa4b

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Initialize CodeQL
3535
uses: github/codeql-action/init@v3
3636

37-
- run: sudo apt install libipc-run3-perl libipc-system-simple-perl libfile-slurp-perl libfile-which-perl pandoc
37+
- run: sudo apt install libipc-run3-perl pandoc
3838
- run: |
3939
./bootstrap
4040
./configure

dev-bin/make-man-pages.pl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
use FindBin qw( $Bin );
77

88
use File::Path qw( mkpath );
9-
use File::Slurp qw( edit_file read_file );
10-
use File::Which qw( which );
119

1210
sub main {
1311
my $target = shift || "$Bin/..";
1412

1513
my @translators = qw ( lowdown pandoc );
1614
my $translator;
1715
foreach my $p (@translators) {
18-
if ( defined which($p) ) {
16+
if ( _which($p) ) {
1917
$translator = $p;
2018
last;
2119
}
@@ -32,6 +30,14 @@ sub main {
3230
_make_man( $translator, $target, 'mmdblookup', 1 );
3331
}
3432

33+
sub _which {
34+
my $program = shift;
35+
for my $path ( split /:/, $ENV{PATH} ) {
36+
return 1 if -x "$path/$program";
37+
}
38+
return 0;
39+
}
40+
3541
sub _make_man {
3642
my $translator = shift;
3743
my $target = shift;
@@ -73,7 +79,11 @@ sub _make_man {
7379
sub _make_lib_man_links {
7480
my $target = shift;
7581

76-
my $header = read_file("$Bin/../include/maxminddb.h");
82+
open my $header_fh, '<', "$Bin/../include/maxminddb.h"
83+
or die "Failed to open header file: $!";
84+
my $header = do { local $/; <$header_fh> };
85+
close $header_fh or die "Failed to close header file: $!";
86+
7787
for my $proto ( $header =~ /^ *extern.+?(MMDB_\w+)\(/gsm ) {
7888
open my $fh, '>', "$target/man/man3/$proto.3"
7989
or die "Failed to open file: $!";
@@ -88,13 +98,18 @@ sub _make_lib_man_links {
8898
sub _pandoc_postprocess {
8999
my $file = shift;
90100

91-
edit_file(
92-
sub {
93-
s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
94-
s/(Automatically generated by Pandoc)(.+)$/$1/m;
95-
},
96-
$file,
97-
);
101+
open my $fh, '<', $file or die "Failed to open man file for reading: $!";
102+
my @lines = <$fh>;
103+
close $fh or die "Failed to close file: $!";
104+
105+
for my $line (@lines) {
106+
$line =~ s/^\.IP\n\.nf/.IP "" 4\n.nf/gm;
107+
$line =~ s/(Automatically generated by Pandoc)(.+)$/$1/m;
108+
}
109+
110+
open $fh, '>', $file or die "Failed to open file for writing: $!";
111+
print $fh @lines or die "Failed to write to file: $!";
112+
close $fh or die "Failed to close file: $!";
98113
}
99114

100115
main(shift);

0 commit comments

Comments
 (0)