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 FindSemicolon from ParseDepend...



details:   https://anonhg.NetBSD.org/src/rev/99282803806d
branches:  trunk
changeset: 944965:99282803806d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 17 20:51:34 2020 +0000

description:
make(1): extract FindSemicolon from ParseDependency

diffstat:

 usr.bin/make/parse.c |  82 ++++++++++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 41 deletions(-)

diffs (133 lines):

diff -r fef20f3f1a9a -r 99282803806d usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Oct 17 20:37:38 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Oct 17 20:51:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.379 2020/10/17 20:37:38 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.380 2020/10/17 20:51:34 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.379 2020/10/17 20:37:38 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.380 2020/10/17 20:51:34 rillig Exp $");
 
 /* types and constants */
 
@@ -2943,13 +2943,42 @@
     return FALSE;
 }
 
+static char *
+FindSemicolon(char *p)
+{
+    int level = 0;
+
+    for (; *p != '\0'; p++) {
+       if (*p == '\\' && p[1] != '\0') {
+           p++;
+           continue;
+       }
+
+       if (*p == '$' && (p[1] == '(' || p[1] == '{')) {
+           level++;
+           continue;
+       }
+
+       if (level > 0 && (*p == ')' || *p == '}')) {
+           level--;
+           continue;
+       }
+
+       if (level == 0 && *p == ';') {
+           break;
+       }
+    }
+    return p;
+}
+
 /* dependency  -> target... op [source...]
  * op          -> ':' | '::' | '!' */
 static void
-ParseDependency(char *line, const char **out_shellcmd)
+ParseDependency(char *line)
 {
     VarEvalFlags eflags;
     char *expanded_line;
+    const char *shellcmd = NULL;
 
     /*
      * For some reason - probably to make the parser impossible -
@@ -2957,35 +2986,12 @@
      * Attempt to avoid ';' inside substitution patterns.
      */
     {
-       int level = 0;
-       char *cp;
-
-       for (cp = line; *cp != 0; cp++) {
-           if (*cp == '\\' && cp[1] != 0) {
-               cp++;
-               continue;
-           }
-           if (*cp == '$' &&
-               (cp[1] == '(' || cp[1] == '{')) {
-               level++;
-               continue;
-           }
-           if (level > 0) {
-               if (*cp == ')' || *cp == '}') {
-                   level--;
-                   continue;
-               }
-           } else if (*cp == ';') {
-               break;
-           }
+        char *semicolon = FindSemicolon(line);
+       if (*semicolon != '\0') {
+           /* Terminate the dependency list at the ';' */
+           *semicolon = '\0';
+           shellcmd = semicolon + 1;
        }
-
-       if (*cp != 0) {
-           /* Terminate the dependency list at the ';' */
-           *cp++ = 0;
-           *out_shellcmd = cp;
-       } else
-           *out_shellcmd = NULL;
     }
 
     /*
@@ -3030,6 +3036,9 @@
 
     ParseDoDependency(expanded_line);
     free(expanded_line);
+
+    if (shellcmd != NULL)
+       ParseLine_ShellCommand(shellcmd);
 }
 
 /* Parse a top-level makefile into its component parts, incorporating them
@@ -3090,18 +3099,9 @@
            if (ParseVarassign(line))
                continue;
 
-#ifndef POSIX
-           if (ParseNoviceMistake())
-               continue;
-#endif
            FinishDependencyGroup();
 
-           {
-               const char *shellcmd;
-               ParseDependency(line, &shellcmd);
-               if (shellcmd != NULL)
-                   ParseLine_ShellCommand(shellcmd);
-           }
+           ParseDependency(line);
        }
        /*
         * Reached EOF, but it may be just EOF of an include file...



Home | Main Index | Thread Index | Old Index