Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): make getBoolean simpler



details:   https://anonhg.NetBSD.org/src/rev/7359a126f536
branches:  trunk
changeset: 1013510:7359a126f536
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 29 13:04:30 2020 +0000

description:
make(1): make getBoolean simpler

This function is so seldom used that there is no point having
complicated code for it.

diffstat:

 usr.bin/make/main.c |  26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diffs (53 lines):

diff -r 0b085520ac8e -r 7359a126f536 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Aug 29 12:48:17 2020 +0000
+++ b/usr.bin/make/main.c       Sat Aug 29 13:04:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.327 2020/08/29 10:41:12 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.327 2020/08/29 10:41:12 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.327 2020/08/29 10:41:12 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.328 2020/08/29 13:04:30 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2183,18 +2183,12 @@
  * is FALSE, otherwise TRUE.
  */
 Boolean
-getBoolean(const char *name, Boolean bf)
+getBoolean(const char *name, Boolean fallback)
 {
-    char tmp[64];
-    char *cp;
-
-    if (snprintf(tmp, sizeof(tmp), "${%s:U:tl}", name) < (int)(sizeof(tmp))) {
-       cp = Var_Subst(tmp, VAR_GLOBAL, VARE_WANTRES);
-
-       if (cp) {
-           bf = s2Boolean(cp, bf);
-           free(cp);
-       }
-    }
-    return bf;
+    char *expr = str_concat3("${", name, ":U:tl}");
+    char *value = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
+    Boolean res = s2Boolean(value, fallback);
+    free(value);
+    free(expr);
+    return res;
 }



Home | Main Index | Thread Index | Old Index