Thu Dec 30 23:56:35 2021 UTC ()
make: condense code in ApplyModifier_Assign

List the assignment operators in the same order as in the manual page.

No functional change.


(rillig)
diff -r1.991 -r1.992 src/usr.bin/make/var.c

cvs diff -r1.991 -r1.992 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2021/12/29 05:05:21 1.991
+++ src/usr.bin/make/var.c 2021/12/30 23:56:34 1.992
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.991 2021/12/29 05:05:21 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.992 2021/12/30 23:56:34 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" */
143MAKE_RCSID("$NetBSD: var.c,v 1.991 2021/12/29 05:05:21 rillig Exp $"); 143MAKE_RCSID("$NetBSD: var.c,v 1.992 2021/12/30 23:56:34 rillig Exp $");
144 144
145/* 145/*
146 * Variables are defined using one of the VAR=value assignments. Their 146 * Variables are defined using one of the VAR=value assignments. Their
147 * value can be queried by expressions such as $V, ${VAR}, or with modifiers 147 * value can be queried by expressions such as $V, ${VAR}, or with modifiers
148 * such as ${VAR:S,from,to,g:Q}. 148 * such as ${VAR:S,from,to,g:Q}.
149 * 149 *
150 * There are 3 kinds of variables: scope variables, environment variables, 150 * There are 3 kinds of variables: scope variables, environment variables,
151 * undefined variables. 151 * undefined variables.
152 * 152 *
153 * Scope variables are stored in a GNode.scope. The only way to undefine 153 * Scope variables are stored in a GNode.scope. The only way to undefine
154 * a scope variable is using the .undef directive. In particular, it must 154 * a scope variable is using the .undef directive. In particular, it must
155 * not be possible to undefine a variable during the evaluation of an 155 * not be possible to undefine a variable during the evaluation of an
156 * expression, or Var.name might point nowhere. 156 * expression, or Var.name might point nowhere.
@@ -3527,47 +3527,38 @@ ApplyModifier_IfElse(const char **pp, Mo @@ -3527,47 +3527,38 @@ ApplyModifier_IfElse(const char **pp, Mo
3527static ApplyModifierResult 3527static ApplyModifierResult
3528ApplyModifier_Assign(const char **pp, ModChain *ch) 3528ApplyModifier_Assign(const char **pp, ModChain *ch)
3529{ 3529{
3530 Expr *expr = ch->expr; 3530 Expr *expr = ch->expr;
3531 GNode *scope; 3531 GNode *scope;
3532 FStr val; 3532 FStr val;
3533 VarParseResult res; 3533 VarParseResult res;
3534 LazyBuf buf; 3534 LazyBuf buf;
3535 3535
3536 const char *mod = *pp; 3536 const char *mod = *pp;
3537 const char *op = mod + 1; 3537 const char *op = mod + 1;
3538 3538
3539 if (op[0] == '=') 3539 if (op[0] == '=')
3540 goto ok; 3540 goto found_op;
3541 if ((op[0] == '!' || op[0] == '+' || op[0] == '?') && op[1] == '=') 3541 if ((op[0] == '+' || op[0] == '?' || op[0] == '!') && op[1] == '=')
3542 goto ok; 3542 goto found_op;
3543 return AMR_UNKNOWN; /* "::<unrecognised>" */ 3543 return AMR_UNKNOWN; /* "::<unrecognised>" */
3544 3544
3545ok: 3545found_op:
3546 if (expr->name[0] == '\0') { 3546 if (expr->name[0] == '\0') {
3547 *pp = mod + 1; 3547 *pp = mod + 1;
3548 return AMR_BAD; 3548 return AMR_BAD;
3549 } 3549 }
3550 3550
3551 switch (op[0]) { 3551 *pp = mod + (op[0] == '+' || op[0] == '?' || op[0] == '!' ? 3 : 2);
3552 case '+': 
3553 case '?': 
3554 case '!': 
3555 *pp = mod + 3; 
3556 break; 
3557 default: 
3558 *pp = mod + 2; 
3559 break; 
3560 } 
3561 3552
3562 res = ParseModifierPart(pp, ch->endc, expr->emode, ch, &buf); 3553 res = ParseModifierPart(pp, ch->endc, expr->emode, ch, &buf);
3563 if (res != VPR_OK) 3554 if (res != VPR_OK)
3564 return AMR_CLEANUP; 3555 return AMR_CLEANUP;
3565 val = LazyBuf_DoneGet(&buf); 3556 val = LazyBuf_DoneGet(&buf);
3566 3557
3567 (*pp)--; /* Go back to the ch->endc. */ 3558 (*pp)--; /* Go back to the ch->endc. */
3568 3559
3569 if (!Expr_ShouldEval(expr)) 3560 if (!Expr_ShouldEval(expr))
3570 goto done; 3561 goto done;
3571 3562
3572 scope = expr->scope; /* scope where v belongs */ 3563 scope = expr->scope; /* scope where v belongs */
3573 if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL) { 3564 if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL) {