From 53ad430b489153e00bd96a9333d5db47f264f341 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Wed, 23 Jan 2019 16:11:22 +0100 Subject: [PATCH] Compose rule matching function more readable --- src/rules.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/rules.c b/src/rules.c index 9fd9ce6..b27419a 100644 --- a/src/rules.c +++ b/src/rules.c @@ -91,18 +91,23 @@ void rule_init(struct rule *r) r->set_stack_tag = NULL; } +static inline bool rule_field_matches_string(const char *value, const char *pattern) +{ + return !pattern || (value && !fnmatch(pattern, value, 0)); +} + /* * Check whether rule should be applied to n. */ bool rule_matches_notification(struct rule *r, struct notification *n) { - return ( (!r->appname || (n->appname && !fnmatch(r->appname, n->appname, 0))) - && (!r->summary || (n->summary && !fnmatch(r->summary, n->summary, 0))) - && (!r->body || (n->body && !fnmatch(r->body, n->body, 0))) - && (!r->icon || (n->iconname && !fnmatch(r->icon, n->iconname,0))) - && (!r->category || (n->category && !fnmatch(r->category, n->category, 0))) - && (!r->stack_tag || (n->stack_tag && !fnmatch(r->stack_tag, n->stack_tag, 0))) + return (r->msg_urgency == URG_NONE || r->msg_urgency == n->urgency) && (r->match_transient == -1 || (r->match_transient == n->transient)) - && (r->msg_urgency == URG_NONE || r->msg_urgency == n->urgency)); + && rule_field_matches_string(n->appname, r->appname) + && rule_field_matches_string(n->summary, r->summary) + && rule_field_matches_string(n->body, r->body) + && rule_field_matches_string(n->iconname, r->icon) + && rule_field_matches_string(n->category, r->category) + && rule_field_matches_string(n->stack_tag, r->stack_tag); } /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */