mirror of
https://github.com/mirror/make.git
synced 2026-09-01 04:08:10 +08:00
[SV 46995] Strip leading/trailing space from variable names
* makeint.h: Change MAP_SPACE to MAP_NEWLINE, and add MAP_PATHSEP and MAP_SPACE which is now MAP_BLANK|MAP_NEWLINE. Create NEW_TOKEN(), END_OF_TOKEN(), ISBLANK(), ISSPACE() macros. * main.c (initialize_stopchar_map): Set MAP_NEWLINE only for newline characters. * Convert all uses of isblank() and isspace() to macros. * Examine all uses of isblank() (doesn't accept newlines) and change them wherever possible to ISSPACE() (does accept newlines). * function.c (func_foreach): Strip leading/trailing space. * variable.c (parse_variable_definition): Clean up. * tests/scripts/functions/foreach: Test settings and errors. * tests/scripts/functions/call: Rewrite to new-style. * tests/scripts/misc/bs-nl: Add many more tests for newlines.
This commit is contained in:
17
variable.c
17
variable.c
@@ -1431,7 +1431,7 @@ parse_variable_definition (const char *p, struct variable *var)
|
||||
int wspace = 0;
|
||||
const char *e = NULL;
|
||||
|
||||
p = next_token (p);
|
||||
NEXT_TOKEN (p);
|
||||
var->name = (char *)p;
|
||||
var->length = 0;
|
||||
|
||||
@@ -1448,7 +1448,7 @@ parse_variable_definition (const char *p, struct variable *var)
|
||||
/* This begins a variable expansion reference. Make sure we don't
|
||||
treat chars inside the reference as assignment tokens. */
|
||||
char closeparen;
|
||||
int count;
|
||||
|
||||
c = *p++;
|
||||
if (c == '(')
|
||||
closeparen = ')';
|
||||
@@ -1462,26 +1462,25 @@ parse_variable_definition (const char *p, struct variable *var)
|
||||
|
||||
/* P now points past the opening paren or brace.
|
||||
Count parens or braces until it is matched. */
|
||||
count = 0;
|
||||
for (; *p != '\0'; ++p)
|
||||
for (unsigned int count = 1; *p != '\0'; ++p)
|
||||
{
|
||||
if (*p == c)
|
||||
++count;
|
||||
else if (*p == closeparen && --count < 0)
|
||||
if (*p == closeparen && --count == 0)
|
||||
{
|
||||
++p;
|
||||
break;
|
||||
}
|
||||
if (*p == c)
|
||||
++count;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If we find whitespace skip it, and remember we found it. */
|
||||
if (isblank ((unsigned char)c))
|
||||
if (ISBLANK (c))
|
||||
{
|
||||
wspace = 1;
|
||||
e = p - 1;
|
||||
p = next_token (p);
|
||||
NEXT_TOKEN (p);
|
||||
c = *p;
|
||||
if (c == '\0')
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user