about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2020-09-13 16:19:52 -0700
committerBart Schaefer <schaefer@zsh.org>2020-09-13 16:19:52 -0700
commit63b6398b7017d3850010f47458818a439479a456 (patch)
tree349aded0a6fbf66d164c0b5220fac9923b98b50f /Src
parent24a82b9dad1cbe109d9fb5753c429fd37b1618cd (diff)
downloadzsh-63b6398b7017d3850010f47458818a439479a456.tar.gz
zsh-63b6398b7017d3850010f47458818a439479a456.tar.xz
zsh-63b6398b7017d3850010f47458818a439479a456.zip
47364: Enable extendedglob in pattern with ${(*)name/pattern/replacement}
Mikael Magnusson: 47382: Completion for 47364
Diffstat (limited to 'Src')
-rw-r--r--Src/subst.c19
-rw-r--r--Src/zsh.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/Src/subst.c b/Src/subst.c
index b98ddaf02..2af61653a 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1708,7 +1708,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
     /*
      * This expressive name refers to the set of flags which
      * is applied to matching for #, %, / and their doubled variants:
-     * (M), (R), (B), (E), (N), (S).
+     * (M), (R), (B), (E), (N), (S), (*).
      */
     int flags = 0;
     /* Value from (I) flag, used for ditto. */
@@ -1930,6 +1930,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		case '@':
 		    nojoin = 2;	/* nojoin = 2 means force */
 		    break;
+		case '*':
+		case Star:
+		    flags |= SUB_EGLOB;
+		    break;
 		case 'M':
 		    flags |= SUB_MATCH;
 		    break;
@@ -2810,7 +2814,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		    c == '#' || c == Pound ||
 		    c == '?' || c == Quest ||
 		    c == '/')) {
-
+	int eglob = isset(EXTENDEDGLOB);
 	/*
 	 * Default index is 1 if no (I) or (I) gave zero.   But
 	 * why don't we set the default explicitly at the start
@@ -2832,9 +2836,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 	    char *ptr;
 	    /*
 	     * previous flags are irrelevant, except for (S) which
-	     * indicates shortest substring; else look for longest.
+	     * indicates shortest substring; else look for longest,
+	     # and (*) which temporarily enables extended globbing.
 	     */
-	    flags = (flags & SUB_SUBSTR) ? 0 : SUB_LONG;
+	    flags = ((flags & SUB_SUBSTR) ? 0 : SUB_LONG)|(flags & SUB_EGLOB);
 	    if ((c = *s) == '/') {
 		/* doubled, so replace all occurrences */
 		flags |= SUB_GLOBAL;
@@ -3136,7 +3141,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		for (ap = aval; *ap; ap++) {
 		    untokenize(*ap);
 		}
+		if (flags & SUB_EGLOB)
+		    opts[EXTENDEDGLOB] = 1;
 		getmatcharr(&aval, s, flags, flnum, replstr);
+		opts[EXTENDEDGLOB] = eglob;
 	    } else {
 		if (vunset) {
 		    if (vunset > 0 && unset(UNSET)) {
@@ -3151,7 +3159,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 		    copied = 1;
 		    untokenize(val);
 		}
+		if (flags & SUB_EGLOB)
+		    opts[EXTENDEDGLOB] = 1;
 		getmatch(&val, s, flags, flnum, replstr);
+		opts[EXTENDEDGLOB] = eglob;
 	    }
 	    break;
 	}
diff --git a/Src/zsh.h b/Src/zsh.h
index 94f5099c6..6cf1b4186 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1991,6 +1991,7 @@ struct tieddata {
 #define SUB_START	0x1000  /* force match at start with SUB_END
 				 * and no SUB_SUBSTR */
 #define SUB_LIST	0x2000  /* no substitution, return list of matches */
+#define SUB_EGLOB	0x4000	/* use extended globbing in patterns */
 
 /*
  * Structure recording multiple matches inside a test string.