Module Name:    src
Committed By:   rillig
Date:           Tue Dec  8 00:50:05 UTC 2020

Modified Files:
        src/usr.bin/make: job.c

Log Message:
make(1): split JobPrintSpecials into manageable pieces


To generate a diff of this commit:
cvs rdiff -u -r1.345 -r1.346 src/usr.bin/make/job.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.345 src/usr.bin/make/job.c:1.346
--- src/usr.bin/make/job.c:1.345	Tue Dec  8 00:23:30 2020
+++ src/usr.bin/make/job.c	Tue Dec  8 00:50:04 2020
@@ -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 @@ JobPrintln(Job *job, const char *line)
 	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;
-	}
 }
 
 /*

Reply via email to