summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-07-03 10:10:07 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-07-03 10:10:07 +0000
commita7f0716ddbcc158463d7aaedc5f866d416deb58c (patch)
tree8111e0e31f7c2bf3e4b751455f50ecde93383a02
parent43f3a585977a34d20e8ab2ac79d39183d1d02103 (diff)
downloadzsh-a7f0716ddbcc158463d7aaedc5f866d416deb58c.tar.gz
zsh-a7f0716ddbcc158463d7aaedc5f866d416deb58c.tar.xz
zsh-a7f0716ddbcc158463d7aaedc5f866d416deb58c.zip
12138: setting arrays in math context
-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