From bfc4a81d2a41d4c8091f44ca72e461cf36a18c7d Mon Sep 17 00:00:00 2001 From: Marco Pfatschbacher Date: Wed, 1 Feb 2006 23:23:38 +0000 Subject: Simplify expression code. Patch from markus@. ok mcbride@ --- usr.sbin/ifstated/ifstated.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'usr.sbin/ifstated') diff --git a/usr.sbin/ifstated/ifstated.c b/usr.sbin/ifstated/ifstated.c index b8057cf4a31..f85ac86f298 100644 --- a/usr.sbin/ifstated/ifstated.c +++ b/usr.sbin/ifstated/ifstated.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifstated.c,v 1.26 2006/02/01 23:13:09 mpf Exp $ */ +/* $OpenBSD: ifstated.c,v 1.27 2006/02/01 23:23:37 mpf Exp $ */ /* * Copyright (c) 2004 Marco Pfatschbacher @@ -310,10 +310,7 @@ adjust_external_expressions(struct ifsd_state *state) TAILQ_FOREACH(expression, &external->expressions, entries) { TAILQ_INSERT_TAIL(&expressions, expression, eval); - if (external->prevstatus == 0) - expression->truth = 1; - else - expression->truth = 0; + expression->truth = !external->prevstatus; } adjust_expressions(&expressions, conf->maxdepth); } @@ -422,10 +419,7 @@ scan_ifstate_single(int ifindex, int s, struct ifsd_state *state) struct ifsd_expression *expression; int truth; - if (ifstate->ifstate == s) - truth = 1; - else - truth = 0; + truth = (ifstate->ifstate == s); TAILQ_FOREACH(expression, &ifstate->expressions, entries) { @@ -481,24 +475,15 @@ adjust_expressions(struct ifsd_expression_list *expressions, int depth) switch (expression->type) { case IFSD_OPER_AND: - if (expression->left->truth && - expression->right->truth) - expression->truth = 1; - else - expression->truth = 0; + expression->truth = expression->left->truth && + expression->right->truth; break; case IFSD_OPER_OR: - if (expression->left->truth || - expression->right->truth) - expression->truth = 1; - else - expression->truth = 0; + expression->truth = expression->left->truth || + expression->right->truth; break; case IFSD_OPER_NOT: - if (expression->right->truth) - expression->truth = 0; - else - expression->truth = 1; + expression->truth = !expression->right->truth; break; default: break; -- cgit v1.2.3