mirror of
https://github.com/0intro/wmii
synced 2025-01-06 02:22:01 +03:00
added rule.c, a starting point for a rule engine
This commit is contained in:
parent
34720c3c0e
commit
6da9bfce1e
@ -9,7 +9,7 @@ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext
|
||||
# Solaris
|
||||
# LDFLAGS += -lsocket
|
||||
|
||||
SRC = area.c bar.c fs.c frame.c wm.c kb.c client.c event.c mouse.c tag.c
|
||||
SRC = area.c bar.c fs.c frame.c wm.c kb.c client.c event.c mouse.c rule.c tag.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: wmiiwm
|
||||
|
99
cmd/wm/rule.c
Normal file
99
cmd/wm/rule.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "wm.h"
|
||||
|
||||
/*
|
||||
* basic rule matching language
|
||||
*
|
||||
* /pattern/ -> tag [tag ...]
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char pattern[256];
|
||||
char tags[256];
|
||||
} Rule;
|
||||
|
||||
enum {
|
||||
IGNORE,
|
||||
PATTERN,
|
||||
TAGS
|
||||
};
|
||||
|
||||
/* free the result */
|
||||
static Rule *
|
||||
parse(char *data, unsigned int *n)
|
||||
{
|
||||
Rule *rules;
|
||||
unsigned int i;
|
||||
int mode = IGNORE;
|
||||
char *last = nil, *p, *pattern, *tags;
|
||||
|
||||
if(!data || !strlen(data))
|
||||
return nil;
|
||||
|
||||
*n = 0;
|
||||
for(last = p = data; *p; p++)
|
||||
if(*p == '\n')
|
||||
*n++;
|
||||
|
||||
rules = cext_emallocz(sizeof(Rule) * (*n));
|
||||
|
||||
i = 0;
|
||||
for(p = data; *p; p++) {
|
||||
switch(mode) {
|
||||
case IGNORE:
|
||||
if(*p == '/') {
|
||||
mode = PATTERN;
|
||||
pattern = rules[i].pattern;
|
||||
}
|
||||
else if(*p == '>' && last && *last == '-') {
|
||||
mode = TAGS;
|
||||
tags = rules[i].tags;
|
||||
}
|
||||
break;
|
||||
case PATTERN:
|
||||
if(*p == '/') {
|
||||
mode = IGNORE;
|
||||
*pattern = 0;
|
||||
}
|
||||
else {
|
||||
*pattern = *p;
|
||||
pattern++;
|
||||
}
|
||||
break;
|
||||
case TAGS:
|
||||
if(*p == ' ' && !strlen(tags))
|
||||
break;
|
||||
else if(*p == '\n') {
|
||||
*tags = 0;
|
||||
mode = IGNORE;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
*tags = *p;
|
||||
tags++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
last = p;
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
char *
|
||||
match_tags(char *ruledef, Client *c)
|
||||
{
|
||||
unsigned int n;
|
||||
Rule *rules = parse(ruledef, &n);
|
||||
|
||||
|
||||
|
||||
free(rules);
|
||||
return nil;
|
||||
}
|
@ -285,6 +285,9 @@ void grab_mouse(Window w, unsigned long mod, unsigned int button);
|
||||
void ungrab_mouse(Window w, unsigned long mod, unsigned int button);
|
||||
char *warp_mouse(char *arg);
|
||||
|
||||
/* rule.c */
|
||||
char *match_tags(char *ruledef, Client *c);
|
||||
|
||||
/* tag.c */
|
||||
Tag *alloc_tag(char *name);
|
||||
char *destroy_tag(Tag *t);
|
||||
|
Loading…
Reference in New Issue
Block a user