* Strange associative array stuff in pws-9
@ 1999-02-21 1:17 Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-02-21 1:17 UTC (permalink / raw)
To: zsh-workers
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%
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Strange associative array stuff in pws-9
@ 1999-02-22 12:55 Sven Wischnowsky
0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-02-22 12:55 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-02-22 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-21 1:17 Strange associative array stuff in pws-9 Bart Schaefer
1999-02-22 12:55 Sven Wischnowsky
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).