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 stylistically



details:   https://anonhg.NetBSD.org/src/rev/b1464dd2643b
branches:  trunk
changeset: 977968:b1464dd2643b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 07 10:16:18 2020 +0000

description:
make(1): clean up code stylistically

* Replace character literal 0 with '\0'.
* Replace pointer literal 0 with NULL.
* Remove redundant parentheses.
* Parentheses in multi-line conditions are not redundant at the
  beginning of a line.
* Replace a few !ptr with ptr == NULL.
* Replace a few ptr with ptr != NULL.
* Replace (expr & mask) == 0 with !(expr & mask).
* Remove redundant braces for blocks in cases where the generated code
  stays the same.  (Assertions further down in the code would get
  different line numbers.)
* Rename parameters in CondParser_String to reflect the data flow.
* Replace #ifdef notdef with #if 0.

The generated code stays exactly the same, at least with GCC 5.5.0 on
NetBSD 8.0 amd64 using the default configuration.

diffstat:

 usr.bin/make/arch.c    |  15 +++++++------
 usr.bin/make/buf.c     |   6 ++--
 usr.bin/make/compat.c  |  13 +++++------
 usr.bin/make/cond.c    |  53 ++++++++++++++++++++++++-------------------------
 usr.bin/make/dir.c     |  12 +++++-----
 usr.bin/make/for.c     |   8 +++---
 usr.bin/make/job.c     |  40 ++++++++++++++++++------------------
 usr.bin/make/main.c    |  22 ++++++++++----------
 usr.bin/make/make.c    |  26 ++++++++++++------------
 usr.bin/make/meta.c    |  14 ++++++------
 usr.bin/make/nonints.h |  14 +++++++-----
 usr.bin/make/parse.c   |  28 +++++++++++++-------------
 usr.bin/make/str.c     |  26 ++++++++++++------------
 usr.bin/make/var.c     |  22 ++++++++++----------
 14 files changed, 150 insertions(+), 149 deletions(-)

diffs (truncated from 1110 to 300 lines):

diff -r fd865ddaf240 -r b1464dd2643b usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Nov 07 08:48:11 2020 +0000
+++ b/usr.bin/make/arch.c       Sat Nov 07 10:16:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.155 2020/11/06 23:59:21 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.156 2020/11/07 10:16:18 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.155 2020/11/06 23:59:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.156 2020/11/07 10:16:18 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -335,7 +335,8 @@
             */
            buf = sacrifice = str_concat4(libName, "(", memName, ")");
 
