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): add debug macros to suff.c



details:   https://anonhg.NetBSD.org/src/rev/2ca7c5a432fc
branches:  trunk
changeset: 938011:2ca7c5a432fc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 30 18:26:41 2020 +0000

description:
make(1): add debug macros to suff.c

This reduces the visual space that the debugging statements need.

diffstat:

 usr.bin/make/suff.c |  135 ++++++++++++++++++++-------------------------------
 1 files changed, 52 insertions(+), 83 deletions(-)

diffs (truncated from 331 to 300 lines):

diff -r c3eba93afc9e -r 2ca7c5a432fc usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sun Aug 30 16:26:56 2020 +0000
+++ b/usr.bin/make/suff.c       Sun Aug 30 18:26:41 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.139 2020/08/30 14:11:42 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.139 2020/08/30 14:11:42 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c     8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.139 2020/08/30 14:11:42 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.140 2020/08/30 18:26:41 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -138,6 +138,18 @@
 #include         "make.h"
 #include         "dir.h"
 
+#define SUFF_DEBUG0(fmt) \
+    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt)
+
+#define SUFF_DEBUG1(fmt, arg1) \
+    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1)
+
+#define SUFF_DEBUG2(fmt, arg1, arg2) \
+    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2)
+
+#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) \
+    if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2, arg3)
+
 static Lst       sufflist;     /* Lst of suffixes */
 #ifdef CLEANUP
 static Lst      suffClean;     /* Lst of suffixes to be cleaned */
@@ -397,25 +409,20 @@
     }
     Lst_Close(l);
 
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "inserting %s(%d)...", s->name, s->sNum);
-    }
+    SUFF_DEBUG2("inserting %s(%d)...", s->name, s->sNum);
+
     if (ln == NULL) {
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "at end of list\n");
-       }
+       SUFF_DEBUG0("at end of list\n");
        Lst_Append(l, s);
        s->refCount++;
        Lst_Append(s->ref, l);
     } else if (s2->sNum != s->sNum) {
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "before %s(%d)\n", s2->name, s2->sNum);
-       }
+       SUFF_DEBUG2("before %s(%d)\n", s2->name, s2->sNum);
        Lst_InsertBefore(l, ln, s);
        s->refCount++;
        Lst_Append(s->ref, l);
-    } else if (DEBUG(SUFF)) {
-       fprintf(debug_file, "already there\n");
+    } else {
+       SUFF_DEBUG0("already there\n");
     }
 }
 
@@ -591,10 +598,8 @@
     /*
      * link the two together in the proper relationship and order
      */
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
+    SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
                s->name, t->name);
-    }
     SuffInsert(t->children, s);
     SuffInsert(s->parents, t);
 
@@ -633,10 +638,8 @@
        if (SuffParseTransform(gn->name, &s, &t)) {
            Lst  p;
 
-           if (DEBUG(SUFF)) {
-               fprintf(debug_file, "deleting transformation from `%s' to `%s'\n",
-               s->name, t->name);
-           }
+           SUFF_DEBUG2("deleting transformation from `%s' to `%s'\n",
+                       s->name, t->name);
 
            /*
             * Store s->parents because s could be deleted in SuffRemove
@@ -658,8 +661,8 @@
             */
            SuffRemove(p, t);
        }
-    } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
-       fprintf(debug_file, "transformation %s complete\n", gn->name);
+    } else if (gn->type & OP_TRANSFORM) {
+        SUFF_DEBUG1("transformation %s complete\n", gn->name);
     }
 
     return 0;
@@ -781,10 +784,8 @@
        /*
         * link the two together in the proper relationship and order
         */
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
-               s->name, t->name);
-       }
+       SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
+                   s->name, t->name);
        SuffInsert(t->children, s);
        SuffInsert(s->parents, t);
     }
