Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Strange associative array stuff in pws-9



Bart Schaefer wrote:

> Has it always been like this?
> 
> zagzig% typeset -A foo
> zagzig% foo[a,b,c]=bar
> zagzig% echo $foo
> bar
> zagzig% echo $foo[a,b,c]
> bar[a,b,c]
> zagzig% echo ${foo[a,b,c]}
> bar
> zagzig% echo $foo['a,b,c'] 
> ['a,b,c']
> zagzig% 

I was fearing that I had broken something, but this was in a piece of
the code I haven't touched...
The loop in getarg() searched for the first comma or closing bracket
even when subscripting an associative array. Since it doesn't make
sense to use ranges for associative arrays (and the docs say that they
are not supported), we should tell the code about it.

Bye
 Sven

--- os/params.c	Mon Feb 22 10:49:22 1999
+++ Src/params.c	Mon Feb 22 13:49:42 1999
@@ -679,11 +679,13 @@
 static long
 getarg(char **str, int *inv, Value v, int a2, long *w)
 {
-    int num = 1, word = 0, rev = 0, ind = 0, down = 0, l, i;
+    int num = 1, word = 0, rev = 0, ind = 0, down = 0, l, i, ishash;
     char *s = *str, *sep = NULL, *t, sav, *d, **ta, **p, *tt;
     long r = 0;
     Comp c;
 
+    ishash = (v->pm && PM_TYPE(v->pm->flags) == PM_HASHED);
+
     /* first parse any subscription flags */
     if (v->pm && (*s == '(' || *s == Inpar)) {
 	int escapes = 0;
@@ -771,12 +773,13 @@
 	} else if (rev) {
 	    v->isarr |= SCANPM_WANTVALS;
 	}
-	if (!down && v->pm && PM_TYPE(v->pm->flags) == PM_HASHED)
+	if (!down && ishash)
 	    v->isarr &= ~SCANPM_MATCHMANY;
 	*inv = ind;
     }
 
-    for (t=s, i=0; *t && ((*t != ']' && *t != Outbrack && *t != ',') || i); t++)
+    for (t=s, i=0;
+	 *t && ((*t != ']' && *t != Outbrack && (ishash || *t != ',')) || i); t++)
 	if (*t == '[' || *t == Inbrack)
 	    i++;
 	else if (*t == ']' || *t == Outbrack)
@@ -791,7 +794,7 @@
     singsub(&s);
 
     if (!rev) {
-	if (v->pm && PM_TYPE(v->pm->flags) == PM_HASHED) {
+	if (ishash) {
 	    HashTable ht = v->pm->gets.hfn(v->pm);
 	    if (!ht) {
 		ht = newparamtable(17, v->pm->nam);
@@ -867,7 +870,7 @@
 
 	if ((c = parsereg(s))) {
 	    if (v->isarr) {
-		if (PM_TYPE(v->pm->flags) == PM_HASHED) {
+		if (ishash) {
 		    scancomp = c;
 		    if (ind)
 			v->isarr |= SCANPM_MATCHKEY;

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author