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 ParseRunOptions from JobPrintC...



details:   https://anonhg.NetBSD.org/src/rev/7c7dfc645ee2
branches:  trunk
changeset: 945574:7c7dfc645ee2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 01 16:57:02 2020 +0000

description:
make(1): extract ParseRunOptions from JobPrintCommand

diffstat:

 usr.bin/make/job.c |  73 +++++++++++++++++++++++++++++++----------------------
 1 files changed, 43 insertions(+), 30 deletions(-)

diffs (113 lines):

diff -r f662a7677efd -r 7c7dfc645ee2 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sun Nov 01 16:47:29 2020 +0000
+++ b/usr.bin/make/job.c        Sun Nov 01 16:57:02 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.297 2020/10/31 11:54:33 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.298 2020/11/01 16:57:02 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.297 2020/10/31 11:54:33 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.298 2020/11/01 16:57:02 rillig Exp $");
 
 /* A shell defines how the commands are run.  All commands for a target are
  * written into a single file, which is then given to the shell to execute
@@ -646,6 +646,34 @@
     return NULL;
 }
 
+/* Parse leading '@', '-' and '+', which control the exact execution mode. */
+static void
+ParseRunOptions(
+       char **pp,
+       Boolean *out_shutUp, Boolean *out_errOff, Boolean *out_runAlways)
+{
+    char *p = *pp;
+    *out_shutUp = FALSE;
+    *out_errOff = FALSE;
+    *out_runAlways = FALSE;
+
+    for (;;) {
+       if (*p == '@')
+           *out_shutUp = !DEBUG(LOUD);
+       else if (*p == '-')
+           *out_errOff = TRUE;
+       else if (*p == '+')
+           *out_runAlways = TRUE;
+       else
+           break;
+       p++;
+    }
+
+    pp_skip_whitespace(&p);
+
+    *pp = p;
+}
+
 /*-
  *-----------------------------------------------------------------------
  * JobPrintCommand  --
@@ -674,11 +702,12 @@
     Boolean noSpecials;                /* true if we shouldn't worry about
                                 * inserting special commands into
                                 * the input stream. */
-    Boolean shutUp = FALSE;    /* true if we put a no echo command
+    Boolean shutUp;            /* true if we put a no echo command
                                 * into the command file */
-    Boolean errOff = FALSE;    /* true if we turned error checking
+    Boolean errOff;            /* true if we turned error checking
                                 * off before printing the command
                                 * and need to turn it back on */
+    Boolean runAlways;
     const char *cmdTemplate;   /* Template to use when printing the
                                 * command */
     char *cmdStart;            /* Start of expanded command */
@@ -700,34 +729,18 @@
 
     cmdTemplate = "%s\n";
 
-    /*
-     * Check for leading @' and -'s to control echoing and error checking.
-     */
-    while (*cmd == '@' || *cmd == '-' || (*cmd == '+')) {
-       switch (*cmd) {
-       case '@':
-           shutUp = DEBUG(LOUD) ? FALSE : TRUE;
-           break;
-       case '-':
-           errOff = TRUE;
-           break;
-       case '+':
-           if (noSpecials) {
-               /*
-                * We're not actually executing anything...
-                * but this one needs to be - use compat mode just for it.
-                */
-               Compat_RunCommand(cmdp, job->node);
-               free(cmdStart);
-               return;
-           }
-           break;
-       }
-       cmd++;
+    ParseRunOptions(&cmd, &shutUp, &errOff, &runAlways);
+
+    if (runAlways && noSpecials) {
+       /*
+        * We're not actually executing anything...
+        * but this one needs to be - use compat mode just for it.
+        */
+       Compat_RunCommand(cmdp, job->node);
+       free(cmdStart);
+       return;
     }
 
-    pp_skip_whitespace(&cmd);
-
     /*
      * If the shell doesn't have error control the alternate echo'ing will
      * be done (to avoid showing additional error checking code)



Home | Main Index | Thread Index | Old Index