mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-04 10:41:11 +02:00
19712, 19740: allow assigning to associations with i and r subscript flags
This commit is contained in:
parent
7af7f23508
commit
98e28ff3ed
3 changed files with 18 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
|||
2004-04-06 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 19712, 19740: Src/params.c, Doc/Zsh/params.c: allow assigning to
|
||||
associative array elements where the i or r subscript flag is used
|
||||
|
||||
2004-04-06 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* Peter Castro <doctor@fruitbat.org>: 19735 (minus texinfo hunk):
|
||||
|
|
|
@ -198,14 +198,14 @@ word (if the parameter is an array, if it is a scalar, or if it is a
|
|||
scalar and the `tt(w)' flag is given, respectively). The subscript used
|
||||
is the number of the matching element, so that pairs of subscripts such as
|
||||
`tt($foo[(r))var(??)tt(,3])' and `tt($foo[(r))var(??)tt(,(r)f*])' are
|
||||
possible. If the parameter is an associative array, only the value part
|
||||
of each pair is compared to the pattern, and the result is that value.
|
||||
Reverse subscripts may be used for assigning to ordinary array elements,
|
||||
but not for assigning to associative arrays.
|
||||
possible if the parameter is not an associative array. If the
|
||||
parameter is an associative array, only the value part of each pair is
|
||||
compared to the pattern, and the result is that value.
|
||||
)
|
||||
item(tt(R))(
|
||||
Like `tt(r)', but gives the last match. For associative arrays, gives
|
||||
all possible matches.
|
||||
all possible matches. May be used for assigning to ordinary array
|
||||
elements, but not for assigning to associative arrays.
|
||||
)
|
||||
item(tt(i))(
|
||||
Like `tt(r)', but gives the index of the match instead; this may not be
|
||||
|
|
|
@ -381,6 +381,7 @@ scancountparams(HashNode hn, int flags)
|
|||
static Patprog scanprog;
|
||||
static char *scanstr;
|
||||
static char **paramvals;
|
||||
static Param foundparam;
|
||||
|
||||
/**/
|
||||
void
|
||||
|
@ -404,6 +405,7 @@ scanparamvals(HashNode hn, int flags)
|
|||
} else if ((flags & SCANPM_MATCHKEY) && !pattry(scanprog, v.pm->nam)) {
|
||||
return;
|
||||
}
|
||||
foundparam = v.pm;
|
||||
if (flags & SCANPM_WANTKEYS) {
|
||||
paramvals[numparamvals++] = v.pm->nam;
|
||||
if (!(flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)))
|
||||
|
@ -1598,7 +1600,7 @@ setstrvalue(Value v, char *val)
|
|||
zsfree(val);
|
||||
return;
|
||||
}
|
||||
if (v->pm->flags & PM_HASHED) {
|
||||
if ((v->pm->flags & PM_HASHED) && (v->isarr & SCANPM_MATCHMANY)) {
|
||||
zerr("%s: attempt to set slice of associative array", v->pm->nam, 0);
|
||||
zsfree(val);
|
||||
return;
|
||||
|
@ -1663,6 +1665,11 @@ setstrvalue(Value v, char *val)
|
|||
setarrvalue(v, ss);
|
||||
}
|
||||
break;
|
||||
case PM_HASHED:
|
||||
{
|
||||
(foundparam->sets.cfn) (foundparam, val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((!v->pm->env && !(v->pm->flags & PM_EXPORTED) &&
|
||||
!(isset(ALLEXPORT) && !(v->pm->flags & PM_HASHELEM))) ||
|
||||
|
|
Loading…
Reference in a new issue