1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "filefn.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/filename.h"
37 // there are just too many of those...
39 #pragma warning(disable:4706) // assignment within conditional expression
46 #if !defined(__WATCOMC__)
47 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
55 #include <sys/types.h>
70 #include "wx/os2/private.h"
73 #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
78 #endif // native Win compiler
83 #include <sys/unistd.h>
87 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
88 // this (3.1 I believe) and how to test for it.
89 // If this works for Borland 4.0 as well, then no worries.
101 // No, Cygwin doesn't appear to have fnmatch.h after all.
102 #if defined(HAVE_FNMATCH_H)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 #define _MAXPATHLEN 500
116 extern wxChar
*wxBuffer
;
119 # include "MoreFiles.h"
120 # include "MoreFilesExtras.h"
121 # include "FullPath.h"
122 # include "FSpCompat.h"
125 IMPLEMENT_DYNAMIC_CLASS(wxPathList
, wxStringList
)
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
133 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
135 // VisualAge C++ V4.0 cannot have any external linkage const decs
136 // in headers included by more than one primary source
138 const off_t wxInvalidOffset
= (off_t
)-1;
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 // we need to translate Mac filenames before passing them to OS functions
146 #define OS_FILENAME(s) (s.fn_str())
148 // ============================================================================
150 // ============================================================================
152 void wxPathList::Add (const wxString
& path
)
154 wxStringList::Add (WXSTRINGCAST path
);
157 // Add paths e.g. from the PATH environment variable
158 void wxPathList::AddEnvList (const wxString
& envVariable
)
160 static const wxChar PATH_TOKS
[] =
162 wxT(" ;"); // Don't seperate with colon in DOS (used for drive)
167 wxChar
*val
= wxGetenv (WXSTRINGCAST envVariable
);
170 wxChar
*s
= copystring (val
);
171 wxChar
*save_ptr
, *token
= wxStrtok (s
, PATH_TOKS
, &save_ptr
);
175 Add (copystring (token
));
178 if ((token
= wxStrtok ((wxChar
*) NULL
, PATH_TOKS
, &save_ptr
)) != NULL
)
179 Add (wxString(token
));
183 // suppress warning about unused variable save_ptr when wxStrtok() is a
184 // macro which throws away its third argument
191 // Given a full filename (with path), ensure that that file can
192 // be accessed again USING FILENAME ONLY by adding the path
193 // to the list if not already there.
194 void wxPathList::EnsureFileAccessible (const wxString
& path
)
196 wxString
path_only(wxPathOnly(path
));
197 if ( !path_only
.IsEmpty() )
199 if ( !Member(path_only
) )
204 bool wxPathList::Member (const wxString
& path
)
206 for (wxNode
* node
= First (); node
!= NULL
; node
= node
->Next ())
208 wxString
path2((wxChar
*) node
->Data ());
210 #if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__)
212 path
.CompareTo (path2
, wxString::ignoreCase
) == 0
214 // Case sensitive File System
215 path
.CompareTo (path2
) == 0
223 wxString
wxPathList::FindValidPath (const wxString
& file
)
225 if (wxFileExists (wxExpandPath(wxFileFunctionsBuffer
, file
)))
226 return wxString(wxFileFunctionsBuffer
);
228 wxChar buf
[_MAXPATHLEN
];
229 wxStrcpy(buf
, wxFileFunctionsBuffer
);
231 wxChar
*filename
= (wxChar
*) NULL
; /* shut up buggy egcs warning */
232 filename
= IsAbsolutePath (buf
) ? wxFileNameFromPath (buf
) : (wxChar
*)buf
;
234 for (wxNode
* node
= First (); node
; node
= node
->Next ())
236 wxChar
*path
= (wxChar
*) node
->Data ();
237 wxStrcpy (wxFileFunctionsBuffer
, path
);
238 wxChar ch
= wxFileFunctionsBuffer
[wxStrlen(wxFileFunctionsBuffer
)-1];
239 if (ch
!= wxT('\\') && ch
!= wxT('/'))
240 wxStrcat (wxFileFunctionsBuffer
, wxT("/"));
241 wxStrcat (wxFileFunctionsBuffer
, filename
);
243 Unix2DosFilename (wxFileFunctionsBuffer
);
245 if (wxFileExists (wxFileFunctionsBuffer
))
247 return wxString(wxFileFunctionsBuffer
); // Found!
251 return wxString(wxT("")); // Not found
254 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
)
256 wxString f
= FindValidPath(file
);
257 if ( wxIsAbsolutePath(f
) )
261 wxGetWorkingDirectory(buf
.GetWriteBuf(_MAXPATHLEN
), _MAXPATHLEN
- 1);
263 if ( !wxEndsWithPathSeparator(buf
) )
265 buf
+= wxFILE_SEP_PATH
;
273 wxFileExists (const wxString
& filename
)
276 // GetFileAttributes can copy with network paths
277 DWORD ret
= GetFileAttributes(filename
);
278 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
279 return ((ret
!= 0xffffffff) && (isDir
== 0));
282 if ( !filename
.empty() && wxStat (OS_FILENAME(filename
), &stbuf
) == 0 )
290 wxIsAbsolutePath (const wxString
& filename
)
292 if (filename
!= wxT(""))
294 #if defined(__WXMAC__) && !defined(__DARWIN__)
295 // Classic or Carbon CodeWarrior like
296 // Carbon with Apple DevTools is Unix like
298 // This seems wrong to me, but there is no fix. since
299 // "MacOS:MyText.txt" is absolute whereas "MyDir:MyText.txt"
300 // is not. Or maybe ":MyDir:MyText.txt" has to be used? RR.
301 if (filename
.Find(':') != wxNOT_FOUND
&& filename
[0] != ':')
304 // Unix like or Windows
305 if (filename
[0] == wxT('/'))
309 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
314 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
322 * Strip off any extension (dot something) from end of file,
323 * IF one exists. Inserts zero into buffer.
327 void wxStripExtension(wxChar
*buffer
)
329 int len
= wxStrlen(buffer
);
333 if (buffer
[i
] == wxT('.'))
342 void wxStripExtension(wxString
& buffer
)
344 size_t len
= buffer
.Length();
348 if (buffer
.GetChar(i
) == wxT('.'))
350 buffer
= buffer
.Left(i
);
357 // Destructive removal of /./ and /../ stuff
358 wxChar
*wxRealPath (wxChar
*path
)
361 static const wxChar SEP
= wxT('\\');
362 Unix2DosFilename(path
);
364 static const wxChar SEP
= wxT('/');
366 if (path
[0] && path
[1]) {
367 /* MATTHEW: special case "/./x" */
369 if (path
[2] == SEP
&& path
[1] == wxT('.'))
377 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
380 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--);
381 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
382 && (q
- 1 <= path
|| q
[-1] != SEP
))
385 if (path
[0] == wxT('\0'))
391 /* Check that path[2] is NULL! */
392 else if (path
[1] == wxT(':') && !path
[2])
401 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
410 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
412 if (filename
== wxT(""))
413 return (wxChar
*) NULL
;
415 if (! IsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
))) {
416 wxChar buf
[_MAXPATHLEN
];
418 wxGetWorkingDirectory(buf
, WXSIZEOF(buf
));
419 wxChar ch
= buf
[wxStrlen(buf
) - 1];
421 if (ch
!= wxT('\\') && ch
!= wxT('/'))
422 wxStrcat(buf
, wxT("\\"));
425 wxStrcat(buf
, wxT("/"));
427 wxStrcat(buf
, wxFileFunctionsBuffer
);
428 return copystring( wxRealPath(buf
) );
430 return copystring( wxFileFunctionsBuffer
);
436 ~user/ => user's home dir
437 If the environment variable a = "foo" and b = "bar" then:
454 /* input name in name, pathname output to buf. */
456 wxChar
*wxExpandPath(wxChar
*buf
, const wxChar
*name
)
458 register wxChar
*d
, *s
, *nm
;
459 wxChar lnm
[_MAXPATHLEN
];
462 // Some compilers don't like this line.
463 // const wxChar trimchars[] = wxT("\n \t");
466 trimchars
[0] = wxT('\n');
467 trimchars
[1] = wxT(' ');
468 trimchars
[2] = wxT('\t');
472 const wxChar SEP
= wxT('\\');
474 const wxChar SEP
= wxT('/');
477 if (name
== NULL
|| *name
== wxT('\0'))
479 nm
= copystring(name
); // Make a scratch copy
482 /* Skip leading whitespace and cr */
483 while (wxStrchr((wxChar
*)trimchars
, *nm
) != NULL
)
485 /* And strip off trailing whitespace and cr */
486 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
487 while (q
-- && wxStrchr((wxChar
*)trimchars
, *s
) != NULL
)
495 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
498 /* Expand inline environment variables */
516 while ((*d
++ = *s
) != 0) {
518 if (*s
== wxT('\\')) {
519 if ((*(d
- 1) = *++s
)) {
528 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
530 if (*s
++ == wxT('$'))
533 register wxChar
*start
= d
;
534 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
535 register wxChar
*value
;
536 while ((*d
++ = *s
) != 0)
537 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
542 value
= wxGetenv(braces
? start
+ 1 : start
);
544 for ((d
= start
- 1); (*d
++ = *value
++) != 0;);
552 /* Expand ~ and ~user */
555 if (nm
[0] == wxT('~') && !q
)
558 if (nm
[1] == SEP
|| nm
[1] == 0)
560 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
561 if ((s
= WXSTRINGCAST
wxGetUserHome(wxT(""))) != NULL
) {
566 { /* ~user/filename */
567 register wxChar
*nnm
;
568 register wxChar
*home
;
569 for (s
= nm
; *s
&& *s
!= SEP
; s
++);
570 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
571 was_sep
= (*s
== SEP
);
572 nnm
= *s
? s
+ 1 : s
;
574 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
575 if ((home
= WXSTRINGCAST
wxGetUserHome(wxString(nm
+ 1))) == NULL
) {
576 if (was_sep
) /* replace only if it was there: */
587 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
589 while (wxT('\0') != (*d
++ = *s
++))
592 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
596 while ((*d
++ = *s
++) != 0);
597 delete[] nm_tmp
; // clean up alloc
598 /* Now clean up the buffer */
599 return wxRealPath(buf
);
602 /* Contract Paths to be build upon an environment variable
605 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
607 The call wxExpandPath can convert these back!
610 wxContractPath (const wxString
& filename
, const wxString
& envname
, const wxString
& user
)
612 static wxChar dest
[_MAXPATHLEN
];
614 if (filename
== wxT(""))
615 return (wxChar
*) NULL
;
617 wxStrcpy (dest
, WXSTRINGCAST filename
);
619 Unix2DosFilename(dest
);
622 // Handle environment
623 const wxChar
*val
= (const wxChar
*) NULL
;
624 wxChar
*tcp
= (wxChar
*) NULL
;
625 if (envname
!= WXSTRINGCAST NULL
&& (val
= wxGetenv (WXSTRINGCAST envname
)) != NULL
&&
626 (tcp
= wxStrstr (dest
, val
)) != NULL
)
628 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ wxStrlen (val
));
631 wxStrcpy (tcp
, WXSTRINGCAST envname
);
632 wxStrcat (tcp
, wxT("}"));
633 wxStrcat (tcp
, wxFileFunctionsBuffer
);
636 // Handle User's home (ignore root homes!)
638 if ((val
= wxGetUserHome (user
)) != NULL
&&
639 (len
= wxStrlen(val
)) > 2 &&
640 wxStrncmp(dest
, val
, len
) == 0)
642 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
644 wxStrcat(wxFileFunctionsBuffer
, (const wxChar
*) user
);
646 // strcat(wxFileFunctionsBuffer, "\\");
648 // strcat(wxFileFunctionsBuffer, "/");
650 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
651 wxStrcpy (dest
, wxFileFunctionsBuffer
);
657 // Return just the filename, not the path
659 wxChar
*wxFileNameFromPath (wxChar
*path
)
663 register wxChar
*tcp
;
665 tcp
= path
+ wxStrlen (path
);
666 while (--tcp
>= path
)
668 #if defined(__WXMAC__) && !defined(__DARWIN__)
669 // Classic or Carbon CodeWarrior like
670 // Carbon with Apple DevTools is Unix like
671 if (*tcp
== wxT(':'))
674 // Unix like or Windows
675 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
679 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
683 #if defined(__WXMSW__) || defined(__WXPM__)
685 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
692 wxString
wxFileNameFromPath (const wxString
& path1
)
694 if (path1
!= wxT(""))
696 wxChar
*path
= WXSTRINGCAST path1
;
697 register wxChar
*tcp
;
699 tcp
= path
+ wxStrlen (path
);
700 while (--tcp
>= path
)
702 #if defined(__WXMAC__) && !defined(__DARWIN__)
703 // Classic or Carbon CodeWarrior like
704 // Carbon with Apple DevTools is Unix like
705 if (*tcp
== wxT(':') )
706 return wxString(tcp
+ 1);
708 // Unix like or Windows
709 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
710 return wxString(tcp
+ 1);
713 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
714 return wxString(tcp
+ 1);
717 #if defined(__WXMSW__) || defined(__WXPM__)
719 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
720 return wxString(path
+ 2);
723 // Yes, this should return the path, not an empty string, otherwise
724 // we get "thing.txt" -> "".
728 // Return just the directory, or NULL if no directory
730 wxPathOnly (wxChar
*path
)
734 static wxChar buf
[_MAXPATHLEN
];
737 wxStrcpy (buf
, path
);
739 int l
= wxStrlen(path
);
742 // Search backward for a backward or forward slash
745 #if defined(__WXMAC__) && !defined(__DARWIN__)
746 // Classic or Carbon CodeWarrior like
747 // Carbon with Apple DevTools is Unix like
748 if (path
[i
] == wxT(':') )
754 // Unix like or Windows
755 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
762 if (path
[i
] == wxT(']'))
771 #if defined(__WXMSW__) || defined(__WXPM__)
772 // Try Drive specifier
773 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
775 // A:junk --> A:. (since A:.\junk Not A:\junk)
782 return (wxChar
*) NULL
;
785 // Return just the directory, or NULL if no directory
786 wxString
wxPathOnly (const wxString
& path
)
790 wxChar buf
[_MAXPATHLEN
];
793 wxStrcpy (buf
, WXSTRINGCAST path
);
795 int l
= path
.Length();
798 // Search backward for a backward or forward slash
801 #if defined(__WXMAC__) && !defined(__DARWIN__)
802 // Classic or Carbon CodeWarrior like
803 // Carbon with Apple DevTools is Unix like
804 if (path
[i
] == wxT(':') )
807 return wxString(buf
);
810 // Unix like or Windows
811 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
814 return wxString(buf
);
818 if (path
[i
] == wxT(']'))
821 return wxString(buf
);
827 #if defined(__WXMSW__) || defined(__WXPM__)
828 // Try Drive specifier
829 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
831 // A:junk --> A:. (since A:.\junk Not A:\junk)
834 return wxString(buf
);
838 return wxString(wxT(""));
841 // Utility for converting delimiters in DOS filenames to UNIX style
842 // and back again - or we get nasty problems with delimiters.
843 // Also, convert to lower case, since case is significant in UNIX.
845 #if defined(__WXMAC__)
846 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
850 char thePath
[FILENAME_MAX
];
852 // convert the FSSpec to an FSRef
853 (void) FSpMakeFSRef( spec
, &theRef
);
854 // get the POSIX path associated with the FSRef
855 (void) FSRefMakePath( &theRef
, (UInt8
*)thePath
, sizeof(thePath
) );
857 // create path string for return value
858 wxString
result( thePath
) ;
863 // get length of path and allocate handle
864 FSpGetFullPath( spec
, &length
, &myPath
) ;
865 ::SetHandleSize( myPath
, length
+ 1 ) ;
867 (*myPath
)[length
] = 0 ;
868 if ((length
> 0) && ((*myPath
)[length
-1] == ':'))
869 (*myPath
)[length
-1] = 0 ;
871 // create path string for return value
872 wxString
result( (char*) *myPath
) ;
874 // free allocated handle
875 ::HUnlock( myPath
) ;
876 ::DisposeHandle( myPath
) ;
882 void wxMacFilename2FSSpec( const char *path
, FSSpec
*spec
)
887 // get the FSRef associated with the POSIX path
888 (void) FSPathMakeRef((const UInt8
*) path
, &theRef
, NULL
);
889 // convert the FSRef to an FSSpec
890 (void) FSGetCatalogInfo(&theRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
892 FSpLocationFromFullPath( strlen(path
) , path
, spec
) ;
897 // Mac file names are POSIX (Unix style) under Darwin
898 // therefore the conversion functions below are not needed
900 static char sMacFileNameConversion
[ 1000 ] ;
902 wxString
wxMac2UnixFilename (const char *str
)
904 char *s
= sMacFileNameConversion
;
908 memmove( s
+1 , s
,strlen( s
) + 1) ;
919 *s
= wxTolower(*s
); // Case INDEPENDENT
923 return wxString(sMacFileNameConversion
) ;
926 wxString
wxUnix2MacFilename (const char *str
)
928 char *s
= sMacFileNameConversion
;
934 // relative path , since it goes on with slash which is translated to a :
935 memmove( s
, s
+1 ,strlen( s
) ) ;
937 else if ( *s
== '/' )
939 // absolute path -> on mac just start with the drive name
940 memmove( s
, s
+1 ,strlen( s
) ) ;
944 wxASSERT_MSG( 1 , "unkown path beginning" ) ;
948 if (*s
== '/' || *s
== '\\')
950 // convert any back-directory situations
951 if ( *(s
+1) == '.' && *(s
+2) == '.' && ( (*(s
+3) == '/' || *(s
+3) == '\\') ) )
954 memmove( s
+1 , s
+3 ,strlen( s
+3 ) + 1 ) ;
962 return wxString (sMacFileNameConversion
) ;
965 wxString
wxMacFSSpec2UnixFilename( const FSSpec
*spec
)
967 return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec
) ) ;
970 void wxUnixFilename2FSSpec( const char *path
, FSSpec
*spec
)
972 wxString var
= wxUnix2MacFilename( path
) ;
973 wxMacFilename2FSSpec( var
, spec
) ;
975 #endif // ! __DARWIN__
980 wxDos2UnixFilename (char *s
)
989 *s
= wxTolower (*s
); // Case INDEPENDENT
996 #if defined(__WXMSW__) || defined(__WXPM__)
997 wxUnix2DosFilename (wxChar
*s
)
999 wxUnix2DosFilename (wxChar
*WXUNUSED(s
) )
1002 // Yes, I really mean this to happen under DOS only! JACS
1003 #if defined(__WXMSW__) || defined(__WXPM__)
1014 // Concatenate two files to form third
1016 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
1019 if ( !wxGetTempFileName("cat", outfile
) )
1022 FILE *fp1
= (FILE *) NULL
;
1023 FILE *fp2
= (FILE *) NULL
;
1024 FILE *fp3
= (FILE *) NULL
;
1025 // Open the inputs and outputs
1026 if ((fp1
= wxFopen (OS_FILENAME( file1
), wxT("rb"))) == NULL
||
1027 (fp2
= wxFopen (OS_FILENAME( file2
), wxT("rb"))) == NULL
||
1028 (fp3
= wxFopen (OS_FILENAME( outfile
), wxT("wb"))) == NULL
)
1040 while ((ch
= getc (fp1
)) != EOF
)
1041 (void) putc (ch
, fp3
);
1044 while ((ch
= getc (fp2
)) != EOF
)
1045 (void) putc (ch
, fp3
);
1049 bool result
= wxRenameFile(outfile
, file3
);
1055 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1057 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1058 // CopyFile() copies file attributes and modification time too, so use it
1059 // instead of our code if available
1061 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1062 return ::CopyFile(file1
, file2
, !overwrite
) != 0;
1063 #elif defined(__WXPM__)
1064 if (::DosCopy(file2
, file2
, overwrite
? DCPY_EXISTING
: 0) == 0)
1071 // get permissions of file1
1072 if ( wxStat(OS_FILENAME(file1
), &fbuf
) != 0 )
1074 // the file probably doesn't exist or we haven't the rights to read
1076 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1081 // open file1 for reading
1082 wxFile
fileIn(file1
, wxFile::read
);
1083 if ( !fileIn
.IsOpened() )
1086 // remove file2, if it exists. This is needed for creating
1087 // file2 with the correct permissions in the next step
1088 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1090 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1096 // reset the umask as we want to create the file with exactly the same
1097 // permissions as the original one
1098 mode_t oldUmask
= umask( 0 );
1101 // create file2 with the same permissions than file1 and open it for
1104 if ( !fileOut
.Create(file2
, overwrite
, fbuf
.st_mode
& 0777) )
1108 /// restore the old umask
1112 // copy contents of file1 to file2
1117 count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1118 if ( fileIn
.Error() )
1125 if ( fileOut
.Write(buf
, count
) < count
)
1129 // we can expect fileIn to be closed successfully, but we should ensure
1130 // that fileOut was closed as some write errors (disk full) might not be
1131 // detected before doing this
1132 if ( !fileIn
.Close() || !fileOut
.Close() )
1135 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1136 // no chmod in VA. Should be some permission API for HPFS386 partitions
1138 if ( chmod(OS_FILENAME(file2
), fbuf
.st_mode
) != 0 )
1140 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1144 #endif // OS/2 || Mac
1147 #endif // __WXMSW__ && __WIN32__
1151 wxRenameFile (const wxString
& file1
, const wxString
& file2
)
1153 // Normal system call
1154 if ( wxRename (file1
, file2
) == 0 )
1158 if (wxCopyFile(file1
, file2
)) {
1159 wxRemoveFile(file1
);
1166 bool wxRemoveFile(const wxString
& file
)
1168 #if defined(__VISUALC__) \
1169 || defined(__BORLANDC__) \
1170 || defined(__WATCOMC__) \
1171 || defined(__GNUWIN32__)
1172 int res
= wxRemove(file
);
1174 int res
= unlink(OS_FILENAME(file
));
1180 bool wxMkdir(const wxString
& dir
, int perm
)
1182 #if defined(__WXMAC__) && !defined(__UNIX__)
1183 return (mkdir( dir
, 0 ) == 0);
1185 const wxChar
*dirname
= dir
.c_str();
1187 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1188 // for the GNU compiler
1189 #if (!(defined(__WXMSW__) || defined(__WXPM__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) || defined(__WXMICROWIN__)
1190 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1191 #elif defined(__WXPM__)
1192 if (::DosCreateDir((PSZ
)dirname
, NULL
) != 0) // enhance for EAB's??
1193 #else // !MSW and !OS/2 VAC++
1195 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1198 wxLogSysError(_("Directory '%s' couldn't be created"), dirname
);
1207 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1210 return FALSE
; //to be changed since rmdir exists in VMS7.x
1211 #elif defined(__WXPM__)
1212 return (::DosDeleteDir((PSZ
)dir
.c_str()) == 0);
1216 return FALSE
; // What to do?
1218 return (wxRmDir(OS_FILENAME(dir
)) == 0);
1224 // does the path exists? (may have or not '/' or '\\' at the end)
1225 bool wxPathExists(const wxChar
*pszPathName
)
1227 wxString
strPath(pszPathName
);
1229 // Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
1230 // so remove all trailing backslashes from the path - but don't do this for
1231 // the pathes "d:\" (which are different from "d:") nor for just "\"
1232 while ( wxEndsWithPathSeparator(strPath
) )
1234 size_t len
= strPath
.length();
1235 if ( len
== 1 || (len
== 3 && strPath
[len
- 2] == _T(':')) )
1238 strPath
.Truncate(len
- 1);
1240 #endif // __WINDOWS__
1243 // Stat can't cope with network paths
1244 DWORD ret
= GetFileAttributes(strPath
.c_str());
1245 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
1246 return ((ret
!= 0xffffffff) && (isDir
!= 0));
1250 #ifndef __VISAGECPP__
1251 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1252 ((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1254 // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
1255 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1256 (st
.st_mode
== S_IFDIR
);
1262 // Get a temporary filename, opening and closing the file.
1263 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1265 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1269 ::GetTempFileName(0, WXSTRINGCAST prefix
, 0, tmp
);
1271 wxChar tmp
[MAX_PATH
];
1272 wxChar tmpPath
[MAX_PATH
];
1273 ::GetTempPath(MAX_PATH
, tmpPath
);
1274 ::GetTempFileName(tmpPath
, WXSTRINGCAST prefix
, 0, tmp
);
1276 if (buf
) wxStrcpy(buf
, tmp
);
1277 else buf
= copystring(tmp
);
1281 static short last_temp
= 0; // cache last to speed things a bit
1282 // At most 1000 temp files to a process! We use a ring count.
1283 wxChar tmp
[100]; // FIXME static buffer
1285 for (short suffix
= last_temp
+ 1; suffix
!= last_temp
; ++suffix
%= 1000)
1287 wxSprintf (tmp
, wxT("/tmp/%s%d.%03x"), WXSTRINGCAST prefix
, (int) getpid (), (int) suffix
);
1288 if (!wxFileExists( tmp
))
1290 // Touch the file to create it (reserve name)
1291 FILE *fd
= fopen (wxFNCONV(tmp
), "w");
1296 wxStrcpy( buf
, tmp
);
1298 buf
= copystring( tmp
);
1302 wxLogError( _("wxWindows: error finding temporary file name.\n") );
1303 if (buf
) buf
[0] = 0;
1304 return (wxChar
*) NULL
;
1308 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1311 if (wxGetTempFileName(prefix
, buf2
) != (wxChar
*) NULL
)
1320 // Get first file name matching given wild card.
1322 #if defined(__UNIX__)
1324 // Get first file name matching given wild card.
1325 // Flags are reserved for future use.
1327 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1328 static DIR *gs_dirStream
= (DIR *) NULL
;
1329 static wxString gs_strFileSpec
;
1330 static int gs_findFlags
= 0;
1333 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1337 wxChar
*specvms
= NULL
;
1340 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1342 closedir(gs_dirStream
); // edz 941103: better housekeping
1344 gs_findFlags
= flags
;
1346 gs_strFileSpec
= spec
;
1348 // Find path only so we can concatenate
1349 // found file onto path
1350 wxString
path(wxPathOnly(gs_strFileSpec
));
1352 // special case: path is really "/"
1353 if ( !path
&& gs_strFileSpec
[0u] == wxT('/') )
1356 wxStrcpy( specvms
, wxT( "[000000]" ) );
1357 gs_strFileSpec
= specvms
;
1358 wxString
path_vms(wxPathOnly(gs_strFileSpec
));
1364 // path is empty => Local directory
1368 wxStrcpy( specvms
, wxT( "[]" ) );
1369 gs_strFileSpec
= specvms
;
1370 wxString
path_vms1(wxPathOnly(gs_strFileSpec
));
1377 gs_dirStream
= opendir(path
.fn_str());
1378 if ( !gs_dirStream
)
1380 wxLogSysError(_("Can not enumerate files in directory '%s'"),
1385 result
= wxFindNextFile();
1387 #endif // !VMS6.x or earlier
1392 wxString
wxFindNextFile()
1396 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1397 wxCHECK_MSG( gs_dirStream
, result
, wxT("must call wxFindFirstFile first") );
1399 // Find path only so we can concatenate
1400 // found file onto path
1401 wxString
path(wxPathOnly(gs_strFileSpec
));
1402 wxString
name(wxFileNameFromPath(gs_strFileSpec
));
1404 /* MATTHEW: special case: path is really "/" */
1405 if ( !path
&& gs_strFileSpec
[0u] == wxT('/'))
1409 struct dirent
*nextDir
;
1410 for ( nextDir
= readdir(gs_dirStream
);
1412 nextDir
= readdir(gs_dirStream
) )
1414 if (wxMatchWild(name
, nextDir
->d_name
, FALSE
) && // RR: added FALSE to find hidden files
1415 strcmp(nextDir
->d_name
, ".") &&
1416 strcmp(nextDir
->d_name
, "..") )
1419 if ( !path
.IsEmpty() )
1422 if ( path
!= wxT('/') )
1426 result
+= nextDir
->d_name
;
1428 // Only return "." and ".." when they match
1430 if ( (strcmp(nextDir
->d_name
, ".") == 0) ||
1431 (strcmp(nextDir
->d_name
, "..") == 0))
1433 if ( (gs_findFlags
& wxDIR
) != 0 )
1439 isdir
= wxDirExists(result
);
1441 // and only return directories when flags & wxDIR
1442 if ( !gs_findFlags
||
1443 ((gs_findFlags
& wxDIR
) && isdir
) ||
1444 ((gs_findFlags
& wxFILE
) && !isdir
) )
1451 result
.Empty(); // not found
1453 closedir(gs_dirStream
);
1454 gs_dirStream
= (DIR *) NULL
;
1455 #endif // !VMS6.2 or earlier
1460 #elif defined(__WXMAC__)
1462 struct MacDirectoryIterator
1470 static int g_iter_flags
;
1472 static MacDirectoryIterator g_iter
;
1473 wxString g_iter_spec
;
1475 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1479 g_iter_spec
= spec
;
1480 g_iter_spec
.MakeUpper() ;
1481 g_iter_flags
= flags
; /* MATTHEW: [5] Remember flags */
1483 // Find path only so we can concatenate found file onto path
1484 wxString
path(wxPathOnly(spec
));
1487 wxMacFilename2FSSpec( path
, &fsspec
) ;
1488 g_iter
.m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
1489 g_iter
.m_CPB
.hFileInfo
.ioNamePtr
= g_iter
.m_name
;
1490 g_iter
.m_index
= 0 ;
1493 FSpGetDirectoryID( &fsspec
, &g_iter
.m_dirId
, &isDir
) ;
1495 return wxEmptyString
;
1497 return wxFindNextFile( ) ;
1500 wxString
wxFindNextFile()
1509 while ( err
== noErr
)
1512 g_iter
.m_CPB
.dirInfo
.ioFDirIndex
= g_iter
.m_index
;
1513 g_iter
.m_CPB
.dirInfo
.ioDrDirID
= g_iter
.m_dirId
; /* we need to do this every time */
1514 err
= PBGetCatInfoSync((CInfoPBPtr
)&g_iter
.m_CPB
);
1518 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (g_iter_flags
& wxDIR
) ) // we have a directory
1521 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(g_iter_flags
& wxFILE
) )
1529 return wxEmptyString
;
1533 FSMakeFSSpecCompat(g_iter
.m_CPB
.hFileInfo
.ioVRefNum
,
1538 wxString name
= wxMacFSSpec2MacFilename( &spec
) ;
1539 if ( g_iter_spec
.Right(4)==(":*.*") || g_iter_spec
.Right(2)==(":*") || name
.Upper().Matches(g_iter_spec
) )
1542 return wxEmptyString
;
1545 #elif defined(__WXMSW__)
1548 static HANDLE gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1549 static WIN32_FIND_DATA gs_findDataStruct
;
1552 static struct ffblk gs_findDataStruct
;
1554 static struct _find_t gs_findDataStruct
;
1558 static wxString gs_strFileSpec
;
1559 static int gs_findFlags
= 0;
1561 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1565 gs_strFileSpec
= spec
;
1566 gs_findFlags
= flags
; /* MATTHEW: [5] Remember flags */
1568 // Find path only so we can concatenate found file onto path
1569 wxString
path(wxPathOnly(gs_strFileSpec
));
1570 if ( !path
.IsEmpty() )
1571 result
<< path
<< wxT('\\');
1574 if ( gs_hFileStruct
!= INVALID_HANDLE_VALUE
)
1575 FindClose(gs_hFileStruct
);
1577 gs_hFileStruct
= ::FindFirstFile(WXSTRINGCAST spec
, &gs_findDataStruct
);
1579 if ( gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1586 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1588 if (isdir
&& !(flags
& wxDIR
))
1589 return wxFindNextFile();
1590 else if (!isdir
&& flags
&& !(flags
& wxFILE
))
1591 return wxFindNextFile();
1593 result
+= gs_findDataStruct
.cFileName
;
1597 int flag
= _A_NORMAL
;
1602 if (findfirst(WXSTRINGCAST spec
, &gs_findDataStruct
, flag
) == 0)
1604 if (_dos_findfirst(WXSTRINGCAST spec
, flag
, &gs_findDataStruct
) == 0)
1610 attrib
= gs_findDataStruct
.ff_attrib
;
1612 attrib
= gs_findDataStruct
.attrib
;
1615 if (attrib
& _A_SUBDIR
) {
1616 if (!(gs_findFlags
& wxDIR
))
1617 return wxFindNextFile();
1618 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1619 return wxFindNextFile();
1623 gs_findDataStruct
.ff_name
1625 gs_findDataStruct
.name
1635 wxString
wxFindNextFile()
1639 // Find path only so we can concatenate found file onto path
1640 wxString
path(wxPathOnly(gs_strFileSpec
));
1645 if (gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1648 bool success
= (FindNextFile(gs_hFileStruct
, &gs_findDataStruct
) != 0);
1651 FindClose(gs_hFileStruct
);
1652 gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1656 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1658 if (isdir
&& !(gs_findFlags
& wxDIR
))
1660 else if (!isdir
&& gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1663 if ( !path
.IsEmpty() )
1664 result
<< path
<< wxT('\\');
1665 result
<< gs_findDataStruct
.cFileName
;
1672 if (findnext(&gs_findDataStruct
) == 0)
1674 if (_dos_findnext(&gs_findDataStruct
) == 0)
1677 /* MATTHEW: [5] Check directory flag */
1681 attrib
= gs_findDataStruct
.ff_attrib
;
1683 attrib
= gs_findDataStruct
.attrib
;
1686 if (attrib
& _A_SUBDIR
) {
1687 if (!(gs_findFlags
& wxDIR
))
1689 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1695 gs_findDataStruct
.ff_name
1697 gs_findDataStruct
.name
1706 #elif defined(__WXPM__)
1708 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1713 // TODO: figure something out here for OS/2
1714 gs_strFileSpec = spec;
1715 gs_findFlags = flags;
1717 // Find path only so we can concatenate found file onto path
1718 wxString path(wxPathOnly(gs_strFileSpec));
1719 if ( !path.IsEmpty() )
1720 result << path << wxT('\\');
1722 int flag = _A_NORMAL;
1726 if (_dos_findfirst(WXSTRINGCAST spec, flag, &gs_findDataStruct) == 0)
1729 attrib = gs_findDataStruct.attrib;
1731 if (attrib & _A_SUBDIR) {
1732 if (!(gs_findFlags & wxDIR))
1733 return wxFindNextFile();
1734 } else if (gs_findFlags && !(gs_findFlags & wxFILE))
1735 return wxFindNextFile();
1737 result += gs_findDataStruct.name;
1743 wxString
wxFindNextFile()
1750 #endif // Unix/Windows/OS/2
1752 // Get current working directory.
1753 // If buf is NULL, allocates space using new, else
1755 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1758 buf
= new wxChar
[sz
+1];
1760 char *cbuf
= new char[sz
+1];
1762 if (_getcwd(cbuf
, sz
) == NULL
) {
1763 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1766 SFSaveDisk
= 0x214, CurDirStore
= 0x398
1770 FSMakeFSSpec( - *(short *) SFSaveDisk
, *(long *) CurDirStore
, NULL
, &cwdSpec
) ;
1771 wxString res
= wxMacFSSpec2UnixFilename( &cwdSpec
) ;
1772 strcpy( buf
, res
) ;
1775 if (getcwd(cbuf
, sz
) == NULL
) {
1780 if (_getcwd(buf
, sz
) == NULL
) {
1781 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1786 pb
.ioNamePtr
= (StringPtr
) &fileName
;
1788 pb
.ioRefNum
= LMGetCurApRefNum();
1790 error
= PBGetFCBInfoSync(&pb
);
1791 if ( error
== noErr
)
1793 cwdSpec
.vRefNum
= pb
.ioFCBVRefNum
;
1794 cwdSpec
.parID
= pb
.ioFCBParID
;
1795 cwdSpec
.name
[0] = 0 ;
1796 wxString res
= wxMacFSSpec2MacFilename( &cwdSpec
) ;
1798 strcpy( buf
, res
) ;
1799 buf
[res
.length()]=0 ;
1804 this version will not always give back the application directory on mac
1807 SFSaveDisk = 0x214, CurDirStore = 0x398
1811 FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ;
1812 wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ;
1813 strcpy( buf , res ) ;
1816 #elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
1818 rc
= ::DosQueryCurrentDir( 0 // current drive
1824 if (getcwd(buf
, sz
) == NULL
) {
1832 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1841 static const size_t maxPathLen
= 1024;
1844 wxGetWorkingDirectory(str
.GetWriteBuf(maxPathLen
), maxPathLen
);
1845 str
.UngetWriteBuf();
1850 bool wxSetWorkingDirectory(const wxString
& d
)
1852 #if defined( __UNIX__ ) || defined( __WXMAC__ )
1853 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1854 #elif defined(__WXPM__)
1855 return (::DosSetCurrentDir((PSZ
)d
.c_str()) == 0);
1856 #elif defined(__WINDOWS__)
1859 return (bool)(SetCurrentDirectory(d
) != 0);
1861 // Must change drive, too.
1862 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1865 wxChar firstChar
= d
[0];
1869 firstChar
= firstChar
- 32;
1871 // To a drive number
1872 unsigned int driveNo
= firstChar
- 64;
1875 unsigned int noDrives
;
1876 _dos_setdrive(driveNo
, &noDrives
);
1879 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1887 // Get the OS directory if appropriate (such as the Windows directory).
1888 // On non-Windows platform, probably just return the empty string.
1889 wxString
wxGetOSDirectory()
1891 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1893 GetWindowsDirectory(buf
, 256);
1894 return wxString(buf
);
1896 return wxEmptyString
;
1900 bool wxEndsWithPathSeparator(const wxChar
*pszFileName
)
1902 size_t len
= wxStrlen(pszFileName
);
1906 return wxIsPathSeparator(pszFileName
[len
- 1]);
1909 // find a file in a list of directories, returns false if not found
1910 bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
)
1912 // we assume that it's not empty
1913 wxCHECK_MSG( !wxIsEmpty(pszFile
), FALSE
,
1914 _T("empty file name in wxFindFileInPath"));
1916 // skip path separator in the beginning of the file name if present
1917 if ( wxIsPathSeparator(*pszFile
) )
1920 // copy the path (strtok will modify it)
1921 wxChar
*szPath
= new wxChar
[wxStrlen(pszPath
) + 1];
1922 wxStrcpy(szPath
, pszPath
);
1925 wxChar
*pc
, *save_ptr
;
1926 for ( pc
= wxStrtok(szPath
, wxPATH_SEP
, &save_ptr
);
1928 pc
= wxStrtok((wxChar
*) NULL
, wxPATH_SEP
, &save_ptr
) )
1930 // search for the file in this directory
1932 if ( !wxEndsWithPathSeparator(pc
) )
1933 strFile
+= wxFILE_SEP_PATH
;
1936 if ( FileExists(strFile
) ) {
1942 // suppress warning about unused variable save_ptr when wxStrtok() is a
1943 // macro which throws away its third argument
1948 return pc
!= NULL
; // if true => we breaked from the loop
1951 void WXDLLEXPORT
wxSplitPath(const wxChar
*pszFileName
,
1956 // it can be empty, but it shouldn't be NULL
1957 wxCHECK_RET( pszFileName
, wxT("NULL file name in wxSplitPath") );
1959 wxFileName::SplitPath(pszFileName
, pstrPath
, pstrName
, pstrExt
);
1962 time_t WXDLLEXPORT
wxFileModificationTime(const wxString
& filename
)
1966 wxStat(filename
.fn_str(), &buf
);
1967 return buf
.st_mtime
;
1971 //------------------------------------------------------------------------
1972 // wild character routines
1973 //------------------------------------------------------------------------
1975 bool wxIsWild( const wxString
& pattern
)
1977 wxString tmp
= pattern
;
1978 wxChar
*pat
= WXSTRINGCAST(tmp
);
1981 case wxT('?'): case wxT('*'): case wxT('['): case wxT('{'):
1991 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1993 #if defined(HAVE_FNMATCH_H)
1995 // this probably won't work well for multibyte chars in Unicode mode?
1997 return fnmatch(pat
.fn_str(), text
.fn_str(), FNM_PERIOD
) == 0;
1999 return fnmatch(pat
.fn_str(), text
.fn_str(), 0) == 0;
2003 // #pragma error Broken implementation of wxMatchWild() -- needs fixing!
2006 * WARNING: this code is broken!
2009 wxString tmp1
= pat
;
2010 wxChar
*pattern
= WXSTRINGCAST(tmp1
);
2011 wxString tmp2
= text
;
2012 wxChar
*str
= WXSTRINGCAST(tmp2
);
2015 bool done
= FALSE
, ret_code
, ok
;
2016 // Below is for vi fans
2017 const wxChar OB
= wxT('{'), CB
= wxT('}');
2019 // dot_special means '.' only matches '.'
2020 if (dot_special
&& *str
== wxT('.') && *pattern
!= *str
)
2023 while ((*pattern
!= wxT('\0')) && (!done
)
2024 && (((*str
==wxT('\0'))&&((*pattern
==OB
)||(*pattern
==wxT('*'))))||(*str
!=wxT('\0')))) {
2028 if (*pattern
!= wxT('\0'))
2034 while ((*str
!=wxT('\0'))
2035 && ((ret_code
=wxMatchWild(pattern
, str
++, FALSE
)) == 0))
2038 while (*str
!= wxT('\0'))
2040 while (*pattern
!= wxT('\0'))
2047 if ((*pattern
== wxT('\0')) || (*pattern
== wxT(']'))) {
2051 if (*pattern
== wxT('\\')) {
2053 if (*pattern
== wxT('\0')) {
2058 if (*(pattern
+ 1) == wxT('-')) {
2061 if (*pattern
== wxT(']')) {
2065 if (*pattern
== wxT('\\')) {
2067 if (*pattern
== wxT('\0')) {
2072 if ((*str
< c
) || (*str
> *pattern
)) {
2076 } else if (*pattern
!= *str
) {
2081 while ((*pattern
!= wxT(']')) && (*pattern
!= wxT('\0'))) {
2082 if ((*pattern
== wxT('\\')) && (*(pattern
+ 1) != wxT('\0')))
2086 if (*pattern
!= wxT('\0')) {
2096 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2099 while (ok
&& (*cp
!= wxT('\0')) && (*pattern
!= wxT('\0'))
2100 && (*pattern
!= wxT(',')) && (*pattern
!= CB
)) {
2101 if (*pattern
== wxT('\\'))
2103 ok
= (*pattern
++ == *cp
++);
2105 if (*pattern
== wxT('\0')) {
2111 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2112 if (*++pattern
== wxT('\\')) {
2113 if (*++pattern
== CB
)
2118 while (*pattern
!=CB
&& *pattern
!=wxT(',') && *pattern
!=wxT('\0')) {
2119 if (*++pattern
== wxT('\\')) {
2120 if (*++pattern
== CB
|| *pattern
== wxT(','))
2125 if (*pattern
!= wxT('\0'))
2130 if (*str
== *pattern
) {
2137 while (*pattern
== wxT('*'))
2139 return ((*str
== wxT('\0')) && (*pattern
== wxT('\0')));
2145 #pragma warning(default:4706) // assignment within conditional expression