@@ -172,7 +172,19 @@ sub _compile_file_filter {
172172 }
173173 }
174174
175+ my $match_filenames = $opt -> {g };
176+ my $match_regex = $opt -> {regex };
177+ my $is_inverted = $opt -> {v };
178+
175179 return sub {
180+ if ( $match_filenames ) {
181+ if ( $File::Next::name =~ / $match_regex / && $is_inverted ) {
182+ return ;
183+ }
184+ if ( $File::Next::name !~ / $match_regex / && !$is_inverted ) {
185+ return ;
186+ }
187+ }
176188 # ack always selects files that are specified on the command
177189 # line, regardless of filetype. If you want to ack a JPEG,
178190 # and say "ack foo whatever.jpg" it will do it for you.
@@ -307,8 +319,11 @@ sub build_regex {
307319
308320 $str = quotemeta ( $str ) if $opt -> {Q };
309321 if ( $opt -> {w } ) {
310- $str = " \\ b$str " if $str =~ / ^\w / ;
311- $str = " $str \\ b" if $str =~ / \w $ / ;
322+ my $pristine_str = $str ;
323+
324+ $str = " (?:$str )" ;
325+ $str = " \\ b$str " if $pristine_str =~ / ^\w / ;
326+ $str = " $str \\ b" if $pristine_str =~ / \w $ / ;
312327 }
313328
314329 my $regex_is_lc = $str eq lc $str ;
@@ -803,14 +818,24 @@ sub resource_has_match {
803818 }
804819 }
805820 else {
806- my $opt_v = $opt -> {v };
807- my $re = $opt -> {regex };
808- while ( <$fh > ) {
809- if (/ $re /o xor $opt_v ) {
810- $has_match = 1;
811- last ;
821+ my $re = $opt -> {regex };
822+ if ( $opt -> {v } ) {
823+ while ( <$fh > ) {
824+ if (!/$re /o) {
825+ $has_match = 1;
826+ last ;
827+ }
812828 }
813829 }
830+ else {
831+ # XXX read in chunks
832+ # XXX only do this for certain file sizes?
833+ my $content = do {
834+ local $/ ;
835+ <$fh >;
836+ };
837+ $has_match = $content =~ / $re /og ;
838+ }
814839 close $fh ;
815840 }
816841
@@ -828,10 +853,18 @@ sub count_matches_in_resource {
828853 }
829854 }
830855 else {
831- my $opt_v = $opt -> {v };
832- my $re = $opt -> {regex };
833- while ( <$fh > ) {
834- ++$nmatches if (/ $re /o xor $opt_v );
856+ my $re = $opt -> {regex };
857+ if ( $opt -> {v } ) {
858+ while ( <$fh > ) {
859+ ++$nmatches if (!/$re /o);
860+ }
861+ }
862+ else {
863+ my $content = do {
864+ local $/ ;
865+ <$fh >;
866+ };
867+ $nmatches =()= ($content =~ / $re /og );
835868 }
836869 close $fh ;
837870 }
@@ -942,19 +975,16 @@ RESOURCES:
942975 last RESOURCES if defined ($max_count ) && $nmatches >= $max_count ;
943976 }
944977 elsif ( $opt -> {g } ) {
945- my $is_match = ( $resource -> name =~ / $opt ->{regex}/o );
946- if ( $opt -> {v } ? !$is_match : $is_match ) {
947- if ( $opt -> {show_types } ) {
948- show_types( $resource , $ors );
949- }
950- else {
951- local $opt -> {show_filename } = 0; # XXX Why is this local?
978+ if ( $opt -> {show_types } ) {
979+ show_types( $resource , $ors );
980+ }
981+ else {
982+ local $opt -> {show_filename } = 0; # XXX Why is this local?
952983
953- print_line_with_options($opt , ' ' , $resource -> name, 0, $ors );
954- }
955- ++$nmatches ;
956- last RESOURCES if defined ($max_count ) && $nmatches >= $max_count ;
984+ print_line_with_options($opt , ' ' , $resource -> name, 0, $ors );
957985 }
986+ ++$nmatches ;
987+ last RESOURCES if defined ($max_count ) && $nmatches >= $max_count ;
958988 }
959989 elsif ( $opt -> {lines } ) {
960990 my $print_filename = $opt -> {show_filename };
@@ -1670,6 +1700,27 @@ If you are not on Windows, you never need to use C<ACK_PAGER_COLOR>.
16701700
16711701=back
16721702
1703+ =head1 AVAILABLE COLORS
1704+
1705+ F<ack> uses the colors available in Perl's L<Term::ANSIColor> module, which
1706+ provides the following listed values. Note that case does not matter when using
1707+ these values.
1708+
1709+ =head2 Foreground colors
1710+
1711+ black red green yellow blue magenta cyan white
1712+
1713+ bright_black bright_red bright_green bright_yellow
1714+ bright_blue bright_magenta bright_cyan bright_white
1715+
1716+ =head2 Background colors
1717+
1718+ on_black on_red on_green on_yellow
1719+ on_blue on_magenta on_cyan on_white
1720+
1721+ on_bright_black on_bright_red on_bright_green on_bright_yellow
1722+ on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
1723+
16731724=head1 ACK & OTHER TOOLS
16741725
16751726=head2 Vim integration
@@ -2183,6 +2234,9 @@ L<https://github.com/petdance/ack2>
21832234How appropriate to have I<ack > nowledgements!
21842235
21852236Thanks to everyone who has contributed to ack in any way, including
2237+ Stephen Thirlwall,
2238+ Jonah Bishop,
2239+ Chris Rebert,
21862240Denis Howe,
21872241RaE<uacute> l GundE<iacute> n,
21882242James McCoy,
0 commit comments