Sat Aug 29 12:27:10 2020 UTC ()
make(1): split ApplyModifier_To into paragraphs


(rillig)
diff -r1.474 -r1.475 src/usr.bin/make/var.c

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

--- src/usr.bin/make/var.c 2020/08/29 11:24:54 1.474
+++ src/usr.bin/make/var.c 2020/08/29 12:27:10 1.475
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.474 2020/08/29 11:24:54 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.475 2020/08/29 12:27:10 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.474 2020/08/29 11:24:54 rillig Exp $"; 72static char rcsid[] = "$NetBSD: var.c,v 1.475 2020/08/29 12:27:10 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.474 2020/08/29 11:24:54 rillig Exp $"); 79__RCSID("$NetBSD: var.c,v 1.475 2020/08/29 12:27:10 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 *
@@ -2553,49 +2553,58 @@ ApplyModifier_To(const char **pp, ApplyM @@ -2553,49 +2553,58 @@ ApplyModifier_To(const char **pp, ApplyM
2553 return AMR_BAD; /* Found ":t<endc>" or ":t:". */ 2553 return AMR_BAD; /* Found ":t<endc>" or ":t:". */
2554 2554
2555 if (mod[1] == 's') 2555 if (mod[1] == 's')
2556 return ApplyModifier_ToSep(pp, st); 2556 return ApplyModifier_ToSep(pp, st);
2557 2557
2558 if (mod[2] != st->endc && mod[2] != ':') 2558 if (mod[2] != st->endc && mod[2] != ':')
2559 return AMR_BAD; /* Found ":t<unrecognised><unrecognised>". */ 2559 return AMR_BAD; /* Found ":t<unrecognised><unrecognised>". */
2560 2560
2561 /* Check for two-character options: ":tu", ":tl" */ 2561 /* Check for two-character options: ":tu", ":tl" */
2562 if (mod[1] == 'A') { /* absolute path */ 2562 if (mod[1] == 'A') { /* absolute path */
2563 st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val, 2563 st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
2564 ModifyWord_Realpath, NULL); 2564 ModifyWord_Realpath, NULL);
2565 *pp = mod + 2; 2565 *pp = mod + 2;
2566 } else if (mod[1] == 'u') { 2566 return AMR_OK;
 2567 }
 2568
 2569 if (mod[1] == 'u') {
2567 size_t i; 2570 size_t i;
2568 size_t len = strlen(st->val); 2571 size_t len = strlen(st->val);
2569 st->newVal = bmake_malloc(len + 1); 2572 st->newVal = bmake_malloc(len + 1);
2570 for (i = 0; i < len + 1; i++) 2573 for (i = 0; i < len + 1; i++)
2571 st->newVal[i] = (char)toupper((unsigned char)st->val[i]); 2574 st->newVal[i] = (char)toupper((unsigned char)st->val[i]);
2572 *pp = mod + 2; 2575 *pp = mod + 2;
2573 } else if (mod[1] == 'l') { 2576 return AMR_OK;
 2577 }
 2578
 2579 if (mod[1] == 'l') {
2574 size_t i; 2580 size_t i;
2575 size_t len = strlen(st->val); 2581 size_t len = strlen(st->val);
2576 st->newVal = bmake_malloc(len + 1); 2582 st->newVal = bmake_malloc(len + 1);
2577 for (i = 0; i < len + 1; i++) 2583 for (i = 0; i < len + 1; i++)
2578 st->newVal[i] = (char)tolower((unsigned char)st->val[i]); 2584 st->newVal[i] = (char)tolower((unsigned char)st->val[i]);
2579 *pp = mod + 2; 2585 *pp = mod + 2;
2580 } else if (mod[1] == 'W' || mod[1] == 'w') { 2586 return AMR_OK;
 2587 }
 2588
 2589 if (mod[1] == 'W' || mod[1] == 'w') {
2581 st->oneBigWord = mod[1] == 'W'; 2590 st->oneBigWord = mod[1] == 'W';
2582 st->newVal = st->val; 2591 st->newVal = st->val;
2583 *pp = mod + 2; 2592 *pp = mod + 2;
2584 } else { 2593 return AMR_OK;
2585 /* Found ":t<unrecognised>:" or ":t<unrecognised><endc>". */ 
2586 return AMR_BAD; 
2587 } 2594 }
2588 return AMR_OK; 2595
 2596 /* Found ":t<unrecognised>:" or ":t<unrecognised><endc>". */
 2597 return AMR_BAD;
2589} 2598}
2590 2599
2591/* :[#], :[1], etc. */ 2600/* :[#], :[1], etc. */
2592static ApplyModifierResult 2601static ApplyModifierResult
2593ApplyModifier_Words(const char **pp, ApplyModifiersState *st) 2602ApplyModifier_Words(const char **pp, ApplyModifiersState *st)
2594{ 2603{
2595 char delim; 2604 char delim;
2596 char *estr; 2605 char *estr;
2597 char *ep; 2606 char *ep;
2598 int first, last; 2607 int first, last;
2599 2608
2600 (*pp)++; /* skip the '[' */ 2609 (*pp)++; /* skip the '[' */
2601 delim = ']'; /* look for closing ']' */ 2610 delim = ']'; /* look for closing ']' */