From 7c187f35225b9ed669d4fc052ba4a9f3c6dbd2d1 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Wed, 28 Sep 2005 20:02:11 +0000 Subject: [PATCH] Add wildmatch(fname, spec, path) function which matches the string fname against the filespec spec, not allowing * to match the path delimiter if path is TRUE. --- src/xpdev/dirwrap.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/xpdev/dirwrap.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index 273dab80e5..7394cfb37d 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -859,3 +859,44 @@ BOOL DLLCALL isfullpath(const char* filename) #endif ); } + +/****************************************************************************/ +/* Matches file name against filespec */ +/* Optionally not allowing * to match PATH_DELIM (for paths) */ +/****************************************************************************/ +BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path) +{ + char *specp; + char *fnamep; + + specp=(char *)spec; + fnamep=(char *)fname; + for(;;specp++, fnamep++) { + switch(*specp) { + case '?': + if(!(*fnamep)) + return(FALSE); + break; + case 0: + if(!*fnamep) + return(TRUE); + break; + case '*': + specp++; + for(;*fnamep!=*specp && *fnamep;fnamep++) { + if(path && IS_PATH_DELIM(*fnamep)) + return(FALSE); + } + default: + if(*specp != *fnamep) + return(FALSE); + } + if(!(*specp && *fnamep)) + break; + } + while(*specp=='*') + specp++; + if(*specp==*fnamep) + return(TRUE); + return(FALSE); +} diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index c2bcd23d8d..1677b0c553 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -230,6 +230,8 @@ DLLEXPORT int DLLCALL getfattr(const char* filename); DLLEXPORT ulong DLLCALL getfreediskspace(const char* path, ulong unit); DLLEXPORT ulong DLLCALL delfiles(char *inpath, char *spec); DLLEXPORT char* DLLCALL backslash(char* path); +DLLEXPORT BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path); + #if defined(__unix__) DLLEXPORT void DLLCALL _splitpath(const char *path, char *drive, char *dir, -- GitLab