@@ -1101,9 +1102,7 @@
     while (!Lst_IsEmpty(srcs)) {
        s = Lst_Dequeue(srcs);
 
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "\ttrying %s...", s->file);
-       }
+       SUFF_DEBUG1("\ttrying %s...", s->file);
 
        /*
         * A file is considered to exist if either a node exists in the
@@ -1126,16 +1125,14 @@
            break;
        }
 
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "not there\n");
-       }
+       SUFF_DEBUG0("not there\n");
 
        SuffAddLevel(srcs, s);
        Lst_Append(slst, s);
     }
 
-    if (DEBUG(SUFF) && rs) {
-       fprintf(debug_file, "got it\n");
+    if (rs) {
+       SUFF_DEBUG0("got it\n");
     }
     return rs;
 }
@@ -1234,9 +1231,7 @@
     Lst_Append(targ->cp, ret);
 #endif
     Lst_Append(slst, ret);
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "\tusing existing source %s\n", s->name);
-    }
+    SUFF_DEBUG1("\tusing existing source %s\n", s->name);
     return ret;
 }
 
@@ -1276,9 +1271,7 @@
        return;
     }
 
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "Expanding \"%s\"...", cgn->name);
-    }
+    SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
     cp = Var_Subst(cgn->name, pgn, VARE_UNDEFERR|VARE_WANTRES);
 
     {
@@ -1367,9 +1360,7 @@
        while(!Lst_IsEmpty(members)) {
            gn = Lst_Dequeue(members);
 
-           if (DEBUG(SUFF)) {
-               fprintf(debug_file, "%s...", gn->name);
-           }
+           SUFF_DEBUG1("%s...", gn->name);
            /* Add gn to the parents child list before the original child */
            Lst_InsertBefore(pgn->children, cln, gn);
            Lst_Append(gn->parents, pgn);
@@ -1385,9 +1376,7 @@
        free(cp);
     }
 
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "\n");
-    }
+    SUFF_DEBUG0("\n");
 
     /*
      * Now the source is expanded, remove it from the list of children to
@@ -1421,9 +1410,7 @@
         */
        cp = Lst_Dequeue(explist);
 
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "%s...", cp);
-       }
+       SUFF_DEBUG1("%s...", cp);
        gn = Targ_FindNode(cp, TARG_CREATE);
 
        /* Add gn to the parents child list before the original child */
@@ -1434,9 +1421,7 @@
 
     Lst_Free(explist);
 
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "\n");
-    }
+    SUFF_DEBUG0("\n");
 
     /*
      * Now the source is expanded, remove it from the list of children to
@@ -1470,18 +1455,14 @@
        sd.ename = gn->name + sd.len;
        ln = Lst_Find(sufflist, SuffSuffIsSuffix, &sd);
 
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name);
-       }
+       SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
        if (ln != NULL)
            suff = LstNode_Datum(ln);
        /* XXX: Here we can save the suffix so we don't have to do this again */
     }
 
     if (suff != NULL) {
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "suffix is \"%s\"...", suff->name);
-       }
+       SUFF_DEBUG1("suffix is \"%s\"...", suff->name);
        return suff->searchPath;
     } else {
        /*
@@ -1542,9 +1523,7 @@
 
     gn = LstNode_Datum(ln);
 
-    if (DEBUG(SUFF)) {
-       fprintf(debug_file, "\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
-    }
+    SUFF_DEBUG3("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
 
     /*
      * Record last child for expansion purposes
@@ -1644,9 +1623,7 @@
        /*
         * Didn't know what it was -- use .NULL suffix if not in make mode
         */
-       if (DEBUG(SUFF)) {
-           fprintf(debug_file, "using null suffix\n");
-       }
+       SUFF_DEBUG0("using null suffix\n");
        ms = suffNull;
     }
 
@@ -1691,11 +1668,10 @@
            /*
             * Got one -- apply it
             */
-           if (!SuffApplyTransform(gn, mem, (Suff *)LstNode_Datum(ln), ms) &&
-               DEBUG(SUFF))
-           {
-               fprintf(debug_file, "\tNo transformation from %s -> %s\n",
-                      ms->name, ((Suff *)LstNode_Datum(ln))->name);
+           Suff *suff = LstNode_Datum(ln);
+           if (!SuffApplyTransform(gn, mem, suff, ms)) {
+               SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
+                           ms->name, suff->name);
            }
        }
     }
@@ -1830,9 +1806,8 @@
         * Handle target of unknown suffix...
         */
        if (Lst_IsEmpty(targs) && suffNull != NULL) {
-           if (DEBUG(SUFF)) {
-               fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
-           }
+           SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n",
+                       gn->name);
 
            targ = bmake_malloc(sizeof(Src));
            targ->file = bmake_strdup(gn->name);
@@ -1855,12 +1830,10 @@
            if (Lst_IsEmpty(gn->commands))
                SuffAddLevel(srcs, targ);
            else {
-               if (DEBUG(SUFF))
-                   fprintf(debug_file, "not ");



Home | Main Index | Thread Index | Old Index