tag.c
changeset 178 e848966a1ac6
parent 177 e890cee887d1
child 191 56fee1dc9d53
equal deleted inserted replaced
177:e890cee887d1 178:e848966a1ac6
    11 
    11 
    12 /* static */
    12 /* static */
    13 
    13 
    14 typedef struct {
    14 typedef struct {
    15 	const char *pattern;
    15 	const char *pattern;
    16 	Bool tags[TLast];
    16 	const unsigned int *tags;
    17 	Bool isfloat;
    17 	Bool isfloat;
    18 } Rule;
    18 } Rule;
    19 
    19 
    20 TAGS
    20 TAGS
    21 RULES
    21 RULES
   143 	int i;
   143 	int i;
   144 
   144 
   145 	if(!sel)
   145 	if(!sel)
   146 		return;
   146 		return;
   147 
   147 
   148 	for(i = 0; i < TLast; i++)
   148 	for(i = 0; i < ntags; i++)
   149 		sel->tags[i] = False;
   149 		sel->tags[i] = False;
   150 	appendtag(arg);
   150 	appendtag(arg);
   151 }
   151 }
   152 
   152 
   153 void
   153 void
   154 settags(Client *c)
   154 settags(Client *c)
   155 {
   155 {
   156 	char classinst[256];
   156 	char classinst[256];
   157 	static unsigned int len = sizeof(rule) / sizeof(rule[0]);
   157 	static unsigned int len = sizeof(rule) / sizeof(rule[0]);
   158 	unsigned int i, j;
   158 	unsigned int i, j, n;
   159 	regex_t regex;
   159 	regex_t regex;
   160 	regmatch_t tmp;
   160 	regmatch_t tmp;
   161 	Bool matched = False;
   161 	Bool matched = False;
   162 	XClassHint ch;
   162 	XClassHint ch;
   163 
   163 
   166 				ch.res_class ? ch.res_class : "",
   166 				ch.res_class ? ch.res_class : "",
   167 				ch.res_name ? ch.res_name : "");
   167 				ch.res_name ? ch.res_name : "");
   168 		for(i = 0; !matched && i < len; i++) {
   168 		for(i = 0; !matched && i < len; i++) {
   169 			if(!regcomp(&regex, rule[i].pattern, 0)) {
   169 			if(!regcomp(&regex, rule[i].pattern, 0)) {
   170 				if(!regexec(&regex, classinst, 1, &tmp, 0)) {
   170 				if(!regexec(&regex, classinst, 1, &tmp, 0)) {
   171 					for(j = 0; j < TLast; j++) {
   171 					n = rule[i].tags ?
   172 						if((c->tags[j] = rule[i].tags[j]))
   172 						sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0;
   173 							matched = True;
   173 					matched = n != 0;
   174 					}
   174 					for(j = 0; j < n; j++)
       
   175 						c->tags[rule[i].tags[j]] = True;
   175 					c->isfloat = rule[i].isfloat;
   176 					c->isfloat = rule[i].isfloat;
   176 				}
   177 				}
   177 				regfree(&regex);
   178 				regfree(&regex);
   178 			}
   179 			}
   179 		}
   180 		}
   202 }
   203 }
   203 
   204 
   204 void
   205 void
   205 viewnext(Arg *arg)
   206 viewnext(Arg *arg)
   206 {
   207 {
   207 	arg->i = (tsel < TLast-1) ? tsel+1 : 0;
   208 	arg->i = (tsel < ntags-1) ? tsel+1 : 0;
   208 	view(arg);
   209 	view(arg);
   209 }
   210 }
   210 
   211 
   211 void
   212 void
   212 viewprev(Arg *arg)
   213 viewprev(Arg *arg)
   213 {
   214 {
   214 	arg->i = (tsel > 0) ? tsel-1 : TLast-1;
   215 	arg->i = (tsel > 0) ? tsel-1 : ntags-1;
   215 	view(arg);
   216 	view(arg);
   216 }
   217 }