| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cond.c,v 1.329 2022/02/09 21:09:24 rillig Exp $ */ | | 1 | /* $NetBSD: cond.c,v 1.330 2022/02/11 21:18:09 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | | 4 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. |
5 | * All rights reserved. | | 5 | * 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. |
| @@ -85,27 +85,27 @@ | | | @@ -85,27 +85,27 @@ |
85 | * Cond_restore_depth | | 85 | * Cond_restore_depth |
86 | * Save and restore the nesting of the conditions, at | | 86 | * Save and restore the nesting of the conditions, at |
87 | * the start and end of including another makefile, to | | 87 | * the start and end of including another makefile, to |
88 | * ensure that in each makefile the conditional | | 88 | * ensure that in each makefile the conditional |
89 | * directives are well-balanced. | | 89 | * directives are well-balanced. |
90 | */ | | 90 | */ |
91 | | | 91 | |
92 | #include <errno.h> | | 92 | #include <errno.h> |
93 | | | 93 | |
94 | #include "make.h" | | 94 | #include "make.h" |
95 | #include "dir.h" | | 95 | #include "dir.h" |
96 | | | 96 | |
97 | /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ | | 97 | /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ |
98 | MAKE_RCSID("$NetBSD: cond.c,v 1.329 2022/02/09 21:09:24 rillig Exp $"); | | 98 | MAKE_RCSID("$NetBSD: cond.c,v 1.330 2022/02/11 21:18:09 rillig Exp $"); |
99 | | | 99 | |
100 | /* | | 100 | /* |
101 | * Conditional expressions conform to this grammar: | | 101 | * Conditional expressions conform to this grammar: |
102 | * Or -> And ('||' And)* | | 102 | * Or -> And ('||' And)* |
103 | * And -> Term ('&&' Term)* | | 103 | * And -> Term ('&&' Term)* |
104 | * Term -> Function '(' Argument ')' | | 104 | * Term -> Function '(' Argument ')' |
105 | * Term -> Leaf Operator Leaf | | 105 | * Term -> Leaf Operator Leaf |
106 | * Term -> Leaf | | 106 | * Term -> Leaf |
107 | * Term -> '(' Or ')' | | 107 | * Term -> '(' Or ')' |
108 | * Term -> '!' Term | | 108 | * Term -> '!' Term |
109 | * Leaf -> "string" | | 109 | * Leaf -> "string" |
110 | * Leaf -> Number | | 110 | * Leaf -> Number |
111 | * Leaf -> VariableExpression | | 111 | * Leaf -> VariableExpression |
| @@ -653,38 +653,31 @@ CondParser_Comparison(CondParser *par, b | | | @@ -653,38 +653,31 @@ CondParser_Comparison(CondParser *par, b |
653 | goto done_lhs; | | 653 | goto done_lhs; |
654 | } | | 654 | } |
655 | | | 655 | |
656 | CondParser_SkipWhitespace(par); | | 656 | CondParser_SkipWhitespace(par); |
657 | | | 657 | |
658 | if (par->p[0] == '\0') { | | 658 | if (par->p[0] == '\0') { |
659 | Parse_Error(PARSE_FATAL, | | 659 | Parse_Error(PARSE_FATAL, |
660 | "Missing right-hand side of operator '%s'", opname[op]); | | 660 | "Missing right-hand side of operator '%s'", opname[op]); |
661 | par->printedError = true; | | 661 | par->printedError = true; |
662 | goto done_lhs; | | 662 | goto done_lhs; |
663 | } | | 663 | } |
664 | | | 664 | |
665 | CondParser_Leaf(par, doEval, true, &rhs, &rhsQuoted); | | 665 | CondParser_Leaf(par, doEval, true, &rhs, &rhsQuoted); |
666 | if (rhs.str == NULL) | | 666 | t = rhs.str == NULL ? TOK_ERROR |
667 | goto done_rhs; | | 667 | : !doEval ? TOK_FALSE |
668 | | | 668 | : EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted); |
669 | if (!doEval) { | | | |
670 | t = TOK_FALSE; | | | |
671 | goto done_rhs; | | | |
672 | } | | | |
673 | | | | |
674 | t = EvalCompare(par, lhs.str, lhsQuoted, op, rhs.str, rhsQuoted); | | | |
675 | | | | |
676 | done_rhs: | | | |
677 | FStr_Done(&rhs); | | 669 | FStr_Done(&rhs); |
| | | 670 | |
678 | done_lhs: | | 671 | done_lhs: |
679 | FStr_Done(&lhs); | | 672 | FStr_Done(&lhs); |
680 | return t; | | 673 | return t; |
681 | } | | 674 | } |
682 | | | 675 | |
683 | /* | | 676 | /* |
684 | * The argument to empty() is a variable name, optionally followed by | | 677 | * The argument to empty() is a variable name, optionally followed by |
685 | * variable modifiers. | | 678 | * variable modifiers. |
686 | */ | | 679 | */ |
687 | static bool | | 680 | static bool |
688 | CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token) | | 681 | CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token) |
689 | { | | 682 | { |
690 | const char *cp = par->p; | | 683 | const char *cp = par->p; |