* lib/exclude.c (FNM_EXTMATCH): Define if system does not.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Feb 2007 00:29:06 +0000 (00:29 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 15 Feb 2007 00:29:06 +0000 (00:29 +0000)
Verify that it doesn't overlap with our flags.
(fnmatch_no_wildcards): Don't use strcasecmp or strncasecmp, which
do not have the desired effect in multibyte locales; instead, use
mbscasecmp.
* modules/exclude (Depends-on): Depend on mbscasecmp, not strcase.
Add dependency on xalloc.  Depend on fnmatch, not fnmatch-gnu, since
we don't require GNU fnmatch ourselves (if our users require it, they
should do so explicitly).

ChangeLog
lib/exclude.c
modules/exclude

index 9222f8b..22233f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2007-02-14  Paul Eggert  <eggert@cs.ucla.edu>
 
+       * lib/exclude.c (FNM_EXTMATCH): Define if system does not.
+       Verify that it doesn't overlap with our flags.
+       (fnmatch_no_wildcards): Don't use strcasecmp or strncasecmp, which
+       do not have the desired effect in multibyte locales; instead, use
+       mbscasecmp.
+       * modules/exclude (Depends-on): Depend on mbscasecmp, not strcase.
+       Add dependency on xalloc.  Depend on fnmatch, not fnmatch-gnu, since
+       we don't require GNU fnmatch ourselves (if our users require it, they
+       should do so explicitly).
+
        Fix regex code so it doesn't rely on strcasecmp.
        * lib/regex_internal.h: Include <langinfo.h> only if _LIBC is defined.
        Otherwise, include gnulib's langinfo.h.
index 5b726ff..ed34d0f 100644 (file)
 #ifndef FNM_CASEFOLD
 # define FNM_CASEFOLD 0
 #endif
+#ifndef FNM_EXTMATCH
+# define FNM_EXTMATCH 0
+#endif
 #ifndef FNM_LEADING_DIR
 # define FNM_LEADING_DIR 0
 #endif
 
 verify (((EXCLUDE_ANCHORED | EXCLUDE_INCLUDE | EXCLUDE_WILDCARDS)
         & (FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD | FNM_LEADING_DIR
-           | FNM_CASEFOLD))
+           | FNM_CASEFOLD | FNM_EXTMATCH))
        == 0);
 
 /* An exclude pattern-options pair.  The options are fnmatch options
@@ -96,14 +99,12 @@ fnmatch_no_wildcards (char const *pattern, char const *f, int options)
 {
   if (! (options & FNM_LEADING_DIR))
     return ((options & FNM_CASEFOLD)
-           ? strcasecmp (pattern, f)
+           ? mbscasecmp (pattern, f)
            : strcmp (pattern, f));
-  else
+  else if (! (options & FNM_CASEFOLD))
     {
       size_t patlen = strlen (pattern);
-      int r = ((options & FNM_CASEFOLD)
-               ? strncasecmp (pattern, f, patlen)
-               : strncmp (pattern, f, patlen));
+      int r = strncmp (pattern, f, patlen);
       if (! r)
        {
          r = f[patlen];
@@ -112,6 +113,30 @@ fnmatch_no_wildcards (char const *pattern, char const *f, int options)
        }
       return r;
     }
+  else
+    {
+      /* Walk through a copy of F, seeing whether P matches any prefix
+        of F.
+
+        FIXME: This is an O(N**2) algorithm; it should be O(N).
+        Also, the copy should not be necessary.  However, fixing this
+        will probably involve a change to the mbs* API.  */
+
+      char *fcopy = xstrdup (f);
+      char *p;
+      int r;
+      for (p = fcopy; ; *p++ = '/')
+       {
+         p = strchr (p, '/');
+         if (p)
+           *p = '\0';
+         r = mbscasecmp (pattern, fcopy);
+         if (!p || r <= 0)
+           break;
+       }
+      free (fcopy);
+      return r;
+    }
 }
 
 bool
index 78efea5..3d5aaef 100644 (file)
@@ -7,11 +7,11 @@ lib/exclude.c
 m4/exclude.m4
 
 Depends-on:
-xalloc
-strcase
-fnmatch-gnu
+fnmatch
+mbscasecmp
 stdbool
 verify
+xalloc
 
 configure.ac:
 gl_EXCLUDE