From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16227 invoked from network); 14 Dec 1998 07:43:35 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 14 Dec 1998 07:43:35 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id CAA27509; Mon, 14 Dec 1998 02:36:39 -0500 (EST) Resent-Date: Mon, 14 Dec 1998 02:36:39 -0500 (EST) From: "Bart Schaefer" Message-Id: <981213233528.ZM19211@candle.brasslantern.com> Date: Sun, 13 Dec 1998 23:35:28 -0800 In-Reply-To: <981213153332.ZM15459@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "PATCH: 3.1.5 + associative arrays: keys, values, and pattern subscripts" (Dec 13, 3:33pm) References: <981213153332.ZM15459@candle.brasslantern.com> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: Re: PATCH: 3.1.5 + associative arrays: keys, values, and pattern subscripts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"DCbV71.0.mj6.70CTs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4766 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Dec 13, 3:33pm, Bart Schaefer wrote: } Subject: PATCH: 3.1.5 + associative arrays: keys, values, and pattern subs } } Implementation notes: } } I overloaded the `isarr' field of struct value to hold flag bits for all } this, and backed out the previous hack of overloading both the `a' and `b' } fields. The difference between $array[*] and $array[@] is still stashed } in the sign bit, mostly to minimize the number of lines changed. I don't } believe this has broken anything, but keep your eyes open. Of course I did break something, in the course of getting [(i)pat] to NOT return all the values in the array. I had also messed up these cases: Associative Array Ordinary Array ----------------- -------------- $param All values in param All values in param or empty if none or empty if none $param[(i)pat] A key in param that Index of first value that matches pattern pat matches pattern pat $param[(I)pat] All keys in param that Index of last value that match pattern pat matches pattern pat They worked correctly if an explicit ${(k)...} or ${(v)...} was given, but not in the default cases. The following patch puts things right, and must be applied *after* the previous patch (zsh-workers/4763). Index: Src/params.c =================================================================== --- params.c 1998/12/14 02:17:35 1.13 +++ params.c 1998/12/14 07:27:11 @@ -751,8 +751,15 @@ *inv = (ind || !(v->isarr & SCANPM_WANTVALS)); else if (v->isarr & SCANPM_WANTVALS) *inv = 0; - else + else { + if (ind) { + v->isarr |= SCANPM_WANTKEYS; + v->isarr &= ~SCANPM_WANTVALS; + } + if (!down) + v->isarr &= ~SCANPM_MATCHMANY; *inv = ind; + } for (t=s, i=0; *t && ((*t != ']' && *t != Outbrack && *t != ',') || i); t++) if (*t == '[' || *t == Inbrack) @@ -1078,6 +1085,12 @@ if (PM_TYPE(pm->flags) & (PM_ARRAY|PM_HASHED)) { /* Overload v->isarr as the flag bits for hashed arrays. */ v->isarr = flags | (isvarat ? SCANPM_ISVAR_AT : 0); + /* If no flags were passed, we need something to represent * + * `true' yet differ from an explicit WANTVALS. This is a * + * bit of a hack, but makes some sense: When no subscript * + * is provided, all values are substituted. */ + if (!v->isarr) + v->isarr = SCANPM_MATCHMANY; } v->pm = pm; v->inv = 0; -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com