| version 1.6, 1993/11/06 00:52:40 |
version 1.7, 1993/11/09 18:22:09 |
| Line 40 static char *rcsid = "$Id$"; |
|
| Line 40 static char *rcsid = "$Id$"; |
|
| #endif /* LIBC_SCCS and not lint */ |
#endif /* LIBC_SCCS and not lint */ |
| |
|
| /* |
/* |
| * Function fnmatch() as proposed in POSIX 1003.2 B.6 (D11.2). |
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. |
| * Compares a filename or pathname to a pattern. |
* Compares a filename or pathname to a pattern. |
| */ |
*/ |
| |
|
| Line 49 static char *rcsid = "$Id$"; |
|
| Line 49 static char *rcsid = "$Id$"; |
|
| |
|
| #define EOS '\0' |
#define EOS '\0' |
| |
|
| static const char *rangematch __P((const char *, int)); |
static const char *rangematch __P((const char *, int, int)); |
| |
|
| fnmatch(pattern, string, flags) |
fnmatch(pattern, string, flags) |
| register const char *pattern, *string; |
register const char *pattern, *string; |
| Line 99 fnmatch(pattern, string, flags) |
|
| Line 99 fnmatch(pattern, string, flags) |
|
| if ((test = *string++) == EOS || |
if ((test = *string++) == EOS || |
| test == '/' && flags & FNM_PATHNAME) |
test == '/' && flags & FNM_PATHNAME) |
| return (FNM_NOMATCH); |
return (FNM_NOMATCH); |
| if ((pattern = rangematch(pattern, test)) == NULL) |
if ((pattern = rangematch(pattern, test, flags)) == NULL) |
| return (FNM_NOMATCH); |
return (FNM_NOMATCH); |
| break; |
break; |
| case '\\': |
case '\\': |
| Line 108 fnmatch(pattern, string, flags) |
|
| Line 108 fnmatch(pattern, string, flags) |
|
| c = '\\'; |
c = '\\'; |
| --pattern; |
--pattern; |
| } |
} |
| if (c != *string++) |
|
| return (FNM_NOMATCH); |
|
| break; |
|
| } |
} |
| /* FALLTHROUGH */ |
/* FALLTHROUGH */ |
| default: |
default: |
| Line 122 fnmatch(pattern, string, flags) |
|
| Line 119 fnmatch(pattern, string, flags) |
|
| } |
} |
| |
|
| static const char * |
static const char * |
| rangematch(pattern, test) |
rangematch(pattern, test, flags) |
| register const char *pattern; |
register const char *pattern; |
| register int test; |
register int test; |
| |
int flags; |
| { |
{ |
| register char c, c2; |
register char c, c2; |
| int negate, ok; |
int negate, ok; |
| |
|
| if (negate = (*pattern == '!')) |
/* A bracket expression starting with an unquoted circumflex |
| ++pattern; |
* character produces unspecified results (IEEE 1003.2-1992, |
| |
* 3.13.2). I have chosen to treat it like '!', for |
| /* |
* consistancy with regular expression syntax. |
| * XXX |
|
| * TO DO: quoting |
|
| */ |
*/ |
| |
if (negate = (*pattern == '!' || *pattern == '^')) { |
| |
pattern++; |
| |
} |
| |
|
| for (ok = 0; (c = *pattern++) != ']';) { |
for (ok = 0; (c = *pattern++) != ']';) { |
| if (c == EOS) |
if (c == '\\' && !(flags & FNM_NOESCAPE)) { |
| return (NULL); /* Illegal pattern. */ |
c = *pattern++; |
| if (*pattern == '-' && (c2 = pattern[1]) != EOS && c2 != ']') { |
} |
| if (c <= test && test <= c2) |
if (c == EOS) { |
| ok = 1; |
return (NULL); |
| pattern += 2; |
|
| } |
} |
| else if (c == test) |
|
| |
if (*pattern == '-' |
| |
&& (c2 = *(pattern+1)) != EOS && c2 != ']') { |
| |
pattern += 2; |
| |
if (c2 == '\\' && !(flags & FNM_NOESCAPE)) { |
| |
c2 = *pattern++; |
| |
} |
| |
if (c2 == EOS) { |
| |
return (NULL); |
| |
} |
| |
|
| |
if (c <= test && test <= c2) { |
| |
ok = 1; |
| |
} |
| |
} else if (c == test) { |
| ok = 1; |
ok = 1; |
| |
} |
| } |
} |
| |
|
| return (ok == negate ? NULL : pattern); |
return (ok == negate ? NULL : pattern); |
| } |
} |