[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposed improvement of diagnostics for missing/extra operands
From: |
Jim Meyering |
Subject: |
Re: proposed improvement of diagnostics for missing/extra operands |
Date: |
Mon, 21 Jun 2004 17:36:36 +0200 |
Paul Eggert <address@hidden> wrote:
>> I have mixed feelings about it.
>
> OK, some good points there, and I've composed a revised patch (below)
> which I hope addresses almost all the problems you mentioned. The
> only exception is the last problem (when getopt reorders arguments),
> which I'll discuss below.
Thanks for adjusting those.
>> Going a little overboard, it can get a ugly if getopt
>> ends up reordering arguments:
>>
>> new$ ./mv a --force
>> ./mv: missing operand after `a'
>
> Here I think the new behavior is OK, since if you add the missing
> operand after the `a', things will work; and that's the most natural
> place to add the missing operand.
This seems fine. No need to go overboard :)
> Here's the revised patch:
>
> 2004-06-20 Paul Eggert <address@hidden>
>
> * src/basename.c (main):
...
Applied.
I've made only one significant change so far:
2004-06-21 Jim Meyering <address@hidden>
* src/mknod.c (main): Don't segfault when calculating the
expected number of operands for `mknod NAME'.
Index: mknod.c
===================================================================
RCS file: /fetish/cu/src/mknod.c,v
retrieving revision 1.80
diff -u -p -r1.80 mknod.c
--- mknod.c 21 Jun 2004 15:03:35 -0000 1.80
+++ mknod.c 21 Jun 2004 15:27:17 -0000
@@ -132,7 +132,12 @@ main (int argc, char **argv)
newmode = mode_adjust (newmode, change);
}
- expected_operands = (argv[optind + 1][0] == 'p' ? 2 : 4);
+ /* If the number of arguments is 0 or 1,
+ or (if it's 2 or more and the second one starts with `p'), then there
+ must be exactly two operands. Otherwise, there must be four. */
+ expected_operands = (argc <= optind
+ || (optind + 1 < argc && argv[optind + 1][0] == 'p')
+ ? 2 : 4);
if (argc - optind < expected_operands)
{