#ifdef __WINDOWS__
#include <windows.h>
#include "wx/msw/mslu.h"
-
+
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
//
// note that it must be included after <windows.h>
// private globals
// ----------------------------------------------------------------------------
+// MT-FIXME: get rid of this horror and all code using it
static wxChar wxFileFunctionsBuffer[4*_MAXPATHLEN];
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
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);
}
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
wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
{
#ifdef __DARWIN__
- FSRef theRef;
- char thePath[FILENAME_MAX];
-
- // convert the FSSpec to an FSRef
- (void) FSpMakeFSRef( spec, &theRef );
- // get the POSIX path associated with the FSRef
- (void) FSRefMakePath( &theRef, (UInt8 *)thePath, sizeof(thePath) );
+ int i;
+ int j;
+ OSErr theErr;
+ OSStatus theStatus;
+ Boolean isDirectory = false;
+ Str255 theParentPath = "\p";
+ FSSpec theParentSpec;
+ FSRef theParentRef;
+ char theFileName[FILENAME_MAX];
+ char thePath[FILENAME_MAX];
+
+ strcpy(thePath, "");
+
+ // GD: Separate file name from path and make a FSRef to the parent
+ // directory. This is necessary since FSRefs cannot reference files
+ // that have not yet been created.
+ // Based on example code from Apple Technical Note TN2022
+ // http://developer.apple.com/technotes/tn/tn2022.html
+
+ // check whether we are converting a directory
+ isDirectory = ((spec->name)[spec->name[0]] == ':');
+ // count length of file name
+ for (i = spec->name[0] - (isDirectory ? 1 : 0); ((spec->name[i] != ':') && (i > 0)); i--);
+ // copy file name
+ // prepend path separator since it will later be appended to the path
+ theFileName[0] = wxFILE_SEP_PATH;
+ for (j = i + 1; j <= spec->name[0] - (isDirectory ? 1 : 0); j++) {
+ theFileName[j - i] = spec->name[j];
+ }
+ theFileName[j - i] = '\0';
+ // copy path if any
+ for (j = 1; j <= i; j++) {
+ theParentPath[++theParentPath[0]] = spec->name[j];
+ }
+ theErr = FSMakeFSSpec(spec->vRefNum, spec->parID, theParentPath, &theParentSpec);
+ if (theErr == noErr) {
+ // convert the FSSpec to an FSRef
+ theErr = FSpMakeFSRef(&theParentSpec, &theParentRef);
+ }
+ if (theErr == noErr) {
+ // get the POSIX path associated with the FSRef
+ theStatus = FSRefMakePath(&theParentRef,
+ (UInt8 *)thePath, sizeof(thePath));
+ }
+ if (theStatus == noErr) {
+ // append file name to path
+ // includes previously prepended path separator
+ strcat(thePath, theFileName);
+ }
// create path string for return value
wxString result( thePath ) ;
wxString wxFindFirstFile(const wxChar *spec, int flags)
{
- gs_dirPath = wxPathOnly(spec);
+ wxSplitPath(spec, &gs_dirPath, NULL, NULL);
if ( gs_dirPath.IsEmpty() )
gs_dirPath = wxT(".");
if ( gs_dirPath.Last() != wxFILE_SEP_PATH )
}
wxString result;
- gs_dir->GetFirst(&result, wxFileNameFromPath(spec), dirFlags);
+ gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags);
if ( result.IsEmpty() )
{
wxDELETE(gs_dir);
// for the compilers which have Unicode version of _getcwd(), call it
// directly, for the others call the ANSI version and do the translation
#if !wxUSE_UNICODE
- #define cbuf buf
+ #define cbuf buf
#else // wxUSE_UNICODE
- bool needsANSI = TRUE;
+ bool needsANSI = TRUE;
- #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
+ #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
wxCharBuffer c_buffer(sz);
- char *cbuf = (char*)(const char*)c_buffer;
- #endif
+ char *cbuf = (char*)(const char*)c_buffer;
+ #endif
#ifdef HAVE_WGETCWD
- #if wxUSE_UNICODE_MSLU
- if ( wxGetOsVersion() != wxWIN95 )
+ #if wxUSE_UNICODE_MSLU
+ if ( wxGetOsVersion() != wxWIN95 )
#else
char *cbuf = NULL; // never really used because needsANSI will always be FALSE
- #endif
- {
- ok = _wgetcwd(buf, sz) != NULL;
- needsANSI = FALSE;
- }
+ #endif
+ {
+ ok = _wgetcwd(buf, sz) != NULL;
+ needsANSI = FALSE;
+ }
#endif
- if ( needsANSI )
+ if ( needsANSI )
#endif // wxUSE_UNICODE
- {
+ {
#ifdef _MSC_VER
ok = _getcwd(cbuf, sz) != NULL;
#elif defined(__WXMAC__) && !defined(__DARWIN__)
#else // !Win32/VC++ !Mac !OS2
ok = getcwd(cbuf, sz) != NULL;
#endif // platform
- }
+
+ #if wxUSE_UNICODE
+ // finally convert the result to Unicode if needed
+ wxConvFile.MB2WC(buf, cbuf, sz);
+ #endif // wxUSE_UNICODE
+ }
if ( !ok )
{
wxString pathUnix = buf;
cygwin_conv_to_full_win32_path(pathUnix, buf);
#endif // __CYGWIN__
-
- // finally convert the result to Unicode if needed
-#if wxUSE_UNICODE
- wxConvFile.MB2WC(buf, cbuf, sz);
-#endif // wxUSE_UNICODE
}
return buf;
#if !wxUSE_UNICODE
- #undef cbuf
+ #undef cbuf
#endif
}
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)
else
return fnmatch(pat.fn_str(), text.fn_str(), 0) == 0;
}
-#else
+#else // !HAVE_FNMATCH
// #pragma error Broken implementation of wxMatchWild() -- needs fixing!
return ((*str == wxT('\0')) && (*pattern == wxT('\0')));
};
-#endif
+#endif // HAVE_FNMATCH/!HAVE_FNMATCH
#ifdef __VISUALC__
#pragma warning(default:4706) // assignment within conditional expression