More verbose warnings if doc tools not present
[awesome.git] / rules.c
blob5cd5305d1cd820033114b61045b903df33d1b7aa
1 /*
2 * rules.c - rules management
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "rules.h"
23 #include "xutil.h"
25 extern AwesomeConf globalconf;
27 regex_t *
28 rules_compile_regex(char *val)
30 regex_t *reg;
32 if(val)
34 reg = p_new(regex_t, 1);
35 if(regcomp(reg, val, REG_EXTENDED))
36 p_delete(&reg);
37 else
38 return reg;
41 return NULL;
44 static Bool
45 client_match_rule(Client *c, Rule *r)
47 char *prop, buf[512];
48 regmatch_t tmp;
49 ssize_t len;
50 XClassHint ch = { 0, 0 };
51 Bool ret = False;
53 if(r->prop_r)
55 /* first try to match on name */
56 XGetClassHint(globalconf.display, c->win, &ch);
58 len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
59 prop = p_new(char, len + 3);
61 /* rule matching */
62 snprintf(prop, len + 3, "%s:%s:%s",
63 ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
65 ret = !regexec(r->prop_r, prop, 1, &tmp, 0);
67 p_delete(&prop);
69 if(ch.res_class)
70 XFree(ch.res_class);
71 if(ch.res_name)
72 XFree(ch.res_name);
74 if(ret)
75 return True;
78 if(r->xprop
79 && r->xpropval_r
80 && xgettextprop(c->win,
81 XInternAtom(globalconf.display, r->xprop, False),
82 buf, ssizeof(buf)))
83 ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
85 return ret;
88 Bool
89 tag_match_rule(Tag *t, Rule *r)
91 regmatch_t tmp;
93 if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0))
94 return True;
96 return False;
99 Rule *
100 rule_matching_client(Client *c)
102 Rule *r;
103 for(r = globalconf.rules; r; r = r->next)
104 if(client_match_rule(c, r))
105 return r;
107 return NULL;
110 Fuzzy
111 rules_get_fuzzy_from_str(const char *str)
113 if(!a_strcmp(str, "true") || !a_strcmp(str, "yes"))
114 return Yes;
115 else if(!a_strcmp(str, "false") || !a_strcmp(str, "no"))
116 return No;
118 return Auto;
121 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80