Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make - Percent on the rhs is special only if the lhs...
details: https://anonhg.NetBSD.org/src/rev/bbc6d6892a29
branches: trunk
changeset: 1009524:bbc6d6892a29
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 25 18:20:57 2020 +0000
description:
- Percent on the rhs is special only if the lhs has one too.
- If the rhs does not have percent, but the lhs has, the result is the rhs
This behavior matches gmake
diffstat:
usr.bin/make/nonints.h | 6 +++---
usr.bin/make/str.c | 23 ++++++++++++++---------
usr.bin/make/unit-tests/sysv.exp | 7 +++++++
usr.bin/make/unit-tests/sysv.mk | 16 ++++++++++++++--
usr.bin/make/var.c | 13 +++++++------
5 files changed, 45 insertions(+), 20 deletions(-)
diffs (195 lines):
diff -r 163d5e3ec200 -r bbc6d6892a29 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sat Apr 25 17:43:23 2020 +0000
+++ b/usr.bin/make/nonints.h Sat Apr 25 18:20:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.74 2016/09/05 00:40:29 sevan Exp $ */
+/* $NetBSD: nonints.h,v 1.75 2020/04/25 18:20:57 christos Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -138,8 +138,8 @@
char **brk_string(const char *, int *, Boolean, char **);
char *Str_FindSubstring(const char *, const char *);
int Str_Match(const char *, const char *);
-char *Str_SYSVMatch(const char *, const char *, int *len);
-void Str_SYSVSubst(Buffer *, char *, char *, int);
+char *Str_SYSVMatch(const char *, const char *, size_t *, Boolean *);
+void Str_SYSVSubst(Buffer *, char *, char *, size_t, Boolean);
/* suff.c */
void Suff_ClearSuffixes(void);
diff -r 163d5e3ec200 -r bbc6d6892a29 usr.bin/make/str.c
--- a/usr.bin/make/str.c Sat Apr 25 17:43:23 2020 +0000
+++ b/usr.bin/make/str.c Sat Apr 25 18:20:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $ */
+/* $NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
-__RCSID("$NetBSD: str.c,v 1.39 2019/12/01 23:53:49 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.40 2020/04/25 18:20:57 christos Exp $");
#endif
#endif /* not lint */
#endif
@@ -452,12 +452,14 @@
*-----------------------------------------------------------------------
*/
char *
-Str_SYSVMatch(const char *word, const char *pattern, int *len)
+Str_SYSVMatch(const char *word, const char *pattern, size_t *len,
+ Boolean *hasPercent)
{
const char *p = pattern;
const char *w = word;
const char *m;
+ *hasPercent = FALSE;
if (*p == '\0') {
/* Null pattern is the whole string */
*len = strlen(w);
@@ -465,6 +467,7 @@
}
if ((m = strchr(p, '%')) != NULL) {
+ *hasPercent = TRUE;
/* check that the prefix matches */
for (; p != m && *w && *w == *p; w++, p++)
continue;
@@ -509,19 +512,21 @@
*-----------------------------------------------------------------------
*/
void
-Str_SYSVSubst(Buffer *buf, char *pat, char *src, int len)
+Str_SYSVSubst(Buffer *buf, char *pat, char *src, size_t len,
+ Boolean lhsHasPercent)
{
char *m;
- if ((m = strchr(pat, '%')) != NULL) {
+ if ((m = strchr(pat, '%')) != NULL && lhsHasPercent) {
/* Copy the prefix */
Buf_AddBytes(buf, m - pat, pat);
/* skip the % */
pat = m + 1;
}
-
- /* Copy the pattern */
- Buf_AddBytes(buf, len, src);
+ if (m != NULL || !lhsHasPercent) {
+ /* Copy the pattern */
+ Buf_AddBytes(buf, len, src);
+ }
/* append the rest */
Buf_AddBytes(buf, strlen(pat), pat);
diff -r 163d5e3ec200 -r bbc6d6892a29 usr.bin/make/unit-tests/sysv.exp
--- a/usr.bin/make/unit-tests/sysv.exp Sat Apr 25 17:43:23 2020 +0000
+++ b/usr.bin/make/unit-tests/sysv.exp Sat Apr 25 18:20:57 2020 +0000
@@ -4,4 +4,11 @@
fun
fun
In the Sun
+acme
+aam.d
+sam.c
+a%.c
+asam.c.c
+asam.c
+a.c.c
exit status 0
diff -r 163d5e3ec200 -r bbc6d6892a29 usr.bin/make/unit-tests/sysv.mk
--- a/usr.bin/make/unit-tests/sysv.mk Sat Apr 25 17:43:23 2020 +0000
+++ b/usr.bin/make/unit-tests/sysv.mk Sat Apr 25 18:20:57 2020 +0000
@@ -1,4 +1,4 @@
-# $Id: sysv.mk,v 1.2 2014/08/30 22:21:08 sjg Exp $
+# $Id: sysv.mk,v 1.3 2020/04/25 18:20:57 christos Exp $
FOO ?=
FOOBAR = ${FOO:=bar}
@@ -11,7 +11,7 @@
SUN = the Sun
# we expect nothing when FOO is empty
-all: foo fun
+all: foo fun sam
foo:
@echo FOOBAR = ${FOOBAR}
@@ -24,3 +24,15 @@
@echo ${FUN:${B}${S}fun=fun}
@echo ${FUN:${B}${S}%=%}
@echo ${In:L:%=% ${SUN}}
+
+
+SAM=sam.c
+
+sam:
+ @echo ${SAM:s%.c=acme}
+ @echo ${SAM:s%.c=a%.d}
+ @echo ${SAM:s.c=a%.d}
+ @echo ${SAM:sam.c=a%.c}
+ @echo ${SAM:%=a%.c}
+ @echo ${SAM:%.c=a%.c}
+ @echo ${SAM:sam%=a%.c}
diff -r 163d5e3ec200 -r bbc6d6892a29 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Apr 25 17:43:23 2020 +0000
+++ b/usr.bin/make/var.c Sat Apr 25 18:20:57 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.222 2019/02/03 03:19:29 mrg Exp $ */
+/* $NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.222 2019/02/03 03:19:29 mrg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.222 2019/02/03 03:19:29 mrg Exp $");
+__RCSID("$NetBSD: var.c,v 1.223 2020/04/25 18:20:57 christos Exp $");
#endif
#endif /* not lint */
#endif
@@ -1402,8 +1402,9 @@
char *word, Boolean addSpace, Buffer *buf,
void *patp)
{
- int len;
+ size_t len;
char *ptr;
+ Boolean hasPercent;
VarPattern *pat = (VarPattern *)patp;
char *varexp;
@@ -1412,9 +1413,9 @@
addSpace = TRUE;
- if ((ptr = Str_SYSVMatch(word, pat->lhs, &len)) != NULL) {
+ if ((ptr = Str_SYSVMatch(word, pat->lhs, &len, &hasPercent)) != NULL) {
varexp = Var_Subst(NULL, pat->rhs, ctx, VARF_WANTRES);
- Str_SYSVSubst(buf, varexp, ptr, len);
+ Str_SYSVSubst(buf, varexp, ptr, len, hasPercent);
free(varexp);
} else {
Buf_AddBytes(buf, strlen(word), word);
Home |
Main Index |
Thread Index |
Old Index