+#if defined(__WXMAC__)
+wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
+{
+#ifdef __DARWIN__
+ int i;
+ int j;
+ OSErr theErr;
+ OSStatus theStatus = noErr;
+ 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 , wxConvLocal) ;
+#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] == ':'))
+ (*myPath)[length-1] = 0 ;
+
+ // create path string for return value
+ wxString result( *myPath , wxConvLocal) ;
+
+ // free allocated handle
+ ::HUnlock( myPath ) ;
+ ::DisposeHandle( myPath ) ;
+#endif
+
+ return result ;
+}
+#ifndef __DARWIN__
+// Mac file names are POSIX (Unix style) under Darwin
+// therefore the conversion functions below are not needed
+
+static wxChar sMacFileNameConversion[ 1000 ] ;
+static char scMacFileNameConversion[ 1000 ] ;
+
+#endif
+void wxMacFilename2FSSpec( const char *path , FSSpec *spec )
+{
+ OSStatus err = noErr ;
+#ifdef __DARWIN__
+ FSRef theRef;
+
+ // get the FSRef associated with the POSIX path
+ err = FSPathMakeRef((const UInt8 *) path, &theRef, NULL);
+ // convert the FSRef to an FSSpec
+ err = FSGetCatalogInfo(&theRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
+#else
+ if ( strchr( path , ':' ) == NULL )
+ {
+ // try whether it is a volume / or a mounted volume
+ strncpy( scMacFileNameConversion , path , 1000 ) ;
+ scMacFileNameConversion[998] = 0 ;
+ strcat( scMacFileNameConversion , ":" ) ;
+ err = FSpLocationFromFullPath( strlen(scMacFileNameConversion) , scMacFileNameConversion , spec ) ;
+ }
+ else
+ {
+ err = FSpLocationFromFullPath( strlen(path) , path , spec ) ;
+ }
+#endif
+}
+
+#if wxUSE_UNICODE
+WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec )
+{
+ return wxMacFilename2FSSpec( wxConvFile.cWC2MB(path) , spec ) ;
+}
+#endif
+
+#ifndef __DARWIN__
+
+wxString wxMac2UnixFilename (const wxChar *str)
+{
+ wxChar *s = sMacFileNameConversion ;
+ wxStrcpy( s , str ) ;
+ if (s)
+ {
+ memmove( s+1 , s ,wxStrlen( s ) + 1 * sizeof(wxChar)) ;
+ if ( *s == ':' )
+ *s = '.' ;
+ else
+ *s = '/' ;
+
+ while (*s)
+ {
+ if (*s == ':')
+ *s = '/';
+ else
+ *s = wxTolower(*s); // Case INDEPENDENT
+ s++;
+ }
+ }
+ return wxString(sMacFileNameConversion) ;
+}
+
+wxString wxUnix2MacFilename (const wxChar *str)
+{
+ wxChar *s = sMacFileNameConversion ;
+ wxStrcpy( s , str ) ;
+ if (s)
+ {
+ if ( *s == '.' )
+ {
+ // relative path , since it goes on with slash which is translated to a :
+ memmove( s , s+1 ,wxStrlen( s ) * sizeof(wxChar)) ;
+ }
+ else if ( *s == '/' )
+ {
+ // absolute path -> on mac just start with the drive name
+ memmove( s , s+1 ,wxStrlen( s ) * sizeof(wxChar) ) ;
+ }
+ else
+ {
+ wxASSERT_MSG( 1 , wxT("unkown path beginning") ) ;
+ }
+ while (*s)
+ {
+ if (*s == '/' || *s == '\\')
+ {
+ // convert any back-directory situations
+ if ( *(s+1) == '.' && *(s+2) == '.' && ( (*(s+3) == '/' || *(s+3) == '\\') ) )
+ {
+ *s = ':';
+ memmove( s+1 , s+3 ,(wxStrlen( s+3 ) + 1)*sizeof(wxChar) ) ;
+ }
+ else
+ *s = ':';
+ }
+ s++ ;
+ }
+ }
+ return wxString(sMacFileNameConversion) ;
+}
+
+wxString wxMacFSSpec2UnixFilename( const FSSpec *spec )
+{
+ return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec) ) ;
+}
+
+void wxUnixFilename2FSSpec( const char *path , FSSpec *spec )
+{
+ wxString var = wxUnix2MacFilename( path ) ;
+ wxMacFilename2FSSpec( var , spec ) ;
+}
+#endif // ! __DARWIN__
+
+#endif // __WXMAC__
+
+void
+wxDos2UnixFilename (wxChar *s)