Deleted Added
full compact
cond.c (241146) cond.c (243115)
1/* $NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $ */
1/* $NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $ */
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 55 unchanged lines hidden (view full) ---

65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
2
3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *

--- 55 unchanged lines hidden (view full) ---

65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 */
71
72#ifndef MAKE_NATIVE
73static char rcsid[] = "$NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $";
73static char rcsid[] = "$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $";
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
79#else
74#else
75#include <sys/cdefs.h>
76#ifndef lint
77#if 0
78static char sccsid[] = "@(#)cond.c 8.2 (Berkeley) 1/2/94";
79#else
80__RCSID("$NetBSD: cond.c,v 1.64 2012/06/12 19:21:50 joerg Exp $");
80__RCSID("$NetBSD: cond.c,v 1.67 2012/11/03 13:59:27 christos Exp $");
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * cond.c --
87 * Functions to handle conditionals in a makefile.
88 *

--- 1133 unchanged lines hidden (view full) ---

1222 * to detect splurious .else lines (as are SKIP_TO_ELSE and SKIP_TO_ENDIF)
1223 * otherwise .else could be treated as '.elif 1'.
1224 *
1225 *-----------------------------------------------------------------------
1226 */
1227int
1228Cond_Eval(char *line)
1229{
81#endif
82#endif /* not lint */
83#endif
84
85/*-
86 * cond.c --
87 * Functions to handle conditionals in a makefile.
88 *

--- 1133 unchanged lines hidden (view full) ---

1222 * to detect splurious .else lines (as are SKIP_TO_ELSE and SKIP_TO_ENDIF)
1223 * otherwise .else could be treated as '.elif 1'.
1224 *
1225 *-----------------------------------------------------------------------
1226 */
1227int
1228Cond_Eval(char *line)
1229{
1230 #define MAXIF 128 /* maximum depth of .if'ing */
1230#define MAXIF 128 /* maximum depth of .if'ing */
1231#define MAXIF_BUMP 32 /* how much to grow by */
1231 enum if_states {
1232 IF_ACTIVE, /* .if or .elif part active */
1233 ELSE_ACTIVE, /* .else part active */
1234 SEARCH_FOR_ELIF, /* searching for .elif/else to execute */
1235 SKIP_TO_ELSE, /* has been true, but not seen '.else' */
1236 SKIP_TO_ENDIF /* nothing else to execute */
1237 };
1232 enum if_states {
1233 IF_ACTIVE, /* .if or .elif part active */
1234 ELSE_ACTIVE, /* .else part active */
1235 SEARCH_FOR_ELIF, /* searching for .elif/else to execute */
1236 SKIP_TO_ELSE, /* has been true, but not seen '.else' */
1237 SKIP_TO_ENDIF /* nothing else to execute */
1238 };
1238 static enum if_states cond_state[MAXIF + 1] = { IF_ACTIVE };
1239 static enum if_states *cond_state = NULL;
1240 static unsigned int max_if_depth = MAXIF;
1239
1240 const struct If *ifp;
1241 Boolean isElif;
1242 Boolean value;
1243 int level; /* Level at which to report errors. */
1244 enum if_states state;
1245
1246 level = PARSE_FATAL;
1241
1242 const struct If *ifp;
1243 Boolean isElif;
1244 Boolean value;
1245 int level; /* Level at which to report errors. */
1246 enum if_states state;
1247
1248 level = PARSE_FATAL;
1247
1249 if (!cond_state) {
1250 cond_state = bmake_malloc(max_if_depth * sizeof(*cond_state));
1251 cond_state[0] = IF_ACTIVE;
1252 }
1248 /* skip leading character (the '.') and any whitespace */
1249 for (line++; *line == ' ' || *line == '\t'; line++)
1250 continue;
1251
1252 /* Find what type of if we're dealing with. */
1253 if (line[0] == 'e') {
1254 if (line[1] != 'l') {
1255 if (!istoken(line + 1, "ndif", 4))
1256 return COND_INVALID;
1257 /* End of conditional section */
1258 if (cond_depth == cond_min_depth) {
1259 Parse_Error(level, "if-less endif");
1260 return COND_PARSE;
1261 }
1262 /* Return state for previous conditional */
1263 cond_depth--;
1253 /* skip leading character (the '.') and any whitespace */
1254 for (line++; *line == ' ' || *line == '\t'; line++)
1255 continue;
1256
1257 /* Find what type of if we're dealing with. */
1258 if (line[0] == 'e') {
1259 if (line[1] != 'l') {
1260 if (!istoken(line + 1, "ndif", 4))
1261 return COND_INVALID;
1262 /* End of conditional section */
1263 if (cond_depth == cond_min_depth) {
1264 Parse_Error(level, "if-less endif");
1265 return COND_PARSE;
1266 }
1267 /* Return state for previous conditional */
1268 cond_depth--;
1264 if (cond_depth > MAXIF)
1265 return COND_SKIP;
1266 return cond_state[cond_depth] <= ELSE_ACTIVE ? COND_PARSE : COND_SKIP;
1267 }
1268
1269 /* Quite likely this is 'else' or 'elif' */
1270 line += 2;
1271 if (istoken(line, "se", 2)) {
1272 /* It is else... */
1273 if (cond_depth == cond_min_depth) {
1274 Parse_Error(level, "if-less else");
1275 return COND_PARSE;
1276 }
1277
1269 return cond_state[cond_depth] <= ELSE_ACTIVE ? COND_PARSE : COND_SKIP;
1270 }
1271
1272 /* Quite likely this is 'else' or 'elif' */
1273 line += 2;
1274 if (istoken(line, "se", 2)) {
1275 /* It is else... */
1276 if (cond_depth == cond_min_depth) {
1277 Parse_Error(level, "if-less else");
1278 return COND_PARSE;
1279 }
1280
1278 if (cond_depth > MAXIF)
1279 return COND_SKIP;
1280 state = cond_state[cond_depth];
1281 switch (state) {
1282 case SEARCH_FOR_ELIF:
1283 state = ELSE_ACTIVE;
1284 break;
1285 case ELSE_ACTIVE:
1286 case SKIP_TO_ENDIF:
1287 Parse_Error(PARSE_WARNING, "extra else");

--- 32 unchanged lines hidden (view full) ---

1320
1321 /* Now we know what sort of 'if' it is... */
1322
1323 if (isElif) {
1324 if (cond_depth == cond_min_depth) {
1325 Parse_Error(level, "if-less elif");
1326 return COND_PARSE;
1327 }
1281 state = cond_state[cond_depth];
1282 switch (state) {
1283 case SEARCH_FOR_ELIF:
1284 state = ELSE_ACTIVE;
1285 break;
1286 case ELSE_ACTIVE:
1287 case SKIP_TO_ENDIF:
1288 Parse_Error(PARSE_WARNING, "extra else");

--- 32 unchanged lines hidden (view full) ---

1321
1322 /* Now we know what sort of 'if' it is... */
1323
1324 if (isElif) {
1325 if (cond_depth == cond_min_depth) {
1326 Parse_Error(level, "if-less elif");
1327 return COND_PARSE;
1328 }
1328 if (cond_depth > MAXIF)
1329 /* Error reported when we saw the .if ... */
1330 return COND_SKIP;
1331 state = cond_state[cond_depth];
1332 if (state == SKIP_TO_ENDIF || state == ELSE_ACTIVE) {
1333 Parse_Error(PARSE_WARNING, "extra elif");
1334 cond_state[cond_depth] = SKIP_TO_ENDIF;
1335 return COND_SKIP;
1336 }
1337 if (state != SEARCH_FOR_ELIF) {
1338 /* Either just finished the 'true' block, or already SKIP_TO_ELSE */
1339 cond_state[cond_depth] = SKIP_TO_ELSE;
1340 return COND_SKIP;
1341 }
1342 } else {
1343 /* Normal .if */
1329 state = cond_state[cond_depth];
1330 if (state == SKIP_TO_ENDIF || state == ELSE_ACTIVE) {
1331 Parse_Error(PARSE_WARNING, "extra elif");
1332 cond_state[cond_depth] = SKIP_TO_ENDIF;
1333 return COND_SKIP;
1334 }
1335 if (state != SEARCH_FOR_ELIF) {
1336 /* Either just finished the 'true' block, or already SKIP_TO_ELSE */
1337 cond_state[cond_depth] = SKIP_TO_ELSE;
1338 return COND_SKIP;
1339 }
1340 } else {
1341 /* Normal .if */
1344 if (cond_depth >= MAXIF) {
1345 cond_depth++;
1346 Parse_Error(PARSE_FATAL, "Too many nested if's. %d max.", MAXIF);
1347 return COND_SKIP;
1342 if (cond_depth + 1 >= max_if_depth) {
1343 /*
1344 * This is rare, but not impossible.
1345 * In meta mode, dirdeps.mk (only runs at level 0)
1346 * can need more than the default.
1347 */
1348 max_if_depth += MAXIF_BUMP;
1349 cond_state = bmake_realloc(cond_state, max_if_depth *
1350 sizeof(*cond_state));
1348 }
1349 state = cond_state[cond_depth];
1350 cond_depth++;
1351 if (state > ELSE_ACTIVE) {
1352 /* If we aren't parsing the data, treat as always false */
1353 cond_state[cond_depth] = SKIP_TO_ELSE;
1354 return COND_SKIP;
1355 }

--- 55 unchanged lines hidden ---
1351 }
1352 state = cond_state[cond_depth];
1353 cond_depth++;
1354 if (state > ELSE_ACTIVE) {
1355 /* If we aren't parsing the data, treat as always false */
1356 cond_state[cond_depth] = SKIP_TO_ELSE;
1357 return COND_SKIP;
1358 }

--- 55 unchanged lines hidden ---