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

tail: retire -h flag #654

Merged
merged 1 commit into from
Jun 15, 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
41 changes: 18 additions & 23 deletions bin/tail
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ use Getopt::Long; # because of some special handling on numeric options
use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

use vars qw($opt_b $opt_c $opt_f $opt_h $opt_n $opt_r);
use vars qw($opt_b $opt_c $opt_f $opt_n $opt_r);

my $me = basename $0;

sub usage($;$)
sub usage
{
print STDERR "$_[1]\n" if $_[1];
my $msg = shift;
print STDERR "$msg\n" if defined $msg;
print STDERR <<EOF;
Usage:
tail [-f | -r] [-h] [-b number | -c number | -n number | [-+]number]
tail [-f | -r] [-b number | -c number | -n number | [-+]number]
[file ...]
xtail [-h] file ...
xtail file ...
EOF
exit $_[0];
exit EX_FAILURE;
}

# Maybe I should use stat() to retrieve the block size ? But the BSD man
Expand All @@ -64,7 +65,7 @@ sub check_number($)
} elsif ($opt =~ m/\A\-?(\d+)\Z/) {
return -($1+0);
} else {
usage(EX_FAILURE, "invalid number '$opt'");
usage("invalid number '$opt'");
}
}

Expand Down Expand Up @@ -95,36 +96,34 @@ sub parse_args()
my $point=-10;
my $type="n"; # one of "b", "c" or "n"

# If called as xtail, then no option is used except -h
# If called as xtail, then no option is used
if ($me eq "xtail") {

GetOptions('h') or usage(EX_FAILURE);
usage(EX_SUCCESS) if $opt_h;
GetOptions('') or usage();

} else {

@ARGV = new_argv();
Getopt::Long::config('bundling');
GetOptions("b=s", "c=s", "f", "h", "n=s", "r") or usage(EX_FAILURE);
usage(EX_SUCCESS) if $opt_h;
usage(EX_FAILURE, '-f and -r cannot be used together')
GetOptions("b=s", "c=s", "f", "n=s", "r") or usage();
usage('-f and -r cannot be used together')
if $opt_f and $opt_r;

if (defined $opt_b) {
usage(EX_FAILURE) if (defined($opt_c) || defined($opt_n));
usage() if (defined($opt_c) || defined($opt_n));
$point = check_number($opt_b);
$type = 'b';
} elsif (defined $opt_c) {
usage(EX_FAILURE) if (defined($opt_b) || defined($opt_n));
usage() if (defined($opt_b) || defined($opt_n));
$point = check_number($opt_c);
$type = 'c';
} elsif (defined $opt_n) {
usage(EX_FAILURE) if (defined($opt_b) || defined($opt_c));
usage() if (defined($opt_b) || defined($opt_c));
$point = check_number($opt_n);
$type = 'n';
}

usage(EX_FAILURE, 'The number cannot be zero') if $point == 0;
usage('The number cannot be zero') if $point == 0;
}

$files = [ @ARGV ];
Expand Down Expand Up @@ -458,7 +457,7 @@ xtail - watch the growth of files
tail [B<-f> | B<-r>] [B<-b number> | B<-c number> | B<-n number> |
B<[-+]number>] [B<file>...]

xtail [B<-h>] file ...
xtail file ...

=head1 DESCRIPTION

Expand Down Expand Up @@ -491,7 +490,7 @@ An interrupt character (usually CTRL/C or DEL) will display a list of
the most recently modified files being watched. Send a quit signal
(usually CTRL/backslash) to stop the program.

The options are the following for I<tail> (only the B<-h> option is
The options are the following for I<tail> (no options are
supported by I<xtail>) :

=over 4
Expand All @@ -514,10 +513,6 @@ reset its position back to the beginning. This makes I<tail> more useful
for watching log files that may get rotated. The B<-f> option is
ignored if the standard input is a pipe, but not if it is a FIFO.

=item B<-h>

Displays a short usage message.

=item B<-n> number

The location is B<number> lines.
Expand Down
Loading