diff options
author | Daniel Carl <danielcarl@gmx.de> | 2014-09-04 22:04:58 +0200 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2014-09-04 22:04:58 +0200 |
commit | e16ba67cc800d2679f8be4fb60a3a84744af28f0 (patch) | |
tree | 04f2d9809ce7d67e1030937c09a76c120f40476a /src/autocmd.c | |
parent | 43f07397dd9b7569be8ffde671e233464da55744 (diff) |
Allow multiple autocmd patterns (#100).
Diffstat (limited to 'src/autocmd.c')
-rw-r--r-- | src/autocmd.c | 35 |
1 files changed, 33 insertions, 2 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); |