bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] exclude: handle wildcards with FNM_EXTMATCH


From: Paul Eggert
Subject: [PATCH] exclude: handle wildcards with FNM_EXTMATCH
Date: Sun, 29 Apr 2012 15:17:07 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120411 Thunderbird/11.0.1

I pushed this hopefully-obvious fix for problems I found
while looking into a bug with grep and --exclude.

---
 ChangeLog     |    8 ++++++++
 lib/exclude.c |   33 ++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b81a470..c8d3576 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-29  Paul Eggert  <address@hidden>
+
+       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-26  Stefano Lattarini  <address@hidden>
bootstrap: support Automake-NG in $buildreq
diff --git a/lib/exclude.c b/lib/exclude.c
index bc3e6e6..d135b09 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
--
1.7.6.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]