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 ParseInclude



details:   https://anonhg.NetBSD.org/src/rev/d790c8625c15
branches:  trunk
changeset: 1026643:d790c8625c15
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Dec 03 23:13:29 2021 +0000

description:
make: clean up ParseInclude

It was confusing to let the variable 'file' point to the '<' of the
.include directive.  In each parsing function, there should only be a
single moving pointer, typically named 'p' or historically 'cp', even
though the 'c' is redundant.

No functional change.

diffstat:

 usr.bin/make/parse.c |  54 +++++++++++++++++++++++++--------------------------
 1 files changed, 26 insertions(+), 28 deletions(-)

diffs (97 lines):

diff -r f48fc350e54a -r d790c8625c15 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Fri Dec 03 22:48:07 2021 +0000
+++ b/usr.bin/make/parse.c      Fri Dec 03 23:13:29 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.565 2021/09/21 23:06:18 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.565 2021/09/21 23:06:18 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.566 2021/12/03 23:13:29 rillig Exp $");
 
 /* types and constants */
 
@@ -2228,54 +2228,52 @@
                doing_depend = depinc;  /* only turn it on */
 }
 
+/*
+ * Parse a directive like '.include' or '.-include'.
+ *
+ * .include "user-makefile.mk"
+ * .include <system-makefile.mk>
+ */
 static void
 ParseInclude(char *directive)
 {
        char endc;              /* the character which ends the file spec */
-       char *cp;               /* current position in file spec */
+       char *p, *xfile;
        bool silent = directive[0] != 'i';
-       char *file = directive + (silent ? 8 : 7);
-
-       /* Skip to delimiter character so we know where to look */
-       pp_skip_hspace(&file);
-
-       if (*file != '"' && *file != '<') {
+       FStr file;
+
+       p = directive + (silent ? 8 : 7);
+       pp_skip_hspace(&p);
+
+       if (*p != '"' && *p != '<') {
                Parse_Error(PARSE_FATAL,
                    ".include filename must be delimited by '\"' or '<'");
                return;
        }
 
-       /*
-        * Set the search path on which to find the include file based on the
-        * characters which bracket its name. Angle-brackets imply it's
-        * a system Makefile while double-quotes imply it's a user makefile
-        */
-       if (*file == '<')
+       if (*p++ == '<')
                endc = '>';
        else
                endc = '"';
+       file = FStr_InitRefer(p);
 
        /* Skip to matching delimiter */
-       for (cp = ++file; *cp != '\0' && *cp != endc; cp++)
-               continue;
-
-       if (*cp != endc) {
+       while (*p != '\0' && *p != endc)
+               p++;
+
+       if (*p != endc) {
                Parse_Error(PARSE_FATAL,
                    "Unclosed .include filename. '%c' expected", endc);
                return;
        }
 
-       *cp = '\0';
-
-       /*
-        * Substitute for any variables in the filename before trying to
-        * find the file.
-        */
-       (void)Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES, &file);
+       *p = '\0';
+
+       (void)Var_Subst(file.str, SCOPE_CMDLINE, VARE_WANTRES, &xfile);
        /* TODO: handle errors */
 
-       IncludeFile(file, endc == '>', directive[0] == 'd', silent);
-       free(file);
+       IncludeFile(xfile, endc == '>', directive[0] == 'd', silent);
+       free(xfile);
 }
 
 /*



Home | Main Index | Thread Index | Old Index