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 code in var.c



details:   https://anonhg.NetBSD.org/src/rev/1ac416109495
branches:  trunk
changeset: 935430:1ac416109495
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jul 02 16:14:50 2020 +0000

description:
make(1): clean up code in var.c

- remove redundant parentheses in return statements
- add missing space after comma
- remove some redundant parentheses around comparisons
- use hexadecimal numbers for bit mask constants
- remove Var_GetTail and Var_GetHead, which had been unused for 19 years

diffstat:

 usr.bin/make/var.c |  155 +++++++++++++++++-----------------------------------
 1 files changed, 52 insertions(+), 103 deletions(-)

diffs (truncated from 388 to 300 lines):

diff -r f9ff61759c04 -r 1ac416109495 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Thu Jul 02 15:47:38 2020 +0000
+++ b/usr.bin/make/var.c        Thu Jul 02 16:14:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.230 2020/07/02 15:47:38 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.231 2020/07/02 16:14:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.230 2020/07/02 15:47:38 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.231 2020/07/02 16:14:50 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.230 2020/07/02 15:47:38 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.231 2020/07/02 16:14:50 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -196,20 +196,20 @@
 #define FIND_ENV       0x4   /* look in the environment also */
 
 typedef enum {
-       VAR_IN_USE      = 1,    /* Variable's value is currently being used.
+       VAR_IN_USE      = 0x01, /* Variable's value is currently being used.
                                 * Used to avoid endless recursion */
-       VAR_FROM_ENV    = 2,    /* Variable comes from the environment */
-       VAR_JUNK        = 4,    /* Variable is a junk variable that
+       VAR_FROM_ENV    = 0x02, /* Variable comes from the environment */
+       VAR_JUNK        = 0x04, /* Variable is a junk variable that
                                 * should be destroyed when done with
                                 * it. Used by Var_Parse for undefined,
                                 * modified variables */
-       VAR_KEEP        = 8,    /* Variable is VAR_JUNK, but we found
+       VAR_KEEP        = 0x08, /* Variable is VAR_JUNK, but we found
                                 * a use for it in some modifier and
                                 * the value is therefore valid */
-       VAR_EXPORTED    = 16,   /* Variable is exported */
-       VAR_REEXPORT    = 32,   /* Indicate if var needs re-export.
+       VAR_EXPORTED    = 0x10, /* Variable is exported */
+       VAR_REEXPORT    = 0x20, /* Indicate if var needs re-export.
                                 * This would be true if it contains $'s */
-       VAR_FROM_CMD    = 64    /* Variable came from command line */
+       VAR_FROM_CMD    = 0x40  /* Variable came from command line */
 } Var_Flags;
 
 typedef struct Var {
@@ -421,19 +421,19 @@
      */
     var = Hash_FindEntry(&ctxt->context, name);
 
-    if ((var == NULL) && (flags & FIND_CMD) && (ctxt != VAR_CMD)) {
+    if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMD) {
        var = Hash_FindEntry(&VAR_CMD->context, name);
     }
-    if (!checkEnvFirst && (var == NULL) && (flags & FIND_GLOBAL) &&
-       (ctxt != VAR_GLOBAL))
+    if (!checkEnvFirst && var == NULL && (flags & FIND_GLOBAL) &&
+       ctxt != VAR_GLOBAL)
     {
        var = Hash_FindEntry(&VAR_GLOBAL->context, name);
-       if ((var == NULL) && (ctxt != VAR_INTERNAL)) {
+       if (var == NULL && ctxt != VAR_INTERNAL) {
            /* VAR_INTERNAL is subordinate to VAR_GLOBAL */
            var = Hash_FindEntry(&VAR_INTERNAL->context, name);
        }
     }
-    if ((var == NULL) && (flags & FIND_ENV)) {
+    if (var == NULL && (flags & FIND_ENV)) {
        char *env;
 
        if ((env = getenv(name)) != NULL) {
@@ -448,18 +448,18 @@
            Buf_AddBytes(&v->val, len, env);
 
            v->flags = VAR_FROM_ENV;
-           return (v);
+           return v;
        } else if (checkEnvFirst && (flags & FIND_GLOBAL) &&
-                  (ctxt != VAR_GLOBAL))
+                  ctxt != VAR_GLOBAL)
        {
            var = Hash_FindEntry(&VAR_GLOBAL->context, name);
-           if ((var == NULL) && (ctxt != VAR_INTERNAL)) {
+           if (var == NULL && ctxt != VAR_INTERNAL) {
                var = Hash_FindEntry(&VAR_INTERNAL->context, name);
            }
            if (var == NULL) {
                return NULL;
            } else {
-               return ((Var *)Hash_GetValue(var));
+               return (Var *)Hash_GetValue(var);
            }
        } else {
            return NULL;
@@ -467,7 +467,7 @@
     } else if (var == NULL) {
        return NULL;
     } else {
-       return ((Var *)Hash_GetValue(var));
+       return (Var *)Hash_GetValue(var);
     }
 }
 
@@ -558,7 +558,7 @@
 {
     Hash_Entry           *ln;
     char *cp;
-    
+
     if (strchr(name, '$')) {
        cp = Var_Subst(NULL, name, VAR_GLOBAL, VARF_WANTRES);
     } else {
@@ -1073,7 +1073,7 @@
        name = expanded_name;
     }
 
-    v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? (FIND_CMD|FIND_ENV) : 0);
+    v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD|FIND_ENV) : 0);
 
     if (v == NULL) {
        Var_Set(name, val, ctxt);
@@ -1130,11 +1130,11 @@
     v = VarFind(cp ? cp : name, ctxt, FIND_CMD|FIND_GLOBAL|FIND_ENV);
     free(cp);
     if (v == NULL) {
-       return(FALSE);
-    } else {
-       (void)VarFreeEnv(v, TRUE);
+       return FALSE;
     }
-    return(TRUE);
+
+    (void)VarFreeEnv(v, TRUE);
+    return TRUE;
 }
 
 /*-
@@ -1156,18 +1156,17 @@
 char *
 Var_Value(const char *name, GNode *ctxt, char **frp)
 {
-    Var            *v;
+    Var *v;
 
     v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
     *frp = NULL;
-    if (v != NULL) {
-       char *p = (Buf_GetAll(&v->val, NULL));
-       if (VarFreeEnv(v, FALSE))
-           *frp = p;
-       return p;
-    } else {
+    if (v == NULL)
        return NULL;
-    }
+
+    char *p = (Buf_GetAll(&v->val, NULL));
+    if (VarFreeEnv(v, FALSE))
+       *frp = p;
+    return p;
 }
 
 /*-
@@ -1206,7 +1205,7 @@
        *slash = '\0';
        Buf_AddBytes(buf, strlen(word), word);
        *slash = '/';
-       return (TRUE);
+       return TRUE;
     } else {
        /*
         * If no directory part, give . (q.v. the POSIX standard)
@@ -1380,7 +1379,7 @@
        addSpace = TRUE;
        Buf_AddBytes(buf, strlen(word), word);
     }
-    return(addSpace);
+    return addSpace;
 }
 
 #ifdef SYSVVARSUB
@@ -1431,7 +1430,7 @@
        Buf_AddBytes(buf, strlen(word), word);
     }
 
-    return(addSpace);
+    return addSpace;
 }
 #endif
 
@@ -1470,7 +1469,7 @@
        addSpace = TRUE;
        Buf_AddBytes(buf, strlen(word), word);
     }
-    return(addSpace);
+    return addSpace;
 }
 
 
@@ -1639,14 +1638,14 @@
             */
            return ((Buf_Size(buf) != origSize) || addSpace);
        }
