Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make Be more selective about detecting a SYSV includ...



details:   https://anonhg.NetBSD.org/src/rev/a4cc262784b9
branches:  trunk
changeset: 831540:a4cc262784b9
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Apr 05 00:31:10 2018 +0000

description:
Be more selective about detecting a SYSV include as opposed to a dependency
line. Dependency lines should contain a '::' operator or ':<space>'.

diffstat:

 usr.bin/make/parse.c |  85 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 70 insertions(+), 15 deletions(-)

diffs (135 lines):

diff -r 93dd9ab75564 -r a4cc262784b9 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Wed Apr 04 23:53:26 2018 +0000
+++ b/usr.bin/make/parse.c      Thu Apr 05 00:31:10 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.227 2018/02/22 01:59:28 sjg Exp $  */
+/*     $NetBSD: parse.c,v 1.228 2018/04/05 00:31:10 christos Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.227 2018/02/22 01:59:28 sjg Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.228 2018/04/05 00:31:10 christos Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.227 2018/02/22 01:59:28 sjg Exp $");
+__RCSID("$NetBSD: parse.c,v 1.228 2018/04/05 00:31:10 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -365,9 +365,6 @@
 static void ParseDoInclude(char *);
 static void ParseSetParseFile(const char *);
 static void ParseSetIncludedFile(void);
-#ifdef SYSVINCLUDE
-static void ParseTraditionalInclude(char *);
-#endif
 #ifdef GMAKEEXPORT
 static void ParseGmakeExport(char *);
 #endif
@@ -2504,8 +2501,73 @@
     ParseSetParseFile(name);
 }
 
+/*-
+ *-----------------------------------------------------------------------
+ * IsInclude --
+ *     Check if the line is an include directive
+ *
+ * Results:
+ *     TRUE if it is.
+ *
+ * Side Effects:
+ *     None
+ *
+ *-----------------------------------------------------------------------
+ */
+static Boolean
+IsInclude(const char *line, Boolean sysv)
+{
+       static const char inc[] = "include";
+       static const size_t inclen = sizeof(inc) - 1;
+
+       // 'd' is not valid for sysv
+       int o = strchr("ds-" + sysv, *line) != NULL;
+
+       if (strncmp(line + o, inc, inclen) != 0)
+               return FALSE;
+
+       // Space is not mandatory for BSD .include
+       return !sysv || isspace((unsigned char)line[inclen + o]);
+}
+
+
 #ifdef SYSVINCLUDE
 /*-
+ *-----------------------------------------------------------------------
+ * IsSysVInclude --
+ *     Check if the line is a SYSV include directive
+ *
+ * Results:
+ *     TRUE if it is.
+ *
+ * Side Effects:
+ *     None
+ *
+ *-----------------------------------------------------------------------
+ */
+static Boolean
+IsSysVInclude(const char *line)
+{
+       const char *p;
+
+       if (!IsInclude(line, TRUE))
+               return FALSE;
+
+       /* Avoid interpeting a dependency line as an include */
+       for (p = line; (p = strchr(p, ':')) != NULL;) {
+               if (*++p == '\0') {
+                       /* end of line -> dependency */
+                       return FALSE;
+               }
+               if (*p == ':' || isspace((unsigned char)*p)) {
+                       /* :: operator or ': ' -> dependency */
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+/*-
  *---------------------------------------------------------------------
  * ParseTraditionalInclude  --
  *     Push to another file.
@@ -3004,9 +3066,7 @@
                for (cp = line + 1; isspace((unsigned char)*cp); cp++) {
                    continue;
                }
-               if (strncmp(cp, "include", 7) == 0 ||
-                       ((cp[0] == 'd' || cp[0] == 's' || cp[0] == '-') &&
-                           strncmp(&cp[1], "include", 7) == 0)) {
+               if (IsInclude(cp, FALSE)) {
                    ParseDoInclude(cp);
                    continue;
                }
@@ -3068,12 +3128,7 @@
            }
 
 #ifdef SYSVINCLUDE
-           if (((strncmp(line, "include", 7) == 0 &&
-                   isspace((unsigned char) line[7])) ||
-                       ((line[0] == 's' || line[0] == '-') &&
-                           strncmp(&line[1], "include", 7) == 0 &&
-                           isspace((unsigned char) line[8]))) &&
-                   strchr(line, ':') == NULL) {
+           if (IsSysVInclude(line)) {
                /*
                 * It's an S3/S5-style "include".
                 */



Home | Main Index | Thread Index | Old Index