From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: PATCH: 3.1.4: getopts not reset properly for new function
Date: Tue, 06 Oct 1998 14:18:25 +0200 [thread overview]
Message-ID: <9810061218.AA31566@ibmth.df.unipi.it> (raw)
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
next reply other threads:[~1998-10-06 12:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-10-06 12:18 Peter Stephenson [this message]
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
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=9810061218.AA31566@ibmth.df.unipi.it \
--to=pws@ibmth.df.unipi.it \
--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).