zsh-workers
 help / color / mirror / code / Atom feed
* Non-patch: Option arguments
@ 2002-08-27 10:48 Peter Stephenson
  2002-08-27 11:36 ` Oliver Kiddle
  2002-08-27 21:21 ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-08-27 10:48 UTC (permalink / raw)
  To: Zsh hackers list

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 <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-patch: Option arguments
  2002-08-27 10:48 Non-patch: Option arguments Peter Stephenson
@ 2002-08-27 11:36 ` Oliver Kiddle
  2002-08-27 16:27   ` Peter Stephenson
  2002-08-27 21:21 ` Peter Stephenson
  1 sibling, 1 reply; 6+ messages in thread
From: Oliver Kiddle @ 2002-08-27 11:36 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On 27 Aug, you wrote:

> 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.

That all sounds good.

A couple of points which you may or may not have thought of.
Will there now be an easier way for precommand modifiers to take
options. We could particularly do with this for command where a couple
of the options (-v was it) should be accepted by the posix definition
but it would also be useful in a couple of other cases for bash/ksh
compatibility (exec perhaps). I forget what the problem was previously
with this.

We may need a bit of care over how `-' and `--' options are handled.
Taking Chet Ramey's recent message on -users, I was wondering whether
printf (to take a particular example but it may be applicable to others)
should ignore an initial `--' argument.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-patch: Option arguments
  2002-08-27 11:36 ` Oliver Kiddle
@ 2002-08-27 16:27   ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-08-27 16:27 UTC (permalink / raw)
  To: Zsh hackers list

Oliver Kiddle wrote:
> A couple of points which you may or may not have thought of.
> Will there now be an easier way for precommand modifiers to take
> options. We could particularly do with this for command where a couple
> of the options (-v was it) should be accepted by the posix definition
> but it would also be useful in a couple of other cases for bash/ksh
> compatibility (exec perhaps). I forget what the problem was previously
> with this.

I think this is a different issue, but actually I'm not sure this is
that difficult.

> We may need a bit of care over how `-' and `--' options are handled.
> Taking Chet Ramey's recent message on -users, I was wondering whether
> printf (to take a particular example but it may be applicable to others)
> should ignore an initial `--' argument.

Yes, this is a bit like cd.  Various things like this will need tidying
up later.  There's no code at the moment to handle `--' even if other
arguments looking like options are being passed straight through is
arguments.

-- 
Peter Stephenson <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-patch: Option arguments
  2002-08-27 10:48 Non-patch: Option arguments Peter Stephenson
  2002-08-27 11:36 ` Oliver Kiddle
@ 2002-08-27 21:21 ` Peter Stephenson
  2002-08-27 23:58   ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2002-08-27 21:21 UTC (permalink / raw)
  To: Zsh hackers list

I wrote:	
> I've rewritten the option handling for builtins to improve the currently
> woeful handling of arguments to options.

I've now committed this.  The tests all pass (one error message changed
due to the fact that option arguments are now handled generically), but
keep a watch out for oddities.

I updated the version to 4.1.0-dev-6 owing to the fact that the
interface between the shell and builtins in modules is now different.

I haven't tackled `cd'.  It would be sensible also to add a BINF_ flag
for `skip -- but don't attempt to parse options otherwise'.

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-patch: Option arguments
  2002-08-27 21:21 ` Peter Stephenson
@ 2002-08-27 23:58   ` Bart Schaefer
  2002-08-28  9:33     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2002-08-27 23:58 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

On Aug 27, 10:21pm, Peter Stephenson wrote:
> Subject: Re: Non-patch: Option arguments
> I wrote:	
> > I've rewritten the option handling for builtins to improve the currently
> > woeful handling of arguments to options.
> 
> I've now committed this.

I was just about to ask you to tag the repository first.  Hmm, maybe I can
tag an appropriate set of revisions from my sandbox, I just updated a few
hours ago ...


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Non-patch: Option arguments
  2002-08-27 23:58   ` Bart Schaefer
@ 2002-08-28  9:33     ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-08-28  9:33 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> On Aug 27, 10:21pm, Peter Stephenson wrote:
> > I've now committed this.
> 
> I was just about to ask you to tag the repository first.  Hmm, maybe I can
> tag an appropriate set of revisions from my sandbox, I just updated a few
> hours ago ...

I think I've successfully tagged the before and after versions with
`pre-opt-arg' and `post-opt-arg'.

-- 
Peter Stephenson <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-08-28  9:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-27 10:48 Non-patch: Option arguments Peter Stephenson
2002-08-27 11:36 ` Oliver Kiddle
2002-08-27 16:27   ` Peter Stephenson
2002-08-27 21:21 ` Peter Stephenson
2002-08-27 23:58   ` Bart Schaefer
2002-08-28  9:33     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).