-       return (addSpace);
+       return addSpace;
     }
  nosub:
     if (addSpace && vpstate->varSpace) {
        Buf_AddByte(buf, vpstate->varSpace);
     }
     Buf_AddBytes(buf, wordLen, word);
-    return(TRUE);
+    return TRUE;
 }
 
 #ifndef NO_REGEX
@@ -1732,7 +1731,7 @@
        for (rp = pat->replace; *rp; rp++) {
            if ((*rp == '\\') && ((rp[1] == '&') || (rp[1] == '\\'))) {
                MAYBE_ADD_SPACE();
-               Buf_AddByte(buf,rp[1]);
+               Buf_AddByte(buf, rp[1]);
                rp++;
            }
            else if ((*rp == '&') ||
@@ -1800,11 +1799,11 @@
     case REG_NOMATCH:
        if (*wp) {
            MAYBE_ADD_SPACE();
-           Buf_AddBytes(buf,strlen(wp),wp);
+           Buf_AddBytes(buf, strlen(wp), wp);
        }
        break;
     }
-    return(addSpace||added);
+    return addSpace || added;
 }
 #endif
 
@@ -1959,7 +1958,7 @@
        struct stat st;
        char rbuf[MAXPATHLEN];
        char *rp;
-                           
+
        if (addSpace && vpstate->varSpace) {
            Buf_AddByte(buf, vpstate->varSpace);
        }
@@ -1967,9 +1966,9 @@
        rp = cached_realpath(word, rbuf);
        if (rp && *rp == '/' && stat(rp, &st) == 0)
                word = rp;
-       
+
        Buf_AddBytes(buf, strlen(word), word);
-       return(addSpace);
+       return addSpace;
 }
 
 /*-
@@ -3720,7 +3719,7 @@
     }
  out:
     *lengthPtr = tstr - start;
-    return (nstr);
+    return nstr;
 
  bad_modifier:
     /* "{(" */
@@ -3734,7 +3733,7 @@
              v->name, delim);
     free(*freePtr);
     *freePtr = NULL;
-    return (var_Error);
+    return var_Error;
 }
 
 /*-
@@ -3896,7 +3895,7 @@
             */
            *lengthPtr = tstr - str;
            Buf_Destroy(&buf, TRUE);
-           return (var_Error);
+           return var_Error;
        }
        str = Buf_GetAll(&buf, &vlen);
 
@@ -3984,7 +3983,7 @@
                    char *pstr = bmake_strndup(start, *lengthPtr);
                    *freePtr = pstr;
                    Buf_Destroy(&buf, TRUE);
-                   return(pstr);



Home | Main Index | Thread Index | Old Index