Module Name: src Committed By: christos Date: Thu Apr 5 00:31:11 UTC 2018
Modified Files: src/usr.bin/make: parse.c Log Message: Be more selective about detecting a SYSV include as opposed to a dependency line. Dependency lines should contain a '::' operator or ':<space>'. To generate a diff of this commit: cvs rdiff -u -r1.227 -r1.228 src/usr.bin/make/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.227 src/usr.bin/make/parse.c:1.228 --- src/usr.bin/make/parse.c:1.227 Wed Feb 21 20:59:28 2018 +++ src/usr.bin/make/parse.c Wed Apr 4 20:31:10 2018 @@ -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 ParseHasCommands(void *); 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 @@ Parse_SetInput(const char *name, int lin 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 @@ Parse_File(const char *name, int fd) 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 @@ Parse_File(const char *name, int fd) } #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". */