From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4041 invoked from network); 29 Oct 1997 12:59:58 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 29 Oct 1997 12:59:58 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id HAA27245; Wed, 29 Oct 1997 07:40:21 -0500 (EST) Resent-Date: Wed, 29 Oct 1997 07:40:21 -0500 (EST) Message-Id: <199710291241.NAA13919@hydra.ifh.de> To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: Re: Anomaly in "getopts" in 3.1.0 (possibly earlier) In-reply-to: "Colm Buckley"'s message of "Mon, 30 Dec 1996 12:59:14 MET." <199612301259.MAA03125@picasso.cs.tcd.ie> Date: Wed, 29 Oct 1997 13:41:19 +0100 From: Peter Stephenson Resent-Message-ID: <"FIIl1.0.ef6.rwoLq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3590 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 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.