summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/params.yo10
-rw-r--r--Src/params.c9
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index b9ab0afb1..a9af3ea69 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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):
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index ced7fb215..650a6e8d8 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -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
diff --git a/Src/params.c b/Src/params.c
index 134355173..26ff2c566 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -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))) ||