summaryrefslogtreecommitdiff
path: root/Src/cond.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/cond.c')
-rw-r--r--Src/cond.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/Src/cond.c b/Src/cond.c
index c67354297..df9065660 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
@@ -282,8 +297,7 @@ evalcond(Estate state, char *fromtest)
right = dupstring(opat = ecrawstr(state->prog, state->pc,
&htok));
- if (htok)
- singsub(&right);
+ singsub(&right);
save = (!(state->prog->flags & EF_HEAP) &&
!strcmp(opat, right) && pprog != dummy_patprog2);