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: clean up code for skipping files with mul...



details:   https://anonhg.NetBSD.org/src/rev/e07e6589b1d6
branches:  trunk
changeset: 376467:e07e6589b1d6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 19 17:30:56 2023 +0000

description:
make: clean up code for skipping files with multiple-inclusion guard

No functional change.

diffstat:

 usr.bin/make/cond.c  |  36 +++++++++++++++---------------------
 usr.bin/make/parse.c |  24 +++++++++++++++---------
 2 files changed, 30 insertions(+), 30 deletions(-)

diffs (139 lines):

diff -r e9e6d2f51a84 -r e07e6589b1d6 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Jun 19 15:37:48 2023 +0000
+++ b/usr.bin/make/cond.c       Mon Jun 19 17:30:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.347 2023/06/19 12:53:57 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -92,7 +92,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.347 2023/06/19 12:53:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -1238,13 +1238,14 @@ Cond_EvalLine(const char *line)
 }
 
 static bool
-skip_identifier(const char **pp)
+ParseVarnameGuard(const char **pp, const char **varname)
 {
        const char *p = *pp;
 
        if (ch_isalpha(*p) || *p == '_') {
                while (ch_isalnum(*p) || *p == '_')
                        p++;
+               *varname = *pp;
                *pp = p;
                return true;
        }
@@ -1258,33 +1259,26 @@ skip_identifier(const char **pp)
 char *
 Cond_ExtractGuard(const char *line)
 {
-       const char *p = line, *dir, *varname;
-       size_t dir_len;
+       const char *p = line, *varname;
+       Substring dir;
 
        if (!skip_string(&p, "."))
                return NULL;
        cpp_skip_hspace(&p);
 
-       dir = p;
+       dir.start = p;
        while (ch_isalpha(*p))
                p++;
-       dir_len = (size_t)(p - dir);
+       dir.end = p;
        cpp_skip_hspace(&p);
 
-       if (dir_len == 2 && memcmp(dir, "if", 2) == 0) {
-               if (!skip_string(&p, "!defined("))
-                       return NULL;
-               varname = p;
-               skip_identifier(&p);
-               if (p > varname && strcmp(p, ")") == 0)
-                       return bmake_strsedup(varname, p);
-       }
-       if (dir_len == 6 && memcmp(dir, "ifndef", 6) == 0) {
-               varname = p;
-               skip_identifier(&p);
-               if (p > varname && *p == '\0')
-                       return bmake_strsedup(varname, p);
-       }
+       if (Substring_Equals(dir, "if"))
+               return skip_string(&p, "!defined(")
+                   && ParseVarnameGuard(&p, &varname) && strcmp(p, ")") == 0
+                   ? bmake_strsedup(varname, p) : NULL;
+       if (Substring_Equals(dir, "ifndef"))
+               return ParseVarnameGuard(&p, &varname) && *p == '\0'
+                   ? bmake_strsedup(varname, p) : NULL;
        return NULL;
 }
 
diff -r e9e6d2f51a84 -r e07e6589b1d6 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Mon Jun 19 15:37:48 2023 +0000
+++ b/usr.bin/make/parse.c      Mon Jun 19 17:30:56 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.700 2023/06/19 12:53:57 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.701 2023/06/19 17:30:56 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.700 2023/06/19 12:53:57 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.701 2023/06/19 17:30:56 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -1210,6 +1210,18 @@ FindInQuotPath(const char *file)
        return fullname;
 }
 
+static bool
+SkipGuarded(const char *fullname)
+{
+       char *guard = HashTable_FindValue(&guards, fullname);
+       if (guard != NULL && GNode_ValueDirect(SCOPE_GLOBAL, guard) != NULL) {
+               DEBUG2(PARSE, "Skipping '%s' because '%s' is already set\n",
+                   fullname, guard);
+               return true;
+       }
+       return false;
+}
+
 /*
  * Handle one of the .[-ds]include directives by remembering the current file
  * and pushing the included file on the stack.  After the included file has
@@ -1225,7 +1237,6 @@ IncludeFile(const char *file, bool isSys
 {
        Buffer buf;
        char *fullname;         /* full pathname of file */
-       char *guardVarname;
        int fd;
 
        fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
@@ -1245,13 +1256,8 @@ IncludeFile(const char *file, bool isSys
                return;
        }
 
-       guardVarname = HashTable_FindValue(&guards, fullname);
-       if (guardVarname != NULL
-           && GNode_ValueDirect(SCOPE_GLOBAL, guardVarname) != NULL) {
-               DEBUG2(PARSE, "Skipping '%s' because '%s' is already set\n",
-                   fullname, guardVarname);
+       if (SkipGuarded(fullname))
                return;
-       }
 
        if ((fd = open(fullname, O_RDONLY)) == -1) {
                if (!silent)



Home | Main Index | Thread Index | Old Index