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): move flag shutUp into struct RunFlags



details:   https://anonhg.NetBSD.org/src/rev/39c02c264b75
branches:  trunk
changeset: 946779:39c02c264b75
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 08 19:58:20 2020 +0000

description:
make(1): move flag shutUp into struct RunFlags

Running a command is controlled by several flags.  Instead of passing
them around individually, it's easier to have them grouped.

diffstat:

 usr.bin/make/job.c |  53 +++++++++++++++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diffs (172 lines):

diff -r 7980ec8b34f0 -r 39c02c264b75 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Tue Dec 08 17:52:11 2020 +0000
+++ b/usr.bin/make/job.c        Tue Dec 08 19:58:20 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.346 2020/12/08 00:50:04 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.347 2020/12/08 19:58:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.346 2020/12/08 00:50:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.347 2020/12/08 19:58:20 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -219,6 +219,11 @@
        const char *exit;       /* exit on error */
 } Shell;
 
+typedef struct RunFlags {
+       /* true if we put a no echo command into the command file */
+       Boolean silent;
+} RunFlags;
+
 /*
  * error handling variables
  */
@@ -671,17 +676,17 @@
 /* Parse leading '@', '-' and '+', which control the exact execution mode. */
 static void
 ParseRunOptions(char **pp,
-               Boolean *out_shutUp, Boolean *out_errOff,
+               RunFlags *out_runFlags, Boolean *out_errOff,
                Boolean *out_runAlways)
 {
        char *p = *pp;
-       *out_shutUp = FALSE;
+       out_runFlags->silent = FALSE;
        *out_errOff = FALSE;
        *out_runAlways = FALSE;
 
        for (;;) {
                if (*p == '@')
-                       *out_shutUp = !DEBUG(LOUD);
+                       out_runFlags->silent = !DEBUG(LOUD);
                else if (*p == '-')
                        *out_errOff = TRUE;
                else if (*p == '+')
@@ -756,18 +761,18 @@
  * Set cmdTemplate to use the weirdness instead of the simple "%s\n" template.
  */
 static void
-JobPrintSpecialsEchoCtl(Job *job, Boolean *inout_shutUp, const char *escCmd,
+JobPrintSpecialsEchoCtl(Job *job, RunFlags *inout_runFlags, const char *escCmd,
                        const char **inout_cmdTemplate, Boolean *out_errOff)
 {
        job->flags |= JOB_IGNERR;
 
-       if (!(job->flags & JOB_SILENT) && !*inout_shutUp) {
+       if (!(job->flags & JOB_SILENT) && !inout_runFlags->silent) {
                if (commandShell->hasEchoCtl)
                        JobPrintln(job, commandShell->echoOff);
                JobPrintf(job, commandShell->errOnOrEcho, escCmd);
-               *inout_shutUp = TRUE;
+               inout_runFlags->silent = TRUE;
        } else {
-               if (!*inout_shutUp)
+               if (!inout_runFlags->silent)
                        JobPrintf(job, commandShell->errOnOrEcho, escCmd);
        }
        *inout_cmdTemplate = commandShell->errOffOrExecIgnore;
@@ -781,17 +786,17 @@
 
 static void
 JobPrintSpecials(Job *const job, const char *const escCmd,
-                Boolean const noSpecials, Boolean *const inout_shutUp,
+                Boolean const noSpecials, RunFlags *const inout_runFlags,
                 const char **const inout_cmdTemplate,
                 Boolean *const inout_errOff)
 {
        if (noSpecials)
                *inout_errOff = FALSE;
        else if (commandShell->hasErrCtl)
-               JobPrintSpecialsErrCtl(job, *inout_shutUp);
+               JobPrintSpecialsErrCtl(job, inout_runFlags->silent);
        else if (commandShell->errOffOrExecIgnore != NULL &&
                 commandShell->errOffOrExecIgnore[0] != '\0') {
-               JobPrintSpecialsEchoCtl(job, inout_shutUp, escCmd,
+               JobPrintSpecialsEchoCtl(job, inout_runFlags, escCmd,
                    inout_cmdTemplate, inout_errOff);
        } else
                *inout_errOff = FALSE;
@@ -824,8 +829,8 @@
         * the input stream.
         */
        Boolean noSpecials;
-       /* true if we put a no echo command into the command file */
-       Boolean shutUp;
+
+       RunFlags runFlags;
        /*
         * true if we turned error checking off before printing the command
         * and need to turn it back on
@@ -847,7 +852,7 @@
 
        cmdTemplate = "%s\n";
 
-       ParseRunOptions(&cmd, &shutUp, &errOff, &runAlways);
+       ParseRunOptions(&cmd, &runFlags, &errOff, &runAlways);
 
        if (runAlways && noSpecials) {
                /*
@@ -868,19 +873,19 @@
        if (!commandShell->hasErrCtl)
                escCmd = EscapeShellDblQuot(cmd);
 
-       if (shutUp) {
+       if (runFlags.silent) {
                if (!(job->flags & JOB_SILENT) && !noSpecials &&
                    commandShell->hasEchoCtl) {
                        JobPrintln(job, commandShell->echoOff);
                } else {
                        if (commandShell->hasErrCtl)
-                               shutUp = FALSE;
+                               runFlags.silent = FALSE;
                }
        }
 
        if (errOff) {
-               JobPrintSpecials(job, escCmd, noSpecials, &shutUp, &cmdTemplate,
-                   &errOff);
+               JobPrintSpecials(job, escCmd, noSpecials, &runFlags,
+                   &cmdTemplate, &errOff);
        } else {
 
                /*
@@ -891,12 +896,12 @@
 
                if (!commandShell->hasErrCtl && commandShell->errExit &&
                    commandShell->errExit[0] != '\0') {
-                       if (!(job->flags & JOB_SILENT) && !shutUp) {
+                       if (!(job->flags & JOB_SILENT) && !runFlags.silent) {
                                if (commandShell->hasEchoCtl)
                                        JobPrintln(job, commandShell->echoOff);
                                JobPrintf(job, commandShell->errOnOrEcho,
                                    escCmd);
-                               shutUp = TRUE;
+                               runFlags.silent = TRUE;
                        }
                        /*
                         * If it's a comment line or blank, treat as an
@@ -926,14 +931,14 @@
                 * echoOff command. Otherwise we issue it and pretend it was on
                 * for the whole command...
                 */
-               if (!shutUp && !(job->flags & JOB_SILENT) &&
+               if (!runFlags.silent && !(job->flags & JOB_SILENT) &&
                    commandShell->hasEchoCtl) {
                        JobPrintln(job, commandShell->echoOff);
-                       shutUp = TRUE;
+                       runFlags.silent = TRUE;
                }
                JobPrintln(job, commandShell->errOnOrEcho);
        }
-       if (shutUp && commandShell->hasEchoCtl)
+       if (runFlags.silent && commandShell->hasEchoCtl)
                JobPrintln(job, commandShell->echoOn);
 }
 



Home | Main Index | Thread Index | Old Index