about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/params.c42
-rw-r--r--Test/06arith.ztst6
3 files changed, 38 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 307e7e25f..4a9002bfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2000-07-03  Peter Stephenson  <pws@cambridgesiliconradio.com>
 
+	* 12138: Src/params.c, Test/06arith.ztst: setting of array
+	elements in math context didn't work (ever). 
+
 	* 12121: Src/utils.c, Doc/Zsh/options.yo: save and restore stopmsg
 	for precmd, fix #ifdef's for variable declaration in read_poll().
 
diff --git a/Src/params.c b/Src/params.c
index e7f5011d1..73b1c0e35 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1898,7 +1898,7 @@ setiparam(char *s, zlong val)
 {
     struct value vbuf;
     Value v;
-    char *t = s;
+    char *t = s, *ss;
     Param pm;
     mnumber mnval;
 
@@ -1908,10 +1908,18 @@ setiparam(char *s, zlong val)
 	return NULL;
     }
     if (!(v = getvalue(&vbuf, &s, 1))) {
-	pm = createparam(t, PM_INTEGER);
+	if ((ss = strchr(s, '[')))
+	    *ss = '\0';
+	pm = createparam(t, ss ? PM_ARRAY : PM_INTEGER);
 	DPUTS(!pm, "BUG: parameter not created");
-	pm->u.val = val;
-	return pm;
+	if (ss) {
+	    *ss = '[';
+	    v = getvalue(&vbuf, &t, 1);
+	    DPUTS(!v, "BUG: value not found for new parameter");
+	} else {
+	    pm->u.val = val;
+	    return pm;
+	}
     }
     mnval.type = MN_INTEGER;
     mnval.u.l = val;
@@ -1930,7 +1938,7 @@ setnparam(char *s, mnumber val)
 {
     struct value vbuf;
     Value v;
-    char *t = s;
+    char *t = s, *ss = NULL;
     Param pm;
 
     if (!isident(s)) {
@@ -1939,15 +1947,23 @@ setnparam(char *s, mnumber val)
 	return NULL;
     }
     if (!(v = getvalue(&vbuf, &s, 1))) {
-	pm = createparam(t, (val.type & MN_INTEGER) ? PM_INTEGER
-			 : PM_FFLOAT);
+	if ((ss = strchr(s, '[')))
+	    *ss = '\0';
+	pm = createparam(t, ss ? PM_ARRAY :
+			 (val.type & MN_INTEGER) ? PM_INTEGER : PM_FFLOAT);
 	DPUTS(!pm, "BUG: parameter not created");
-	if (val.type & MN_INTEGER) {
-	    pm->ct = outputradix;
-	    pm->u.val = val.u.l;
-	} else
-	    pm->u.dval = val.u.d;
-	return pm;
+	if (ss) {
+	    *ss = '[';
+	    v = getvalue(&vbuf, &t, 1);
+	    DPUTS(!v, "BUG: value not found for new parameter");
+	} else {
+	    if (val.type & MN_INTEGER) {
+		pm->ct = outputradix;
+		pm->u.val = val.u.l;
+	    } else
+		pm->u.dval = val.u.d;
+	    return pm;
+	}
     }
     setnumvalue(v, val);
     return v->pm;
diff --git a/Test/06arith.ztst b/Test/06arith.ztst
index 35d1ba494..c72bd5acb 100644
--- a/Test/06arith.ztst
+++ b/Test/06arith.ztst
@@ -82,3 +82,9 @@
 0:use of scalars to store integers and floats
 >3.5
 >4
+
+  (( newarray[unsetvar]++ ))
+  (( newarray[unsetvar]++ ))
+  print ${(t)newarray} ${#newarray} ${newarray[1]}
+0:setting array elements in math context
+>array 1 2