Skip to content

Commit

Permalink
Merge pull request #309 from mknos/cmp-skipnum
Browse files Browse the repository at this point in the history
cmp: read hex input with hex()
  • Loading branch information
briandfoy authored Nov 3, 2023
2 parents 17f109a + c42f5c8 commit 5f2bfba
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions bin/cmp
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,8 @@ if ($stat1[ST_SIZE] == 0 || $stat2[ST_SIZE] == 0) {
}
}

if (@ARGV) {
$skip1 = shift;
usage() unless $skip1 =~ /^(0x[A-F\d]+|\d+)$/; # exits;
}

if (@ARGV) {
$skip2 = shift;
usage() unless $skip2 =~ /^(0x[A-F\d]+|\d+)$/; # exits;
}

$skip1 = eval "$skip1" if defined $skip1;
$skip2 = eval "$skip2" if defined $skip2;
$skip1 = skipnum(shift) if @ARGV;
$skip2 = skipnum(shift) if @ARGV;

if( -d $file1 ) {
warn( "$Program: $file1 is a directory\n" );
Expand Down Expand Up @@ -201,6 +191,14 @@ close FILE2;

exit $saw_difference;

sub skipnum {
my $n = shift;
return hex($n) if ($n =~ m/\A0x/);
return int($n) if ($n =~ m/\A[0-9]+\z/);
warn "$Program: invalid offset number '$n'\n";
usage();
}

sub usage {
warn "usage: $Program [-l] [-s] file1 file2 [skip1 [skip2]]\n";
exit EX_USAGE;
Expand Down

0 comments on commit 5f2bfba

Please sign in to comment.