Mon Jul 27 22:50:01 2020 UTC ()
make(1): replace comment in ApplyModifier_Match with code


(rillig)
diff -r1.344 -r1.345 src/usr.bin/make/var.c

cvs diff -r1.344 -r1.345 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/07/27 22:30:00 1.344
+++ src/usr.bin/make/var.c 2020/07/27 22:50:01 1.345
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.344 2020/07/27 22:30:00 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.345 2020/07/27 22:50:01 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: var.c,v 1.344 2020/07/27 22:30:00 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.345 2020/07/27 22:50:01 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: var.c,v 1.344 2020/07/27 22:30:00 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.345 2020/07/27 22:50:01 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * var.c -- 85 * var.c --
86 * Variable-handling functions 86 * Variable-handling functions
87 * 87 *
88 * Interface: 88 * Interface:
89 * Var_Set Set the value of a variable in the given 89 * Var_Set Set the value of a variable in the given
90 * context. The variable is created if it doesn't 90 * context. The variable is created if it doesn't
91 * yet exist. 91 * yet exist.
92 * 92 *
@@ -2341,39 +2341,34 @@ ApplyModifier_Match(const char *mod, App @@ -2341,39 +2341,34 @@ ApplyModifier_Match(const char *mod, App
2341 if (*st->cp == '(' || *st->cp == '{') 2341 if (*st->cp == '(' || *st->cp == '{')
2342 ++nest; 2342 ++nest;
2343 if (*st->cp == ')' || *st->cp == '}') { 2343 if (*st->cp == ')' || *st->cp == '}') {
2344 --nest; 2344 --nest;
2345 if (nest == 0) 2345 if (nest == 0)
2346 break; 2346 break;
2347 } 2347 }
2348 } 2348 }
2349 st->termc = *st->cp; 2349 st->termc = *st->cp;
2350 const char *endpat = st->cp; 2350 const char *endpat = st->cp;
2351 2351
2352 char *pattern = NULL; 2352 char *pattern = NULL;
2353 if (copy) { 2353 if (copy) {
2354 /* 2354 /* Compress the \:'s out of the pattern. */
2355 * Need to compress the \:'s out of the pattern, so 2355 pattern = bmake_malloc(st->cp - (mod + 1) + 1);
2356 * allocate enough room to hold the uncompressed 
2357 * pattern (note that st->cp started at mod+1, so 
2358 * st->cp - mod takes the null byte into account) and 
2359 * compress the pattern into the space. 
2360 */ 
2361 pattern = bmake_malloc(st->cp - mod); 
2362 char *cp2; 2356 char *cp2;
2363 for (cp2 = pattern, st->cp = mod + 1; 2357 for (cp2 = pattern, st->cp = mod + 1;
2364 st->cp < endpat; 2358 st->cp < endpat;
2365 st->cp++, cp2++) { 2359 st->cp++, cp2++) {
2366 if ((*st->cp == '\\') && (st->cp+1 < endpat) && 2360 if ((*st->cp == '\\') && (st->cp+1 < endpat) &&
 2361 /* XXX: st->startc is missing here; see above */
2367 (st->cp[1] == ':' || st->cp[1] == st->endc)) 2362 (st->cp[1] == ':' || st->cp[1] == st->endc))
2368 st->cp++; 2363 st->cp++;
2369 *cp2 = *st->cp; 2364 *cp2 = *st->cp;
2370 } 2365 }
2371 *cp2 = '\0'; 2366 *cp2 = '\0';
2372 endpat = cp2; 2367 endpat = cp2;
2373 } else { 2368 } else {
2374 /* 2369 /*
2375 * Either Var_Subst or ModifyWords will need a 2370 * Either Var_Subst or ModifyWords will need a
2376 * nul-terminated string soon, so construct one now. 2371 * nul-terminated string soon, so construct one now.
2377 */ 2372 */
2378 pattern = bmake_strndup(mod + 1, endpat - (mod + 1)); 2373 pattern = bmake_strndup(mod + 1, endpat - (mod + 1));
2379 } 2374 }