Module Name: src
Committed By: rillig
Date: Sat Dec 5 17:12:02 UTC 2020
Modified Files:
src/usr.bin/make: suff.c
Log Message:
make(1): extract ExpandChildrenRegular from ExpandChildren
To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 src/usr.bin/make/suff.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/suff.c
diff -u src/usr.bin/make/suff.c:1.324 src/usr.bin/make/suff.c:1.325
--- src/usr.bin/make/suff.c:1.324 Sat Dec 5 16:59:47 2020
+++ src/usr.bin/make/suff.c Sat Dec 5 17:12:02 2020
@@ -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, GNod
}
/*
+ * 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
* 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);
}
/*