Module Name: src
Committed By: rillig
Date: Thu Aug 20 07:01:39 UTC 2020
Modified Files:
src/usr.bin/make: var.c
Log Message:
make(1): remove VARP_SUB_MATCHED
This flag didn't really belong to the other flags. The other flags are
set during parsing and are then left as-is by ModifyWord_Subst and
ModifyWord_SubstRegex.
It's clearer to use a separate variable for storing whether there was a
match already.
To generate a diff of this commit:
cvs rdiff -u -r1.451 -r1.452 src/usr.bin/make/var.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/var.c
diff -u src/usr.bin/make/var.c:1.451 src/usr.bin/make/var.c:1.452
--- src/usr.bin/make/var.c:1.451 Thu Aug 20 06:48:18 2020
+++ src/usr.bin/make/var.c Thu Aug 20 07:01:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.451 2020/08/20 06:48:18 rillig Exp $ */
+/* $NetBSD: var.c,v 1.452 2020/08/20 07:01:39 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.451 2020/08/20 06:48:18 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.452 2020/08/20 07:01:39 rillig 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.451 2020/08/20 06:48:18 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.452 2020/08/20 07:01:39 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -277,9 +277,8 @@ typedef enum {
typedef enum {
VARP_SUB_GLOBAL = 0x01, /* Apply substitution globally */
VARP_SUB_ONE = 0x02, /* Apply substitution to one word */
- VARP_SUB_MATCHED = 0x04, /* There was a match */
- VARP_ANCHOR_START = 0x08, /* Match at start of word */
- VARP_ANCHOR_END = 0x10 /* Match at end of word */
+ VARP_ANCHOR_START = 0x04, /* Match at start of word */
+ VARP_ANCHOR_END = 0x08 /* Match at end of word */
} VarPatternFlags;
typedef enum {
@@ -1269,6 +1268,7 @@ typedef struct {
const char *rhs;
size_t rhsLen;
VarPatternFlags pflags;
+ Boolean matched;
} ModifyWord_SubstArgs;
/* Callback for ModifyWords to implement the :S,from,to, modifier.
@@ -1280,7 +1280,7 @@ ModifyWord_Subst(const char *word, SepBu
ModifyWord_SubstArgs *args = data;
const char *match;
- if ((args->pflags & VARP_SUB_ONE) && (args->pflags & VARP_SUB_MATCHED))
+ if ((args->pflags & VARP_SUB_ONE) && args->matched)
goto nosub;
if (args->pflags & VARP_ANCHOR_START) {
@@ -1293,11 +1293,11 @@ ModifyWord_Subst(const char *word, SepBu
goto nosub;
SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
- args->pflags |= VARP_SUB_MATCHED;
+ args->matched = TRUE;
} else {
SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
SepBuf_AddBytes(buf, word + args->lhsLen, wordLen - args->lhsLen);
- args->pflags |= VARP_SUB_MATCHED;
+ args->matched = TRUE;
}
return;
}
@@ -1314,7 +1314,7 @@ ModifyWord_Subst(const char *word, SepBu
SepBuf_AddBytesBetween(buf, word, start);
SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
- args->pflags |= VARP_SUB_MATCHED;
+ args->matched = TRUE;
return;
}
@@ -1322,7 +1322,7 @@ ModifyWord_Subst(const char *word, SepBu
while ((match = Str_FindSubstring(word, args->lhs)) != NULL) {
SepBuf_AddBytesBetween(buf, word, match);
SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
- args->pflags |= VARP_SUB_MATCHED;
+ args->matched = TRUE;
wordLen -= (size_t)(match - word) + args->lhsLen;
word += (size_t)(match - word) + args->lhsLen;
if (wordLen == 0 || !(args->pflags & VARP_SUB_GLOBAL))
@@ -1349,6 +1349,7 @@ typedef struct {
size_t nsub;
char *replace;
VarPatternFlags pflags;
+ Boolean matched;
} ModifyWord_SubstRegexArgs;
/* Callback for ModifyWords to implement the :C/from/to/ modifier.
@@ -1363,7 +1364,7 @@ ModifyWord_SubstRegex(const char *word,
int flags = 0;
regmatch_t m[10];
- if ((args->pflags & VARP_SUB_ONE) && (args->pflags & VARP_SUB_MATCHED))
+ if ((args->pflags & VARP_SUB_ONE) && args->matched)
goto nosub;
tryagain:
@@ -1371,7 +1372,7 @@ tryagain:
switch (xrv) {
case 0:
- args->pflags |= VARP_SUB_MATCHED;
+ args->matched = TRUE;
SepBuf_AddBytes(buf, wp, (size_t)m[0].rm_so);
for (rp = args->replace; *rp; rp++) {
@@ -2316,6 +2317,7 @@ ApplyModifier_Subst(const char **pp, App
*pp += 2;
args.pflags = 0;
+ args.matched = FALSE;
/*
* If pattern begins with '^', it is anchored to the
@@ -2401,6 +2403,7 @@ ApplyModifier_Regex(const char **pp, App
}
args.pflags = 0;
+ args.matched = FALSE;
oneBigWord = st->oneBigWord;
for (;; (*pp)++) {
switch (**pp) {