Module Name: src Committed By: rillig Date: Sun Jul 26 22:43:17 UTC 2020
Modified Files: src/usr.bin/make: var.c Log Message: make(1): extract code for dynamic variable names out of Var_Parse To generate a diff of this commit: cvs rdiff -u -r1.334 -r1.335 src/usr.bin/make/var.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/var.c diff -u src/usr.bin/make/var.c:1.334 src/usr.bin/make/var.c:1.335 --- src/usr.bin/make/var.c:1.334 Sun Jul 26 22:19:11 2020 +++ src/usr.bin/make/var.c Sun Jul 26 22:43:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.334 2020/07/26 22:19:11 rillig Exp $ */ +/* $NetBSD: var.c,v 1.335 2020/07/26 22:43:16 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.334 2020/07/26 22:19:11 rillig Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.335 2020/07/26 22:43:16 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: var.c,v 1.334 2020/07/26 22:19:11 rillig Exp $"); +__RCSID("$NetBSD: var.c,v 1.335 2020/07/26 22:43:16 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -3358,6 +3358,45 @@ cleanup: return var_Error; } +static Boolean +VarIsDynamic(GNode *ctxt, const char *varname, size_t namelen) +{ + if ((namelen == 1 || + (namelen == 2 && (varname[1] == 'F' || varname[1] == 'D'))) && + (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) + { + /* + * If substituting a local variable in a non-local context, + * assume it's for dynamic source stuff. We have to handle + * this specially and return the longhand for the variable + * with the dollar sign escaped so it makes it back to the + * caller. Only four of the local variables are treated + * specially as they are the only four that will be set + * when dynamic sources are expanded. + */ + switch (varname[0]) { + case '@': + case '%': + case '*': + case '!': + return TRUE; + } + return FALSE; + } + + if (namelen > 2 && varname[0] == '.' && + isupper((unsigned char) varname[1]) && + (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) + { + return strcmp(varname, ".TARGET") == 0 || + strcmp(varname, ".ARCHIVE") == 0 || + strcmp(varname, ".PREFIX") == 0 || + strcmp(varname, ".MEMBER") == 0; + } + + return FALSE; +} + /*- *----------------------------------------------------------------------- * Var_Parse -- @@ -3542,39 +3581,7 @@ Var_Parse(const char * const str, GNode } if (v == NULL) { - if ((namelen == 1 || - (namelen == 2 && (varname[1] == 'F' || varname[1] == 'D'))) && - (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) - { - /* - * If substituting a local variable in a non-local context, - * assume it's for dynamic source stuff. We have to handle - * this specially and return the longhand for the variable - * with the dollar sign escaped so it makes it back to the - * caller. Only four of the local variables are treated - * specially as they are the only four that will be set - * when dynamic sources are expanded. - */ - switch (varname[0]) { - case '@': - case '%': - case '*': - case '!': - dynamic = TRUE; - break; - } - } else if (namelen > 2 && varname[0] == '.' && - isupper((unsigned char) varname[1]) && - (ctxt == VAR_CMD || ctxt == VAR_GLOBAL)) - { - if ((strcmp(varname, ".TARGET") == 0) || - (strcmp(varname, ".ARCHIVE") == 0) || - (strcmp(varname, ".PREFIX") == 0) || - (strcmp(varname, ".MEMBER") == 0)) - { - dynamic = TRUE; - } - } + dynamic = VarIsDynamic(ctxt, varname, namelen); if (!haveModifier) { /*