zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Re: Oh no, parameter expansion
Date: Thu, 17 Feb 2000 14:49:41 +0100 (MET)	[thread overview]
Message-ID: <200002171349.OAA26252@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Sven Wischnowsky's message of Thu, 17 Feb 2000 11:30:51 +0100 (MET)


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


             reply	other threads:[~2000-02-17 13:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-17 13:49 Sven Wischnowsky [this message]
2000-02-17 18:39 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200002171349.OAA26252@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).