File: grepc

package info (click to toggle)
perl-tk 1%3A800.011-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 16,820 kB
  • ctags: 17,448
  • sloc: ansic: 189,575; perl: 31,426; makefile: 4,360; sh: 1,921; yacc: 762
file content (57 lines) | stat: -rwxr-xr-x 809 bytes parent folder | download
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
#!/usr/local/bin/perl 

use File::Find;
use Getopt::Std;

my %opt;
getopts("mlc",\%opt);

$expr = shift;
print "Matching '$expr'\n";


sub match
{
 if (/$expr/o)
  {
   if ($opt{'l'})
    {
     print "$File::Find::name\n";
     return 1;
    }
   $count++;
   unless ($opt{'c'})
    {
     print "$File::Find::name:$.: $_" 
    }
  }
 return 0;
}

sub wanted
{
 $File::Find::prune = 0;
 if (-T $_ && !/%$/ && /\.[ch]$/)
  {
   local $file   = ($_);
   local ($_);
   open($file,"<$file") || die "Cannot open $file:$!";
   while (<$file>)
    {
     last if &match;
    }
   close($file);
   if ($opt{'c'} && $count)
    {
     print "$File::Find::name: $count\n" 
    }
  }
 elsif (-d $_)
  {
   $File::Find::prune = 1 if ($_ eq 'mTk' && $opt{'m'});
  }
}

@ARGV = '.' unless (@ARGV);

find(\&wanted,@ARGV);