Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: help with _match, globcomplete etc. (with a PATCH)
- X-seq: zsh-workers 9763
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: help with _match, globcomplete etc. (with a PATCH)
- Date: Wed, 16 Feb 2000 16:39:36 +0100 (MET)
- In-reply-to: "Bart Schaefer"'s message of Wed, 16 Feb 2000 10:57:55 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Bart Schaefer wrote:
> } No. Seems like the (e) flag makes the thing be quoted as in double
> } quotes. I.e. with a='${~^arr}*', ${(e)a} gives `[sS] Src/M ../*', but
> } a='${(@)~^arr}' gives what we would have expected. The patch below
> } changes the calls to parsestr() to calls to parse_subst_string() to
> } get that. Hm, should we call that only conditionally, e.g. if the
> } ${(e)...} is not inquotes and has no (@) or something?
>
> My first reaction would be to answer "yes," and a little fooling around
> with 9757 applied seems to bear it out:
>
> a='*'
> print -l "${(e)a}"
>
> Would you really expect to get one file name per line in that case?
First: no. Second: it shouldn't have done globbing -- that should
happen only with ${~...}.
So, next try: always use parsestr() but sometimes turn the `Qstring's
into `String's. This gives:
% a=(a b) b='$a/'
% print -l ${(e)b}
a/
b/
% print -l "${(e)b}"
a b/
% print -l "${(e@)b}"
a/
b/
Which seems quite sensible, right?
Bye
Sven
diff -ru ../z.old/Src/subst.c Src/subst.c
--- ../z.old/Src/subst.c Wed Feb 16 12:40:05 2000
+++ Src/subst.c Wed Feb 16 16:32:12 2000
@@ -694,6 +694,22 @@
return ret < 0 ? -ret : ret;
}
+/* Parsing for the (e) flag. */
+
+static int
+subst_parse_str(char *s, int single)
+{
+ if (!parsestr(s)) {
+ if (!single) {
+ for (; *s; s++)
+ if (*s == Qstring)
+ *s = String;
+ }
+ return 0;
+ }
+ return 1;
+}
+
/* parameter substitution */
#define isstring(c) ((c) == '$' || (char)(c) == String || (char)(c) == Qstring)
@@ -1766,7 +1782,7 @@
if (prenum || postnum)
x = dopadding(x, prenum, postnum, preone, postone,
premul, postmul);
- if (eval && parse_subst_string(x))
+ if (eval && subst_parse_str(x, (qt && !nojoin)))
return NULL;
xlen = strlen(x);
for (tn = firstnode(tl);
@@ -1801,7 +1817,7 @@
if (prenum || postnum)
x = dopadding(x, prenum, postnum, preone, postone,
premul, postmul);
- if (eval && parse_subst_string(x))
+ if (eval && subst_parse_str(x, (qt && !nojoin)))
return NULL;
xlen = strlen(x);
strcatsub(&y, ostr, aptr, x, xlen, NULL, globsubst);
@@ -1816,7 +1832,7 @@
if (prenum || postnum)
x = dopadding(x, prenum, postnum, preone, postone,
premul, postmul);
- if (eval && parse_subst_string(x))
+ if (eval && subst_parse_str(x, (qt && !nojoin)))
return NULL;
if (qt && !*x && isarr != 2)
y = dupstring(nulstring);
@@ -1832,7 +1848,7 @@
if (prenum || postnum)
x = dopadding(x, prenum, postnum, preone, postone,
premul, postmul);
- if (eval && parse_subst_string(x))
+ if (eval && subst_parse_str(x, (qt && !nojoin)))
return NULL;
xlen = strlen(x);
*str = strcatsub(&y, aptr, aptr, x, xlen, fstr, globsubst);
@@ -1851,7 +1867,7 @@
if (prenum || postnum)
x = dopadding(x, prenum, postnum, preone, postone,
premul, postmul);
- if (eval && parse_subst_string(x))
+ if (eval && subst_parse_str(x, (qt && !nojoin)))
return NULL;
xlen = strlen(x);
*str = strcatsub(&y, ostr, aptr, x, xlen, fstr, globsubst);
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author