- bool rc;
-
- switch (seg->type)
- {
- case exclude_pattern:
- rc = excluded_file_pattern_p (seg, f);
- break;
-
- case exclude_hash:
- if (!filename)
- filename = xmalloc (strlen (f) + 1);
- rc = excluded_file_name_p (seg, f, filename);
- break;
- }
- if (rc != excluded)
- {
- excluded = rc;
- break;
- }
+ if (seg->type == exclude_hash)
+ {
+ if (!filename)
+ filename = xmalloc (strlen (f) + 1);
+ if (file_name_matches (seg, f, filename))
+ break;
+ }
+ else
+ {
+ if (file_pattern_matches (seg, f))
+ break;
+ }
+
+ if (! seg->next)
+ {
+ /* If patterns are given but none match, the default is the
+ opposite of the last segment (i.e., the first in the
+ original option list). For example, in the command
+ 'grep -r --exclude="a*" --include="*b" pat dir', the
+ first option is --exclude so any file name matching
+ neither a* nor *b is included. */
+ invert = true;
+ break;
+ }