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"
72 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
73 #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
78 #endif // native Win compiler
80 #if defined(__DOS__) && defined(__WATCOMC__)
89 #include <sys/unistd.h>
93 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
94 // this (3.1 I believe) and how to test for it.
95 // If this works for Borland 4.0 as well, then no worries.
104 #include "wx/setup.h"
107 // No, Cygwin doesn't appear to have fnmatch.h after all.
108 #if defined(HAVE_FNMATCH_H)
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 #define _MAXPATHLEN 500
122 extern wxChar
*wxBuffer
;
125 # include "MoreFiles.h"
126 # include "MoreFilesExtras.h"
127 # include "FullPath.h"
128 # include "FSpCompat.h"
131 IMPLEMENT_DYNAMIC_CLASS(wxPathList
, wxStringList
)
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
139 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
141 // VisualAge C++ V4.0 cannot have any external linkage const decs
142 // in headers included by more than one primary source
144 const off_t wxInvalidOffset
= (off_t
)-1;
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 // we need to translate Mac filenames before passing them to OS functions
152 #define OS_FILENAME(s) (s.fn_str())
154 // ============================================================================
156 // ============================================================================
158 void wxPathList::Add (const wxString
& path
)
160 wxStringList::Add (WXSTRINGCAST path
);
163 // Add paths e.g. from the PATH environment variable
164 void wxPathList::AddEnvList (const wxString
& envVariable
)
166 static const wxChar PATH_TOKS
[] =
168 wxT(" ;"); // Don't seperate with colon in DOS (used for drive)
173 wxChar
*val
= wxGetenv (WXSTRINGCAST envVariable
);
176 wxChar
*s
= copystring (val
);
177 wxChar
*save_ptr
, *token
= wxStrtok (s
, PATH_TOKS
, &save_ptr
);
181 Add (copystring (token
));
184 if ((token
= wxStrtok ((wxChar
*) NULL
, PATH_TOKS
, &save_ptr
)) != NULL
)
185 Add (wxString(token
));
189 // suppress warning about unused variable save_ptr when wxStrtok() is a
190 // macro which throws away its third argument
197 // Given a full filename (with path), ensure that that file can
198 // be accessed again USING FILENAME ONLY by adding the path
199 // to the list if not already there.
200 void wxPathList::EnsureFileAccessible (const wxString
& path
)
202 wxString
path_only(wxPathOnly(path
));
203 if ( !path_only
.IsEmpty() )
205 if ( !Member(path_only
) )
210 bool wxPathList::Member (const wxString
& path
)
212 for (wxNode
* node
= First (); node
!= NULL
; node
= node
->Next ())
214 wxString
path2((wxChar
*) node
->Data ());
216 #if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__)
218 path
.CompareTo (path2
, wxString::ignoreCase
) == 0
220 // Case sensitive File System
221 path
.CompareTo (path2
) == 0
229 wxString
wxPathList::FindValidPath (const wxString
& file
)
231 if (wxFileExists (wxExpandPath(wxFileFunctionsBuffer
, file
)))
232 return wxString(wxFileFunctionsBuffer
);
234 wxChar buf
[_MAXPATHLEN
];
235 wxStrcpy(buf
, wxFileFunctionsBuffer
);
237 wxChar
*filename
= (wxChar
*) NULL
; /* shut up buggy egcs warning */
238 filename
= IsAbsolutePath (buf
) ? wxFileNameFromPath (buf
) : (wxChar
*)buf
;
240 for (wxNode
* node
= First (); node
; node
= node
->Next ())
242 wxChar
*path
= (wxChar
*) node
->Data ();
243 wxStrcpy (wxFileFunctionsBuffer
, path
);
244 wxChar ch
= wxFileFunctionsBuffer
[wxStrlen(wxFileFunctionsBuffer
)-1];
245 if (ch
!= wxT('\\') && ch
!= wxT('/'))
246 wxStrcat (wxFileFunctionsBuffer
, wxT("/"));
247 wxStrcat (wxFileFunctionsBuffer
, filename
);
249 Unix2DosFilename (wxFileFunctionsBuffer
);
251 if (wxFileExists (wxFileFunctionsBuffer
))
253 return wxString(wxFileFunctionsBuffer
); // Found!
257 return wxString(wxT("")); // Not found
260 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
)
262 wxString f
= FindValidPath(file
);
263 if ( wxIsAbsolutePath(f
) )
267 wxGetWorkingDirectory(buf
.GetWriteBuf(_MAXPATHLEN
), _MAXPATHLEN
- 1);
269 if ( !wxEndsWithPathSeparator(buf
) )
271 buf
+= wxFILE_SEP_PATH
;
279 wxFileExists (const wxString
& filename
)
281 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
282 // GetFileAttributes can copy with network paths
283 DWORD ret
= GetFileAttributes(filename
);
284 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
285 return ((ret
!= 0xffffffff) && (isDir
== 0));
288 if ( !filename
.empty() && wxStat (OS_FILENAME(filename
), &stbuf
) == 0 )
296 wxIsAbsolutePath (const wxString
& filename
)
298 if (filename
!= wxT(""))
300 #if defined(__WXMAC__) && !defined(__DARWIN__)
301 // Classic or Carbon CodeWarrior like
302 // Carbon with Apple DevTools is Unix like
304 // This seems wrong to me, but there is no fix. since
305 // "MacOS:MyText.txt" is absolute whereas "MyDir:MyText.txt"
306 // is not. Or maybe ":MyDir:MyText.txt" has to be used? RR.
307 if (filename
.Find(':') != wxNOT_FOUND
&& filename
[0] != ':')
310 // Unix like or Windows
311 if (filename
[0] == wxT('/'))
315 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
320 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
328 * Strip off any extension (dot something) from end of file,
329 * IF one exists. Inserts zero into buffer.
333 void wxStripExtension(wxChar
*buffer
)
335 int len
= wxStrlen(buffer
);
339 if (buffer
[i
] == wxT('.'))
348 void wxStripExtension(wxString
& buffer
)
350 size_t len
= buffer
.Length();
354 if (buffer
.GetChar(i
) == wxT('.'))
356 buffer
= buffer
.Left(i
);
363 // Destructive removal of /./ and /../ stuff
364 wxChar
*wxRealPath (wxChar
*path
)
367 static const wxChar SEP
= wxT('\\');
368 Unix2DosFilename(path
);
370 static const wxChar SEP
= wxT('/');
372 if (path
[0] && path
[1]) {
373 /* MATTHEW: special case "/./x" */
375 if (path
[2] == SEP
&& path
[1] == wxT('.'))
383 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
386 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--);
387 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
388 && (q
- 1 <= path
|| q
[-1] != SEP
))
391 if (path
[0] == wxT('\0'))
397 /* Check that path[2] is NULL! */
398 else if (path
[1] == wxT(':') && !path
[2])
407 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
416 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
418 if (filename
== wxT(""))
419 return (wxChar
*) NULL
;
421 if (! IsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
))) {
422 wxChar buf
[_MAXPATHLEN
];
424 wxGetWorkingDirectory(buf
, WXSIZEOF(buf
));
425 wxChar ch
= buf
[wxStrlen(buf
) - 1];
427 if (ch
!= wxT('\\') && ch
!= wxT('/'))
428 wxStrcat(buf
, wxT("\\"));
431 wxStrcat(buf
, wxT("/"));
433 wxStrcat(buf
, wxFileFunctionsBuffer
);
434 return copystring( wxRealPath(buf
) );
436 return copystring( wxFileFunctionsBuffer
);
442 ~user/ => user's home dir
443 If the environment variable a = "foo" and b = "bar" then:
460 /* input name in name, pathname output to buf. */
462 wxChar
*wxExpandPath(wxChar
*buf
, const wxChar
*name
)
464 register wxChar
*d
, *s
, *nm
;
465 wxChar lnm
[_MAXPATHLEN
];
468 // Some compilers don't like this line.
469 // const wxChar trimchars[] = wxT("\n \t");
472 trimchars
[0] = wxT('\n');
473 trimchars
[1] = wxT(' ');
474 trimchars
[2] = wxT('\t');
478 const wxChar SEP
= wxT('\\');
480 const wxChar SEP
= wxT('/');
483 if (name
== NULL
|| *name
== wxT('\0'))
485 nm
= copystring(name
); // Make a scratch copy
488 /* Skip leading whitespace and cr */
489 while (wxStrchr((wxChar
*)trimchars
, *nm
) != NULL
)
491 /* And strip off trailing whitespace and cr */
492 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
493 while (q
-- && wxStrchr((wxChar
*)trimchars
, *s
) != NULL
)
501 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
504 /* Expand inline environment variables */
522 while ((*d
++ = *s
) != 0) {
524 if (*s
== wxT('\\')) {
525 if ((*(d
- 1) = *++s
)) {
534 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
536 if (*s
++ == wxT('$'))
539 register wxChar
*start
= d
;
540 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
541 register wxChar
*value
;
542 while ((*d
++ = *s
) != 0)
543 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
548 value
= wxGetenv(braces
? start
+ 1 : start
);
550 for ((d
= start
- 1); (*d
++ = *value
++) != 0;);
558 /* Expand ~ and ~user */
561 if (nm
[0] == wxT('~') && !q
)
564 if (nm
[1] == SEP
|| nm
[1] == 0)
566 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
567 if ((s
= WXSTRINGCAST
wxGetUserHome(wxT(""))) != NULL
) {
572 { /* ~user/filename */
573 register wxChar
*nnm
;
574 register wxChar
*home
;
575 for (s
= nm
; *s
&& *s
!= SEP
; s
++);
576 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
577 was_sep
= (*s
== SEP
);
578 nnm
= *s
? s
+ 1 : s
;
580 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
581 if ((home
= WXSTRINGCAST
wxGetUserHome(wxString(nm
+ 1))) == NULL
) {
582 if (was_sep
) /* replace only if it was there: */
593 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
595 while (wxT('\0') != (*d
++ = *s
++))
598 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
602 while ((*d
++ = *s
++) != 0);
603 delete[] nm_tmp
; // clean up alloc
604 /* Now clean up the buffer */
605 return wxRealPath(buf
);
608 /* Contract Paths to be build upon an environment variable
611 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
613 The call wxExpandPath can convert these back!
616 wxContractPath (const wxString
& filename
, const wxString
& envname
, const wxString
& user
)
618 static wxChar dest
[_MAXPATHLEN
];
620 if (filename
== wxT(""))
621 return (wxChar
*) NULL
;
623 wxStrcpy (dest
, WXSTRINGCAST filename
);
625 Unix2DosFilename(dest
);
628 // Handle environment
629 const wxChar
*val
= (const wxChar
*) NULL
;
630 wxChar
*tcp
= (wxChar
*) NULL
;
631 if (envname
!= WXSTRINGCAST NULL
&& (val
= wxGetenv (WXSTRINGCAST envname
)) != NULL
&&
632 (tcp
= wxStrstr (dest
, val
)) != NULL
)
634 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ wxStrlen (val
));
637 wxStrcpy (tcp
, WXSTRINGCAST envname
);
638 wxStrcat (tcp
, wxT("}"));
639 wxStrcat (tcp
, wxFileFunctionsBuffer
);
642 // Handle User's home (ignore root homes!)
644 if ((val
= wxGetUserHome (user
)) != NULL
&&
645 (len
= wxStrlen(val
)) > 2 &&
646 wxStrncmp(dest
, val
, len
) == 0)
648 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
650 wxStrcat(wxFileFunctionsBuffer
, (const wxChar
*) user
);
652 // strcat(wxFileFunctionsBuffer, "\\");
654 // strcat(wxFileFunctionsBuffer, "/");
656 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
657 wxStrcpy (dest
, wxFileFunctionsBuffer
);
663 // Return just the filename, not the path
665 wxChar
*wxFileNameFromPath (wxChar
*path
)
669 register wxChar
*tcp
;
671 tcp
= path
+ wxStrlen (path
);
672 while (--tcp
>= path
)
674 #if defined(__WXMAC__) && !defined(__DARWIN__)
675 // Classic or Carbon CodeWarrior like
676 // Carbon with Apple DevTools is Unix like
677 if (*tcp
== wxT(':'))
680 // Unix like or Windows
681 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
685 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
689 #if defined(__WXMSW__) || defined(__WXPM__)
691 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
698 wxString
wxFileNameFromPath (const wxString
& path1
)
700 if (path1
!= wxT(""))
702 wxChar
*path
= WXSTRINGCAST path1
;
703 register wxChar
*tcp
;
705 tcp
= path
+ wxStrlen (path
);
706 while (--tcp
>= path
)
708 #if defined(__WXMAC__) && !defined(__DARWIN__)
709 // Classic or Carbon CodeWarrior like
710 // Carbon with Apple DevTools is Unix like
711 if (*tcp
== wxT(':') )
712 return wxString(tcp
+ 1);
714 // Unix like or Windows
715 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
716 return wxString(tcp
+ 1);
719 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
720 return wxString(tcp
+ 1);
723 #if defined(__WXMSW__) || defined(__WXPM__)
725 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
726 return wxString(path
+ 2);
729 // Yes, this should return the path, not an empty string, otherwise
730 // we get "thing.txt" -> "".
734 // Return just the directory, or NULL if no directory
736 wxPathOnly (wxChar
*path
)
740 static wxChar buf
[_MAXPATHLEN
];
743 wxStrcpy (buf
, path
);
745 int l
= wxStrlen(path
);
748 // Search backward for a backward or forward slash
751 #if defined(__WXMAC__) && !defined(__DARWIN__)
752 // Classic or Carbon CodeWarrior like
753 // Carbon with Apple DevTools is Unix like
754 if (path
[i
] == wxT(':') )
760 // Unix like or Windows
761 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
768 if (path
[i
] == wxT(']'))
777 #if defined(__WXMSW__) || defined(__WXPM__)
778 // Try Drive specifier
779 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
781 // A:junk --> A:. (since A:.\junk Not A:\junk)
788 return (wxChar
*) NULL
;
791 // Return just the directory, or NULL if no directory
792 wxString
wxPathOnly (const wxString
& path
)
796 wxChar buf
[_MAXPATHLEN
];
799 wxStrcpy (buf
, WXSTRINGCAST path
);
801 int l
= path
.Length();
804 // Search backward for a backward or forward slash
807 #if defined(__WXMAC__) && !defined(__DARWIN__)
808 // Classic or Carbon CodeWarrior like
809 // Carbon with Apple DevTools is Unix like
810 if (path
[i
] == wxT(':') )
813 return wxString(buf
);
816 // Unix like or Windows
817 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
820 return wxString(buf
);
824 if (path
[i
] == wxT(']'))
827 return wxString(buf
);
833 #if defined(__WXMSW__) || defined(__WXPM__)
834 // Try Drive specifier
835 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
837 // A:junk --> A:. (since A:.\junk Not A:\junk)
840 return wxString(buf
);
844 return wxString(wxT(""));
847 // Utility for converting delimiters in DOS filenames to UNIX style
848 // and back again - or we get nasty problems with delimiters.
849 // Also, convert to lower case, since case is significant in UNIX.
851 #if defined(__WXMAC__)
852 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
856 char thePath
[FILENAME_MAX
];
858 // convert the FSSpec to an FSRef
859 (void) FSpMakeFSRef( spec
, &theRef
);
860 // get the POSIX path associated with the FSRef
861 (void) FSRefMakePath( &theRef
, (UInt8
*)thePath
, sizeof(thePath
) );
863 // create path string for return value
864 wxString
result( thePath
) ;
869 // get length of path and allocate handle
870 FSpGetFullPath( spec
, &length
, &myPath
) ;
871 ::SetHandleSize( myPath
, length
+ 1 ) ;
873 (*myPath
)[length
] = 0 ;
874 if ((length
> 0) && ((*myPath
)[length
-1] == ':'))
875 (*myPath
)[length
-1] = 0 ;
877 // create path string for return value
878 wxString
result( (char*) *myPath
) ;
880 // free allocated handle
881 ::HUnlock( myPath
) ;
882 ::DisposeHandle( myPath
) ;
888 void wxMacFilename2FSSpec( const char *path
, FSSpec
*spec
)
893 // get the FSRef associated with the POSIX path
894 (void) FSPathMakeRef((const UInt8
*) path
, &theRef
, NULL
);
895 // convert the FSRef to an FSSpec
896 (void) FSGetCatalogInfo(&theRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
898 FSpLocationFromFullPath( strlen(path
) , path
, spec
) ;
903 // Mac file names are POSIX (Unix style) under Darwin
904 // therefore the conversion functions below are not needed
906 static char sMacFileNameConversion
[ 1000 ] ;
908 wxString
wxMac2UnixFilename (const char *str
)
910 char *s
= sMacFileNameConversion
;
914 memmove( s
+1 , s
,strlen( s
) + 1) ;
925 *s
= wxTolower(*s
); // Case INDEPENDENT
929 return wxString(sMacFileNameConversion
) ;
932 wxString
wxUnix2MacFilename (const char *str
)
934 char *s
= sMacFileNameConversion
;
940 // relative path , since it goes on with slash which is translated to a :
941 memmove( s
, s
+1 ,strlen( s
) ) ;
943 else if ( *s
== '/' )
945 // absolute path -> on mac just start with the drive name
946 memmove( s
, s
+1 ,strlen( s
) ) ;
950 wxASSERT_MSG( 1 , "unkown path beginning" ) ;
954 if (*s
== '/' || *s
== '\\')
956 // convert any back-directory situations
957 if ( *(s
+1) == '.' && *(s
+2) == '.' && ( (*(s
+3) == '/' || *(s
+3) == '\\') ) )
960 memmove( s
+1 , s
+3 ,strlen( s
+3 ) + 1 ) ;
968 return wxString (sMacFileNameConversion
) ;
971 wxString
wxMacFSSpec2UnixFilename( const FSSpec
*spec
)
973 return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec
) ) ;
976 void wxUnixFilename2FSSpec( const char *path
, FSSpec
*spec
)
978 wxString var
= wxUnix2MacFilename( path
) ;
979 wxMacFilename2FSSpec( var
, spec
) ;
981 #endif // ! __DARWIN__
986 wxDos2UnixFilename (char *s
)
995 *s
= wxTolower (*s
); // Case INDEPENDENT
1002 #if defined(__WXMSW__) || defined(__WXPM__)
1003 wxUnix2DosFilename (wxChar
*s
)
1005 wxUnix2DosFilename (wxChar
*WXUNUSED(s
) )
1008 // Yes, I really mean this to happen under DOS only! JACS
1009 #if defined(__WXMSW__) || defined(__WXPM__)
1020 // Concatenate two files to form third
1022 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
1025 if ( !wxGetTempFileName("cat", outfile
) )
1028 FILE *fp1
= (FILE *) NULL
;
1029 FILE *fp2
= (FILE *) NULL
;
1030 FILE *fp3
= (FILE *) NULL
;
1031 // Open the inputs and outputs
1032 if ((fp1
= wxFopen (OS_FILENAME( file1
), wxT("rb"))) == NULL
||
1033 (fp2
= wxFopen (OS_FILENAME( file2
), wxT("rb"))) == NULL
||
1034 (fp3
= wxFopen (OS_FILENAME( outfile
), wxT("wb"))) == NULL
)
1046 while ((ch
= getc (fp1
)) != EOF
)
1047 (void) putc (ch
, fp3
);
1050 while ((ch
= getc (fp2
)) != EOF
)
1051 (void) putc (ch
, fp3
);
1055 bool result
= wxRenameFile(outfile
, file3
);
1061 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1063 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1064 // CopyFile() copies file attributes and modification time too, so use it
1065 // instead of our code if available
1067 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1068 return ::CopyFile(file1
, file2
, !overwrite
) != 0;
1069 #elif defined(__WXPM__)
1070 if (::DosCopy(file2
, file2
, overwrite
? DCPY_EXISTING
: 0) == 0)
1077 // get permissions of file1
1078 if ( wxStat(OS_FILENAME(file1
), &fbuf
) != 0 )
1080 // the file probably doesn't exist or we haven't the rights to read
1082 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1087 // open file1 for reading
1088 wxFile
fileIn(file1
, wxFile::read
);
1089 if ( !fileIn
.IsOpened() )
1092 // remove file2, if it exists. This is needed for creating
1093 // file2 with the correct permissions in the next step
1094 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1096 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1102 // reset the umask as we want to create the file with exactly the same
1103 // permissions as the original one
1104 mode_t oldUmask
= umask( 0 );
1107 // create file2 with the same permissions than file1 and open it for
1110 if ( !fileOut
.Create(file2
, overwrite
, fbuf
.st_mode
& 0777) )
1114 /// restore the old umask
1118 // copy contents of file1 to file2
1123 count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1124 if ( fileIn
.Error() )
1131 if ( fileOut
.Write(buf
, count
) < count
)
1135 // we can expect fileIn to be closed successfully, but we should ensure
1136 // that fileOut was closed as some write errors (disk full) might not be
1137 // detected before doing this
1138 if ( !fileIn
.Close() || !fileOut
.Close() )
1141 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1142 // no chmod in VA. Should be some permission API for HPFS386 partitions
1144 if ( chmod(OS_FILENAME(file2
), fbuf
.st_mode
) != 0 )
1146 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1150 #endif // OS/2 || Mac
1153 #endif // __WXMSW__ && __WIN32__
1157 wxRenameFile (const wxString
& file1
, const wxString
& file2
)
1159 // Normal system call
1160 if ( wxRename (file1
, file2
) == 0 )
1164 if (wxCopyFile(file1
, file2
)) {
1165 wxRemoveFile(file1
);
1172 bool wxRemoveFile(const wxString
& file
)
1174 #if defined(__VISUALC__) \
1175 || defined(__BORLANDC__) \
1176 || defined(__WATCOMC__) \
1177 || defined(__GNUWIN32__)
1178 int res
= wxRemove(file
);
1180 int res
= unlink(OS_FILENAME(file
));
1186 bool wxMkdir(const wxString
& dir
, int perm
)
1188 #if defined(__WXMAC__) && !defined(__UNIX__)
1189 return (mkdir( dir
, 0 ) == 0);
1191 const wxChar
*dirname
= dir
.c_str();
1193 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1194 // for the GNU compiler
1195 #if (!(defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) || defined(__WXMICROWIN__)
1196 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1197 #elif defined(__WXPM__)
1198 if (::DosCreateDir((PSZ
)dirname
, NULL
) != 0) // enhance for EAB's??
1199 #else // !MSW and !OS/2 VAC++
1201 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1204 wxLogSysError(_("Directory '%s' couldn't be created"), dirname
);
1213 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1216 return FALSE
; //to be changed since rmdir exists in VMS7.x
1217 #elif defined(__WXPM__)
1218 return (::DosDeleteDir((PSZ
)dir
.c_str()) == 0);
1222 return FALSE
; // What to do?
1224 return (wxRmDir(OS_FILENAME(dir
)) == 0);
1230 // does the path exists? (may have or not '/' or '\\' at the end)
1231 bool wxPathExists(const wxChar
*pszPathName
)
1233 wxString
strPath(pszPathName
);
1235 // Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
1236 // so remove all trailing backslashes from the path - but don't do this for
1237 // the pathes "d:\" (which are different from "d:") nor for just "\"
1238 while ( wxEndsWithPathSeparator(strPath
) )
1240 size_t len
= strPath
.length();
1241 if ( len
== 1 || (len
== 3 && strPath
[len
- 2] == _T(':')) )
1244 strPath
.Truncate(len
- 1);
1246 #endif // __WINDOWS__
1248 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1249 // Stat can't cope with network paths
1250 DWORD ret
= GetFileAttributes(strPath
.c_str());
1251 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
1252 return ((ret
!= 0xffffffff) && (isDir
!= 0));
1256 #ifndef __VISAGECPP__
1257 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1258 ((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1260 // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
1261 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1262 (st
.st_mode
== S_IFDIR
);
1268 // Get a temporary filename, opening and closing the file.
1269 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1271 wxString filename
= wxFileName::CreateTempFileName(prefix
);
1272 if ( filename
.empty() )
1276 wxStrcpy(buf
, filename
);
1278 buf
= copystring(filename
);
1283 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1285 buf
= wxFileName::CreateTempFileName(prefix
);
1287 return !buf
.empty();
1290 // Get first file name matching given wild card.
1292 #if defined(__UNIX__)
1294 // Get first file name matching given wild card.
1295 // Flags are reserved for future use.
1297 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1298 static DIR *gs_dirStream
= (DIR *) NULL
;
1299 static wxString gs_strFileSpec
;
1300 static int gs_findFlags
= 0;
1303 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1307 wxChar
*specvms
= NULL
;
1310 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1312 closedir(gs_dirStream
); // edz 941103: better housekeping
1314 gs_findFlags
= flags
;
1316 gs_strFileSpec
= spec
;
1318 // Find path only so we can concatenate
1319 // found file onto path
1320 wxString
path(wxPathOnly(gs_strFileSpec
));
1322 // special case: path is really "/"
1323 if ( !path
&& gs_strFileSpec
[0u] == wxT('/') )
1326 wxStrcpy( specvms
, wxT( "[000000]" ) );
1327 gs_strFileSpec
= specvms
;
1328 wxString
path_vms(wxPathOnly(gs_strFileSpec
));
1334 // path is empty => Local directory
1338 wxStrcpy( specvms
, wxT( "[]" ) );
1339 gs_strFileSpec
= specvms
;
1340 wxString
path_vms1(wxPathOnly(gs_strFileSpec
));
1347 gs_dirStream
= opendir(path
.fn_str());
1348 if ( !gs_dirStream
)
1350 wxLogSysError(_("Can not enumerate files in directory '%s'"),
1355 result
= wxFindNextFile();
1357 #endif // !VMS6.x or earlier
1362 wxString
wxFindNextFile()
1366 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1367 wxCHECK_MSG( gs_dirStream
, result
, wxT("must call wxFindFirstFile first") );
1369 // Find path only so we can concatenate
1370 // found file onto path
1371 wxString
path(wxPathOnly(gs_strFileSpec
));
1372 wxString
name(wxFileNameFromPath(gs_strFileSpec
));
1374 /* MATTHEW: special case: path is really "/" */
1375 if ( !path
&& gs_strFileSpec
[0u] == wxT('/'))
1379 struct dirent
*nextDir
;
1380 for ( nextDir
= readdir(gs_dirStream
);
1382 nextDir
= readdir(gs_dirStream
) )
1384 if (wxMatchWild(name
, nextDir
->d_name
, FALSE
) && // RR: added FALSE to find hidden files
1385 strcmp(nextDir
->d_name
, ".") &&
1386 strcmp(nextDir
->d_name
, "..") )
1389 if ( !path
.IsEmpty() )
1392 if ( path
!= wxT('/') )
1396 result
+= nextDir
->d_name
;
1398 // Only return "." and ".." when they match
1400 if ( (strcmp(nextDir
->d_name
, ".") == 0) ||
1401 (strcmp(nextDir
->d_name
, "..") == 0))
1403 if ( (gs_findFlags
& wxDIR
) != 0 )
1409 isdir
= wxDirExists(result
);
1411 // and only return directories when flags & wxDIR
1412 if ( !gs_findFlags
||
1413 ((gs_findFlags
& wxDIR
) && isdir
) ||
1414 ((gs_findFlags
& wxFILE
) && !isdir
) )
1421 result
.Empty(); // not found
1423 closedir(gs_dirStream
);
1424 gs_dirStream
= (DIR *) NULL
;
1425 #endif // !VMS6.2 or earlier
1430 #elif defined(__WXMAC__)
1432 struct MacDirectoryIterator
1440 static int g_iter_flags
;
1442 static MacDirectoryIterator g_iter
;
1443 wxString g_iter_spec
;
1445 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1449 g_iter_spec
= spec
;
1450 g_iter_spec
.MakeUpper() ;
1451 g_iter_flags
= flags
; /* MATTHEW: [5] Remember flags */
1453 // Find path only so we can concatenate found file onto path
1454 wxString
path(wxPathOnly(spec
));
1457 wxMacFilename2FSSpec( path
, &fsspec
) ;
1458 g_iter
.m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
1459 g_iter
.m_CPB
.hFileInfo
.ioNamePtr
= g_iter
.m_name
;
1460 g_iter
.m_index
= 0 ;
1463 FSpGetDirectoryID( &fsspec
, &g_iter
.m_dirId
, &isDir
) ;
1465 return wxEmptyString
;
1467 return wxFindNextFile( ) ;
1470 wxString
wxFindNextFile()
1479 while ( err
== noErr
)
1482 g_iter
.m_CPB
.dirInfo
.ioFDirIndex
= g_iter
.m_index
;
1483 g_iter
.m_CPB
.dirInfo
.ioDrDirID
= g_iter
.m_dirId
; /* we need to do this every time */
1484 err
= PBGetCatInfoSync((CInfoPBPtr
)&g_iter
.m_CPB
);
1488 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (g_iter_flags
& wxDIR
) ) // we have a directory
1491 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(g_iter_flags
& wxFILE
) )
1499 return wxEmptyString
;
1503 FSMakeFSSpecCompat(g_iter
.m_CPB
.hFileInfo
.ioVRefNum
,
1508 wxString name
= wxMacFSSpec2MacFilename( &spec
) ;
1509 if ( g_iter_spec
.Right(4)==(":*.*") || g_iter_spec
.Right(2)==(":*") || name
.Upper().Matches(g_iter_spec
) )
1512 return wxEmptyString
;
1515 #elif defined(__WXMSW__)
1518 static HANDLE gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1519 static WIN32_FIND_DATA gs_findDataStruct
;
1522 static struct ffblk gs_findDataStruct
;
1524 static struct _find_t gs_findDataStruct
;
1528 static wxString gs_strFileSpec
;
1529 static int gs_findFlags
= 0;
1531 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1535 gs_strFileSpec
= spec
;
1536 gs_findFlags
= flags
; /* MATTHEW: [5] Remember flags */
1538 // Find path only so we can concatenate found file onto path
1539 wxString
path(wxPathOnly(gs_strFileSpec
));
1540 if ( !path
.IsEmpty() )
1541 result
<< path
<< wxT('\\');
1544 if ( gs_hFileStruct
!= INVALID_HANDLE_VALUE
)
1545 FindClose(gs_hFileStruct
);
1547 gs_hFileStruct
= ::FindFirstFile(WXSTRINGCAST spec
, &gs_findDataStruct
);
1549 if ( gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1556 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1558 if (isdir
&& !(flags
& wxDIR
))
1559 return wxFindNextFile();
1560 else if (!isdir
&& flags
&& !(flags
& wxFILE
))
1561 return wxFindNextFile();
1563 result
+= gs_findDataStruct
.cFileName
;
1567 int flag
= _A_NORMAL
;
1572 if (findfirst(WXSTRINGCAST spec
, &gs_findDataStruct
, flag
) == 0)
1574 if (_dos_findfirst(WXSTRINGCAST spec
, flag
, &gs_findDataStruct
) == 0)
1580 attrib
= gs_findDataStruct
.ff_attrib
;
1582 attrib
= gs_findDataStruct
.attrib
;
1585 if (attrib
& _A_SUBDIR
) {
1586 if (!(gs_findFlags
& wxDIR
))
1587 return wxFindNextFile();
1588 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1589 return wxFindNextFile();
1593 gs_findDataStruct
.ff_name
1595 gs_findDataStruct
.name
1605 wxString
wxFindNextFile()
1609 // Find path only so we can concatenate found file onto path
1610 wxString
path(wxPathOnly(gs_strFileSpec
));
1615 if (gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1618 bool success
= (FindNextFile(gs_hFileStruct
, &gs_findDataStruct
) != 0);
1621 FindClose(gs_hFileStruct
);
1622 gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1626 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1628 if (isdir
&& !(gs_findFlags
& wxDIR
))
1630 else if (!isdir
&& gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1633 if ( !path
.IsEmpty() )
1634 result
<< path
<< wxT('\\');
1635 result
<< gs_findDataStruct
.cFileName
;
1642 if (findnext(&gs_findDataStruct
) == 0)
1644 if (_dos_findnext(&gs_findDataStruct
) == 0)
1647 /* MATTHEW: [5] Check directory flag */
1651 attrib
= gs_findDataStruct
.ff_attrib
;
1653 attrib
= gs_findDataStruct
.attrib
;
1656 if (attrib
& _A_SUBDIR
) {
1657 if (!(gs_findFlags
& wxDIR
))
1659 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1665 gs_findDataStruct
.ff_name
1667 gs_findDataStruct
.name
1676 #elif defined(__WXPM__)
1678 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1683 // TODO: figure something out here for OS/2
1684 gs_strFileSpec = spec;
1685 gs_findFlags = flags;
1687 // Find path only so we can concatenate found file onto path
1688 wxString path(wxPathOnly(gs_strFileSpec));
1689 if ( !path.IsEmpty() )
1690 result << path << wxT('\\');
1692 int flag = _A_NORMAL;
1696 if (_dos_findfirst(WXSTRINGCAST spec, flag, &gs_findDataStruct) == 0)
1699 attrib = gs_findDataStruct.attrib;
1701 if (attrib & _A_SUBDIR) {
1702 if (!(gs_findFlags & wxDIR))
1703 return wxFindNextFile();
1704 } else if (gs_findFlags && !(gs_findFlags & wxFILE))
1705 return wxFindNextFile();
1707 result += gs_findDataStruct.name;
1713 wxString
wxFindNextFile()
1720 #endif // Unix/Windows/OS/2
1722 // Get current working directory.
1723 // If buf is NULL, allocates space using new, else
1725 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1728 buf
= new wxChar
[sz
+1];
1730 char *cbuf
= new char[sz
+1];
1732 if (_getcwd(cbuf
, sz
) == NULL
) {
1733 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1736 SFSaveDisk
= 0x214, CurDirStore
= 0x398
1740 FSMakeFSSpec( - *(short *) SFSaveDisk
, *(long *) CurDirStore
, NULL
, &cwdSpec
) ;
1741 wxString res
= wxMacFSSpec2UnixFilename( &cwdSpec
) ;
1742 strcpy( buf
, res
) ;
1745 if (getcwd(cbuf
, sz
) == NULL
) {
1750 if (_getcwd(buf
, sz
) == NULL
) {
1751 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1756 pb
.ioNamePtr
= (StringPtr
) &fileName
;
1758 pb
.ioRefNum
= LMGetCurApRefNum();
1760 error
= PBGetFCBInfoSync(&pb
);
1761 if ( error
== noErr
)
1763 cwdSpec
.vRefNum
= pb
.ioFCBVRefNum
;
1764 cwdSpec
.parID
= pb
.ioFCBParID
;
1765 cwdSpec
.name
[0] = 0 ;
1766 wxString res
= wxMacFSSpec2MacFilename( &cwdSpec
) ;
1768 strcpy( buf
, res
) ;
1769 buf
[res
.length()]=0 ;
1774 this version will not always give back the application directory on mac
1777 SFSaveDisk = 0x214, CurDirStore = 0x398
1781 FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ;
1782 wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ;
1783 strcpy( buf , res ) ;
1786 #elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
1788 rc
= ::DosQueryCurrentDir( 0 // current drive
1794 if (getcwd(buf
, sz
) == NULL
) {
1802 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1811 static const size_t maxPathLen
= 1024;
1814 wxGetWorkingDirectory(str
.GetWriteBuf(maxPathLen
), maxPathLen
);
1815 str
.UngetWriteBuf();
1820 bool wxSetWorkingDirectory(const wxString
& d
)
1822 #if defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1823 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1824 #elif defined(__WXPM__)
1825 return (::DosSetCurrentDir((PSZ
)d
.c_str()) == 0);
1826 #elif defined(__WINDOWS__)
1829 return (bool)(SetCurrentDirectory(d
) != 0);
1831 // Must change drive, too.
1832 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1835 wxChar firstChar
= d
[0];
1839 firstChar
= firstChar
- 32;
1841 // To a drive number
1842 unsigned int driveNo
= firstChar
- 64;
1845 unsigned int noDrives
;
1846 _dos_setdrive(driveNo
, &noDrives
);
1849 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1857 // Get the OS directory if appropriate (such as the Windows directory).
1858 // On non-Windows platform, probably just return the empty string.
1859 wxString
wxGetOSDirectory()
1861 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1863 GetWindowsDirectory(buf
, 256);
1864 return wxString(buf
);
1866 return wxEmptyString
;
1870 bool wxEndsWithPathSeparator(const wxChar
*pszFileName
)
1872 size_t len
= wxStrlen(pszFileName
);
1876 return wxIsPathSeparator(pszFileName
[len
- 1]);
1879 // find a file in a list of directories, returns false if not found
1880 bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
)
1882 // we assume that it's not empty
1883 wxCHECK_MSG( !wxIsEmpty(pszFile
), FALSE
,
1884 _T("empty file name in wxFindFileInPath"));
1886 // skip path separator in the beginning of the file name if present
1887 if ( wxIsPathSeparator(*pszFile
) )
1890 // copy the path (strtok will modify it)
1891 wxChar
*szPath
= new wxChar
[wxStrlen(pszPath
) + 1];
1892 wxStrcpy(szPath
, pszPath
);
1895 wxChar
*pc
, *save_ptr
;
1896 for ( pc
= wxStrtok(szPath
, wxPATH_SEP
, &save_ptr
);
1898 pc
= wxStrtok((wxChar
*) NULL
, wxPATH_SEP
, &save_ptr
) )
1900 // search for the file in this directory
1902 if ( !wxEndsWithPathSeparator(pc
) )
1903 strFile
+= wxFILE_SEP_PATH
;
1906 if ( FileExists(strFile
) ) {
1912 // suppress warning about unused variable save_ptr when wxStrtok() is a
1913 // macro which throws away its third argument
1918 return pc
!= NULL
; // if true => we breaked from the loop
1921 void WXDLLEXPORT
wxSplitPath(const wxChar
*pszFileName
,
1926 // it can be empty, but it shouldn't be NULL
1927 wxCHECK_RET( pszFileName
, wxT("NULL file name in wxSplitPath") );
1929 wxFileName::SplitPath(pszFileName
, pstrPath
, pstrName
, pstrExt
);
1932 time_t WXDLLEXPORT
wxFileModificationTime(const wxString
& filename
)
1936 wxStat(filename
.fn_str(), &buf
);
1937 return buf
.st_mtime
;
1941 //------------------------------------------------------------------------
1942 // wild character routines
1943 //------------------------------------------------------------------------
1945 bool wxIsWild( const wxString
& pattern
)
1947 wxString tmp
= pattern
;
1948 wxChar
*pat
= WXSTRINGCAST(tmp
);
1951 case wxT('?'): case wxT('*'): case wxT('['): case wxT('{'):
1961 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1963 #if defined(HAVE_FNMATCH_H)
1965 // this probably won't work well for multibyte chars in Unicode mode?
1967 return fnmatch(pat
.fn_str(), text
.fn_str(), FNM_PERIOD
) == 0;
1969 return fnmatch(pat
.fn_str(), text
.fn_str(), 0) == 0;
1973 // #pragma error Broken implementation of wxMatchWild() -- needs fixing!
1976 * WARNING: this code is broken!
1979 wxString tmp1
= pat
;
1980 wxChar
*pattern
= WXSTRINGCAST(tmp1
);
1981 wxString tmp2
= text
;
1982 wxChar
*str
= WXSTRINGCAST(tmp2
);
1985 bool done
= FALSE
, ret_code
, ok
;
1986 // Below is for vi fans
1987 const wxChar OB
= wxT('{'), CB
= wxT('}');
1989 // dot_special means '.' only matches '.'
1990 if (dot_special
&& *str
== wxT('.') && *pattern
!= *str
)
1993 while ((*pattern
!= wxT('\0')) && (!done
)
1994 && (((*str
==wxT('\0'))&&((*pattern
==OB
)||(*pattern
==wxT('*'))))||(*str
!=wxT('\0')))) {
1998 if (*pattern
!= wxT('\0'))
2004 while ((*str
!=wxT('\0'))
2005 && ((ret_code
=wxMatchWild(pattern
, str
++, FALSE
)) == 0))
2008 while (*str
!= wxT('\0'))
2010 while (*pattern
!= wxT('\0'))
2017 if ((*pattern
== wxT('\0')) || (*pattern
== wxT(']'))) {
2021 if (*pattern
== wxT('\\')) {
2023 if (*pattern
== wxT('\0')) {
2028 if (*(pattern
+ 1) == wxT('-')) {
2031 if (*pattern
== wxT(']')) {
2035 if (*pattern
== wxT('\\')) {
2037 if (*pattern
== wxT('\0')) {
2042 if ((*str
< c
) || (*str
> *pattern
)) {
2046 } else if (*pattern
!= *str
) {
2051 while ((*pattern
!= wxT(']')) && (*pattern
!= wxT('\0'))) {
2052 if ((*pattern
== wxT('\\')) && (*(pattern
+ 1) != wxT('\0')))
2056 if (*pattern
!= wxT('\0')) {
2066 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2069 while (ok
&& (*cp
!= wxT('\0')) && (*pattern
!= wxT('\0'))
2070 && (*pattern
!= wxT(',')) && (*pattern
!= CB
)) {
2071 if (*pattern
== wxT('\\'))
2073 ok
= (*pattern
++ == *cp
++);
2075 if (*pattern
== wxT('\0')) {
2081 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2082 if (*++pattern
== wxT('\\')) {
2083 if (*++pattern
== CB
)
2088 while (*pattern
!=CB
&& *pattern
!=wxT(',') && *pattern
!=wxT('\0')) {
2089 if (*++pattern
== wxT('\\')) {
2090 if (*++pattern
== CB
|| *pattern
== wxT(','))
2095 if (*pattern
!= wxT('\0'))
2100 if (*str
== *pattern
) {
2107 while (*pattern
== wxT('*'))
2109 return ((*str
== wxT('\0')) && (*pattern
== wxT('\0')));
2115 #pragma warning(default:4706) // assignment within conditional expression