Module Name: src
Committed By: rillig
Date: Fri Nov 6 20:50:49 UTC 2020
Modified Files:
src/usr.bin/make: cond.c
Log Message:
make(1): fix tests directive-ifmake and varcmd with custom boolean
When make is compiled with -DUSE_UCHAR_BOOLEAN, these tests failed.
Merge duplicate code and don't depend on the actual value of TRUE when
evaluating conditions.
To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/make/cond.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.175 src/usr.bin/make/cond.c:1.176
--- src/usr.bin/make/cond.c:1.175 Thu Nov 5 17:27:16 2020
+++ src/usr.bin/make/cond.c Fri Nov 6 20:50:48 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.175 2020/11/05 17:27:16 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.176 2020/11/06 20:50:48 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.175 2020/11/05 17:27:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.176 2020/11/06 20:50:48 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -502,13 +502,15 @@ cleanup:
return str;
}
-/* The different forms of .if directives. */
-static const struct If {
+struct If {
const char *form; /* Form of if */
size_t formlen; /* Length of form */
Boolean doNot; /* TRUE if default function should be negated */
Boolean (*defProc)(size_t, const char *); /* Default function to apply */
-} ifs[] = {
+};
+
+/* The different forms of .if directives. */
+static const struct If ifs[] = {
{ "def", 3, FALSE, FuncDefined },
{ "ndef", 4, TRUE, FuncDefined },
{ "make", 4, FALSE, FuncMake },
@@ -517,6 +519,13 @@ static const struct If {
{ NULL, 0, FALSE, NULL }
};
+static Boolean
+If_Eval(const struct If *if_info, const char *arg, size_t arglen)
+{
+ Boolean res = if_info->defProc(arglen, arg);
+ return (if_info->doNot ? !res : res) ? TOK_TRUE : TOK_FALSE;
+}
+
/* Evaluate a "comparison without operator", such as in ".if ${VAR}" or
* ".if 0". */
static Token
@@ -537,7 +546,7 @@ EvalNotEmpty(CondParser *par, const char
return lhs[0] != 0;
/* Otherwise action default test ... */
- return par->if_info->defProc(strlen(lhs), lhs) == !par->if_info->doNot;
+ return If_Eval(par->if_info, lhs, strlen(lhs));
}
/* Evaluate a numerical comparison, such as in ".if ${VAR} >= 9". */
@@ -785,7 +794,7 @@ CondParser_Func(CondParser *par, Boolean
* after .if must have been taken literally, so the argument cannot
* be empty - even if it contained a variable expansion.
*/
- t = !doEval || par->if_info->defProc(arglen, arg) == !par->if_info->doNot;
+ t = !doEval || If_Eval(par->if_info, arg, arglen);
free(arg);
return t;
}