diff options
Diffstat (limited to 'mdk-stage1/dietlibc/libshell/fnmatch.c')
-rw-r--r-- | mdk-stage1/dietlibc/libshell/fnmatch.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/mdk-stage1/dietlibc/libshell/fnmatch.c b/mdk-stage1/dietlibc/libshell/fnmatch.c index 4e7664510..ef43735f6 100644 --- a/mdk-stage1/dietlibc/libshell/fnmatch.c +++ b/mdk-stage1/dietlibc/libshell/fnmatch.c @@ -1,5 +1,6 @@ #include <ctype.h> #include <fnmatch.h> +#include <string.h> #define NOTFIRST 128 @@ -11,6 +12,7 @@ static int match(char c,char d,int flags) { } int fnmatch(const char *pattern, const char *string, int flags) { + /*printf("fnmatch(\"%s\",\"%s\")\n",pattern,string);*/ if (*string==0) { while (*pattern=='*') ++pattern; return (!!*pattern); @@ -18,31 +20,36 @@ int fnmatch(const char *pattern, const char *string, int flags) { if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) { /* don't match if FNM_PERIOD and this is the first char */ if ((flags&FNM_PERIOD) && (!(flags&NOTFIRST))) - return 1; + return FNM_NOMATCH; /* don't match if FNM_PERIOD and FNM_FILE_NAME and previous was '/' */ if ((flags&(FNM_FILE_NAME|FNM_PERIOD)) && string[-1]=='/') - return 1; + return FNM_NOMATCH; } flags|=NOTFIRST; switch (*pattern) { case '[': - ++pattern; - while (*pattern && *pattern!=']') { - if (flags&FNM_PATHNAME || *string!='/') { + { + int neg=0; + ++pattern; + if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH; + if (*pattern=='^') { neg=1; ++pattern; } + while (*pattern && *pattern!=']') { int res=0; if (pattern[1]=='-') { if (*string>=*pattern && *string<=pattern[2]) res=1; if (flags&FNM_CASEFOLD) { if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1; } - } else + pattern+=3; + } else { res=match(*pattern,*string,flags); - if (res) { + ++pattern; + } + if (res ^ neg) { while (*pattern && *pattern!=']') ++pattern; return fnmatch(pattern+1,string+1,flags); } } - ++pattern; } break; case '\\': @@ -55,12 +62,9 @@ int fnmatch(const char *pattern, const char *string, int flags) { } break; case '*': - if (!pattern[1] || fnmatch(pattern+1,string,flags)==0) - return 0; - else - if (*string!='/') - return fnmatch(pattern,string+1,flags); - break; + if ((*string=='/' && flags&FNM_PATHNAME) || fnmatch(pattern,string+1,flags)) + return fnmatch(pattern+1,string,flags); + return 0; case 0: if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR))) return 0; @@ -70,5 +74,5 @@ int fnmatch(const char *pattern, const char *string, int flags) { return fnmatch(pattern+1,string+1,flags); break; } - return 1; + return FNM_NOMATCH; } |