corrected Carbon to/from POSIX path conversions for Mac OS X

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12387 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Gilles Depeyrot
2001-11-12 20:32:23 +00:00
parent 3de71bc877
commit a1c34a786a
2 changed files with 80 additions and 62 deletions

View File

@@ -171,10 +171,13 @@ WXDLLEXPORT void wxUnix2DosFilename(wxChar *s);
#ifdef __WXMAC__
WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ;
# ifndef __DARWIN__
// Mac file names are POSIX (Unix style) under Darwin, so these are not needed
WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ;
WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ;
WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ;
WXDLLEXPORT wxString wxUnix2MacFilename( const char *s);
# endif
#endif
// Strip the extension, in situ

View File

@@ -845,36 +845,58 @@ wxString wxPathOnly (const wxString& path)
#if defined(__WXMAC__)
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) );
// create path string for return value
wxString result( thePath ) ;
#else
Handle myPath ;
short length ;
// get length of path and allocate handle
FSpGetFullPath( spec , &length , &myPath ) ;
::SetHandleSize( myPath , length + 1 ) ;
::HLock( myPath ) ;
(*myPath)[length] = 0 ;
if ( length > 0 && (*myPath)[length-1] ==':' )
if ((length > 0) && ((*myPath)[length-1] == ':'))
(*myPath)[length-1] = 0 ;
#ifdef __DARWIN__
wxString result( wxMac2UnixFilename((char*) *myPath) ) ;
#else
// create path string for return value
wxString result( (char*) *myPath ) ;
#endif
// free allocated handle
::HUnlock( myPath ) ;
::DisposeHandle( myPath ) ;
#endif
return result ;
}
void wxMacFilename2FSSpec( const char *path , FSSpec *spec )
{
#ifdef __DARWIN__
const char *s = wxUnix2MacFilename(path);
FSpLocationFromFullPath( strlen(s) , s , spec ) ;
FSRef theRef;
// get the FSRef associated with the POSIX path
(void) FSPathMakeRef((const UInt8 *) path, &theRef, NULL);
// convert the FSRef to an FSSpec
(void) FSGetCatalogInfo(&theRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
#else
FSpLocationFromFullPath( strlen(path) , path , spec ) ;
#endif
}
#ifndef __DARWIN__
// Mac file names are POSIX (Unix style) under Darwin
// therefore the conversion functions below are not needed
static char sMacFileNameConversion[ 1000 ] ;
wxString wxMac2UnixFilename (const char *str)
@@ -894,11 +916,11 @@ wxString wxMac2UnixFilename (const char *str)
if (*s == ':')
*s = '/';
else
*s = wxTolower (*s); // Case INDEPENDENT
*s = wxTolower(*s); // Case INDEPENDENT
s++;
}
}
return wxString (sMacFileNameConversion) ;
return wxString(sMacFileNameConversion) ;
}
wxString wxUnix2MacFilename (const char *str)
@@ -934,7 +956,6 @@ wxString wxUnix2MacFilename (const char *str)
else
*s = ':';
}
s++ ;
}
}
@@ -951,6 +972,7 @@ void wxUnixFilename2FSSpec( const char *path , FSSpec *spec )
wxString var = wxUnix2MacFilename( path ) ;
wxMacFilename2FSSpec( var , spec ) ;
}
#endif // ! __DARWIN__
#endif // __WXMAC__
@@ -1297,7 +1319,7 @@ bool wxGetTempFileName(const wxString& prefix, wxString& buf)
// Get first file name matching given wild card.
#if defined(__UNIX__) && !defined(__WXMAC__)
#if defined(__UNIX__)
// Get first file name matching given wild card.
// Flags are reserved for future use.
@@ -1460,16 +1482,9 @@ wxString wxFindFirstFile(const wxChar *spec, int flags)
// Find path only so we can concatenate found file onto path
wxString path(wxPathOnly(spec));
#ifdef __DARWIN__
// TODO:check whether is necessary/correct
if ( !path.IsEmpty() )
result << path << wxT('/');
#else
result = path ;
#endif
FSSpec fsspec ;
wxMacFilename2FSSpec( result , &fsspec ) ;
wxMacFilename2FSSpec( path , &fsspec ) ;
g_iter.m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ;
g_iter.m_CPB.hFileInfo.ioNamePtr = g_iter.m_name ;
g_iter.m_index = 0 ;