summaryrefslogtreecommitdiff
path: root/Src/cond.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2014-06-01 20:55:39 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2014-06-01 20:55:39 +0100
commit501f2003a89673cebc956ec5aa5f4f401b3a8f5f (patch)
tree22b93c8461fbf6a9de5ff234bfd8f3292a8ab896 /Src/cond.c
parent880020ca2ed8207fe39aa95169a6f9226ff7b8dc (diff)
downloadzsh-501f2003a89673cebc956ec5aa5f4f401b3a8f5f.tar.gz
zsh-501f2003a89673cebc956ec5aa5f4f401b3a8f5f.zip
32640: (#q) in [[ ... ]] forces globbing
Diffstat (limited to 'Src/cond.c')
-rw-r--r--Src/cond.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/Src/cond.c b/Src/cond.c
index c67354297..6e9b55806 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -37,6 +37,21 @@ static char *condstr[COND_MOD] = {
"-ne", "-lt", "-gt", "-le", "-ge", "=~"
};
+static void cond_subst(char **strp, int glob_ok)
+{
+ if (glob_ok &&
+ checkglobqual(*strp, strlen(*strp), 1, NULL)) {
+ LinkList args = newlinklist();
+ addlinknode(args, *strp);
+ prefork(args, 0);
+ while (!errflag && args && nonempty(args) &&
+ has_token((char *)peekfirst(args)))
+ zglob(args, firstnode(args), 0);
+ *strp = sepjoin(hlinklist2array(args, 0), NULL, 1);
+ } else
+ singsub(strp);
+}
+
/*
* Evaluate a conditional expression given the arguments.
* If fromtest is set, the caller is the test or [ builtin;
@@ -177,13 +192,13 @@ evalcond(Estate state, char *fromtest)
}
left = ecgetstr(state, EC_DUPTOK, &htok);
if (htok) {
- singsub(&left);
+ cond_subst(&left, !fromtest);
untokenize(left);
}
if (ctype <= COND_GE && ctype != COND_STREQ && ctype != COND_STRNEQ) {
right = ecgetstr(state, EC_DUPTOK, &htok);
if (htok) {
- singsub(&right);
+ cond_subst(&right, !fromtest);
untokenize(right);
}
}
@@ -194,7 +209,7 @@ evalcond(Estate state, char *fromtest)
fprintf(xtrerr, " %s ", condstr[ctype]);
if (ctype == COND_STREQ || ctype == COND_STRNEQ) {
char *rt = dupstring(ecrawstr(state->prog, state->pc, NULL));
- singsub(&rt);
+ cond_subst(&rt, !fromtest);
quote_tokenized_output(rt, xtrerr);
}
else
@@ -283,7 +298,7 @@ evalcond(Estate state, char *fromtest)
right = dupstring(opat = ecrawstr(state->prog, state->pc,
&htok));
if (htok)
- singsub(&right);
+ cond_subst(&right, !fromtest);
save = (!(state->prog->flags & EF_HEAP) &&
!strcmp(opat, right) && pprog != dummy_patprog2);
@@ -517,17 +532,6 @@ cond_val(char **args, int num)
}
/**/
-mod_export int
-cond_match(char **args, int num, char *str)
-{
- char *s = args[num];
-
- singsub(&s);
-
- return matchpat(str, s);
-}
-
-/**/
static void
tracemodcond(char *name, char **args, int inf)
{