| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cond.c,v 1.277 2021/09/21 22:48:04 rillig Exp $ */ | | 1 | /* $NetBSD: cond.c,v 1.278 2021/09/21 22:53:35 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.277 2021/09/21 22:48:04 rillig Exp $"); | | 98 | MAKE_RCSID("$NetBSD: cond.c,v 1.278 2021/09/21 22:53:35 rillig Exp $"); |
99 | | | 99 | |
100 | /* | | 100 | /* |
101 | * The parsing of conditional expressions is based on this grammar: | | 101 | * The parsing of conditional expressions is based on this grammar: |
102 | * Or -> And | | 102 | * Or -> And |
103 | * Or -> Or '||' And | | 103 | * Or -> Or '||' And |
104 | * And -> Term | | 104 | * And -> Term |
105 | * And -> And '&&' Term | | 105 | * And -> And '&&' Term |
106 | * Term -> Function '(' Argument ')' | | 106 | * Term -> Function '(' Argument ')' |
107 | * Term -> Leaf Operator Leaf | | 107 | * Term -> Leaf Operator Leaf |
108 | * Term -> Leaf | | 108 | * Term -> Leaf |
109 | * Term -> '(' Or ')' | | 109 | * Term -> '(' Or ')' |
110 | * Term -> '!' Term | | 110 | * Term -> '!' Term |
111 | * Leaf -> "string" | | 111 | * Leaf -> "string" |
| @@ -176,27 +176,27 @@ typedef struct CondParser { | | | @@ -176,27 +176,27 @@ typedef struct CondParser { |
176 | * condition. The first available error message is usually the most | | 176 | * condition. The first available error message is usually the most |
177 | * specific one, therefore it makes sense to suppress the standard | | 177 | * specific one, therefore it makes sense to suppress the standard |
178 | * "Malformed conditional" message. | | 178 | * "Malformed conditional" message. |
179 | */ | | 179 | */ |
180 | bool printedError; | | 180 | bool printedError; |
181 | } CondParser; | | 181 | } CondParser; |
182 | | | 182 | |
183 | static CondResult CondParser_Or(CondParser *par, bool); | | 183 | static CondResult CondParser_Or(CondParser *par, bool); |
184 | | | 184 | |
185 | static unsigned int cond_depth = 0; /* current .if nesting level */ | | 185 | static unsigned int cond_depth = 0; /* current .if nesting level */ |
186 | static unsigned int cond_min_depth = 0; /* depth at makefile open */ | | 186 | static unsigned int cond_min_depth = 0; /* depth at makefile open */ |
187 | | | 187 | |
188 | /* Names for ComparisonOp. */ | | 188 | /* Names for ComparisonOp. */ |
189 | static const char *opname[] = { "<", "<=", ">", ">=", "==", "!=" }; | | 189 | static const char opname[][3] = { "<", "<=", ">", ">=", "==", "!=" }; |
190 | | | 190 | |
191 | static bool | | 191 | static bool |
192 | is_token(const char *str, const char *tok, size_t len) | | 192 | is_token(const char *str, const char *tok, size_t len) |
193 | { | | 193 | { |
194 | return strncmp(str, tok, len) == 0 && !ch_isalpha(str[len]); | | 194 | return strncmp(str, tok, len) == 0 && !ch_isalpha(str[len]); |
195 | } | | 195 | } |
196 | | | 196 | |
197 | static Token | | 197 | static Token |
198 | ToToken(bool cond) | | 198 | ToToken(bool cond) |
199 | { | | 199 | { |
200 | return cond ? TOK_TRUE : TOK_FALSE; | | 200 | return cond ? TOK_TRUE : TOK_FALSE; |
201 | } | | 201 | } |
202 | | | 202 | |