Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Oh no, parameter expansion
- X-seq: zsh-workers 9776
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: Re: Oh no, parameter expansion
- Date: Thu, 17 Feb 2000 14:49:41 +0100 (MET)
- In-reply-to: Sven Wischnowsky's message of Thu, 17 Feb 2000 11:30:51 +0100 (MET)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
I wrote:
> Remember our fight to get arrays in nested parameter expansions right?
> I just found another on of those:
>
> % a=(aaa b c)
> % echo ${(M)a[1,1]:#aaa}
> 3
>
> That's because $a[1,1] gives a string instead of an array. We could
> remove the `a == b' in params.c:1160 to avoid that, but I don't know
> what this would break.
The patch below should make it return a string only if the subscript
does not contain a comma. I.e. with $a being an array, $a[1] gives a
string and $a[1,1] gives an array. Seems sensible, doesn't it?
> And one more:
>
> % a=::: b=_foo
> % echo ${a/::/:${b#_}:}
> :::
>
> It works with $b[2,-1], haven't investigated any further.
compgetmatch() parsed the pattern in the static pattern buffer which
was then overwritten by the singsub(). The patch makes it return a
heap duplicate for the pattern if there is a replstr. It's a pity.
Bye
Sven
diff -ru ../z.old/Completion/Core/_main_complete Completion/Core/_main_complete
--- ../z.old/Completion/Core/_main_complete Thu Feb 17 13:37:18 2000
+++ Completion/Core/_main_complete Thu Feb 17 14:05:11 2000
@@ -66,8 +66,7 @@
_completer_num=1
for _completer; do
- _matcher="${_completer[2,-1]}-${(M)#_completers[1,_completer_num]:#$_completer}"
- zstyle -a ":completion:${curcontext/::/:${_matcher}:}:" matcher-list _matchers ||
+ zstyle -a ":completion:${curcontext/::/:${_completer[2,-1]}-${(M)#_completers[1,_completer_num]:#$_completer}:}:" matcher-list _matchers ||
_matchers=( '' )
_matcher_num=1
diff -ru ../z.old/Src/glob.c Src/glob.c
--- ../z.old/Src/glob.c Thu Feb 17 13:36:48 2000
+++ Src/glob.c Thu Feb 17 14:47:49 2000
@@ -1936,7 +1936,14 @@
* have one pattern at a time; we will try the must-match test ourselves,
* so tell the pattern compiler we are scanning.
*/
- int patflags = PAT_STATIC|PAT_SCAN|PAT_NOANCH;
+
+ /* int patflags = PAT_STATIC|PAT_SCAN|PAT_NOANCH;*/
+
+ /* Unfortunately, PAT_STATIC doesn't work if we have a replstr with
+ * something like ${x#...} in it which will be singsub()ed below because
+ * that would overwrite the pattern buffer. */
+
+ int patflags = PAT_SCAN|PAT_NOANCH | (*replstrp ? 0 : PAT_STATIC);
/*
* Search is anchored to the end of the string if we want to match
diff -ru ../z.old/Src/params.c Src/params.c
--- ../z.old/Src/params.c Thu Feb 17 13:36:50 2000
+++ Src/params.c Thu Feb 17 14:41:42 2000
@@ -1145,9 +1145,11 @@
if (*s == ']' || *s == Outbrack)
s++;
} else {
+ int com;
+
if (a > 0)
a--;
- if (*s == ',') {
+ if ((com = (*s == ','))) {
s++;
b = getarg(&s, &inv, v, 1, &dummy);
if (b > 0)
@@ -1157,7 +1159,7 @@
}
if (*s == ']' || *s == Outbrack) {
s++;
- if (v->isarr && a == b &&
+ if (v->isarr && a == b && !com &&
(!(v->isarr & SCANPM_MATCHMANY) ||
!(v->isarr & (SCANPM_MATCHKEY | SCANPM_MATCHVAL |
SCANPM_KEYMATCH))))
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author