From: Karl DeBisschop Date: Mon, 18 Nov 2002 07:22:28 +0000 (+0000) Subject: more readable max_state() code X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=57c32f34730554dcd7ccd8e0e1f9c9e40bfb325a;p=nagiosplug.git more readable max_state() code git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@207 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/plugins/utils.c b/plugins/utils.c index 10d544c..da9cced 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -60,8 +60,8 @@ char *strpcat (char *dest, const char *src, const char *str); #define max(a,b) ((a)>(b))?(a):(b) /* ************************************************************************** - * max_state(result, STATE_x) - * compares STATE_x to result and returns result if STATE_x is less than a based on the following + * max_state(STATE_x, STATE_y) + * compares STATE_x to STATE_y and returns result based on the following * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL * * Note that numerically the above does not hold @@ -70,31 +70,18 @@ char *strpcat (char *dest, const char *src, const char *str); int max_state(int a, int b) { - if(a == STATE_CRITICAL){ - return a; - } - else if (a == STATE_WARNING) { - - if (b == STATE_CRITICAL){ - return b; - }else { - return a; - } - } - else if (a == STATE_OK) { - - if ( b== STATE_CRITICAL || b == STATE_WARNING) { - return b; - }else{ - return a; - } - } - else { - /* a == UNKNOWN */ - return b; - } - - + if (a == STATE_CRITICAL || b == STATE_CRITICAL) + return STATE_CRITICAL; + else if (a == STATE_WARNING || b == STATE_WARNING) + return STATE_WARNING; + else if (a == STATE_OK || b == STATE_OK) + return STATE_OK; + else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) + return STATE_UNKNOWN; + else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) + return STATE_DEPENDENT; + else + return max (a, b); } char *