Module Name:    src
Committed By:   rillig
Date:           Tue Dec  8 00:09:51 UTC 2020

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

Log Message:
make(1): extract InitShellNameAndPath from Shell_Init

This gets rid of the ugly "else #endif".


To generate a diff of this commit:
cvs rdiff -u -r1.343 -r1.344 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.343 src/usr.bin/make/job.c:1.344
--- src/usr.bin/make/job.c:1.343	Mon Dec  7 23:59:59 2020
+++ src/usr.bin/make/job.c	Tue Dec  8 00:09:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.343 2020/12/07 23:59:59 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.344 2020/12/08 00:09:51 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.343 2020/12/07 23:59:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.344 2020/12/08 00:09:51 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2047,25 +2047,28 @@ Job_Make(GNode *gn)
 	(void)JobStart(gn, JOB_NONE);
 }
 
-void
-Shell_Init(void)
+static void
+InitShellNameAndPath(void)
 {
-	if (shellPath == NULL) {
-		/*
-		 * We are using the default shell, which may be an absolute
-		 * path if DEFSHELL_CUSTOM is defined.
-		 */
-		shellName = commandShell->name;
+	shellName = commandShell->name;
+
 #ifdef DEFSHELL_CUSTOM
-		if (*shellName == '/') {
-			shellPath = shellName;
-			shellName = strrchr(shellPath, '/');
-			shellName++;
-		} else /* XXX: else #endif breaks automatic formatting. */
-#endif
-		shellPath = str_concat3(_PATH_DEFSHELLDIR, "/",
-		    shellName);
+	if (shellName[0] == '/') {
+		shellPath = shellName;
+		shellName = strrchr(shellPath, '/') + 1;
+		return;
 	}
+#endif
+
+	shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
+}
+
+void
+Shell_Init(void)
+{
+	if (shellPath == NULL)
+		InitShellNameAndPath();
+
 	Var_SetWithFlags(".SHELL", shellPath, VAR_CMDLINE, VAR_SET_READONLY);
 	if (commandShell->exit == NULL) {
 		commandShell->exit = "";

Reply via email to