Lines Matching refs:Var
1 /* $NetBSD: var.c,v 1.1172 2025/09/16 15:15:47 sjg Exp $ */
74 * Variables are set using lines of the form VAR=value. Both the variable
76 * expressions like ${VAR}, ${VAR:Modifiers}, ${${VARNAME}} or ${VAR:${MODS}}.
98 * Var_Parse Parse an expression such as ${VAR:Mpattern}.
130 /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
131 MAKE_RCSID("$NetBSD: var.c,v 1.1172 2025/09/16 15:15:47 sjg Exp $");
134 * Variables are defined using one of the VAR=value assignments. Their
135 * value can be queried by expressions such as $V, ${VAR}, or with modifiers
136 * such as ${VAR:S,from,to,g:Q}.
144 * expression, or Var.name might point nowhere. (There is another,
153 typedef struct Var {
176 * Appending to its value depends on the scope, see var-op-append.mk.
215 } Var;
417 static Var *
422 Var *var = bmake_malloc(sizeof *var);
423 var->name = name;
424 Buf_InitSize(&var->val, value_len + 1);
425 Buf_AddBytes(&var->val, value, value_len);
426 var->fromCmd = false;
427 var->shortLived = shortLived;
428 var->fromEnvironment = fromEnvironment;
429 var->readOnly = readOnly;
430 var->readOnlyLoud = false;
431 var->inUse = false;
432 var->exported = false;
433 var->reexport = false;
434 return var;
467 static Var *
486 static Var *
489 Var *var;
496 var = GNode_FindVar(scope, name, nameHash);
498 return var;
500 if (var == NULL && scope != SCOPE_CMDLINE)
501 var = GNode_FindVar(SCOPE_CMDLINE, name, nameHash);
503 if (!opts.checkEnvFirst && var == NULL && scope != SCOPE_GLOBAL) {
504 var = GNode_FindVar(SCOPE_GLOBAL, name, nameHash);
505 if (var == NULL && scope != SCOPE_INTERNAL) {
507 var = GNode_FindVar(SCOPE_INTERNAL, name, nameHash);
511 if (var == NULL) {
519 var = GNode_FindVar(SCOPE_GLOBAL, name, nameHash);
520 if (var == NULL && scope != SCOPE_INTERNAL)
521 var = GNode_FindVar(SCOPE_INTERNAL, name,
523 return var;
529 return var;
532 static Var *
540 VarFreeShortLived(Var *v)
561 static Var *
565 Var *v = VarNew(FStr_InitRefer(/* aliased to */ he->key), value,
568 DEBUG4(VAR, "%s: %s = %s%s\n",
581 Var *v;
584 DEBUG2(VAR, "%s: ignoring delete '%s' as it is not found\n",
597 DEBUG2(VAR, "%s: ignoring delete '%s' as it is read-only\n",
608 DEBUG2(VAR, "%s: delete %s\n", scope->name, varname);
627 Var *v = hi.entry->value;
698 ExportVarEnv(Var *v, GNode *scope)
733 ExportVarPlain(Var *v)
754 ExportVarLiteral(Var *v)
773 Var *v;
820 Var *var = hi.entry->value;
821 ExportVar(var->name.str, scope, VEM_ENV);
957 Var *v = VarFindSubstring(varname, SCOPE_GLOBAL, false);
959 DEBUG2(VAR, "Not unexporting \"%.*s\" (not found)\n",
964 DEBUG2(VAR, "Unexporting \"%.*s\"\n",
1019 Var *v;
1023 DEBUG3(VAR,
1035 DEBUG3(VAR,
1058 Var *gl = VarFind(name, SCOPE_GLOBAL, false);
1060 DEBUG3(VAR,
1075 DEBUG3(VAR,
1089 DEBUG3(VAR,
1097 DEBUG4(VAR, "%s: %s = %s%s\n",
1155 DEBUG4(VAR,
1193 Var *v;
1204 DEBUG3(VAR, "%s: ignoring '%s += %s' as it is read-only\n",
1210 DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data);
1242 DEBUG4(VAR,
1261 Var *v = VarFind(name, scope, true);
1304 Var *v = VarFind(name, scope, true);
1324 Var *v;
1328 DEBUG1(VAR, "Var_ReadOnly: %s not found\n", name);
1332 DEBUG2(VAR, "Var_ReadOnly: %s %s\n", name, bf ? "true" : "false");
1342 Var *v = VarFind(name, gn, false);
1696 const char *var; /* name of the temporary variable */
1712 Var_SetWithFlags(args->scope, args->var, word.start,
1717 DEBUG2(VAR, "ModifyWord_Loop: expand \"%s\" to \"%s\"\n",
1964 * If parsing fails and the SysV modifier ${VAR:from=to} should not be used
1979 * expression from ch->expr->value, or the variable name from ch->var->name,
2012 /* An expression based on a variable, such as $@ or ${VAR:Mpattern:Q}. */
2029 * For example, the expression ${VAR:M*:${IND1}:${IND2}:O:u} has 3 chains of
2189 * the "var" or "replacement ${var}" in :@var@replacement ${var}@, up to and
2258 DEBUG2(VAR, "Modifier part: \"%.*s\"\n",
2380 DEBUG3(VAR, "ModifyWords: split \"%s\" into %u %s\n",
2396 /* :@var@...${var}...@ */
2413 args.var = tvar.str;
2414 if (strchr(args.var, '$') != NULL) {
2418 args.var);
2437 Var_Delete(expr->scope, args.var);
2800 DEBUG2(VAR, "Pattern for ':%c' is \"%s\"\n", mod[0], pattern);
3931 * such as in ${VAR:${M_indirect}}.
3934 * expression. ${VAR:${M1}} is valid but ${VAR:${M1}${M2}} is not.
3937 * with colons. ${VAR:${M1}:${M2}} contains 2 indirect modifiers.
3940 * back to trying the SysV modifier, such as in ${VAR:${FROM}=${TO}}.
3955 DEBUG3(VAR, "Indirect modifier \"%s\" from \"%.*s\"\n",
3993 if (DEBUG(VAR))
4027 if (DEBUG(VAR))
4067 /* Apply any modifiers (such as :Mpattern or :@var@loop@ or :Q or ::=value). */
4257 Var **out_true_var)
4260 Var *v;
4297 static Var *
4301 Var *v;
4365 * Parse a long variable name enclosed in braces or parentheses such as $(VAR)
4366 * or ${VAR}, up to the closing brace or parenthesis, or in the case of
4367 * ${VAR:Modifiers}, up to the ':' that starts the modifiers.
4383 Var **out_true_v,
4392 Var *v;
4452 * Nevertheless it needs a Var, for modifiers that access the
4525 * Given the start of an expression (such as $v, $(VAR), ${VAR:Mpattern}),
4560 bool haveModifier; /* true for ${VAR:...}, false for ${VAR} */
4571 Var *v;
4584 DEBUG2(VAR, "Var_Parse: %s (%s)\n", start, VarEvalMode_Name[emode]);
4623 * possible (since var.c 1.212 from 2017-02-01) to delete the variable
4626 * VAR= value
4627 * _:= ${VAR:${:U:@VAR@@}:S,^,prefix,}
4754 * Expand all expressions like $V, ${VAR}, $(VAR:Modifiers) in the
4865 const Var *var = HashTable_FindValue(&scope->vars, varname);
4867 var->val.data, ValueDescription(var->val.data));