From: Paul Eggert Date: Sun, 29 Apr 2012 22:53:53 +0000 (-0700) Subject: exclude: handle wildcards with FNM_EXTMATCH X-Git-Tag: v0.1~723 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=c116f3004c8173c1df5fc0ead911567192e6625b;p=gnulib.git exclude: handle wildcards with FNM_EXTMATCH * lib/exclude.c (fnmatch_pattern_has_wildcards): Also treat '+(', '+@', '!(' as wildcards, if FNM_EXTMATCH. Make it clear in a comment that "has wildcards" really means "has or may have wildcards". Simplify by avoiding the need to call strcspn. --- diff --git a/ChangeLog b/ChangeLog index e1f07983e..9d5195f49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-04-29 Paul Eggert + + exclude: handle wildcards with FNM_EXTMATCH + * lib/exclude.c (fnmatch_pattern_has_wildcards): Also treat '+(', + '+@', '!(' as wildcards, if FNM_EXTMATCH. Make it clear in a + comment that "has wildcards" really means "has or may have + wildcards". Simplify by avoiding the need to call strcspn. + 2012-04-29 Bruno Haible gnulib-tool: Fix list of authors. diff --git a/lib/exclude.c b/lib/exclude.c index bc3e6e62f..d135b09df 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -110,28 +110,31 @@ struct exclude struct exclude_segment *head, *tail; }; -/* Return true if str has wildcard characters */ +/* Return true if STR has or may have wildcards, when matched with OPTIONS. + Return false if STR definitely does not have wildcards. */ bool fnmatch_pattern_has_wildcards (const char *str, int options) { - const char *cset = "\\?*[]"; - if (options & FNM_NOESCAPE) - cset++; - while (*str) + while (1) { - size_t n = strcspn (str, cset); - if (str[n] == 0) - break; - else if (str[n] == '\\') + switch (*str++) { - str += n + 1; - if (*str) - str++; + case '\\': + str += ! (options & FNM_NOESCAPE) && *str; + break; + + case '+': case '@': case '!': + if (options & FNM_EXTMATCH && *str == '(') + return true; + break; + + case '?': case '*': case '[': + return true; + + case '\0': + return false; } - else - return true; } - return false; } static void