From bc3256997b737f6158e9768dcf5738a7c0fbb454 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 10 Sep 1999 09:28:43 +0000 Subject: zsh-workers/7765 --- Src/builtin.c | 6 ++++-- Src/exec.c | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/builtin.c b/Src/builtin.c index ed9d01909..9184fd719 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2936,6 +2936,9 @@ bin_shift(char *name, char **argv, char *ops, int func) return ret; } +/**/ +int optcind; + /* getopts: automagical option handling for shell scripts */ /**/ @@ -2945,7 +2948,6 @@ bin_getopts(char *name, char **argv, char *ops, int func) 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 * @@ -2994,8 +2996,8 @@ bin_getopts(char *name, char **argv, char *ops, int func) p = "?"; err: zsfree(zoptarg); + setsparam(var, ztrdup(p)); if(quiet) { - setsparam(var, ztrdup(p)); zoptarg = metafy(optbuf, lenoptbuf, META_DUP); } else { zerr(*p == '?' ? "bad option: -%c" : diff --git a/Src/exec.c b/Src/exec.c index 720620e71..3e44adfc2 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2918,7 +2918,7 @@ doshfunc(char *name, List list, LinkList doshargs, int flags, int noreturnval) * was executed. */ { char **tab, **x, *oargv0 = NULL; - int oldzoptind, oldlastval; + int oldzoptind, oldlastval, oldoptcind; char saveopts[OPT_SIZE], *oldscriptname; int obreaks = breaks; @@ -2935,6 +2935,8 @@ doshfunc(char *name, List list, LinkList doshargs, int flags, int noreturnval) scriptname = dupstring(name); 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 * @@ -2974,6 +2976,7 @@ doshfunc(char *name, List list, LinkList doshargs, int flags, int noreturnval) zsfree(argzero); argzero = oargv0; } + optcind = oldoptcind; zoptind = oldzoptind; scriptname = oldscriptname; pparams = tab; -- cgit 1.4.1