Compose rule matching function more readable

This commit is contained in:
Benedikt Heine 2019-01-23 16:11:22 +01:00
parent fb29047679
commit 53ad430b48

View File

@ -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: */