X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/53c6e7ccd2c012afe1819485260e9d34eba09538..cfad3750c3ecc821ffae8b9b3de852551270846d:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 109eeabbd4..e828319ae0 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -43,8 +43,13 @@ #endif #endif #include +#ifndef __MWERKS__ #include #include +#else +#include +#include +#endif #ifdef __UNIX__ #include @@ -52,14 +57,17 @@ #endif #ifdef __WINDOWS__ -#ifndef __GNUWIN32__ +#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) #include #include #endif #endif #ifdef __GNUWIN32__ +#ifndef __TWIN32__ #include +#endif + #define stricmp strcasecmp #endif @@ -69,8 +77,16 @@ #include #endif +#ifdef __SALFORDC__ +#include +#include +#endif + #include "wx/setup.h" -#ifdef HAVE_FNMATCH_H +#include "wx/log.h" + +// No, Cygwin doesn't appear to have fnmatch.h after all. +#if defined(HAVE_FNMATCH_H) #include "fnmatch.h" #endif @@ -81,6 +97,15 @@ #define _MAXPATHLEN 500 extern char *wxBuffer; +#ifdef __WXMAC__ +extern char gwxMacFileName[] ; +extern char gwxMacFileName2[] ; +extern char gwxMacFileName3[] ; +#endif + +#if !USE_SHARED_LIBRARIES +IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) +#endif void wxPathList::Add (const wxString& path) { @@ -136,7 +161,7 @@ bool wxPathList::Member (const wxString& path) { wxString path2((char *) node->Data ()); if ( -#if defined(__WINDOWS__) || defined(__VMS__) +#if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__) // Case INDEPENDENT path.CompareTo (path2, wxString::ignoreCase) == 0 #else @@ -157,7 +182,8 @@ wxString wxPathList::FindValidPath (const wxString& file) char buf[_MAXPATHLEN]; strcpy(buf, wxBuffer); - char *filename = IsAbsolutePath (buf) ? wxFileNameFromPath (buf) : (char *)buf; + char *filename = (char*) NULL; /* shut up buggy egcs warning */ + filename = IsAbsolutePath (buf) ? wxFileNameFromPath (buf) : (char *)buf; for (wxNode * node = First (); node; node = node->Next ()) { @@ -214,10 +240,22 @@ wxFileExists (const wxString& filename) return FALSE; else return TRUE; +#elif defined(__WXMAC__) + struct stat stbuf; + strcpy( gwxMacFileName , filename ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + if (gwxMacFileName && stat ((char *)(const char *)gwxMacFileName, &stbuf) == 0) + return TRUE; + return FALSE ; +#else + +#ifdef __SALFORDC__ + struct _stat stbuf; #else struct stat stbuf; +#endif - if (filename && stat ((char *)(const char *)filename, &stbuf) == 0) + if ((filename != "") && stat ((char *)(const char *)filename, &stbuf) == 0) return TRUE; return FALSE; #endif @@ -558,8 +596,8 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin strncmp(dest, val, len) == 0) { strcpy(wxBuffer, "~"); - if (user && *user) - strcat(wxBuffer, user); + if (user != "") + strcat(wxBuffer, (const char*) user); #ifdef __WXMSW__ // strcat(wxBuffer, "\\"); #else @@ -623,7 +661,9 @@ wxString wxFileNameFromPath (const wxString& path1) return wxString(path + 2); #endif } - return wxString(""); + // Yes, this should return the path, not an empty string, otherwise + // we get "thing.txt" -> "". + return path1; } // Return just the directory, or NULL if no directory @@ -727,6 +767,58 @@ wxString wxPathOnly (const wxString& path) // and back again - or we get nasty problems with delimiters. // Also, convert to lower case, since case is significant in UNIX. +#ifdef __WXMAC__ +void +wxMac2UnixFilename (char *s) +{ + if (s) + { + memmove( s+1 , s ,strlen( s ) + 1) ; + if ( *s == ':' ) + *s = '.' ; + else + *s = '/' ; + + while (*s) + { + if (*s == ':') + *s = '/'; + else + *s = wxToLower (*s); // Case INDEPENDENT + s++; + } + } +} + +void +wxUnix2MacFilename (char *s) +{ + if (s) + { + if ( *s == '.' ) + { + // relative path , since it goes on with slash which is translated to a : + memmove( s , s+1 ,strlen( s ) ) ; + } + else if ( *s == '/' ) + { + // absolute path -> on mac just start with the drive name + memmove( s , s+1 ,strlen( s ) ) ; + } + else + { + wxASSERT_MSG( 1 , "unkown path beginning" ) ; + } + while (*s) + { + if (*s == '/' || *s == '\\') + *s = ':'; + + s++ ; + } + } +} +#endif void wxDos2UnixFilename (char *s) { @@ -772,9 +864,22 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil FILE *fp2 = (FILE *) NULL; FILE *fp3 = (FILE *) NULL; // Open the inputs and outputs +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + strcpy( gwxMacFileName3 , outfile) ; + wxUnix2MacFilename( gwxMacFileName3 ) ; + + if ((fp1 = fopen (gwxMacFileName, "rb")) == NULL || + (fp2 = fopen (gwxMacFileName2, "rb")) == NULL || + (fp3 = fopen (gwxMacFileName3, "wb")) == NULL) +#else if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL || (fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL || (fp3 = fopen (outfile, "wb")) == NULL) +#endif { if (fp1) fclose (fp1); @@ -808,9 +913,20 @@ wxCopyFile (const wxString& file1, const wxString& file2) FILE *fd2; int ch; +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + + if ((fd1 = fopen (gwxMacFileName, "rb")) == NULL) + return FALSE; + if ((fd2 = fopen (gwxMacFileName2, "wb")) == NULL) +#else if ((fd1 = fopen (WXSTRINGCAST file1, "rb")) == NULL) return FALSE; if ((fd2 = fopen (WXSTRINGCAST file2, "wb")) == NULL) +#endif { fclose (fd1); return FALSE; @@ -827,9 +943,19 @@ wxCopyFile (const wxString& file1, const wxString& file2) bool wxRenameFile (const wxString& file1, const wxString& file2) { +#ifdef __WXMAC__ + strcpy( gwxMacFileName , file1 ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + strcpy( gwxMacFileName2 , file2) ; + wxUnix2MacFilename( gwxMacFileName2 ) ; + + if (0 == rename (gwxMacFileName, gwxMacFileName2)) + return TRUE; +#else // Normal system call if (0 == rename (WXSTRINGCAST file1, WXSTRINGCAST file2)) return TRUE; +#endif // Try to copy if (wxCopyFile(file1, file2)) { wxRemoveFile(file1); @@ -841,8 +967,12 @@ wxRenameFile (const wxString& file1, const wxString& file2) bool wxRemoveFile(const wxString& file) { -#if defined(_MSC_VER) || defined(__BORLANDC__) +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) int flag = remove(WXSTRINGCAST file); +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , file ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + int flag = unlink(gwxMacFileName); #else int flag = unlink(WXSTRINGCAST file); #endif @@ -855,6 +985,10 @@ bool wxMkdir(const wxString& dir) return FALSE; #elif defined(__VMS__) return FALSE; +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , dir ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + return (mkdir(gwxMacFileName , 0 ) == 0); #elif (defined(__GNUWIN32__) && !defined(__MINGW32__)) || !defined(__WXMSW__) return (mkdir (WXSTRINGCAST dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0); #else @@ -866,9 +1000,19 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #ifdef __VMS__ return FALSE; +#elif defined( __WXMAC__ ) + strcpy( gwxMacFileName , dir ) ; + wxUnix2MacFilename( gwxMacFileName ) ; + return (rmdir(WXSTRINGCAST gwxMacFileName) == 0); +#else + +#ifdef __SALFORDC__ + return FALSE; // What to do? #else return (rmdir(WXSTRINGCAST dir) == 0); #endif + +#endif } #if 0 @@ -926,8 +1070,13 @@ bool wxPathExists(const char *pszPathName) if ( wxEndsWithPathSeparator(pszPathName) && pszPathName[1] != '\0' ) strPath.Last() = '\0'; +#ifdef __SALFORDC__ + struct _stat st; +#else struct stat st; - return stat(strPath, &st) == 0 && (st.st_mode & S_IFDIR); +#endif + + return stat((char*) (const char*) strPath, &st) == 0 && (st.st_mode & S_IFDIR); } // Get a temporary filename, opening and closing the file. @@ -970,7 +1119,7 @@ char *wxGetTempFileName(const wxString& prefix, char *buf) return buf; } } - cerr << _("wxWindows: error finding temporary file name.\n"); + wxLogError( _("wxWindows: error finding temporary file name.\n") ); if (buf) buf[0] = 0; return (char *) NULL; #endif @@ -1254,7 +1403,7 @@ char *wxGetWorkingDirectory(char *buf, int sz) { if (!buf) buf = new char[sz+1]; -#ifdef _MSC_VER +#ifdef _MSC_VER if (_getcwd(buf, sz) == NULL) { #else if (getcwd(buf, sz) == NULL) { @@ -1267,7 +1416,7 @@ char *wxGetWorkingDirectory(char *buf, int sz) bool wxSetWorkingDirectory(const wxString& d) { -#ifdef __UNIX__ +#if defined( __UNIX__ ) || defined( __WXMAC__ ) return (chdir(d) == 0); #elif defined(__WINDOWS__) @@ -1400,7 +1549,8 @@ bool wxIsWild( const wxString& pattern ) }; bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) -#ifdef HAVE_FNMATCH_H + +#if defined(HAVE_FNMATCH_H) { if(dot_special) return fnmatch(pat.c_str(), text.c_str(), FNM_PERIOD) == 0; @@ -1409,7 +1559,8 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) } #else -#pragma error Broken implementation of wxMatchWild() -- needs fixing! +// #pragma error Broken implementation of wxMatchWild() -- needs fixing! + /* * WARNING: this code is broken! */