X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ba14d9861d043d53cc53ea70a2fab4146f7be9f3..217c78b80b34f31b4341d6257e28077255d6eb93:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 587a0582f5..a45a871c00 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -115,7 +115,7 @@ #ifdef __WINDOWS__ #include #include "wx/msw/mslu.h" - + // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() // // note that it must be included after @@ -156,6 +156,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) // private globals // ---------------------------------------------------------------------------- +// MT-FIXME: get rid of this horror and all code using it static wxChar wxFileFunctionsBuffer[4*_MAXPATHLEN]; #if defined(__VISAGECPP__) && __IBMCPP__ >= 400 @@ -669,11 +670,6 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin wxStrcpy(wxFileFunctionsBuffer, wxT("~")); if (user != wxT("")) wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user); -#ifdef __WXMSW__ -// strcat(wxFileFunctionsBuffer, "\\"); -#else -// strcat(wxFileFunctionsBuffer, "/"); -#endif wxStrcat(wxFileFunctionsBuffer, dest + len); wxStrcpy (dest, wxFileFunctionsBuffer); } @@ -681,75 +677,27 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin return dest; } -// Return just the filename, not the path -// (basename) +// Return just the filename, not the path (basename) wxChar *wxFileNameFromPath (wxChar *path) { - if (path) - { - register wxChar *tcp; + wxString p = path; + wxString n = wxFileNameFromPath(p); - tcp = path + wxStrlen (path); - while (--tcp >= path) - { -#if defined(__WXMAC__) && !defined(__DARWIN__) - // Classic or Carbon CodeWarrior like - // Carbon with Apple DevTools is Unix like - if (*tcp == wxT(':')) - return tcp + 1; -#else - // Unix like or Windows - if (*tcp == wxT('/') || *tcp == wxT('\\')) - return tcp + 1; -#endif -#ifdef __VMS__ - if (*tcp == wxT(':') || *tcp == wxT(']')) - return tcp + 1; -#endif - } /* while */ -#if defined(__WXMSW__) || defined(__WXPM__) - // MSDOS like - if (wxIsalpha (*path) && *(path + 1) == wxT(':')) - return path + 2; -#endif - } - return path; + return path + p.length() - n.length(); } -wxString wxFileNameFromPath (const wxString& path1) +wxString wxFileNameFromPath (const wxString& path) { - if (path1 != wxT("")) - { - wxChar *path = WXSTRINGCAST path1 ; - register wxChar *tcp; + wxString name, ext; + wxFileName::SplitPath(path, NULL, &name, &ext); - tcp = path + wxStrlen (path); - while (--tcp >= path) - { -#if defined(__WXMAC__) && !defined(__DARWIN__) - // Classic or Carbon CodeWarrior like - // Carbon with Apple DevTools is Unix like - if (*tcp == wxT(':') ) - return wxString(tcp + 1); -#else - // Unix like or Windows - if (*tcp == wxT('/') || *tcp == wxT('\\')) - return wxString(tcp + 1); -#endif -#ifdef __VMS__ - if (*tcp == wxT(':') || *tcp == wxT(']')) - return wxString(tcp + 1); -#endif - } /* while */ -#if defined(__WXMSW__) || defined(__WXPM__) - // MSDOS like - if (wxIsalpha (*path) && *(path + 1) == wxT(':')) - return wxString(path + 2); -#endif + wxString fullname = name; + if ( !ext.empty() ) + { + fullname << wxFILE_SEP_EXT << ext; } - // Yes, this should return the path, not an empty string, otherwise - // we get "thing.txt" -> "". - return path1; + + return fullname; } // Return just the directory, or NULL if no directory @@ -922,7 +870,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) // includes previously prepended path separator strcat(thePath, theFileName); } - + // create path string for return value wxString result( thePath ) ; #else @@ -1396,7 +1344,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) } wxString result; - gs_dir->GetFirst(&result, wxFileNameFromPath((wxChar) spec), dirFlags); + gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags); if ( result.IsEmpty() ) { wxDELETE(gs_dir); @@ -1698,7 +1646,7 @@ bool wxIsWild( const wxString& pattern ) bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) -#if defined(HAVE_FNMATCH_H) +#ifdef HAVE_FNMATCH { // this probably won't work well for multibyte chars in Unicode mode? if(dot_special) @@ -1706,7 +1654,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) else return fnmatch(pat.fn_str(), text.fn_str(), 0) == 0; } -#else +#else // !HAVE_FNMATCH // #pragma error Broken implementation of wxMatchWild() -- needs fixing! @@ -1847,7 +1795,7 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) return ((*str == wxT('\0')) && (*pattern == wxT('\0'))); }; -#endif +#endif // HAVE_FNMATCH/!HAVE_FNMATCH #ifdef __VISUALC__ #pragma warning(default:4706) // assignment within conditional expression