From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2335 invoked from network); 17 Dec 1998 13:46:49 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 17 Dec 1998 13:46:49 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id IAA04644; Thu, 17 Dec 1998 08:41:43 -0500 (EST) Resent-Date: Thu, 17 Dec 1998 08:41:43 -0500 (EST) From: "Bart Schaefer" Message-Id: <981217054042.ZM21030@candle.brasslantern.com> Date: Thu, 17 Dec 1998 05:40:42 -0800 In-Reply-To: <9812171017.AA27233@ibmth.df.unipi.it> Comments: In reply to Peter Stephenson "Re: PATCH: 3.1.5 + associative arrays: keys, values, and pattern subscripts" (Dec 17, 11:17am) References: <9812171017.AA27233@ibmth.df.unipi.it> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5 + associative arrays: fix to keys, values MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"oQr_z2.0.V81.NeGUs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4836 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Dec 17, 11:17am, Peter Stephenson wrote: } Subject: Re: PATCH: 3.1.5 + associative arrays: keys, values, and pattern } } "Bart Schaefer" wrote: } > The appended patch improves the implementation of the (kv) parameter flags } > and their interaction with the (iIrR) subscripting flags. } } I finally had a look at these and a couple seem to be giving problems. } } For the tests, } } % typeset -A assoc } % assoc=(one eins two zwei three drei four vier five funf) } % print ${(k)assoc[four]} } 0 } % print ${assoc[(r)v*]} } eins Fortunately these weren't too hard to fix. (I knew SCANPM_WANTINDEX was there for something.) } The remaining cases as far as I've tested seem fine. There is of } course the point that the ordering is random (the `first' match of } something could be any of them), but that's a feature of associative } arrays which just needs to be made clear in the docs. I hope I did so ... }The syntax seems as good as anything I can think of. OK. (I did go to bed early. Then I got up early. Bleah.) Index: Src/params.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/params.c,v retrieving revision 1.17 diff -u -r1.17 params.c --- params.c 1998/12/16 18:00:57 1.17 +++ params.c 1998/12/17 13:11:48 @@ -762,6 +762,8 @@ if (ind) { v->isarr |= SCANPM_WANTKEYS; v->isarr &= ~SCANPM_WANTVALS; + } else if (rev) { + v->isarr |= SCANPM_WANTVALS; } if (!down) v->isarr &= ~SCANPM_MATCHMANY; @@ -795,8 +797,9 @@ v->pm = createparam(s, PM_SCALAR|PM_UNSET); paramtab = tht; } - v->isarr = 0; + v->isarr = (*inv ? SCANPM_WANTINDEX : 0); v->a = 0; + *inv = 0; /* We've already obtained the "index" (key) */ *w = v->b = -1; r = isset(KSHARRAYS) ? 1 : 0; } else @@ -986,9 +989,11 @@ } if (a > 0 && (isset(KSHARRAYS) || (v->pm->flags & PM_HASHED))) a--; - v->inv = 1; - v->isarr = 0; - v->a = v->b = a; + if (v->isarr != SCANPM_WANTINDEX) { + v->inv = 1; + v->isarr = 0; + v->a = v->b = a; + } if (*s == ',') { zerr("invalid subscript", NULL, 0); while (*s != ']' && *s != Outbrack) Index: Src/subst.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/subst.c,v retrieving revision 1.7 diff -u -r1.7 subst.c --- subst.c 1998/12/15 06:58:15 1.7 +++ subst.c 1998/12/17 13:27:35 @@ -1009,7 +1009,11 @@ if ((isarr = v->isarr)) { /* No way to get here with v->inv != 0, so getvaluearr() * * is called by getarrvalue(); needn't test PM_HASHED. */ - aval = getarrvalue(v); + if (v->isarr == SCANPM_WANTINDEX) { + isarr = v->isarr = 0; + val = dupstring(v->pm->nam); + } else + aval = getarrvalue(v); } else { if (v->pm->flags & PM_ARRAY) { int tmplen = arrlen(v->pm->gets.afn(v->pm)); Index: Src/zsh.h =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/zsh.h,v retrieving revision 1.11 diff -u -r1.11 zsh.h --- zsh.h 1998/12/15 20:14:15 1.11 +++ zsh.h 1998/12/17 13:14:04 @@ -915,7 +915,7 @@ /* Flags for extracting elements of arrays and associative arrays */ #define SCANPM_WANTVALS (1<<0) #define SCANPM_WANTKEYS (1<<1) -#define SCANPM_WANTINDEX (1<<2) /* Presently unused */ +#define SCANPM_WANTINDEX (1<<2) #define SCANPM_MATCHKEY (1<<3) #define SCANPM_MATCHVAL (1<<4) #define SCANPM_MATCHMANY (1<<5) -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com