zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: Anomaly in "getopts" in 3.1.0 (possibly earlier)
Date: Wed, 29 Oct 1997 13:41:19 +0100	[thread overview]
Message-ID: <199710291241.NAA13919@hydra.ifh.de> (raw)
In-Reply-To: "Colm Buckley"'s message of "Mon, 30 Dec 1996 12:59:14 MET." <199612301259.MAA03125@picasso.cs.tcd.ie>

This finally fixes this old bug.

Colm Buckley wrote:
> I don't know if this has been pointed out before, but 3.1.0 is
> exhibiting slightly anomalous behaviour in "getopts".  It seems that a
> leading "+" sign is ignored for the last option in the list, if further
> arguments follow - the following should demonstrate the problem...
> 
> vangogh % cat test.zsh
> #!/usr/local/bin/zsh
> # Test script to demonstrate "getopts"
> 
> while getopts ":abc" opt ; do
>   echo "Option is : $opt"
> done
> shift ((--OPTIND))
> echo Remaining arguments are : $@
>
> vangogh % test.zsh +a +b
> Option is : +a
> Option is : +b
> Remaining arguments are :
> vangogh % test.zsh +a +b hello
> Option is : +a
> Option is : b
> Remaining arguments are : hello

*** Src/builtin.c.plus	Fri Sep 26 17:38:55 1997
--- Src/builtin.c	Wed Oct 29 12:27:41 1997
***************
*** 2362,2368 ****
  int
  bin_getopts(char *name, char **argv, char *ops, int func)
  {
!     int lenstr, lenoptstr, i;
      char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
      char **args = (*argv) ? argv : pparams;
      static int optcind = 1, quiet;
--- 2362,2368 ----
  int
  bin_getopts(char *name, char **argv, char *ops, int func)
  {
!     int lenstr, lenoptstr, i, plus;
      char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
      char **args = (*argv) ? argv : pparams;
      static int optcind = 1, quiet;
***************
*** 2399,2404 ****
--- 2399,2405 ----
      if (!optcind)
  	optcind = 1;
      *opch = str[optcind++];
+     plus = (*str == '+');
      if (optcind == lenstr) {
  	if(args[zoptind++])
  	    str = unmetafy(args[zoptind - 1], &lenstr);
***************
*** 2421,2427 ****
  	return 0;
      }
      /* copy option into specified parameter, with + if required */
!     setsparam(var, metafy(opch - (*str == '+'), 1 + (*str == '+'), META_DUP));
      /* handle case of an expected extra argument */
      if (optstr[i + 1] == ':') {
  	if (!args[zoptind - 1]) {
--- 2422,2428 ----
  	return 0;
      }
      /* copy option into specified parameter, with + if required */
!     setsparam(var, metafy(opch - plus, 1 + plus, META_DUP));
      /* handle case of an expected extra argument */
      if (optstr[i + 1] == ':') {
  	if (!args[zoptind - 1]) {

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


      reply	other threads:[~1997-10-29 12:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-12-30 12:59 Colm Buckley
1997-10-29 12:41 ` Peter Stephenson [this message]

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=199710291241.NAA13919@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).