* PATCH: Re: Oh no, parameter expansion
@ 2000-02-17 13:49 Sven Wischnowsky
2000-02-17 18:39 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Sven Wischnowsky @ 2000-02-17 13:49 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: Re: Oh no, parameter expansion
2000-02-17 13:49 PATCH: Re: Oh no, parameter expansion Sven Wischnowsky
@ 2000-02-17 18:39 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2000-02-17 18:39 UTC (permalink / raw)
To: zsh-workers
Sven Wischnowsky wrote:
> 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?
Yes, that's much more logical.
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-02-17 18:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-17 13:49 PATCH: Re: Oh no, parameter expansion Sven Wischnowsky
2000-02-17 18:39 ` Peter Stephenson
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).