From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1355 invoked from network); 28 Aug 1999 22:14:25 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 28 Aug 1999 22:14:25 -0000 Received: (qmail 25318 invoked by alias); 28 Aug 1999 22:14:14 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7527 Received: (qmail 25311 invoked from network); 28 Aug 1999 22:14:11 -0000 From: "Bart Schaefer" Message-Id: <990828221406.ZM32663@candle.brasslantern.com> Date: Sat, 28 Aug 1999 22:14:06 +0000 In-Reply-To: <990828050003.ZM30545@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "PATCH: ksharrays and assoc array assignments (was Re: Files modified after a given date)" (Aug 28, 5:00am) References: <199908230809.KAA02317@beta.informatik.hu-berlin.de> <19990827175122.A2818@vmunix.com> <990827224347.ZM28594@candle.brasslantern.com> <19990827194419.A7511@vmunix.com> <990828050003.ZM30545@candle.brasslantern.com> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.auc.dk Subject: PATCH: Re: ksharrays and assoc array assignments MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 28, 5:00am, Bart Schaefer wrote: } Subject: PATCH: ksharrays and assoc array assignments (was Re: Files modif } } + int k = opts[KSHARRAYS]; /* Remember the value of KSHARRAYS */ } + opts[KSHARRAYS] = 0; /* and clear it to avoid special- */ } + v = getvalue(&t, 1); /* case of $array --> ${array[0]}. */ } + opts[KSHARRAYS] = k; /* OK because we can't assign to a */ } + if (!v) /* slice of an association anyway, */ } + return NULL; /* so ANY subscript will be wrong. */ Turns out there are other problems with ksharrays and ${(AA)...}. Even after the patch quoted above, ${(AA)var:=value} complains about slices when var is already set; which means it's acting like ${(AA)var::=value}, attempting to assign when it should not. This is yet another side-effect of the $array --> ${array[0]} mapping when KSHARRAYS is set. So, scrap the patch above and apply the following one instead (that is, on the original 3.1.6-pws-1 source, not on top of zsh-users/2529). One hunk below is to fix a typo in my patch from zsh-workers/7521. If you didn't apply 7521 or Sven's patches that preceded it, remove the exec.c hunk before applying the following. Index: Src/exec.c =================================================================== @@ -622,7 +622,7 @@ else if (!cn->u.name) return 0; else { - strcpy(fullnam, cn->u.name); + strcpy(fullnam, *(cn->u.name)); strcat(fullnam, "/"); strcat(fullnam, cn->nam); } Index: Src/params.c =================================================================== @@ -1217,7 +1217,8 @@ *pptr = s; return v; } - } else if (v->isarr && iident(*t) && isset(KSHARRAYS)) + } else if (!(flags & SCANPM_ASSIGNING) && v->isarr && + iident(*t) && isset(KSHARRAYS)) v->b = 0, v->isarr = 0; } if (!bracks && *s) @@ -1649,7 +1650,7 @@ } v = NULL; } else { - if (!(v = getvalue(&s, 1))) + if (!(v = fetchvalue(&s, 1, SCANPM_ASSIGNING))) createparam(t, PM_ARRAY); else if (!(PM_TYPE(v->pm->flags) & (PM_ARRAY|PM_HASHED)) && !(v->pm->flags & (PM_SPECIAL|PM_TIED))) { @@ -1660,11 +1661,8 @@ } } if (!v) - if (!(v = getvalue(&t, 1))) + if (!(v = fetchvalue(&t, 1, SCANPM_ASSIGNING))) return NULL; - if (isset(KSHARRAYS) && !ss) - /* the whole array should be set instead of only the first element */ - v->b = -1; setarrvalue(v, val); return v->pm; } @@ -1688,7 +1686,7 @@ errflag = 1; return NULL; } else { - if (!(v = getvalue(&s, 1))) + if (!(v = fetchvalue(&s, 1, SCANPM_ASSIGNING))) createparam(t, PM_HASHED); else if (!(PM_TYPE(v->pm->flags) & PM_HASHED) && !(v->pm->flags & PM_SPECIAL)) { @@ -1698,7 +1696,7 @@ } } if (!v) - if (!(v = getvalue(&t, 1))) + if (!(v = fetchvalue(&t, 1, SCANPM_ASSIGNING))) return NULL; setarrvalue(v, val); return v->pm; Index: Src/subst.c =================================================================== @@ -1028,7 +1028,7 @@ if (!(v = fetchvalue((subexp ? &ov : &s), (wantt ? -1 : ((unset(KSHARRAYS) || inbrace) ? 1 : -1)), - hkeys|hvals)) || + hkeys|hvals|(arrasg ? SCANPM_ASSIGNING : 0))) || (v->pm && (v->pm->flags & PM_UNSET))) vunset = 1; Index: Src/zsh.h =================================================================== @@ -1045,6 +1045,7 @@ #define SCANPM_MATCHKEY (1<<3) #define SCANPM_MATCHVAL (1<<4) #define SCANPM_MATCHMANY (1<<5) +#define SCANPM_ASSIGNING (1<<6) #define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */ /* -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com