From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11544 invoked from network); 27 Aug 2002 10:48:44 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 27 Aug 2002 10:48:44 -0000 Received: (qmail 16811 invoked by alias); 27 Aug 2002 10:48:36 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17582 Received: (qmail 16733 invoked from network); 27 Aug 2002 10:48:35 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Non-patch: Option arguments Date: Tue, 27 Aug 2002 11:48:06 +0100 Message-ID: <22562.1030445286@csr.com> From: Peter Stephenson I've rewritten the option handling for builtins to improve the currently woeful handling of arguments to options. As I didn't see fit to maintain compatibility with the current broken form, this changes everything involving options. So the patch is huge and unless anyone screams I will commit it without posting it from home, where I've been writing it, in the next couple of days. The syntax for option arguments uses a trailing `:' for a mandatory argument, as usual, a trailing `::' for an optional argument (one which must occur in the same word or will be assumed not to be present), which seems to be how the GNU getopts library function works, and I've invented `:%' for an optional integer argument, which is different because `-i 10' and `-i10' are both allowed. Maybe someone knows some more standard conventions. I have't seen fit to provide compatibility for the following current weirdnesses: - in `read -k num', num is actually the first argument to `read', not an option argument at all (undocumented). - in print and read, -u0 can be specified as -0u, -u -0, etc. However, I have written a special case for -up (equivalent to -p) which, although undocumented, is at least half-way logical. - `fc -e' was silently allowed as meaning `fc', even though -e supposedly had a mandatory argument. - (Still to do) `cd' has non-standard option handling, so that `cd -' and `cd -3' work. However, this is probably best handled as a special case in the option parsing code rather than in cd. One current oddity is that cd is limited to two arguments including any options: % cd -P -P -P cd: too many arguments However, there is also the fact that `cd -directory' doesn't try to parse options though `cd -sPL' does. As `cd -- -directory' doesn't work at the moment, there's no way of standardizing this without creating an incompatibility. So I may quietly forget about cd for the moment. Note, however, that other shells use standard option handling with cd, so I think'll we'll have to fix it and maybe just take the hit with the (rare) case of directories beginning with a `-' working differently from now on. P.S.: I hate cd. Not addressed in this patch, but may want looking at: - Some modules advertise builtins with options which instead of normal arguments take `the first non-option argument'. Many of these might be less confusing if they were real option arguments. (This doesn't apply to `-m' pattern arguments which tend to alter the meaning of real arguments instead of the option taking an argument.) - Some commands which handle their own options may now work with standard option handling, although it's still complicated with things like `kill'. - It would not be that difficult to add handling of repeated options as a linked list, e.g. -o opt1 -o opt2 creates a linked list of strings instead of a single string for the option argument. If the option argument becomes a union, handling of integer arguments can be standardised, too (currently they get converted from a string at the point of use resulting in multiple bits of code that issue similar `this isn't an integer, idiot' error messages). - Something else I've forgotten but may remember later on. -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************