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): split JobPrintSpecials into manageable...



details:   https://anonhg.NetBSD.org/src/rev/c00c0638d9e1
branches:  trunk
changeset: 946770:c00c0638d9e1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 08 00:50:04 2020 +0000

description:
make(1): split JobPrintSpecials into manageable pieces

diffstat:

 usr.bin/make/job.c |  125 +++++++++++++++++++++++++---------------------------
 1 files changed, 60 insertions(+), 65 deletions(-)

diffs (153 lines):

diff -r 3fe9f3b4ef0c -r c00c0638d9e1 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Tue Dec 08 00:23:30 2020 +0000
+++ b/usr.bin/make/job.c        Tue Dec 08 00:50:04 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.345 2020/12/08 00:23:30 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.346 2020/12/08 00:50:04 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.345 2020/12/08 00:23:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.346 2020/12/08 00:50:04 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -730,76 +730,71 @@
        JobPrintf(job, "%s\n", line);
 }
 
+/*
+ * We don't want the error-control commands showing up either, so we turn
+ * off echoing while executing them. We could put another field in the shell
+ * structure to tell JobDoOutput to look for this string too, but why make
+ * it any more complex than it already is?
+ */
+static void
+JobPrintSpecialsErrCtl(Job *job, Boolean shutUp)
+{
+       if (!(job->flags & JOB_SILENT) && !shutUp && commandShell->hasEchoCtl) {
+               JobPrintln(job, commandShell->echoOff);
+               JobPrintln(job, commandShell->errOffOrExecIgnore);
+               JobPrintln(job, commandShell->echoOn);
+       } else {
+               JobPrintln(job, commandShell->errOffOrExecIgnore);
+       }
+}
+
+/*
+ * The shell has no error control, so we need to be weird to get it to
+ * ignore any errors from the command. If echoing is turned on, we turn it
+ * off and use the errOnOrEcho template to echo the command. Leave echoing
+ * off so the user doesn't see the weirdness we go through to ignore errors.
+ * Set cmdTemplate to use the weirdness instead of the simple "%s\n" template.
+ */
+static void
+JobPrintSpecialsEchoCtl(Job *job, Boolean *inout_shutUp, const char *escCmd,
+                       const char **inout_cmdTemplate, Boolean *out_errOff)
+{
+       job->flags |= JOB_IGNERR;
+
+       if (!(job->flags & JOB_SILENT) && !*inout_shutUp) {
+               if (commandShell->hasEchoCtl)
+                       JobPrintln(job, commandShell->echoOff);
+               JobPrintf(job, commandShell->errOnOrEcho, escCmd);
+               *inout_shutUp = TRUE;
+       } else {
+               if (!*inout_shutUp)
+                       JobPrintf(job, commandShell->errOnOrEcho, escCmd);
+       }
+       *inout_cmdTemplate = commandShell->errOffOrExecIgnore;
+
+       /*
+        * The error ignoration (hee hee) is already taken care of by the
+        * errOffOrExecIgnore template, so pretend error checking is still on.
+        */
+       *out_errOff = FALSE;
+}
+
 static void
 JobPrintSpecials(Job *const job, const char *const escCmd,
                 Boolean const noSpecials, Boolean *const inout_shutUp,
                 const char **const inout_cmdTemplate,
                 Boolean *const inout_errOff)
 {
-       if (!noSpecials) {
-               if (commandShell->hasErrCtl) {
-                       /*
-                        * we don't want the error-control commands
-                        * showing up either, so we turn off echoing
-                        * while executing them. We could put another
-                        * field in the shell structure to tell
-                        * JobDoOutput to look for this string too,
-                        * but why make it any more complex than
-                        * it already is?
-                        */
-                       if (!(job->flags & JOB_SILENT) && !*inout_shutUp &&
-                           (commandShell->hasEchoCtl)) {
-                               JobPrintln(job, commandShell->echoOff);
-                               JobPrintln(job,
-                                   commandShell->errOffOrExecIgnore);
-                               JobPrintln(job, commandShell->echoOn);
-                       } else {
-                               JobPrintln(job,
-                                   commandShell->errOffOrExecIgnore);
-                       }
-               } else if (commandShell->errOffOrExecIgnore &&
-                          commandShell->errOffOrExecIgnore[0] !=
-                          '\0') {
-                       /*
-                        * The shell has no error control, so we need
-                        * to be weird to get it to ignore any errors
-                        * from the command. If echoing is turned on,
-                        * we turn it off and use the errOnOrEcho
-                        * template to echo the command. Leave echoing
-                        * off so the user doesn't see the weirdness
-                        * we go through to ignore errors. Set
-                        * cmdTemplate to use the weirdness instead
-                        * of the simple "%s\n" template.
-                        */
-                       job->flags |= JOB_IGNERR;
-                       if (!(job->flags & JOB_SILENT) && !*inout_shutUp) {
-                               if (commandShell->hasEchoCtl) {
-                                       JobPrintln(job,
-                                           commandShell->echoOff);
-                               }
-                               JobPrintf(job,
-                                   commandShell->errOnOrEcho, escCmd);
-                               *inout_shutUp = TRUE;
-                       } else {
-                               if (!*inout_shutUp)
-                                       JobPrintf(job,
-                                           commandShell->errOnOrEcho,
-                                           escCmd);
-                       }
-                       *inout_cmdTemplate = commandShell->errOffOrExecIgnore;
-                       /*
-                        * The error ignoration (hee hee) is already
-                        * taken care of by the errOffOrExecIgnore
-                        * template, so pretend error checking is
-                        * still on.
-                        */
-                       *inout_errOff = FALSE;
-               } else {
-                       *inout_errOff = FALSE;
-               }
-       } else {
+       if (noSpecials)
                *inout_errOff = FALSE;
-       }
+       else if (commandShell->hasErrCtl)
+               JobPrintSpecialsErrCtl(job, *inout_shutUp);
+       else if (commandShell->errOffOrExecIgnore != NULL &&
+                commandShell->errOffOrExecIgnore[0] != '\0') {
+               JobPrintSpecialsEchoCtl(job, inout_shutUp, escCmd,
+                   inout_cmdTemplate, inout_errOff);
+       } else
+               *inout_errOff = FALSE;
 }
 
 /*



Home | Main Index | Thread Index | Old Index