Dave Ewart <[email protected]> writes:
> Seeking help with this bug via
> http://sourceforge.net/mailarchive/message.php?msg_id=29298774
>From the three scenarios, 1 and 3 has non-option command line arguments,
option 2 does not. It seems to me that the condition could be the
presence of non-option command line arguments. If there's any, it's
either case 1 or 3, otherwise it is 2.
However, for this to work, you need to check if there are any non-option
arguments, which would be passed down to diff. A simple case would be to
discard options beginning with a '-' (but if there is a '--' in itself,
everything is a file after that), and live happily ever after.
This obviously has the downside of accepting any kind of option that
diff wouldn't, and not fail until diff is called (if called at all),
which makes the behaviour slightly different in these two cases. I don't
think this matters much, though.
A simple function to do just this would look something like:
sub check_for_files {
my $nonopts = 0;
my $ddash = 0;
while (my $arg = shift) {
if ($arg eq "--") {
$ddash = 1;
next;
}
if ($ddash) {
$nonopts++;
next;
}
if ($arg !~ /^-/) {
$nonopts++;
}
}
return $nonopts;
}
This will return 0 if there are no file arguments, a positive number
otherwise.
Then you can do something along these lines:
if (check_for_files (@ARGV)) {
# we have files specified, run diff!
} else {
# no files, use stdin
}
Hope this helps!
--
|8]
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]