Hello, I propose to move part of excluded_file_name in the separate function. This will make it possible for an application to use fnmatch-like interface with and without wildcards. In particular, this is needed for GNU tar.
The patch is enclosed. Regards, Sergey Index: lib/exclude.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/exclude.c,v retrieving revision 1.27 diff -p -u -r1.27 exclude.c --- lib/exclude.c 2 Oct 2005 22:44:15 -0000 1.27 +++ lib/exclude.c 24 May 2006 07:37:54 -0000 @@ -129,6 +129,24 @@ fnmatch_no_wildcards (char const *patter } } +bool +exclude_fnmatch (char const *pattern, char const *f, int options) +{ + int (*matcher) (char const *, char const *, int) = + (options & EXCLUDE_WILDCARDS + ? fnmatch + : fnmatch_no_wildcards); + bool matched = ((*matcher) (pattern, f, options) == 0); + char const *p; + + if (! (options & EXCLUDE_ANCHORED)) + for (p = f; *p && ! matched; p++) + if (*p == '/' && p[1] != '/') + matched = ((*matcher) (pattern, p + 1, options) == 0); + + return matched; +} + /* Return true if EX excludes F. */ bool @@ -154,21 +172,7 @@ excluded_file_name (struct exclude const char const *pattern = exclude[i].pattern; int options = exclude[i].options; if (excluded == !! (options & EXCLUDE_INCLUDE)) - { - int (*matcher) (char const *, char const *, int) = - (options & EXCLUDE_WILDCARDS - ? fnmatch - : fnmatch_no_wildcards); - bool matched = ((*matcher) (pattern, f, options) == 0); - char const *p; - - if (! (options & EXCLUDE_ANCHORED)) - for (p = f; *p && ! matched; p++) - if (*p == '/' && p[1] != '/') - matched = ((*matcher) (pattern, p + 1, options) == 0); - - excluded ^= matched; - } + excluded ^= exclude_fnmatch (pattern, f, options); } return excluded; Index: lib/exclude.h =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/exclude.h,v retrieving revision 1.10 diff -p -u -r1.10 exclude.h --- lib/exclude.h 2 Jun 2005 20:41:05 -0000 1.10 +++ lib/exclude.h 24 May 2006 07:37:54 -0000 @@ -41,3 +41,4 @@ void add_exclude (struct exclude *, char int add_exclude_file (void (*) (struct exclude *, char const *, int), struct exclude *, char const *, int, char); bool excluded_file_name (struct exclude const *, char const *); +bool exclude_fnmatch (char const *pattern, char const *f, int options);