summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2014-09-04 22:04:58 +0200
committerDaniel Carl <danielcarl@gmx.de>2014-09-04 22:04:58 +0200
commite16ba67cc800d2679f8be4fb60a3a84744af28f0 (patch)
tree04f2d9809ce7d67e1030937c09a76c120f40476a /src
parent43f07397dd9b7569be8ffde671e233464da55744 (diff)
Allow multiple autocmd patterns (#100).
Diffstat (limited to 'src')
-rw-r--r--src/autocmd.c35
-rw-r--r--src/util.c2
2 files changed, 33 insertions, 4 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 1d69a7e..c12b471 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -55,6 +55,7 @@ static GSList *groups = NULL;
static guint get_event_bits(const char *name);
static AuGroup *get_group(const char *name);
static char *get_next_word(char **line);
+static gboolean wildmatch(char *patterns, const char *uri);
static AuGroup *new_group(const char *name);
static void free_group(AuGroup *group);
static AutoCmd *new_autocmd(const char *excmd, const char *pattern);
@@ -171,7 +172,7 @@ gboolean autocmd_add(char *name, gboolean delete)
}
/* skip if pattern does not match - we check the pattern against
* another pattern */
- if (!util_wildmatch(pattern, cmd->pattern)) {
+ if (!wildmatch(pattern, cmd->pattern)) {
continue;
}
/* remove the bits from the item */
@@ -226,7 +227,7 @@ gboolean autocmd_run(const char *group, AuEvent event, const char *uri)
}
/* check pattern only if uri was given */
/* skip if pattern does not match */
- if (uri && !util_wildmatch(cmd->pattern, uri)) {
+ if (uri && !wildmatch(cmd->pattern, uri)) {
continue;
}
/* run the command */
@@ -331,6 +332,36 @@ static char *get_next_word(char **line)
return word;
}
+/**
+ * Check if given uri matches one of the patterns given as comma separated
+ * string.
+ */
+static gboolean wildmatch(char *patterns, const char *uri)
+{
+ char *cur, *start;
+ gboolean matched;
+
+ for (cur = start = patterns; *cur; cur++) {
+ /* iterate through the patterns until the next ',' */
+ if (*cur == ',') {
+ *cur = '\0';
+ matched = util_wildmatch(start, uri);
+ *cur = ',';
+
+ /* return if the first match is found */
+ if (matched) {
+ return true;
+ }
+
+ /* set the start right after the ',' */
+ start = cur + 1;
+ }
+ }
+
+ /* still no match found - check the last pattern */
+ return util_wildmatch(start, uri);
+}
+
static AuGroup *new_group(const char *name)
{
AuGroup *new = g_slice_new(AuGroup);
diff --git a/src/util.c b/src/util.c
index 6a7d3b4..5c4a2ee 100644
--- a/src/util.c
+++ b/src/util.c
@@ -512,8 +512,6 @@ gboolean util_parse_expansion(const char **input, GString *str, int flags,
* * matches any sequence of characters
* ? matches any single character except of /
* \? matches a ?
- * . matches a .
- * ~ matches a ~
*/
gboolean util_wildmatch(const char *pattern, const char *string)
{