Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Anomaly in "getopts" in 3.1.0 (possibly earlier)
- X-seq: zsh-workers 3590
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Re: Anomaly in "getopts" in 3.1.0 (possibly earlier)
- Date: Wed, 29 Oct 1997 13:41:19 +0100
- In-reply-to: "Colm Buckley"'s message of "Mon, 30 Dec 1996 12:59:14 MET." <199612301259.MAA03125@xxxxxxxxxxxxxxxxx>
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@xxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author