Be more selective about detecting a SYSV include as opposed to a dependency

line. Dependency lines should contain a '::' operator or ':<space>'.
This commit is contained in:
christos 2018-04-05 00:31:10 +00:00
parent 8e4f836c68
commit 331fc54718
1 changed files with 70 additions and 15 deletions

View File

@ -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,7 +2501,72 @@ Parse_SetInput(const char *name, int line, int fd,
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 --
@ -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".
*/