mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-05-18 21:51:02 +02:00
51510: Skip namespaces in "set"/"typeset" output, add tests, fix bug
This commit is contained in:
parent
0562be0af8
commit
8d009d35a9
6 changed files with 130 additions and 8 deletions
|
@ -1,5 +1,10 @@
|
|||
2023-03-06 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 51510: Src/builtin.c, Src/params.c, Src/utils.c, Src/zsh.h,
|
||||
Test/K02parameter.ztst: parameters with a leading namespace are
|
||||
skipped in output of "set" and "typeset", add tests for ksh-like
|
||||
parameter handling and fix a bug thus revealed
|
||||
|
||||
* 51509 (+ fix typo): Src/params.c, Src/subst.c, Src/zsh.h: Add
|
||||
${(!)name} for the referred-to parameter of a named reference,
|
||||
and extend ${!name} in ksh emulation for same
|
||||
|
|
|
@ -2240,7 +2240,8 @@ typeset_single(char *cname, char *pname, Param pm, int func,
|
|||
paramtab->printnode(&pm->node, PRINT_TYPESET);
|
||||
else if (!OPT_ISSET(ops,'g') &&
|
||||
(unset(TYPESETSILENT) || OPT_ISSET(ops,'m')))
|
||||
paramtab->printnode(&pm->node, PRINT_INCLUDEVALUE);
|
||||
paramtab->printnode(&pm->node,
|
||||
PRINT_INCLUDEVALUE|PRINT_WITH_NAMESPACE);
|
||||
return pm;
|
||||
}
|
||||
if ((pm->node.flags & PM_RESTRICTED) && isset(RESTRICTED)) {
|
||||
|
@ -2274,7 +2275,7 @@ typeset_single(char *cname, char *pname, Param pm, int func,
|
|||
}
|
||||
}
|
||||
if (OPT_ISSET(ops,'p')) {
|
||||
paramtab->printnode(&pm->node, PRINT_TYPESET);
|
||||
paramtab->printnode(&pm->node, PRINT_TYPESET|PRINT_WITH_NAMESPACE);
|
||||
return pm;
|
||||
}
|
||||
if (usepm == 2) /* do not change the PM_UNSET flag */
|
||||
|
@ -2662,7 +2663,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
|
|||
char *optstr = TYPESET_OPTSTR;
|
||||
int on = 0, off = 0, roff, bit = PM_ARRAY;
|
||||
int i;
|
||||
int returnval = 0, printflags = 0;
|
||||
int returnval = 0, printflags = PRINT_WITH_NAMESPACE;
|
||||
int hasargs = *argv != NULL || (assigns && firstnode(assigns));
|
||||
|
||||
/* POSIXBUILTINS is set for bash/ksh and both ignore -p with args */
|
||||
|
@ -2730,7 +2731,6 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
|
|||
|
||||
queue_signals();
|
||||
|
||||
/* Given no arguments, list whatever the options specify. */
|
||||
if (OPT_ISSET(ops,'p')) {
|
||||
|
||||
if (isset(POSIXBUILTINS) && SHELL_EMULATION() != EMULATE_KSH) {
|
||||
|
@ -2756,8 +2756,14 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
|
|||
/* -p0 treated as -p for consistency */
|
||||
}
|
||||
}
|
||||
|
||||
/* Given no arguments, list whatever the options specify. */
|
||||
if (!hasargs) {
|
||||
int exclude = 0;
|
||||
|
||||
if (!OPT_ISSET(ops,'m'))
|
||||
printflags &= ~PRINT_WITH_NAMESPACE;
|
||||
|
||||
if (!OPT_ISSET(ops,'p')) {
|
||||
if (!(on|roff))
|
||||
printflags |= PRINT_TYPE;
|
||||
|
|
|
@ -5966,6 +5966,10 @@ printparamnode(HashNode hn, int printflags)
|
|||
Param p = (Param) hn;
|
||||
Param peer = NULL;
|
||||
|
||||
if (!(p->node.flags & PM_HASHELEM) &&
|
||||
!(printflags & PRINT_WITH_NAMESPACE) && *(p->node.nam) == '.')
|
||||
return;
|
||||
|
||||
if (p->node.flags & PM_UNSET) {
|
||||
if ((printflags & (PRINT_POSIX_READONLY|PRINT_POSIX_EXPORT) &&
|
||||
p->node.flags & (PM_READONLY|PM_EXPORTED)) ||
|
||||
|
|
|
@ -4319,13 +4319,13 @@ itype_end(const char *ptr, int itype, int once)
|
|||
{
|
||||
if (itype == INAMESPC) {
|
||||
itype = IIDENT;
|
||||
if (once == 0 && (!isset(POSIXIDENTIFIERS) || EMULATION(EMULATE_KSH))) {
|
||||
if (!isset(POSIXIDENTIFIERS) || EMULATION(EMULATE_KSH)) {
|
||||
/* Special case for names containing ".", ksh93 namespaces */
|
||||
char *t = itype_end(ptr + (*ptr == '.'), itype, 0);
|
||||
if (t > ptr+1) {
|
||||
if (t > ptr + (*ptr == '.')) {
|
||||
if (*t == '.')
|
||||
return itype_end(t+1, itype, 0);
|
||||
else
|
||||
ptr = t + 1; /* Fall through */
|
||||
else if (!once)
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2184,6 +2184,7 @@ typedef groupset *Groupset;
|
|||
#define PRINT_LINE (1<<6)
|
||||
#define PRINT_POSIX_EXPORT (1<<7)
|
||||
#define PRINT_POSIX_READONLY (1<<8)
|
||||
#define PRINT_WITH_NAMESPACE (1<<9)
|
||||
|
||||
/* flags for printing for the whence builtin */
|
||||
#define PRINT_WHENCE_CSH (1<<7)
|
||||
|
|
106
Test/K02parameter.ztst
Normal file
106
Test/K02parameter.ztst
Normal file
|
@ -0,0 +1,106 @@
|
|||
# Test parameter expansion with namespace syntax
|
||||
# (heavily borrowed from D04parameter.ztst)
|
||||
|
||||
%prep
|
||||
|
||||
%test
|
||||
|
||||
.k02.foo='the first parameter'
|
||||
.k02.bar='the second parameter'
|
||||
print -l $.k02.foo ${.k02.bar}
|
||||
0:Basic scalars with namespace
|
||||
F:Braces are required
|
||||
>$.k02.foo
|
||||
>the second parameter
|
||||
|
||||
typeset .k02.bar='the second parameter'
|
||||
print -l ${.k02.bar}
|
||||
0:Scalar but with typeset
|
||||
>the second parameter
|
||||
|
||||
.k02.array1=(the first array)
|
||||
.k02.array2=(the second array)
|
||||
print -l $.k02.array1 ${.k02.array2}
|
||||
0:Basic arrays with namespace
|
||||
>$.k02.array1
|
||||
>the
|
||||
>second
|
||||
>array
|
||||
|
||||
typeset -a .k02.array2=(the second array)
|
||||
print -l ${.k02.array2}
|
||||
0:Array but with typeset
|
||||
>the
|
||||
>second
|
||||
>array
|
||||
|
||||
setopt ksharrays
|
||||
print -l ${.k02.array2}
|
||||
unsetopt ksharrays
|
||||
0:Basic ksharray with namespace
|
||||
>the
|
||||
|
||||
setopt shwordsplit
|
||||
print -l ${.k02.foo} ${==.k02.bar}
|
||||
unsetopt shwordsplit
|
||||
0:Basic shwordsplit with namespace
|
||||
>the
|
||||
>first
|
||||
>parameter
|
||||
>the second parameter
|
||||
|
||||
print ${+.k02.foo} ${+.k02.notappearinginthistest}
|
||||
0:$+... and namespace
|
||||
>1 0
|
||||
|
||||
.k02.x=()
|
||||
print ${+.k02.x} ${+.k02.x[1]} ${+.k02.x[(r)foo]} ${+.k02.x[(r)bar]}
|
||||
.k02.x=(foo)
|
||||
print ${+.k02.x} ${+.k02.x[1]} ${+.k02.x[(r)foo]} ${+.k02.x[(r)bar]}
|
||||
0:$+... with arrays and namespace
|
||||
>1 0 0 0
|
||||
>1 1 1 0
|
||||
|
||||
# See D04 for complete explanation.
|
||||
# For K02 we're just testing that flag syntax works.
|
||||
.k02.foo='<five> {six} (seven) >eight< }nine{ |forty-two| $many$ )ten( more'
|
||||
.k02.array=(${(z).k02.foo})
|
||||
print -l ${(Q).k02.array}
|
||||
0:${(z)...} and ${(Q)...} for some hard to parse cases
|
||||
><
|
||||
>five
|
||||
>>
|
||||
>{six}
|
||||
>(
|
||||
>seven
|
||||
>)
|
||||
>>
|
||||
>eight
|
||||
><
|
||||
>}nine{
|
||||
>|
|
||||
>forty-two
|
||||
>|
|
||||
>$many$
|
||||
>)
|
||||
>ten( more
|
||||
|
||||
.k02.array=(characters in an array)
|
||||
print ${(c)#.k02.array}
|
||||
0:${(c)#...}
|
||||
>22
|
||||
|
||||
() {
|
||||
typeset -n .k02.ref=.k02.array
|
||||
emulate -L ksh
|
||||
print -l ${!.k02.ref} ${(!).k02.ref} ${.k02.ref}
|
||||
}
|
||||
0:namerefs with namespaces
|
||||
>.k02.array
|
||||
>.k02.array
|
||||
>characters
|
||||
|
||||
k.2=test
|
||||
print ${k.2}
|
||||
0:Parse without leading dot (future proofing)
|
||||
>test
|
Loading…
Reference in a new issue