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.
26 compileregs(Rule
*rules
)
30 for(r
= rules
; r
; r
= r
->next
)
34 reg
= p_new(regex_t
, 1);
35 if(regcomp(reg
, r
->prop
, REG_EXTENDED
))
42 reg
= p_new(regex_t
, 1);
43 if(regcomp(reg
, r
->tags
, REG_EXTENDED
))
52 client_match_rule(Client
*c
, Rule
*r
)
57 XClassHint ch
= { 0, 0 };
60 XGetClassHint(c
->display
, c
->win
, &ch
);
62 len
= a_strlen(ch
.res_class
) + a_strlen(ch
.res_name
) + a_strlen(c
->name
);
63 prop
= p_new(char, len
+ 3);
66 snprintf(prop
, len
+ 3, "%s:%s:%s",
67 ch
.res_class
? ch
.res_class
: "", ch
.res_name
? ch
.res_name
: "", c
->name
);
69 ret
= (r
->propregex
&& !regexec(r
->propregex
, prop
, 1, &tmp
, 0));
82 is_tag_match_rules(Tag
*t
, Rule
*r
)
86 if(r
->tagregex
&& !regexec(r
->tagregex
, t
->name
, 1, &tmp
, 0))
92 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99