| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: var.c,v 1.861 2021/03/14 15:19:15 rillig Exp $ */ | | 1 | /* $NetBSD: var.c,v 1.862 2021/03/14 15:22:21 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -130,27 +130,27 @@ | | | @@ -130,27 +130,27 @@ |
130 | #include <regex.h> | | 130 | #include <regex.h> |
131 | #endif | | 131 | #endif |
132 | #include <errno.h> | | 132 | #include <errno.h> |
133 | #include <inttypes.h> | | 133 | #include <inttypes.h> |
134 | #include <limits.h> | | 134 | #include <limits.h> |
135 | #include <time.h> | | 135 | #include <time.h> |
136 | | | 136 | |
137 | #include "make.h" | | 137 | #include "make.h" |
138 | #include "dir.h" | | 138 | #include "dir.h" |
139 | #include "job.h" | | 139 | #include "job.h" |
140 | #include "metachar.h" | | 140 | #include "metachar.h" |
141 | | | 141 | |
142 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ | | 142 | /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ |
143 | MAKE_RCSID("$NetBSD: var.c,v 1.861 2021/03/14 15:19:15 rillig Exp $"); | | 143 | MAKE_RCSID("$NetBSD: var.c,v 1.862 2021/03/14 15:22:21 rillig Exp $"); |
144 | | | 144 | |
145 | typedef enum VarFlags { | | 145 | typedef enum VarFlags { |
146 | VFL_NONE = 0, | | 146 | VFL_NONE = 0, |
147 | | | 147 | |
148 | /* | | 148 | /* |
149 | * The variable's value is currently being used by Var_Parse or | | 149 | * The variable's value is currently being used by Var_Parse or |
150 | * Var_Subst. This marker is used to avoid endless recursion. | | 150 | * Var_Subst. This marker is used to avoid endless recursion. |
151 | */ | | 151 | */ |
152 | VFL_IN_USE = 1 << 0, | | 152 | VFL_IN_USE = 1 << 0, |
153 | | | 153 | |
154 | /* | | 154 | /* |
155 | * The variable comes from the environment. | | 155 | * The variable comes from the environment. |
156 | * These variables are not registered in any GNode, therefore they | | 156 | * These variables are not registered in any GNode, therefore they |
| @@ -3319,28 +3319,28 @@ ApplyModifier_Assign(const char **pp, Ap | | | @@ -3319,28 +3319,28 @@ ApplyModifier_Assign(const char **pp, Ap |
3319 | Expr *expr = st->expr; | | 3319 | Expr *expr = st->expr; |
3320 | GNode *scope; | | 3320 | GNode *scope; |
3321 | char *val; | | 3321 | char *val; |
3322 | VarParseResult res; | | 3322 | VarParseResult res; |
3323 | | | 3323 | |
3324 | const char *mod = *pp; | | 3324 | const char *mod = *pp; |
3325 | const char *op = mod + 1; | | 3325 | const char *op = mod + 1; |
3326 | | | 3326 | |
3327 | if (op[0] == '=') | | 3327 | if (op[0] == '=') |
3328 | goto ok; | | 3328 | goto ok; |
3329 | if ((op[0] == '!' || op[0] == '+' || op[0] == '?') && op[1] == '=') | | 3329 | if ((op[0] == '!' || op[0] == '+' || op[0] == '?') && op[1] == '=') |
3330 | goto ok; | | 3330 | goto ok; |
3331 | return AMR_UNKNOWN; /* "::<unrecognised>" */ | | 3331 | return AMR_UNKNOWN; /* "::<unrecognised>" */ |
3332 | ok: | | | |
3333 | | | 3332 | |
| | | 3333 | ok: |
3334 | if (expr->var->name.str[0] == '\0') { | | 3334 | if (expr->var->name.str[0] == '\0') { |
3335 | *pp = mod + 1; | | 3335 | *pp = mod + 1; |
3336 | return AMR_BAD; | | 3336 | return AMR_BAD; |
3337 | } | | 3337 | } |
3338 | | | 3338 | |
3339 | scope = expr->scope; /* scope where v belongs */ | | 3339 | scope = expr->scope; /* scope where v belongs */ |
3340 | if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL) { | | 3340 | if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL) { |
3341 | Var *gv = VarFind(expr->var->name.str, expr->scope, FALSE); | | 3341 | Var *gv = VarFind(expr->var->name.str, expr->scope, FALSE); |
3342 | if (gv == NULL) | | 3342 | if (gv == NULL) |
3343 | scope = SCOPE_GLOBAL; | | 3343 | scope = SCOPE_GLOBAL; |
3344 | else | | 3344 | else |
3345 | VarFreeEnv(gv); | | 3345 | VarFreeEnv(gv); |
3346 | } | | 3346 | } |
| @@ -3432,32 +3432,33 @@ ApplyModifier_WordFunc(const char **pp, | | | @@ -3432,32 +3432,33 @@ ApplyModifier_WordFunc(const char **pp, |
3432 | ModifyWordProc modifyWord) | | 3432 | ModifyWordProc modifyWord) |
3433 | { | | 3433 | { |
3434 | if (!IsDelimiter((*pp)[1], st)) | | 3434 | if (!IsDelimiter((*pp)[1], st)) |
3435 | return AMR_UNKNOWN; | | 3435 | return AMR_UNKNOWN; |
3436 | | | 3436 | |
3437 | ModifyWords(st, modifyWord, NULL, st->oneBigWord); | | 3437 | ModifyWords(st, modifyWord, NULL, st->oneBigWord); |
3438 | (*pp)++; | | 3438 | (*pp)++; |
3439 | return AMR_OK; | | 3439 | return AMR_OK; |
3440 | } | | 3440 | } |
3441 | | | 3441 | |
3442 | static ApplyModifierResult | | 3442 | static ApplyModifierResult |
3443 | ApplyModifier_Unique(const char **pp, ApplyModifiersState *st) | | 3443 | ApplyModifier_Unique(const char **pp, ApplyModifiersState *st) |
3444 | { | | 3444 | { |
3445 | if (IsDelimiter((*pp)[1], st)) { | | 3445 | if (!IsDelimiter((*pp)[1], st)) |
3446 | Expr_SetValueOwn(st->expr, VarUniq(st->expr->value.str)); | | | |
3447 | (*pp)++; | | | |
3448 | return AMR_OK; | | | |
3449 | } else | | | |
3450 | return AMR_UNKNOWN; | | 3446 | return AMR_UNKNOWN; |
| | | 3447 | (*pp)++; |
| | | 3448 | |
| | | 3449 | Expr_SetValueOwn(st->expr, VarUniq(st->expr->value.str)); |
| | | 3450 | |
| | | 3451 | return AMR_OK; |
3451 | } | | 3452 | } |
3452 | | | 3453 | |
3453 | #ifdef SYSVVARSUB | | 3454 | #ifdef SYSVVARSUB |
3454 | /* :from=to */ | | 3455 | /* :from=to */ |
3455 | static ApplyModifierResult | | 3456 | static ApplyModifierResult |
3456 | ApplyModifier_SysV(const char **pp, ApplyModifiersState *st) | | 3457 | ApplyModifier_SysV(const char **pp, ApplyModifiersState *st) |
3457 | { | | 3458 | { |
3458 | Expr *expr = st->expr; | | 3459 | Expr *expr = st->expr; |
3459 | char *lhs, *rhs; | | 3460 | char *lhs, *rhs; |
3460 | VarParseResult res; | | 3461 | VarParseResult res; |
3461 | | | 3462 | |
3462 | const char *mod = *pp; | | 3463 | const char *mod = *pp; |
3463 | Boolean eqFound = FALSE; | | 3464 | Boolean eqFound = FALSE; |