zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Non-patch: Option arguments
Date: Tue, 27 Aug 2002 11:48:06 +0100	[thread overview]
Message-ID: <22562.1030445286@csr.com> (raw)

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


             reply	other threads:[~2002-08-27 10:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-27 10:48 Peter Stephenson [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22562.1030445286@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).