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): extract InitShellNameAndPath from Shel...



details:   https://anonhg.NetBSD.org/src/rev/eab8e95a6d1d
branches:  trunk
changeset: 978939:eab8e95a6d1d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Dec 08 00:09:51 2020 +0000

description:
make(1): extract InitShellNameAndPath from Shell_Init

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

diffstat:

 usr.bin/make/job.c |  39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diffs (63 lines):

diff -r 7f5e08bded5d -r eab8e95a6d1d usr.bin/make/job.c
--- a/usr.bin/make/job.c        Mon Dec 07 23:59:59 2020 +0000
+++ b/usr.bin/make/job.c        Tue Dec 08 00:09:51 2020 +0000
@@ -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 @@
        (void)JobStart(gn, JOB_NONE);
 }
 
+static void
+InitShellNameAndPath(void)
+{
+       shellName = commandShell->name;
+
+#ifdef DEFSHELL_CUSTOM
+       if (shellName[0] == '/') {
+               shellPath = shellName;
+               shellName = strrchr(shellPath, '/') + 1;
+               return;
+       }
+#endif
+
+       shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
+}
+
 void
 Shell_Init(void)
 {
-       if (shellPath == NULL) {
-               /*
-                * We are using the default shell, which may be an absolute
-                * path if DEFSHELL_CUSTOM is defined.
-                */
-               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 (shellPath == NULL)
+               InitShellNameAndPath();
+
        Var_SetWithFlags(".SHELL", shellPath, VAR_CMDLINE, VAR_SET_READONLY);
        if (commandShell->exit == NULL) {
                commandShell->exit = "";



Home | Main Index | Thread Index | Old Index