Thu Sep 3 17:16:01 2020 UTC ()
make(1): document use of magic values in CondDoEmpty


(rillig)
diff -r1.108 -r1.109 src/usr.bin/make/cond.c

cvs diff -r1.108 -r1.109 src/usr.bin/make/cond.c (expand / switch to unified diff)

--- src/usr.bin/make/cond.c 2020/09/03 16:14:58 1.108
+++ src/usr.bin/make/cond.c 2020/09/03 17:16:01 1.109
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $ */ 1/* $NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -60,34 +60,34 @@ @@ -60,34 +60,34 @@
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE. 69 * SUCH DAMAGE.
70 */ 70 */
71 71
72#ifndef MAKE_NATIVE 72#ifndef MAKE_NATIVE
73static char rcsid[] = "$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $"; 73static char rcsid[] = "$NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 rillig Exp $";
74#else 74#else
75#include <sys/cdefs.h> 75#include <sys/cdefs.h>
76#ifndef lint 76#ifndef lint
77#if 0 77#if 0
78static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94"; 78static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
79#else 79#else
80__RCSID("$NetBSD: cond.c,v 1.108 2020/09/03 16:14:58 rillig Exp $"); 80__RCSID("$NetBSD: cond.c,v 1.109 2020/09/03 17:16:01 rillig Exp $");
81#endif 81#endif
82#endif /* not lint */ 82#endif /* not lint */
83#endif 83#endif
84 84
85/*- 85/*-
86 * cond.c -- 86 * cond.c --
87 * Functions to handle conditionals in a makefile. 87 * Functions to handle conditionals in a makefile.
88 * 88 *
89 * Interface: 89 * Interface:
90 * Cond_Eval Evaluate the conditional in the passed line. 90 * Cond_Eval Evaluate the conditional in the passed line.
91 * 91 *
92 */ 92 */
93 93
@@ -709,26 +709,27 @@ get_mpt_arg(Boolean doEval, const char * @@ -709,26 +709,27 @@ get_mpt_arg(Boolean doEval, const char *
709 709
710 /* 710 /*
711 * For consistency with the other functions we can't generate the 711 * For consistency with the other functions we can't generate the
712 * true/false here. 712 * true/false here.
713 */ 713 */
714 length = *val ? 2 : 1; 714 length = *val ? 2 : 1;
715 free(val_freeIt); 715 free(val_freeIt);
716 return length; 716 return length;
717} 717}
718 718
719static Boolean 719static Boolean
720CondDoEmpty(int arglen, const char *arg MAKE_ATTR_UNUSED) 720CondDoEmpty(int arglen, const char *arg MAKE_ATTR_UNUSED)
721{ 721{
 722 /* Magic values ahead, see get_mpt_arg. */
722 return arglen == 1; 723 return arglen == 1;
723} 724}
724 725
725static Token 726static Token
726compare_function(Boolean doEval) 727compare_function(Boolean doEval)
727{ 728{
728 static const struct fn_def { 729 static const struct fn_def {
729 const char *fn_name; 730 const char *fn_name;
730 size_t fn_name_len; 731 size_t fn_name_len;
731 int (*fn_getarg)(Boolean, const char **, char **, const char *); 732 int (*fn_getarg)(Boolean, const char **, char **, const char *);
732 Boolean (*fn_proc)(int, const char *); 733 Boolean (*fn_proc)(int, const char *);
733 } fn_defs[] = { 734 } fn_defs[] = {
734 { "defined", 7, CondGetArg, CondDoDefined }, 735 { "defined", 7, CondGetArg, CondDoDefined },
@@ -1222,27 +1223,27 @@ Cond_Eval(const char *line) @@ -1222,27 +1223,27 @@ Cond_Eval(const char *line)
1222 max_if_depth += MAXIF_BUMP; 1223 max_if_depth += MAXIF_BUMP;
1223 cond_state = bmake_realloc(cond_state, 1224 cond_state = bmake_realloc(cond_state,
1224 max_if_depth * sizeof(*cond_state)); 1225 max_if_depth * sizeof(*cond_state));
1225 } 1226 }
1226 state = cond_state[cond_depth]; 1227 state = cond_state[cond_depth];
1227 cond_depth++; 1228 cond_depth++;
1228 if (state > ELSE_ACTIVE) { 1229 if (state > ELSE_ACTIVE) {
1229 /* If we aren't parsing the data, treat as always false */ 1230 /* If we aren't parsing the data, treat as always false */
1230 cond_state[cond_depth] = SKIP_TO_ELSE; 1231 cond_state[cond_depth] = SKIP_TO_ELSE;
1231 return COND_SKIP; 1232 return COND_SKIP;
1232 } 1233 }
1233 } 1234 }
1234 1235
1235 /* And evaluate the conditional expresssion */ 1236 /* And evaluate the conditional expression */
1236 if (Cond_EvalExpression(ifp, line, &value, 1, TRUE) == COND_INVALID) { 1237 if (Cond_EvalExpression(ifp, line, &value, 1, TRUE) == COND_INVALID) {
1237 /* Syntax error in conditional, error message already output. */ 1238 /* Syntax error in conditional, error message already output. */
1238 /* Skip everything to matching .endif */ 1239 /* Skip everything to matching .endif */
1239 cond_state[cond_depth] = SKIP_TO_ELSE; 1240 cond_state[cond_depth] = SKIP_TO_ELSE;
1240 return COND_SKIP; 1241 return COND_SKIP;
1241 } 1242 }
1242 1243
1243 if (!value) { 1244 if (!value) {
1244 cond_state[cond_depth] = SEARCH_FOR_ELIF; 1245 cond_state[cond_depth] = SEARCH_FOR_ELIF;
1245 return COND_SKIP; 1246 return COND_SKIP;
1246 } 1247 }
1247 cond_state[cond_depth] = IF_ACTIVE; 1248 cond_state[cond_depth] = IF_ACTIVE;
1248 return COND_PARSE; 1249 return COND_PARSE;