*
*/
struct regex {
- const char *pattern;
+ char *pattern;
pcre *regex;
pcre_extra *extra;
};
*/
bool match_matches_window(Match *match, i3Window *window);
+/**
+ * Frees the given match. It must not be used afterwards!
+ *
+ */
+void match_free(Match *match);
+
#endif
*/
struct regex *regex_new(const char *pattern);
+/**
+ * Frees the given regular expression. It must not be used afterwards!
+ *
+ */
+void regex_free(struct regex *regex);
+
/**
* Checks if the given regular expression matches the given input and returns
* true if it does. In either case, it logs the outcome using LOG(), so it will
SLIST_REMOVE(&modes, mode, Mode, modes);
}
-#if 0
struct Assignment *assign;
while (!TAILQ_EMPTY(&assignments)) {
assign = TAILQ_FIRST(&assignments);
- FREE(assign->windowclass_title);
+ if (assign->type == A_TO_WORKSPACE)
+ FREE(assign->dest.workspace);
+ else if (assign->type == A_TO_OUTPUT)
+ FREE(assign->dest.output);
+ else if (assign->type == A_COMMAND)
+ FREE(assign->dest.command);
+ match_free(&(assign->match));
TAILQ_REMOVE(&assignments, assign, assignments);
FREE(assign);
}
-#endif
/* Clear workspace names */
#if 0
return true;
}
+
+/*
+ * Frees the given match. It must not be used afterwards!
+ *
+ */
+void match_free(Match *match) {
+ /* First step: free the regex fields / patterns */
+ regex_free(match->title);
+ regex_free(match->application);
+ regex_free(match->class);
+ regex_free(match->instance);
+ regex_free(match->mark);
+
+ /* Second step: free the regex helper struct itself */
+ FREE(match->title);
+ FREE(match->application);
+ FREE(match->class);
+ FREE(match->instance);
+ FREE(match->mark);
+}
return re;
}
+/*
+ * Frees the given regular expression. It must not be used afterwards!
+ *
+ */
+void regex_free(struct regex *regex) {
+ if (!regex)
+ return;
+ FREE(regex->pattern);
+ FREE(regex->regex);
+ FREE(regex->extra);
+}
+
/*
* Checks if the given regular expression matches the given input and returns
* true if it does. In either case, it logs the outcome using LOG(), so it will