Commit e4f61b63 authored by Niclas Karlsson's avatar Niclas Karlsson Committed by Alexandre Julliard

Fixed pattern matching in PathMatchSpecA/W

parent dd93b71c
...@@ -422,77 +422,88 @@ BOOL WINAPI PathFileExistsA(LPSTR fn) { ...@@ -422,77 +422,88 @@ BOOL WINAPI PathFileExistsA(LPSTR fn) {
return TRUE; return TRUE;
} }
/************************************************************************* /*************************************************************************
* PathMatchSingleMask
*
* NOTES
* internal (used by PathMatchSpec)
*/
static BOOL PathMatchSingleMaskA(LPCSTR name, LPCSTR mask)
{
while (*name && *mask && *mask!=';') {
if (*mask=='*') {
do {
if (PathMatchSingleMaskA(name,mask+1)) return 1; /* try substrings */
} while (*name++);
return 0;
}
if (toupper(*mask)!=toupper(*name) && *mask!='?') return 0;
name++;
mask++;
}
if (!*name) {
while (*mask=='*') mask++;
if (!*mask || *mask==';') return 1;
}
return 0;
}
static BOOL PathMatchSingleMaskW(LPCWSTR name, LPCWSTR mask)
{
while (*name && *mask && *mask!=';') {
if (*mask=='*') {
do {
if (PathMatchSingleMaskW(name,mask+1)) return 1; /* try substrings */
} while (*name++);
return 0;
}
if (towupper(*mask)!=towupper(*name) && *mask!='?') return 0;
name++;
mask++;
}
if (!*name) {
while (*mask=='*') mask++;
if (!*mask || *mask==';') return 1;
}
return 0;
}
/*************************************************************************
* PathMatchSpec [SHELL32.46] * PathMatchSpec [SHELL32.46]
* *
* NOTES * NOTES
* used from COMDLG32 * used from COMDLG32
*/ */
BOOL WINAPI PathMatchSpecA(LPCSTR name, LPCSTR mask) BOOL WINAPI PathMatchSpecA(LPCSTR name, LPCSTR mask)
{ LPCSTR _name; {
TRACE("%s %s\n",name,mask);
TRACE("%s %s stub\n",name,mask); if (!lstrcmpA( mask, "*.*" )) return 1; /* we don't require a period */
_name = name; while (*mask) {
while (*_name && *mask) if (PathMatchSingleMaskA(name,mask)) return 1; /* helper function */
{ if (*mask ==';') while (*mask && *mask!=';') mask++;
{ mask++; if (*mask==';') {
_name = name; mask++;
} while (*mask==' ') mask++; /* masks may be separated by "; " */
else if (*mask == '*')
{ mask++;
while (*mask == '*') mask++; /* Skip consecutive '*' */
if (!*mask || *mask==';') return TRUE; /* '*' matches everything */
while (*_name && (toupper(*_name) != toupper(*mask))) _name++;
if (!*_name)
{ while ( *mask && *mask != ';') mask++;
_name = name;
}
}
else if ( (*mask == '?') || (toupper(*mask) == toupper(*_name)) )
{ mask++;
_name++;
}
else
{ while ( *mask && *mask != ';') mask++;
} }
} }
return (!*_name && (!*mask || *mask==';')); return 0;
} }
BOOL WINAPI PathMatchSpecW(LPCWSTR name, LPCWSTR mask) BOOL WINAPI PathMatchSpecW(LPCWSTR name, LPCWSTR mask)
{ WCHAR stemp[4]; {
LPCWSTR _name; WCHAR stemp[4];
TRACE("%s %s\n",debugstr_w(name),debugstr_w(mask));
TRACE("%s %s stub\n",debugstr_w(name),debugstr_w(mask));
lstrcpyAtoW(stemp,"*.*"); lstrcpyAtoW(stemp,"*.*");
if (!lstrcmpW( mask, stemp )) return 1; if (!lstrcmpW( mask, stemp )) return 1; /* we don't require a period */
_name = name; while (*mask) {
while (*_name && *mask) if (PathMatchSingleMaskW(name,mask)) return 1; /* helper function */
{ if (*mask ==';') while (*mask && *mask!=';') mask++;
{ mask++; if (*mask==';') {
_name = name; mask++;
} while (*mask==' ') mask++; /* masks may be separated by "; " */
else if (*mask == '*')
{ mask++;
while (*mask == '*') mask++; /* Skip consecutive '*' */
if (!*mask || *mask==';') return TRUE; /* '*' matches everything */
while (*_name && (towupper(*_name) != towupper(*mask))) _name++;
if (!*_name)
{ while ( *mask && *mask != ';') mask++;
_name = name;
}
}
else if ( (*mask == '?') || (towupper(*mask) == towupper(*_name)) )
{ mask++;
_name++;
}
else
{ while ( *mask && *mask != ';') mask++;
} }
} }
return (!*_name && (!*mask || *mask==';')); return 0;
} }
BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask) BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
{ if (VERSION_OsIsUnicode()) { if (VERSION_OsIsUnicode())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment