Skip to content
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

what: exit(0) only for match #754

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions bin/what
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ use strict;

use Getopt::Std qw(getopts);

my $matches = 0;
my %opt;
getopts('s', \%opt) or usage();
@ARGV or usage();

for my $file (@ARGV)
{
open(FILE, '<', $file) or die "Unable to read $file: $!";
printWhat(\*FILE, $file, $opt{'s'});
close FILE;
my $fh;
unless (open $fh, '<', $file) {
warn "Unable to open '$file': $!\n";
last;
}
printWhat($fh, $file, $opt{'s'});
close $fh;
}
exit ($matches ? 0 : 1);

#### read open file and print "what" statements...
#### pass in file handle, file name, and whether to stop printing after 1st "what"
Expand All @@ -38,6 +44,7 @@ sub printWhat
while (defined($line = <$file_handle>))
{
next unless $line =~ m/\@\(#\)/;
$matches++;

if ($line =~ m/\0/) ## there may be more than 1 in here
{
Expand Down Expand Up @@ -68,8 +75,6 @@ sub usage {
Pod::Usage::pod2usage({ -exitval => 1, -verbose => 0 });
}

exit;

__END__

=pod
Expand All @@ -95,6 +100,11 @@ pattern in your file and you are set.

B<->B<s> Stop after the first occurrence of the pattern.

=head1 EXIT STATUS

The what utility exits with status of 0 if any version information was found,
or with a status of 1 otherwise.

=head1 ENVIRONMENT

The working of B<what> is not influenced by any environment variables.
Expand Down
Loading