summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-09-13 09:42:24 +0100
committerPeter Stephenson <pws@zsh.org>2016-09-13 09:42:24 +0100
commit1993a3cd2a7b479530da8f37f6fb3ea05a0efb71 (patch)
tree1b352222ea93c281cddae037a09847439a1ace2f /Src
parent23c1c774b95861209fe97d1436b6563d5946f939 (diff)
downloadzsh-1993a3cd2a7b479530da8f37f6fb3ea05a0efb71.tar.gz
zsh-1993a3cd2a7b479530da8f37f6fb3ea05a0efb71.zip
39292: Distinguish "=" and "==" tests in output.
This is both in xtrace output and shell code rebuilt from internal structures.
Diffstat (limited to 'Src')
-rw-r--r--Src/cond.c11
-rw-r--r--Src/parse.c9
-rw-r--r--Src/text.c3
-rw-r--r--Src/zsh.h39
4 files changed, 39 insertions, 23 deletions
diff --git a/Src/cond.c b/Src/cond.c
index 0381fe94b..f25ebd4a3 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -34,7 +34,7 @@
int tracingcond; /* updated by execcond() in exec.c */
static char *condstr[COND_MOD] = {
- "!", "&&", "||", "==", "!=", "<", ">", "-nt", "-ot", "-ef", "-eq",
+ "!", "&&", "||", "=", "==", "!=", "<", ">", "-nt", "-ot", "-ef", "-eq",
"-ne", "-lt", "-gt", "-le", "-ge", "=~"
};
@@ -196,7 +196,8 @@ evalcond(Estate state, char *fromtest)
cond_subst(&left, !fromtest);
untokenize(left);
}
- if (ctype <= COND_GE && ctype != COND_STREQ && ctype != COND_STRNEQ) {
+ if (ctype <= COND_GE && ctype != COND_STREQ && ctype != COND_STRDEQ &&
+ ctype != COND_STRNEQ) {
right = ecgetstr(state, EC_DUPTOK, &htok);
if (htok) {
cond_subst(&right, !fromtest);
@@ -208,7 +209,8 @@ evalcond(Estate state, char *fromtest)
fputc(' ',xtrerr);
quotedzputs(left, xtrerr);
fprintf(xtrerr, " %s ", condstr[ctype]);
- if (ctype == COND_STREQ || ctype == COND_STRNEQ) {
+ if (ctype == COND_STREQ || ctype == COND_STRDEQ ||
+ ctype == COND_STRNEQ) {
char *rt = dupstring(ecrawstr(state->prog, state->pc, NULL));
cond_subst(&rt, !fromtest);
quote_tokenized_output(rt, xtrerr);
@@ -287,6 +289,7 @@ evalcond(Estate state, char *fromtest)
switch (ctype) {
case COND_STREQ:
+ case COND_STRDEQ:
case COND_STRNEQ:
{
int test, npat = state->pc[1];
@@ -313,7 +316,7 @@ evalcond(Estate state, char *fromtest)
state->pc += 2;
test = (pprog && pattry(pprog, left));
- return !(ctype == COND_STREQ ? test : !test);
+ return !(ctype == COND_STRNEQ ? !test : test);
}
case COND_STRLT:
return !(strcmp(left, right) < 0);
diff --git a/Src/parse.c b/Src/parse.c
index 94ac04922..6e7d40e29 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2498,12 +2498,17 @@ par_cond_triple(char *a, char *b, char *c)
{
int t0;
- if ((b[0] == Equals || b[0] == '=') &&
- (!b[1] || ((b[1] == Equals || b[1] == '=') && !b[2]))) {
+ if ((b[0] == Equals || b[0] == '=') && !b[1]) {
ecadd(WCB_COND(COND_STREQ, 0));
ecstr(a);
ecstr(c);
ecadd(ecnpats++);
+ } else if ((b[0] == Equals || b[0] == '=') &&
+ (b[1] == Equals || b[1] == '=') && !b[2]) {
+ ecadd(WCB_COND(COND_STRDEQ, 0));
+ ecstr(a);
+ ecstr(c);
+ ecadd(ecnpats++);
} else if (b[0] == '!' && (b[1] == Equals || b[1] == '=') && !b[2]) {
ecadd(WCB_COND(COND_STRNEQ, 0));
ecstr(a);
diff --git a/Src/text.c b/Src/text.c
index d387d361a..3658b1bc6 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -46,7 +46,7 @@ int text_expand_tabs;
* et seq. in zsh.h.
*/
static const char *cond_binary_ops[] = {
- "=", "!=", "<", ">", "-nt", "-ot", "-ef", "-eq",
+ "=", "==", "!=", "<", ">", "-nt", "-ot", "-ef", "-eq",
"-ne", "-lt", "-gt", "-le", "-ge", "=~", NULL
};
@@ -934,6 +934,7 @@ gettext2(Estate state)
taddstr(" ");
taddstr(ecgetstr(state, EC_NODUP, NULL));
if (ctype == COND_STREQ ||
+ ctype == COND_STRDEQ ||
ctype == COND_STRNEQ)
state->pc++;
} else {
diff --git a/Src/zsh.h b/Src/zsh.h
index 87e6a9868..996bc3369 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -622,27 +622,34 @@ struct timedfn {
/* (1<<4) is used for Z_END, see the wordcode definitions */
/* (1<<5) is used for Z_SIMPLE, see the wordcode definitions */
-/* Condition types. */
+/*
+ * Condition types.
+ *
+ * Careful when changing these: both cond_binary_ops in text.c and
+ * condstr in cond.c depend on these. (The zsh motto is "two instances
+ * are better than one". Or something.)
+ */
#define COND_NOT 0
#define COND_AND 1
#define COND_OR 2
#define COND_STREQ 3
-#define COND_STRNEQ 4
-#define COND_STRLT 5
-#define COND_STRGTR 6
-#define COND_NT 7
-#define COND_OT 8
-#define COND_EF 9
-#define COND_EQ 10
-#define COND_NE 11
-#define COND_LT 12
-#define COND_GT 13
-#define COND_LE 14
-#define COND_GE 15
-#define COND_REGEX 16
-#define COND_MOD 17
-#define COND_MODI 18
+#define COND_STRDEQ 4
+#define COND_STRNEQ 5
+#define COND_STRLT 6
+#define COND_STRGTR 7
+#define COND_NT 8
+#define COND_OT 9
+#define COND_EF 10
+#define COND_EQ 11
+#define COND_NE 12
+#define COND_LT 13
+#define COND_GT 14
+#define COND_LE 15
+#define COND_GE 16
+#define COND_REGEX 17
+#define COND_MOD 18
+#define COND_MODI 19
typedef int (*CondHandler) _((char **, int));