void match_copy(Match *dest, Match *src) {
memcpy(dest, src, sizeof(Match));
-#define STRDUP(field) do { \
+/* The DUPLICATE_REGEX macro creates a new regular expression from the
+ * ->pattern of the old one. It therefore does use a little more memory then
+ * with a refcounting system, but it’s easier this way. */
+#define DUPLICATE_REGEX(field) do { \
if (src->field != NULL) \
- dest->field = sstrdup(src->field); \
+ dest->field = regex_new(src->field->pattern); \
} while (0)
- STRDUP(title);
- STRDUP(mark);
- STRDUP(application);
- STRDUP(class);
- STRDUP(instance);
+ DUPLICATE_REGEX(title);
+ DUPLICATE_REGEX(mark);
+ DUPLICATE_REGEX(application);
+ DUPLICATE_REGEX(class);
+ DUPLICATE_REGEX(instance);
}
/*
bool match_matches_window(Match *match, i3Window *window) {
LOG("checking window %d (%s)\n", window->id, window->class_class);
- /* TODO: pcre, full matching, … */
if (match->class != NULL) {
- if (window->class_class != NULL && strcasecmp(match->class, window->class_class) == 0) {
+ if (window->class_class != NULL &&
+ regex_matches(match->class, window->class_class)) {
LOG("window class matches (%s)\n", window->class_class);
} else {
LOG("window class does not match\n");
}
if (match->instance != NULL) {
- if (window->class_instance != NULL && strcasecmp(match->instance, window->class_instance) == 0) {
+ if (window->class_instance != NULL &&
+ regex_matches(match->instance, window->class_instance)) {
LOG("window instance matches (%s)\n", window->class_instance);
} else {
LOG("window instance does not match\n");
}
}
- /* TODO: pcre match */
if (match->title != NULL) {
- if (window->name_json != NULL && strcasecmp(match->title, window->name_json) == 0) {
+ if (window->name_json != NULL &&
+ regex_matches(match->title, window->name_json)) {
LOG("title matches (%s)\n", window->name_json);
} else {
LOG("title does not match\n");