+
+//------------------------------------------------------------------------
+// wild character routines
+//------------------------------------------------------------------------
+
+bool wxIsWild( const wxString& pattern )
+{
+ wxString tmp = pattern;
+ wxChar *pat = WXSTRINGCAST(tmp);
+ while (*pat) {
+ switch (*pat++) {
+ case _T('?'): case _T('*'): case _T('['): case _T('{'):
+ return TRUE;
+ case _T('\\'):
+ if (!*pat++)
+ return FALSE;
+ }
+ }
+ return FALSE;
+};
+
+bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
+
+#if defined(HAVE_FNMATCH_H)
+{
+// this probably won't work well for multibyte chars in Unicode mode?
+ if(dot_special)
+ return fnmatch(pat.fn_str(), text.fn_str(), FNM_PERIOD) == 0;
+ else
+ return fnmatch(pat.fn_str(), text.fn_str(), 0) == 0;
+}
+#else
+
+// #pragma error Broken implementation of wxMatchWild() -- needs fixing!
+
+ /*
+ * WARNING: this code is broken!
+ */
+{
+ wxString tmp1 = pat;
+ wxChar *pattern = WXSTRINGCAST(tmp1);
+ wxString tmp2 = text;
+ wxChar *str = WXSTRINGCAST(tmp2);
+ wxChar c;
+ wxChar *cp;
+ bool done = FALSE, ret_code, ok;
+ // Below is for vi fans
+ const wxChar OB = _T('{'), CB = _T('}');
+
+ // dot_special means '.' only matches '.'
+ if (dot_special && *str == _T('.') && *pattern != *str)
+ return FALSE;
+
+ while ((*pattern != _T('\0')) && (!done)
+ && (((*str==_T('\0'))&&((*pattern==OB)||(*pattern==_T('*'))))||(*str!=_T('\0')))) {
+ switch (*pattern) {
+ case _T('\\'):
+ pattern++;
+ if (*pattern != _T('\0'))
+ pattern++;
+ break;
+ case _T('*'):
+ pattern++;
+ ret_code = FALSE;
+ while ((*str!=_T('\0'))
+ && (!(ret_code=wxMatchWild(pattern, str++, FALSE))))
+ /*loop*/;
+ if (ret_code) {
+ while (*str != _T('\0'))
+ str++;
+ while (*pattern != _T('\0'))
+ pattern++;
+ }
+ break;
+ case _T('['):
+ pattern++;
+ repeat:
+ if ((*pattern == _T('\0')) || (*pattern == _T(']'))) {
+ done = TRUE;
+ break;
+ }
+ if (*pattern == _T('\\')) {
+ pattern++;
+ if (*pattern == _T('\0')) {
+ done = TRUE;
+ break;
+ }
+ }
+ if (*(pattern + 1) == _T('-')) {
+ c = *pattern;
+ pattern += 2;
+ if (*pattern == _T(']')) {
+ done = TRUE;
+ break;
+ }
+ if (*pattern == _T('\\')) {
+ pattern++;
+ if (*pattern == _T('\0')) {
+ done = TRUE;
+ break;
+ }
+ }
+ if ((*str < c) || (*str > *pattern)) {
+ pattern++;
+ goto repeat;
+ }
+ } else if (*pattern != *str) {
+ pattern++;
+ goto repeat;
+ }
+ pattern++;
+ while ((*pattern != _T(']')) && (*pattern != _T('\0'))) {
+ if ((*pattern == _T('\\')) && (*(pattern + 1) != _T('\0')))
+ pattern++;
+ pattern++;
+ }
+ if (*pattern != _T('\0')) {
+ pattern++, str++;
+ }
+ break;
+ case _T('?'):
+ pattern++;
+ str++;
+ break;
+ case OB:
+ pattern++;
+ while ((*pattern != CB) && (*pattern != _T('\0'))) {
+ cp = str;
+ ok = TRUE;
+ while (ok && (*cp != _T('\0')) && (*pattern != _T('\0'))
+ && (*pattern != _T(',')) && (*pattern != CB)) {
+ if (*pattern == _T('\\'))
+ pattern++;
+ ok = (*pattern++ == *cp++);
+ }
+ if (*pattern == _T('\0')) {
+ ok = FALSE;
+ done = TRUE;
+ break;
+ } else if (ok) {
+ str = cp;
+ while ((*pattern != CB) && (*pattern != _T('\0'))) {
+ if (*++pattern == _T('\\')) {
+ if (*++pattern == CB)
+ pattern++;
+ }
+ }
+ } else {
+ while (*pattern!=CB && *pattern!=_T(',') && *pattern!=_T('\0')) {
+ if (*++pattern == _T('\\')) {
+ if (*++pattern == CB || *pattern == _T(','))
+ pattern++;
+ }
+ }
+ }
+ if (*pattern != _T('\0'))
+ pattern++;
+ }
+ break;
+ default:
+ if (*str == *pattern) {
+ str++, pattern++;
+ } else {
+ done = TRUE;
+ }
+ }
+ }
+ while (*pattern == _T('*'))
+ pattern++;
+ return ((*str == _T('\0')) && (*pattern == _T('\0')));
+};
+
+#endif
+
+#ifdef __VISUALC__
+ #pragma warning(default:4706) // assignment within conditional expression
+#endif // VC++