-           if (strchr(memName, '$') && strcmp(memName, oldMemName) == 0) {
+           if (strchr(memName, '$') != NULL &&
+               strcmp(memName, oldMemName) == 0) {
                /*
                 * Must contain dynamic sources, so we can't deal with it now.
                 * Just create an ARCHV node for the thing and let
@@ -490,8 +491,8 @@
      * We use the ARMAG string to make sure this is an archive we
      * can handle...
      */
-    if ((fread(magic, SARMAG, 1, arch) != 1) ||
-       (strncmp(magic, ARMAG, SARMAG) != 0)) {
+    if (fread(magic, SARMAG, 1, arch) != 1 ||
+       strncmp(magic, ARMAG, SARMAG) != 0) {
        fclose(arch);
        return NULL;
     }
@@ -721,8 +722,8 @@
      * We use the ARMAG string to make sure this is an archive we
      * can handle...
      */
-    if ((fread(magic, SARMAG, 1, arch) != 1) ||
-       (strncmp(magic, ARMAG, SARMAG) != 0)) {
+    if (fread(magic, SARMAG, 1, arch) != 1 ||
+       strncmp(magic, ARMAG, SARMAG) != 0) {
        fclose(arch);
        return NULL;
     }
diff -r fd865ddaf240 -r b1464dd2643b usr.bin/make/buf.c
--- a/usr.bin/make/buf.c        Sat Nov 07 08:48:11 2020 +0000
+++ b/usr.bin/make/buf.c        Sat Nov 07 10:16:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $  */
+/*     $NetBSD: buf.c,v 1.43 2020/11/07 10:16:18 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -75,7 +75,7 @@
 #include "make.h"
 
 /*     "@(#)buf.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $");
+MAKE_RCSID("$NetBSD: buf.c,v 1.43 2020/11/07 10:16:18 rillig Exp $");
 
 /* Make space in the buffer for adding a single byte. */
 void
@@ -160,7 +160,7 @@
 void
 Buf_Init(Buffer *buf, size_t cap)
 {
-    if (cap <= 0)
+    if (cap == 0)
        cap = 256;
     buf->cap = cap;
     buf->len = 0;
diff -r fd865ddaf240 -r b1464dd2643b usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sat Nov 07 08:48:11 2020 +0000
+++ b/usr.bin/make/compat.c     Sat Nov 07 10:16:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.175 2020/11/07 10:16:18 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.175 2020/11/07 10:16:18 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -201,7 +201,7 @@
     (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
     /* TODO: handle errors */
 
-    if (*cmdStart == '\0') {
+    if (cmdStart[0] == '\0') {
        free(cmdStart);
        return 0;
     }
@@ -243,7 +243,7 @@
     /*
      * If we did not end up with a command, just skip it.
      */
-    if (!*cmd)
+    if (cmd[0] == '\0')
        return 0;
 
 #if !defined(MAKE_NATIVE)
@@ -599,15 +599,14 @@
                pgn->flags &= ~(unsigned)REMAKE;
                break;
            case MADE:
-               if ((gn->type & OP_EXEC) == 0) {
+               if (!(gn->type & OP_EXEC)) {
                    pgn->flags |= CHILDMADE;
                    Make_TimeStamp(pgn, gn);
                }
                break;
            case UPTODATE:
-               if ((gn->type & OP_EXEC) == 0) {
+               if (!(gn->type & OP_EXEC))
                    Make_TimeStamp(pgn, gn);
-               }
                break;
            default:
                break;
diff -r fd865ddaf240 -r b1464dd2643b usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Nov 07 08:48:11 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Nov 07 10:16:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.177 2020/11/06 22:39:10 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.178 2020/11/07 10:16:18 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.177 2020/11/06 22:39:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.178 2020/11/07 10:16:18 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -230,7 +230,7 @@
     paren_depth = 0;
     for (;;) {
        char ch = *p;
-       if (ch == 0 || ch == ' ' || ch == '\t')
+       if (ch == '\0' || ch == ' ' || ch == '\t')
            break;
        if ((ch == '&' || ch == '|') && paren_depth == 0)
            break;
@@ -381,13 +381,13 @@
  *
  * Results:
  *     Returns the string, absent any quotes, or NULL on error.
- *     Sets quoted if the string was quoted.
- *     Sets freeIt if needed.
+ *     Sets out_quoted if the string was quoted.
+ *     Sets out_freeIt.
  */
 /* coverity:[+alloc : arg-*4] */
 static const char *
 CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS,
-                 Boolean *quoted, void **freeIt)
+                 Boolean *out_quoted, void **out_freeIt)
 {
     Buffer buf;
     const char *str;
@@ -400,12 +400,12 @@
 
     Buf_Init(&buf, 0);
     str = NULL;
-    *freeIt = NULL;
-    *quoted = qt = par->p[0] == '"' ? 1 : 0;
+    *out_freeIt = NULL;
+    *out_quoted = qt = par->p[0] == '"';
     start = par->p;
     if (qt)
        par->p++;
-    while (par->p[0] && str == NULL) {
+    while (par->p[0] != '\0' && str == NULL) {
        switch (par->p[0]) {
        case '\\':
            par->p++;
@@ -441,14 +441,14 @@
            nested_p = par->p;
            atStart = nested_p == start;
            parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags, &str,
-                                   freeIt);
+                                   out_freeIt);
            /* TODO: handle errors */
            if (str == var_Error) {
                if (parseResult & VPR_ANY_MSG)
                    par->printedError = TRUE;
-               if (*freeIt) {
-                   free(*freeIt);
-                   *freeIt = NULL;
+               if (*out_freeIt) {
+                   free(*out_freeIt);
+                   *out_freeIt = NULL;
                }
                /*
                 * Even if !doEval, we still report syntax errors, which
@@ -469,18 +469,18 @@
                goto cleanup;
 
            Buf_AddStr(&buf, str);
-           if (*freeIt) {
-               free(*freeIt);
-               *freeIt = NULL;
+           if (*out_freeIt) {
+               free(*out_freeIt);
+               *out_freeIt = NULL;
            }
            str = NULL;         /* not finished yet */
            continue;
        default:
            if (strictLHS && !qt && *start != '$' && !ch_isdigit(*start)) {
                /* lhs must be quoted, a variable reference or number */
-               if (*freeIt) {
-                   free(*freeIt);
-                   *freeIt = NULL;
+               if (*out_freeIt) {
+                   free(*out_freeIt);
+                   *out_freeIt = NULL;
                }
                str = NULL;
                goto cleanup;
@@ -491,8 +491,8 @@
        }
     }
 got_str:
-    *freeIt = Buf_GetAll(&buf, NULL);
-    str = *freeIt;
+    *out_freeIt = Buf_GetAll(&buf, NULL);
+    str = *out_freeIt;
 cleanup:
     Buf_Destroy(&buf, FALSE);
     return str;
@@ -539,7 +539,7 @@
 
     /* For .if ${...} check for non-empty string (defProc is ifdef). */
     if (par->if_info->form[0] == '\0')
-       return lhs[0] != 0;
+       return lhs[0] != '\0';
 
     /* Otherwise action default test ... */
     return If_Eval(par->if_info, lhs, strlen(lhs));
@@ -766,7 +766,7 @@
 
     /* Push anything numeric through the compare expression */
     cp = par->p;
-    if (ch_isdigit(cp[0]) || strchr("+-", cp[0]))
+    if (ch_isdigit(cp[0]) || strchr("+-", cp[0]) != NULL)
        return CondParser_Comparison(par, doEval);
 
     /*
@@ -1017,7 +1017,7 @@
     if (info == NULL && (info = dflt_info) == NULL) {
        /* Scan for the entry for .if - it can't be first */
        for (info = ifs;; info++)
-           if (info->form[0] == 0)
+           if (info->form[0] == '\0')
                break;
        dflt_info = info;
     }
@@ -1083,7 +1083,7 @@
     Boolean value;
     enum if_states state;
 
-    if (!cond_state) {
+    if (cond_state == NULL) {
        cond_state = bmake_malloc(max_if_depth * sizeof *cond_state);
        cond_state[0] = IF_ACTIVE;
     }
@@ -1139,8 +1139,7 @@
        isElif = FALSE;
 
     if (line[0] != 'i' || line[1] != 'f')
-       /* Not an ifxxx or elifxxx line */
-       return COND_INVALID;
+       return COND_INVALID;    /* Not an ifxxx or elifxxx line */
 
     /*
      * Figure out what sort of conditional it is -- what its default
diff -r fd865ddaf240 -r b1464dd2643b usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Sat Nov 07 08:48:11 2020 +0000
+++ b/usr.bin/make/dir.c        Sat Nov 07 10:16:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.195 2020/11/06 23:59:21 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.196 2020/11/07 10:16:18 rillig Exp $ */
 
 /*



Home | Main Index | Thread Index | Old Index