* PATCH: 3.1.4: getopts not reset properly for new function
@ 1998-10-06 12:18 Peter Stephenson
1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
1998-10-06 14:44 ` mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function) Geoff Wing
0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 1998-10-06 12:18 UTC (permalink / raw)
To: Zsh hackers list
There have been various getopts() patches, but this hadn't been fixed
up to the last I saw, Bernd Eggink's in
http://www.zsh.org/mla/workers/1998/msg00132.html
which looks like it hasn't appeared yet.
However, my link to www.zsh.org is awful, involving 22 hops and more
delays than Gatwick Airport, so I couldn't check for anything more
recent. We could do with a mirror north of the Equator, even if it
was only the index.
Strange, though, because it's a fairly blatant bug...
% zsh -f
% fn() { local f; while getopts abcd f; do print $f; done; }
% fn -a
a
% fn -abc
b
c
% fn -abc
%
(Workaround, if you get very frustrated in the meanwhile: finish all
options with a -:
% fn -abcd -
a
b
c
d
% fn -a -
a
% fn -abc -
a
b
c
% fn -abc -
a
b
c
.)
*** Src/builtin.c.opt Tue Oct 6 11:57:57 1998
--- Src/builtin.c Tue Oct 6 12:04:37 1998
***************
*** 2537,2542 ****
--- 2537,2545 ----
return ret;
}
+ /**/
+ int optcind;
+
/* getopts: automagical option handling for shell scripts */
/**/
***************
*** 2546,2552 ****
int lenstr, lenoptstr, quiet, lenoptbuf;
char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
char **args = (*argv) ? argv : pparams;
- static int optcind = 0;
char *str, optbuf[2], *p, opch;
/* zoptind keeps count of the current argument number. The *
--- 2549,2554 ----
*** Src/exec.c.opt Mon Sep 28 11:37:19 1998
--- Src/exec.c Tue Oct 6 12:06:13 1998
***************
*** 2654,2660 ****
* was executed. */
{
char **tab, **x, *oargv0 = NULL;
! int xexittr, newexittr, oldzoptind, oldlastval;
char *ou;
void *xexitfn, *newexitfn;
char saveopts[OPT_SIZE];
--- 2654,2660 ----
* was executed. */
{
char **tab, **x, *oargv0 = NULL;
! int xexittr, newexittr, oldzoptind, oldlastval, oldoptcind;
char *ou;
void *xexitfn, *newexitfn;
char saveopts[OPT_SIZE];
***************
*** 2673,2680 ****
--- 2673,2683 ----
sigtrapped[SIGEXIT] = 0;
sigfuncs[SIGEXIT] = NULL;
tab = pparams;
+ /* Reset getopts variables for new function */
oldzoptind = zoptind;
zoptind = 1;
+ oldoptcind = optcind;
+ optcind = 0;
/* We need to save the current options even if LOCALOPTIONS is *
* not currently set. That's because if it gets set in the *
***************
*** 2721,2726 ****
--- 2724,2730 ----
argzero = oargv0;
}
zoptind = oldzoptind;
+ optcind = oldoptcind;
pparams = tab;
if (isset(LOCALOPTIONS)) {
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: 3.1.4: getopts: forget it.
1998-10-06 12:18 PATCH: 3.1.4: getopts not reset properly for new function Peter Stephenson
@ 1998-10-06 12:45 ` Peter Stephenson
1998-10-07 3:43 ` PATCH: 3.1.4: getopts Bart Schaefer
1998-10-06 14:44 ` mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function) Geoff Wing
1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 1998-10-06 12:45 UTC (permalink / raw)
To: Zsh hackers list
I spoke too soon. Bernd's patch that I referred to does fix the
problem, only more simply, so use that. It needs merging by hand.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy
^ permalink raw reply [flat|nested] 6+ messages in thread
* mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function)
1998-10-06 12:18 PATCH: 3.1.4: getopts not reset properly for new function Peter Stephenson
1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
@ 1998-10-06 14:44 ` Geoff Wing
1 sibling, 0 replies; 6+ messages in thread
From: Geoff Wing @ 1998-10-06 14:44 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson <pws@ibmth.df.unipi.it> typed:
:There have been various getopts() patches, but this hadn't been fixed
:up to the last I saw, Bernd Eggink's in
:http://www.zsh.org/mla/workers/1998/msg00132.html
Just a reminder that you should be referencing that by its official
archive number 3797 - (from the X-Mailing-List line) and you can now
search on numbers (though from the index you might get slight
inaccuracies - e.g. too many matches) - because the msg numbers may
change if for some rare reason it's reindexed (usually only latter
numbers may change if, say, a spam delete occurs.)
:which looks like it hasn't appeared yet.
:However, my link to www.zsh.org is awful, involving 22 hops and more
:delays than Gatwick Airport, so I couldn't check for anything more
:recent. We could do with a mirror north of the Equator, even if it
:was only the index.
Currently at ~46.5 MB for the whole lot.
~33 MB for the html versions
~5 MB for index files for searching html versions
~8.5 MB for original mails
Oh, and about 30KB of CGI scripts :-)
--
Geoff Wing <gcw@pobox.com> Mobile : 0412 162 441
Work URL: http://www.primenet.com.au/ Ego URL: http://pobox.com/~gcw/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: 3.1.4: getopts
1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
@ 1998-10-07 3:43 ` Bart Schaefer
1998-10-07 7:39 ` Peter Stephenson
1998-10-07 7:53 ` Bernd Eggink
0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 1998-10-07 3:43 UTC (permalink / raw)
To: Peter Stephenson, Zsh hackers list
On Oct 6, 2:45pm, Peter Stephenson wrote:
} Subject: Re: PATCH: 3.1.4: getopts: forget it.
}
} I spoke too soon. Bernd's patch that I referred to does fix the
} problem, only more simply, so use that. It needs merging by hand.
Is the following the correct merge?
Index: Src/builtin.c
===================================================================
*** builtin.c 1998/09/16 15:35:52 1.2
--- builtin.c 1998/10/07 03:37:08
***************
*** 2546,2552 ****
char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
char **args = (*argv) ? argv : pparams;
static int optcind = 0;
! char *str, optbuf[2], *p, opch;
/* zoptind keeps count of the current argument number. The *
* user can set it to zero to start a new option parse. */
--- 2546,2552 ----
char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
char **args = (*argv) ? argv : pparams;
static int optcind = 0;
! char *str, optbuf[2] = " ", *p, opch;
/* zoptind keeps count of the current argument number. The *
* user can set it to zero to start a new option parse. */
***************
*** 2567,2576 ****
/* find place in relevant argument */
str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
if(optcind >= lenstr) {
if(!args[zoptind++])
return 1;
str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
- optcind = 0;
}
if(!optcind) {
if(lenstr < 2 || (*str != '-' && *str != '+'))
--- 2567,2576 ----
/* find place in relevant argument */
str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
if(optcind >= lenstr) {
+ optcind = 0;
if(!args[zoptind++])
return 1;
str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
}
if(!optcind) {
if(lenstr < 2 || (*str != '-' && *str != '+'))
***************
*** 2593,2605 ****
if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) {
p = "?";
err:
if(quiet) {
setsparam(var, ztrdup(p));
- zsfree(zoptarg);
zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
} else {
zerr(*p == '?' ? "bad option: -%c" :
"argument expected after -%c option", NULL, opch);
errflag = 0;
}
return 0;
--- 2593,2606 ----
if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) {
p = "?";
err:
+ zsfree(zoptarg);
if(quiet) {
setsparam(var, ztrdup(p));
zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
} else {
zerr(*p == '?' ? "bad option: -%c" :
"argument expected after -%c option", NULL, opch);
+ zoptarg=ztrdup("");
errflag = 0;
}
return 0;
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: 3.1.4: getopts
1998-10-07 3:43 ` PATCH: 3.1.4: getopts Bart Schaefer
@ 1998-10-07 7:39 ` Peter Stephenson
1998-10-07 7:53 ` Bernd Eggink
1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 1998-10-07 7:39 UTC (permalink / raw)
To: Zsh hackers list
"Bart Schaefer" wrote:
> Is the following the correct merge?
That fits in with what I've got.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: PATCH: 3.1.4: getopts
1998-10-07 3:43 ` PATCH: 3.1.4: getopts Bart Schaefer
1998-10-07 7:39 ` Peter Stephenson
@ 1998-10-07 7:53 ` Bernd Eggink
1 sibling, 0 replies; 6+ messages in thread
From: Bernd Eggink @ 1998-10-07 7:53 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh hackers list
Bart Schaefer wrote:
>
> On Oct 6, 2:45pm, Peter Stephenson wrote:
> } Subject: Re: PATCH: 3.1.4: getopts: forget it.
> }
> } I spoke too soon. Bernd's patch that I referred to does fix the
> } problem, only more simply, so use that. It needs merging by hand.
>
> Is the following the correct merge?
>
> Index: Src/builtin.c
> ===================================================================
> *** builtin.c 1998/09/16 15:35:52 1.2
> --- builtin.c 1998/10/07 03:37:08
> ***************
> *** 2546,2552 ****
> char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
> char **args = (*argv) ? argv : pparams;
> static int optcind = 0;
> ! char *str, optbuf[2], *p, opch;
>
> /* zoptind keeps count of the current argument number. The *
> * user can set it to zero to start a new option parse. */
> --- 2546,2552 ----
> char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
> char **args = (*argv) ? argv : pparams;
> static int optcind = 0;
> ! char *str, optbuf[2] = " ", *p, opch;
>
> /* zoptind keeps count of the current argument number. The *
> * user can set it to zero to start a new option parse. */
> ***************
> *** 2567,2576 ****
> /* find place in relevant argument */
> str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
> if(optcind >= lenstr) {
> if(!args[zoptind++])
> return 1;
> str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
> - optcind = 0;
> }
> if(!optcind) {
> if(lenstr < 2 || (*str != '-' && *str != '+'))
> --- 2567,2576 ----
> /* find place in relevant argument */
> str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
> if(optcind >= lenstr) {
> + optcind = 0;
> if(!args[zoptind++])
> return 1;
> str = unmetafy(dupstring(args[zoptind - 1]), &lenstr);
> }
> if(!optcind) {
> if(lenstr < 2 || (*str != '-' && *str != '+'))
> ***************
> *** 2593,2605 ****
> if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) {
> p = "?";
> err:
> if(quiet) {
> setsparam(var, ztrdup(p));
> - zsfree(zoptarg);
> zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
> } else {
> zerr(*p == '?' ? "bad option: -%c" :
> "argument expected after -%c option", NULL, opch);
> errflag = 0;
> }
> return 0;
> --- 2593,2606 ----
> if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) {
> p = "?";
> err:
> + zsfree(zoptarg);
> if(quiet) {
> setsparam(var, ztrdup(p));
> zoptarg = metafy(optbuf, lenoptbuf, META_DUP);
> } else {
> zerr(*p == '?' ? "bad option: -%c" :
> "argument expected after -%c option", NULL, opch);
> + zoptarg=ztrdup("");
> errflag = 0;
> }
> return 0;
>
Yes, looks OK.
Bernd
--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1998-10-07 8:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-06 12:18 PATCH: 3.1.4: getopts not reset properly for new function Peter Stephenson
1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
1998-10-07 3:43 ` PATCH: 3.1.4: getopts Bart Schaefer
1998-10-07 7:39 ` Peter Stephenson
1998-10-07 7:53 ` Bernd Eggink
1998-10-06 14:44 ` mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function) Geoff Wing
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).