From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19939 invoked from network); 6 Oct 1998 12:42:36 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 6 Oct 1998 12:42:36 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id IAA12547; Tue, 6 Oct 1998 08:27:51 -0400 (EDT) Resent-Date: Tue, 6 Oct 1998 08:27:51 -0400 (EDT) Message-Id: <9810061218.AA31566@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 From: Peter Stephenson Resent-Message-ID: <"wKruU1.0.-33.7pW6s"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4413 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Gruppo Teorico, Dipartimento di Fisica Piazza Torricelli 2, 56100 Pisa, Italy