diff options
| author | rillig <rillig@NetBSD.org> | 2020-12-05 17:12:02 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2020-12-05 17:12:02 +0000 |
| commit | de29d451aa45b3c5d4975c331a5d8d040d9f145e (patch) | |
| tree | 4bdfde053548ffe3266d3dbf89873575b7acf4f6 /usr.bin/make/suff.c | |
| parent | 1fc7c975da7650151ae47ba7f1ab6220845c0093 (diff) | |
make(1): extract ExpandChildrenRegular from ExpandChildren
Diffstat (limited to 'usr.bin/make/suff.c')
| -rw-r--r-- | usr.bin/make/suff.c | 155 |
1 files changed, 73 insertions, 82 deletions
diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c index 137fd5b8536..505f87efd7a 100644 --- a/usr.bin/make/suff.c +++ b/usr.bin/make/suff.c @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.324 2020/12/05 16:59:47 rillig Exp $ */ +/* $NetBSD: suff.c,v 1.325 2020/12/05 17:12:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -114,7 +114,7 @@ #include "dir.h" /* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ -MAKE_RCSID("$NetBSD: suff.c,v 1.324 2020/12/05 16:59:47 rillig Exp $"); +MAKE_RCSID("$NetBSD: suff.c,v 1.325 2020/12/05 17:12:02 rillig Exp $"); #define SUFF_DEBUG0(text) DEBUG0(SUFF, text) #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1) @@ -1278,6 +1278,74 @@ ExpandWildcards(GNodeListNode *cln, GNode *pgn) } /* + * Break the result into a vector of strings whose nodes we can find, then + * add those nodes to the members list. + * + * Unfortunately, we can't use Str_Words because it doesn't understand about + * variable specifications with spaces in them. + */ +static void +ExpandChildrenRegular(char *cp, GNode *pgn, GNodeList *members) +{ + char *start; + + pp_skip_hspace(&cp); + start = cp; + while (*cp != '\0') { + if (*cp == ' ' || *cp == '\t') { + GNode *gn; + /* + * White-space -- terminate element, find the node, + * add it, skip any further spaces. + */ + *cp++ = '\0'; + gn = Targ_GetNode(start); + Lst_Append(members, gn); + pp_skip_hspace(&cp); + /* Continue at the next non-space. */ + start = cp; + } else if (*cp == '$') { + /* Skip over the variable expression. */ + const char *nested_p = cp; + const char *junk; + void *freeIt; + + (void)Var_Parse(&nested_p, pgn, + VARE_NONE, &junk, &freeIt); + /* TODO: handle errors */ + if (junk == var_Error) { + Parse_Error(PARSE_FATAL, + "Malformed variable expression at \"%s\"", + cp); + cp++; + } else { + cp += nested_p - cp; + } + + free(freeIt); + } else if (cp[0] == '\\' && cp[1] != '\0') { + /* Escaped something -- skip over it. */ + /* + * XXX: In other places, escaping at this syntactical + * position is done by a '$', not a '\'. The '\' is + * only used in variable modifiers. + */ + cp += 2; + } else { + cp++; + } + } + + if (cp != start) { + /* + * Stuff left over -- add it to the list too + */ + GNode *gn = Targ_GetNode(start); + Lst_Append(members, gn); + } +} + +/* * Expand the names of any children of a given node that contain variable * expressions or file wildcards into actual targets. * @@ -1326,87 +1394,10 @@ ExpandChildren(GNodeListNode *cln, GNode *pgn) * call on the Arch module to find the nodes for us, * expanding variables in the parent's context. */ - char *sacrifice = cp; - - (void)Arch_ParseArchive(&sacrifice, &members, pgn); + char *p = cp; + (void)Arch_ParseArchive(&p, &members, pgn); } else { - /* - * Break the result into a vector of strings whose - * nodes we can find, then add those nodes to the - * members list. - * - * Unfortunately, we can't use Str_Words because it - * doesn't understand about variable specifications - * with spaces in them. - */ - char *start; - char *initcp = cp; /* For freeing... */ - - start = cp; - pp_skip_hspace(&start); - cp = start; - while (*cp != '\0') { - if (*cp == ' ' || *cp == '\t') { - GNode *gn; - /* - * White-space -- terminate element, - * find the node, add it, skip any - * further spaces. - */ - *cp++ = '\0'; - gn = Targ_GetNode(start); - Lst_Append(&members, gn); - pp_skip_hspace(&cp); - /* Continue at the next non-space. */ - start = cp; - } else if (*cp == '$') { - /* Skip over the variable expression. */ - const char *nested_p = cp; - const char *junk; - void *freeIt; - - (void)Var_Parse(&nested_p, pgn, - VARE_NONE, &junk, &freeIt); - /* TODO: handle errors */ - if (junk == var_Error) { - Parse_Error(PARSE_FATAL, - "Malformed variable " - "expression at \"%s\"", - cp); - cp++; - } else { - cp += nested_p - cp; - } - - free(freeIt); - } else if (cp[0] == '\\' && cp[1] != '\0') { - /* - * Escaped something -- skip over it - */ - /* - * XXX: In other places, escaping at - * this syntactical position is done - * by a '$', not a '\'. The '\' is - * only used in variable modifiers. - */ - cp += 2; - } else { - cp++; - } - } - - if (cp != start) { - /* - * Stuff left over -- add it to the list too - */ - GNode *gn = Targ_GetNode(start); - Lst_Append(&members, gn); - } - /* - * Point cp back at the beginning again so the - * variable value can be freed. - */ - cp = initcp; + ExpandChildrenRegular(cp, pgn, &members); } /* |
