mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-30 05:40:58 +01:00
35318: POSIX_BUILTINS behaviour for getopts.
It needs to keep OPTIND, as well as the index within the string pointed to by OPTIND, global in this case.
This commit is contained in:
parent
cb596a55d9
commit
2b08d0ed67
5 changed files with 24 additions and 5 deletions
|
|
@ -1,3 +1,9 @@
|
|||
2015-05-28 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 35318: Doc/Zsh/builtins.yo, Doc/Zsh/options.yo, Src/builtin.c,
|
||||
Src/exec.c: POSIX_BUILTINS compatibility for OPTIND processing
|
||||
in getopts.
|
||||
|
||||
2015-05-27 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
||||
* 35306: Src/parse.c, Test/C02cond.ztst: "test -z \("
|
||||
|
|
|
|||
|
|
@ -866,7 +866,8 @@ vindex(OPTARG, use of)
|
|||
|
||||
The first option to be examined may be changed by explicitly assigning
|
||||
to tt(OPTIND). tt(OPTIND) has an initial value of tt(1), and is
|
||||
normally reset to tt(1) upon exit from a shell function. tt(OPTARG)
|
||||
normally set to tt(1) upon entry to a shell function and restored
|
||||
upon exit (this is disabled by the tt(POSIX_BUILTINS) option). tt(OPTARG)
|
||||
is not reset and retains its value from the most recent call to
|
||||
tt(getopts). If either of tt(OPTIND) or tt(OPTARG) is explicitly
|
||||
unset, it remains unset, and the index or option argument is not
|
||||
|
|
|
|||
|
|
@ -2038,6 +2038,10 @@ tt(unset).
|
|||
In addition, various error conditions associated with the above builtins
|
||||
or tt(exec) cause a non-interactive shell to exit and an interactive
|
||||
shell to return to its top-level processing.
|
||||
|
||||
Furthermore, the tt(getopts) builtin behaves in a POSIX-compatible
|
||||
fashion in that the associated variable tt(OPTIND) is not made
|
||||
local to functions.
|
||||
)
|
||||
pindex(POSIX_IDENTIFIERS)
|
||||
pindex(NO_POSIX_IDENTIFIERS)
|
||||
|
|
|
|||
|
|
@ -4713,6 +4713,10 @@ bin_shift(char *name, char **argv, Options ops, UNUSED(int func))
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Position of getopts option within OPTIND argument with multiple options.
|
||||
*/
|
||||
|
||||
/**/
|
||||
int optcind;
|
||||
|
||||
|
|
|
|||
|
|
@ -4910,9 +4910,11 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
|
|||
if (!(flags & PM_UNDEFINED))
|
||||
scriptname = dupstring(name);
|
||||
oldzoptind = zoptind;
|
||||
zoptind = 1;
|
||||
oldoptcind = optcind;
|
||||
if (!isset(POSIXBUILTINS)) {
|
||||
zoptind = 1;
|
||||
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 *
|
||||
|
|
@ -5049,8 +5051,10 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
|
|||
argzero = oargv0;
|
||||
}
|
||||
pparams = pptab;
|
||||
optcind = oldoptcind;
|
||||
if (!isset(POSIXBUILTINS)) {
|
||||
zoptind = oldzoptind;
|
||||
optcind = oldoptcind;
|
||||
}
|
||||
scriptname = oldscriptname;
|
||||
oflags = ooflags;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue