diff --git a/bin/ar b/bin/ar index eafd1974..c52341b5 100755 --- a/bin/ar +++ b/bin/ar @@ -11,6 +11,8 @@ License: perl =cut +use strict; + use POSIX qw(strftime); use File::Basename; use FileHandle; @@ -18,15 +20,18 @@ use Getopt::Std qw(getopts); use constant MAGIC => "!\n"; +use vars qw($opt_d $opt_m $opt_p $opt_q $opt_r $opt_t $opt_x $opt_a $opt_b + $opt_c $opt_i $opt_o $opt_u $opt_v); + # allow the first arg to not have a '-'. -if ($ARGV[0] !~ /^\-/) { $ARGV[0] = '-' . $ARGV[0]; } +if (@ARGV && $ARGV[0] !~ /^\-/) { $ARGV[0] = '-' . $ARGV[0]; } getopts('dmpqrtxabciouv') or usage(); # take only one of the following major opts -if (($opt_d + $opt_m + $opt_p + $opt_q + $opt_r + $opt_t + $opt_x) != 1) { - usage(); -} +my @major = map { $_ || () } ($opt_d, $opt_m, $opt_p, $opt_q, $opt_r, + $opt_t, $opt_x); +usage() unless scalar(@major) == 1; # -i is the same as -b $opt_b |= $opt_i;