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): clean up PrintVar



details:   https://anonhg.NetBSD.org/src/rev/be66853fba8c
branches:  trunk
changeset: 941461:be66853fba8c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 22 07:12:13 2020 +0000

description:
make(1): clean up PrintVar

Conceptually, the last parameters of Var_Subst and Var_Value differ a
lot.  The former is the actual variable value while the latter is just a
pointer to be freed.  It will be changed to a void pointer in a few
commits.

To keep the number of needed variables small and the code simple, the
printf statement is mentioned in each branch.  An additional benefit is
that in 2 of the 3 branches, no null pointer can occur.

diffstat:

 usr.bin/make/main.c |  30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diffs (58 lines):

diff -r 6308915b4792 -r be66853fba8c usr.bin/make/main.c
--- a/usr.bin/make/main.c       Thu Oct 22 07:01:25 2020 +0000
+++ b/usr.bin/make/main.c       Thu Oct 22 07:12:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.383 2020/10/22 07:01:25 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.384 2020/10/22 07:12:13 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
 #include "trace.h"
 
 /*     "@(#)main.c     8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.383 2020/10/22 07:01:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.384 2020/10/22 07:12:13 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
            "The Regents of the University of California.  "
@@ -870,24 +870,28 @@
 static void
 PrintVar(const char *varname, Boolean expandVars)
 {
-       const char *value;
-       char *p1;
+       if (strchr(varname, '$')) {
+               char *evalue;
+               (void)Var_Subst(varname, VAR_GLOBAL, VARE_WANTRES, &evalue);
+               /* TODO: handle errors */
+               printf("%s\n", evalue);
+               bmake_free(evalue);
 
-       if (strchr(varname, '$')) {
-               (void)Var_Subst(varname, VAR_GLOBAL, VARE_WANTRES, &p1);
-               /* TODO: handle errors */
-               value = p1;
        } else if (expandVars) {
                char *expr = str_concat3("${", varname, "}");
-               (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &p1);
+               char *evalue;
+               (void)Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES, &evalue);
                /* TODO: handle errors */
-               value = p1;
                free(expr);
+               printf("%s\n", evalue);
+               bmake_free(evalue);
+
        } else {
-               value = Var_Value(varname, VAR_GLOBAL, &p1);
+               char *freeIt;
+               const char *value = Var_Value(varname, VAR_GLOBAL, &freeIt);
+               printf("%s\n", value ? value : "");
+               bmake_free(freeIt);
        }
-       printf("%s\n", value ? value : "");
-       bmake_free(p1);
 }
 
 static void



Home | Main Index | Thread Index | Old Index