This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add probe for strnlen
[metaconfig.git] / bin / metagrep
CommitLineData
6092c506 1#!/usr/bin/perl
f83b5b07
MB
2
3use strict;
4use warnings;
5
6use Getopt::Long qw(:config bundling nopermute passthrough);
459d3fb5 7my $opt_l = 0;
f83b5b07 8my $opt_w = 0;
0d4505f5 9my $opt_F = 0;
f83b5b07 10GetOptions (
459d3fb5
MBT
11 "w|word!" => \$opt_w,
12 "l|list!" => \$opt_l,
0d4505f5
AC
13 "F|fixed!" => \$opt_F,
14 ) or die "usage: metagrep [-w] [-l] [-F] pattern\n";
f83b5b07 15
a8ae8817 16use Cwd qw(getcwd);
f83b5b07 17use File::Find;
a8ae8817 18use FindBin;
f83b5b07
MB
19
20my $pat = shift or die "usage: metagrep pattern\n";
0d4505f5 21$opt_F and $pat = quotemeta $pat;
f83b5b07
MB
22$opt_w and $pat = "\\b$pat\\b";
23$pat = qr/$pat/i;
24
f6353537 25my $cwd = getcwd;
a8ae8817 26my $mcpath = "$FindBin::Bin/../";
f6353537
MB
27my $onmeta = $cwd =~ m{CPAN/meta[^/]+$} ? 1 : 0;
28
459d3fb5 29my @dir = ($mcpath, "$mcpath/dist/U");
f83b5b07
MB
30my %dir; # I don't want a file for which any path component symlinks
31find (sub {
32 -l and return;
33 -d and $dir{$File::Find::name}++;
459d3fb5 34 }, @dir);
f83b5b07
MB
35
36print STDERR "<$pat>\n";
459d3fb5 37my %seen;
f83b5b07
MB
38find (sub {
39 -l and return;
40 -f or return;
41 m/\.U$/ or return;
42
43 exists $dir{$File::Find::dir} or return;
44 #print STDERR "$File::Find::dir - $_\n";
45
f8ed6dd4
MBT
46 $seen{$File::Find::name}++ and return;
47
459d3fb5
MBT
48 $File::Find::dir =~ m{^(?:$cwd/)?dist-3} and return;
49
f83b5b07 50 open my $f, "<$_" or die "$File::Find::name: $!\n";
f6353537
MB
51 my $fnm = $File::Find::name;
52 $fnm =~ s{^$cwd/}{};
459d3fb5
MBT
53 for (grep /$pat/, <$f>) {
54 if ($opt_l) {
f8ed6dd4
MBT
55 print "$fnm\n";
56 return;
459d3fb5
MBT
57 }
58 print "$fnm:$_";
59 }
60 }, @dir);