aboutsummaryrefslogtreecommitdiff
path: root/cond.c
diff options
context:
space:
mode:
Diffstat (limited to 'cond.c')
-rw-r--r--cond.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/cond.c b/cond.c
index 3dd177d5acb8..fb7f789af0d1 100644
--- a/cond.c
+++ b/cond.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -81,12 +81,9 @@
* of one of the .if directives or the condition in a
* ':?then:else' variable modifier.
*
- * Cond_save_depth
- * Cond_restore_depth
- * Save and restore the nesting of the conditions, at
- * the start and end of including another makefile, to
- * ensure that in each makefile the conditional
- * directives are well-balanced.
+ * Cond_EndFile
+ * At the end of reading a makefile, ensure that the
+ * conditional directives are well-balanced.
*/
#include <errno.h>
@@ -95,7 +92,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.342 2022/09/24 16:13:48 rillig Exp $");
/*
* Conditional expressions conform to this grammar:
@@ -178,8 +175,7 @@ typedef struct CondParser {
static CondResult CondParser_Or(CondParser *par, bool);
-static unsigned int cond_depth = 0; /* current .if nesting level */
-static unsigned int cond_min_depth = 0; /* depth at makefile open */
+unsigned int cond_depth = 0; /* current .if nesting level */
/* Names for ComparisonOp. */
static const char opname[][3] = { "<", "<=", ">", ">=", "==", "!=" };
@@ -570,10 +566,10 @@ EvalCompareNum(double lhs, ComparisonOp op, double rhs)
return lhs > rhs;
case GE:
return lhs >= rhs;
- case NE:
- return lhs != rhs;
- default:
+ case EQ:
return lhs == rhs;
+ default:
+ return lhs != rhs;
}
}
@@ -583,7 +579,9 @@ EvalCompareStr(CondParser *par, const char *lhs,
{
if (op != EQ && op != NE) {
Parse_Error(PARSE_FATAL,
- "String comparison operator must be either == or !=");
+ "Comparison with '%s' requires both operands "
+ "'%s' and '%s' to be numeric",
+ opname[op], lhs, rhs);
par->printedError = true;
return TOK_ERROR;
}
@@ -1135,7 +1133,7 @@ Cond_EvalLine(const char *line)
"The .endif directive does not take arguments");
}
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less endif");
return CR_TRUE;
}
@@ -1165,7 +1163,7 @@ Cond_EvalLine(const char *line)
"The .else directive "
"does not take arguments");
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less else");
return CR_TRUE;
}
@@ -1200,7 +1198,7 @@ Cond_EvalLine(const char *line)
return CR_ERROR;
if (isElif) {
- if (cond_depth == cond_min_depth) {
+ if (cond_depth == CurFile_CondMinDepth()) {
Parse_Error(PARSE_FATAL, "if-less elif");
return CR_TRUE;
}
@@ -1254,24 +1252,13 @@ Cond_EvalLine(const char *line)
}
void
-Cond_restore_depth(unsigned int saved_depth)
+Cond_EndFile(void)
{
- unsigned int open_conds = cond_depth - cond_min_depth;
+ unsigned int open_conds = cond_depth - CurFile_CondMinDepth();
- if (open_conds != 0 || saved_depth > cond_depth) {
+ if (open_conds != 0) {
Parse_Error(PARSE_FATAL, "%u open conditional%s",
open_conds, open_conds == 1 ? "" : "s");
- cond_depth = cond_min_depth;
+ cond_depth = CurFile_CondMinDepth();
}
-
- cond_min_depth = saved_depth;
-}
-
-unsigned int
-Cond_save_depth(void)
-{
- unsigned int depth = cond_min_depth;
-
- cond_min_depth = cond_depth;
- return depth;
}