#include "wx/utils.h"
#include <wx/intl.h>
+// there are just too many of those...
+#ifdef _MSC_VER
+ #pragma warning(disable:4706) // assignment within conditional expression
+#endif // VC++
+
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#endif
#endif
#include <time.h>
+#ifndef __MWERKS__
#include <sys/types.h>
#include <sys/stat.h>
+#else
+#include <stat.h>
+#include <unistd.h>
+#endif
#ifdef __UNIX__
#include <unistd.h>
#endif
#ifdef __WINDOWS__
-#ifndef __GNUWIN32__
+#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ )
#include <direct.h>
#include <dos.h>
#endif
#ifdef __GNUWIN32__
#include <sys/unistd.h>
-// #include <sys/stat.h>
-
-#ifndef __MINGW32__
-#include <std.h>
-#endif
-
#define stricmp strcasecmp
#endif
#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
#define _MAXPATHLEN 500
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
+extern char *wxBuffer;
+#ifdef __WXMAC__
+extern char gwxMacFileName[] ;
+extern char gwxMacFileName2[] ;
+extern char gwxMacFileName3[] ;
#endif
-extern char *wxBuffer;
+#if !USE_SHARED_LIBRARIES
+IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
+#endif
void wxPathList::Add (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
bool
wxFileExists (const wxString& filename)
{
+#ifdef __GNUWIN32__ // (fix a B20 bug)
+ if (GetFileAttributes(filename) == 0xFFFFFFFF)
+ 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
struct stat stbuf;
if (filename && stat ((char *)(const char *)filename, &stbuf) == 0)
return TRUE;
return FALSE;
+#endif
}
/* Vadim's alternative implementation
// 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)
{
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);
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;
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);
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
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
{
#ifdef __VMS__
return FALSE;
+#elif defined( __WXMAC__ )
+ strcpy( gwxMacFileName , dir ) ;
+ wxUnix2MacFilename( gwxMacFileName ) ;
+ return (rmdir(WXSTRINGCAST gwxMacFileName) == 0);
#else
return (rmdir(WXSTRINGCAST dir) == 0);
#endif
#else
static short last_temp = 0; // cache last to speed things a bit
// At most 1000 temp files to a process! We use a ring count.
- char tmp[100];
+ char tmp[100]; // FIXME static buffer
for (short suffix = last_temp + 1; suffix != last_temp; ++suffix %= 1000)
{
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
char *wxFindNextFile(void)
{
#ifndef __VMS__
- static char buf[400];
+ static char buf[400]; // FIXME static buffer
/* MATTHEW: [2] Don't crash if we read too many times */
if (!wxDirStream)
{
if (!buf)
buf = new char[sz+1];
-#ifdef _MSC_VER
+#ifdef _MSC_VER
if (_getcwd(buf, sz) == NULL) {
#else
if (getcwd(buf, sz) == NULL) {
bool wxSetWorkingDirectory(const wxString& d)
{
-#ifdef __UNIX__
+#if defined( __UNIX__ ) || defined( __WXMAC__ )
return (chdir(d) == 0);
#elif defined(__WINDOWS__)
return FALSE;
};
+bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
-#ifdef HAVE_FNMATCH_H
+#if defined(HAVE_FNMATCH_H)
{
- // dot_special: what is it supposed to do?
- return fnmatch(pat.c_str(), text.c_str(), FNM_PERIOD) == 0;
+ if(dot_special)
+ return fnmatch(pat.c_str(), text.c_str(), FNM_PERIOD) == 0;
+ else
+ return fnmatch(pat.c_str(), text.c_str(), 0) == 0;
}
#else
-#pragma error Broken implementation of wxMatchWild() -- needs fixing!
+// #pragma error Broken implementation of wxMatchWild() -- needs fixing!
+
/*
* WARNING: this code is broken!
*/
-bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
{
wxString tmp1 = pat;
char *pattern = WXSTRINGCAST(tmp1);
pattern++;
return ((*str == '\0') && (*pattern == '\0'));
};
+
#endif
+#ifdef _MSC_VER
+ #pragma warning(default:4706) // assignment within conditional expression
+#endif // VC++