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"
38 // there are just too many of those...
40 #pragma warning(disable:4706) // assignment within conditional expression
47 #if !defined(__WATCOMC__)
48 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
56 #include <sys/types.h>
71 #include "wx/os2/private.h"
73 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
74 #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
79 #endif // native Win compiler
81 #if defined(__DOS__) && defined(__WATCOMC__)
90 #include <sys/unistd.h>
94 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
95 // this (3.1 I believe) and how to test for it.
96 // If this works for Borland 4.0 as well, then no worries.
105 #include "wx/setup.h"
108 // No, Cygwin doesn't appear to have fnmatch.h after all.
109 #if defined(HAVE_FNMATCH_H)
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 #define _MAXPATHLEN 500
123 extern wxChar
*wxBuffer
;
126 # include "MoreFiles.h"
127 # include "MoreFilesExtras.h"
128 # include "FullPath.h"
129 # include "FSpCompat.h"
132 IMPLEMENT_DYNAMIC_CLASS(wxPathList
, wxStringList
)
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
140 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
142 // VisualAge C++ V4.0 cannot have any external linkage const decs
143 // in headers included by more than one primary source
145 const off_t wxInvalidOffset
= (off_t
)-1;
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 // we need to translate Mac filenames before passing them to OS functions
153 #define OS_FILENAME(s) (s.fn_str())
155 // ============================================================================
157 // ============================================================================
159 void wxPathList::Add (const wxString
& path
)
161 wxStringList::Add (WXSTRINGCAST path
);
164 // Add paths e.g. from the PATH environment variable
165 void wxPathList::AddEnvList (const wxString
& envVariable
)
167 static const wxChar PATH_TOKS
[] =
169 wxT(" ;"); // Don't seperate with colon in DOS (used for drive)
174 wxChar
*val
= wxGetenv (WXSTRINGCAST envVariable
);
177 wxChar
*s
= copystring (val
);
178 wxChar
*save_ptr
, *token
= wxStrtok (s
, PATH_TOKS
, &save_ptr
);
182 Add (copystring (token
));
185 if ((token
= wxStrtok ((wxChar
*) NULL
, PATH_TOKS
, &save_ptr
)) != NULL
)
186 Add (wxString(token
));
190 // suppress warning about unused variable save_ptr when wxStrtok() is a
191 // macro which throws away its third argument
198 // Given a full filename (with path), ensure that that file can
199 // be accessed again USING FILENAME ONLY by adding the path
200 // to the list if not already there.
201 void wxPathList::EnsureFileAccessible (const wxString
& path
)
203 wxString
path_only(wxPathOnly(path
));
204 if ( !path_only
.IsEmpty() )
206 if ( !Member(path_only
) )
211 bool wxPathList::Member (const wxString
& path
)
213 for (wxNode
* node
= First (); node
!= NULL
; node
= node
->Next ())
215 wxString
path2((wxChar
*) node
->Data ());
217 #if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__)
219 path
.CompareTo (path2
, wxString::ignoreCase
) == 0
221 // Case sensitive File System
222 path
.CompareTo (path2
) == 0
230 wxString
wxPathList::FindValidPath (const wxString
& file
)
232 if (wxFileExists (wxExpandPath(wxFileFunctionsBuffer
, file
)))
233 return wxString(wxFileFunctionsBuffer
);
235 wxChar buf
[_MAXPATHLEN
];
236 wxStrcpy(buf
, wxFileFunctionsBuffer
);
238 wxChar
*filename
= (wxChar
*) NULL
; /* shut up buggy egcs warning */
239 filename
= IsAbsolutePath (buf
) ? wxFileNameFromPath (buf
) : (wxChar
*)buf
;
241 for (wxNode
* node
= First (); node
; node
= node
->Next ())
243 wxChar
*path
= (wxChar
*) node
->Data ();
244 wxStrcpy (wxFileFunctionsBuffer
, path
);
245 wxChar ch
= wxFileFunctionsBuffer
[wxStrlen(wxFileFunctionsBuffer
)-1];
246 if (ch
!= wxT('\\') && ch
!= wxT('/'))
247 wxStrcat (wxFileFunctionsBuffer
, wxT("/"));
248 wxStrcat (wxFileFunctionsBuffer
, filename
);
250 Unix2DosFilename (wxFileFunctionsBuffer
);
252 if (wxFileExists (wxFileFunctionsBuffer
))
254 return wxString(wxFileFunctionsBuffer
); // Found!
258 return wxString(wxT("")); // Not found
261 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
)
263 wxString f
= FindValidPath(file
);
264 if ( wxIsAbsolutePath(f
) )
268 wxGetWorkingDirectory(buf
.GetWriteBuf(_MAXPATHLEN
), _MAXPATHLEN
- 1);
270 if ( !wxEndsWithPathSeparator(buf
) )
272 buf
+= wxFILE_SEP_PATH
;
280 wxFileExists (const wxString
& filename
)
282 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
283 // GetFileAttributes can copy with network paths
284 DWORD ret
= GetFileAttributes(filename
);
285 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
286 return ((ret
!= 0xffffffff) && (isDir
== 0));
289 if ( !filename
.empty() && wxStat (OS_FILENAME(filename
), &stbuf
) == 0 )
297 wxIsAbsolutePath (const wxString
& filename
)
299 if (filename
!= wxT(""))
301 #if defined(__WXMAC__) && !defined(__DARWIN__)
302 // Classic or Carbon CodeWarrior like
303 // Carbon with Apple DevTools is Unix like
305 // This seems wrong to me, but there is no fix. since
306 // "MacOS:MyText.txt" is absolute whereas "MyDir:MyText.txt"
307 // is not. Or maybe ":MyDir:MyText.txt" has to be used? RR.
308 if (filename
.Find(':') != wxNOT_FOUND
&& filename
[0] != ':')
311 // Unix like or Windows
312 if (filename
[0] == wxT('/'))
316 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
321 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
329 * Strip off any extension (dot something) from end of file,
330 * IF one exists. Inserts zero into buffer.
334 void wxStripExtension(wxChar
*buffer
)
336 int len
= wxStrlen(buffer
);
340 if (buffer
[i
] == wxT('.'))
349 void wxStripExtension(wxString
& buffer
)
351 size_t len
= buffer
.Length();
355 if (buffer
.GetChar(i
) == wxT('.'))
357 buffer
= buffer
.Left(i
);
364 // Destructive removal of /./ and /../ stuff
365 wxChar
*wxRealPath (wxChar
*path
)
368 static const wxChar SEP
= wxT('\\');
369 Unix2DosFilename(path
);
371 static const wxChar SEP
= wxT('/');
373 if (path
[0] && path
[1]) {
374 /* MATTHEW: special case "/./x" */
376 if (path
[2] == SEP
&& path
[1] == wxT('.'))
384 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
387 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--);
388 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
389 && (q
- 1 <= path
|| q
[-1] != SEP
))
392 if (path
[0] == wxT('\0'))
398 /* Check that path[2] is NULL! */
399 else if (path
[1] == wxT(':') && !path
[2])
408 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
417 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
419 if (filename
== wxT(""))
420 return (wxChar
*) NULL
;
422 if (! IsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
))) {
423 wxChar buf
[_MAXPATHLEN
];
425 wxGetWorkingDirectory(buf
, WXSIZEOF(buf
));
426 wxChar ch
= buf
[wxStrlen(buf
) - 1];
428 if (ch
!= wxT('\\') && ch
!= wxT('/'))
429 wxStrcat(buf
, wxT("\\"));
432 wxStrcat(buf
, wxT("/"));
434 wxStrcat(buf
, wxFileFunctionsBuffer
);
435 return copystring( wxRealPath(buf
) );
437 return copystring( wxFileFunctionsBuffer
);
443 ~user/ => user's home dir
444 If the environment variable a = "foo" and b = "bar" then:
461 /* input name in name, pathname output to buf. */
463 wxChar
*wxExpandPath(wxChar
*buf
, const wxChar
*name
)
465 register wxChar
*d
, *s
, *nm
;
466 wxChar lnm
[_MAXPATHLEN
];
469 // Some compilers don't like this line.
470 // const wxChar trimchars[] = wxT("\n \t");
473 trimchars
[0] = wxT('\n');
474 trimchars
[1] = wxT(' ');
475 trimchars
[2] = wxT('\t');
479 const wxChar SEP
= wxT('\\');
481 const wxChar SEP
= wxT('/');
484 if (name
== NULL
|| *name
== wxT('\0'))
486 nm
= copystring(name
); // Make a scratch copy
489 /* Skip leading whitespace and cr */
490 while (wxStrchr((wxChar
*)trimchars
, *nm
) != NULL
)
492 /* And strip off trailing whitespace and cr */
493 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
494 while (q
-- && wxStrchr((wxChar
*)trimchars
, *s
) != NULL
)
502 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
505 /* Expand inline environment variables */
523 while ((*d
++ = *s
) != 0) {
525 if (*s
== wxT('\\')) {
526 if ((*(d
- 1) = *++s
)) {
535 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
537 if (*s
++ == wxT('$'))
540 register wxChar
*start
= d
;
541 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
542 register wxChar
*value
;
543 while ((*d
++ = *s
) != 0)
544 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
549 value
= wxGetenv(braces
? start
+ 1 : start
);
551 for ((d
= start
- 1); (*d
++ = *value
++) != 0;);
559 /* Expand ~ and ~user */
562 if (nm
[0] == wxT('~') && !q
)
565 if (nm
[1] == SEP
|| nm
[1] == 0)
567 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
568 if ((s
= WXSTRINGCAST
wxGetUserHome(wxT(""))) != NULL
) {
573 { /* ~user/filename */
574 register wxChar
*nnm
;
575 register wxChar
*home
;
576 for (s
= nm
; *s
&& *s
!= SEP
; s
++);
577 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
578 was_sep
= (*s
== SEP
);
579 nnm
= *s
? s
+ 1 : s
;
581 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
582 if ((home
= WXSTRINGCAST
wxGetUserHome(wxString(nm
+ 1))) == NULL
) {
583 if (was_sep
) /* replace only if it was there: */
594 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
596 while (wxT('\0') != (*d
++ = *s
++))
599 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
603 while ((*d
++ = *s
++) != 0);
604 delete[] nm_tmp
; // clean up alloc
605 /* Now clean up the buffer */
606 return wxRealPath(buf
);
609 /* Contract Paths to be build upon an environment variable
612 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
614 The call wxExpandPath can convert these back!
617 wxContractPath (const wxString
& filename
, const wxString
& envname
, const wxString
& user
)
619 static wxChar dest
[_MAXPATHLEN
];
621 if (filename
== wxT(""))
622 return (wxChar
*) NULL
;
624 wxStrcpy (dest
, WXSTRINGCAST filename
);
626 Unix2DosFilename(dest
);
629 // Handle environment
630 const wxChar
*val
= (const wxChar
*) NULL
;
631 wxChar
*tcp
= (wxChar
*) NULL
;
632 if (envname
!= WXSTRINGCAST NULL
&& (val
= wxGetenv (WXSTRINGCAST envname
)) != NULL
&&
633 (tcp
= wxStrstr (dest
, val
)) != NULL
)
635 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ wxStrlen (val
));
638 wxStrcpy (tcp
, WXSTRINGCAST envname
);
639 wxStrcat (tcp
, wxT("}"));
640 wxStrcat (tcp
, wxFileFunctionsBuffer
);
643 // Handle User's home (ignore root homes!)
645 if ((val
= wxGetUserHome (user
)) != NULL
&&
646 (len
= wxStrlen(val
)) > 2 &&
647 wxStrncmp(dest
, val
, len
) == 0)
649 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
651 wxStrcat(wxFileFunctionsBuffer
, (const wxChar
*) user
);
653 // strcat(wxFileFunctionsBuffer, "\\");
655 // strcat(wxFileFunctionsBuffer, "/");
657 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
658 wxStrcpy (dest
, wxFileFunctionsBuffer
);
664 // Return just the filename, not the path
666 wxChar
*wxFileNameFromPath (wxChar
*path
)
670 register wxChar
*tcp
;
672 tcp
= path
+ wxStrlen (path
);
673 while (--tcp
>= path
)
675 #if defined(__WXMAC__) && !defined(__DARWIN__)
676 // Classic or Carbon CodeWarrior like
677 // Carbon with Apple DevTools is Unix like
678 if (*tcp
== wxT(':'))
681 // Unix like or Windows
682 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
686 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
690 #if defined(__WXMSW__) || defined(__WXPM__)
692 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
699 wxString
wxFileNameFromPath (const wxString
& path1
)
701 if (path1
!= wxT(""))
703 wxChar
*path
= WXSTRINGCAST path1
;
704 register wxChar
*tcp
;
706 tcp
= path
+ wxStrlen (path
);
707 while (--tcp
>= path
)
709 #if defined(__WXMAC__) && !defined(__DARWIN__)
710 // Classic or Carbon CodeWarrior like
711 // Carbon with Apple DevTools is Unix like
712 if (*tcp
== wxT(':') )
713 return wxString(tcp
+ 1);
715 // Unix like or Windows
716 if (*tcp
== wxT('/') || *tcp
== wxT('\\'))
717 return wxString(tcp
+ 1);
720 if (*tcp
== wxT(':') || *tcp
== wxT(']'))
721 return wxString(tcp
+ 1);
724 #if defined(__WXMSW__) || defined(__WXPM__)
726 if (wxIsalpha (*path
) && *(path
+ 1) == wxT(':'))
727 return wxString(path
+ 2);
730 // Yes, this should return the path, not an empty string, otherwise
731 // we get "thing.txt" -> "".
735 // Return just the directory, or NULL if no directory
737 wxPathOnly (wxChar
*path
)
741 static wxChar buf
[_MAXPATHLEN
];
744 wxStrcpy (buf
, path
);
746 int l
= wxStrlen(path
);
749 // Search backward for a backward or forward slash
752 #if defined(__WXMAC__) && !defined(__DARWIN__)
753 // Classic or Carbon CodeWarrior like
754 // Carbon with Apple DevTools is Unix like
755 if (path
[i
] == wxT(':') )
761 // Unix like or Windows
762 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
769 if (path
[i
] == wxT(']'))
778 #if defined(__WXMSW__) || defined(__WXPM__)
779 // Try Drive specifier
780 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
782 // A:junk --> A:. (since A:.\junk Not A:\junk)
789 return (wxChar
*) NULL
;
792 // Return just the directory, or NULL if no directory
793 wxString
wxPathOnly (const wxString
& path
)
797 wxChar buf
[_MAXPATHLEN
];
800 wxStrcpy (buf
, WXSTRINGCAST path
);
802 int l
= path
.Length();
805 // Search backward for a backward or forward slash
808 #if defined(__WXMAC__) && !defined(__DARWIN__)
809 // Classic or Carbon CodeWarrior like
810 // Carbon with Apple DevTools is Unix like
811 if (path
[i
] == wxT(':') )
814 return wxString(buf
);
817 // Unix like or Windows
818 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
821 return wxString(buf
);
825 if (path
[i
] == wxT(']'))
828 return wxString(buf
);
834 #if defined(__WXMSW__) || defined(__WXPM__)
835 // Try Drive specifier
836 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
838 // A:junk --> A:. (since A:.\junk Not A:\junk)
841 return wxString(buf
);
845 return wxString(wxT(""));
848 // Utility for converting delimiters in DOS filenames to UNIX style
849 // and back again - or we get nasty problems with delimiters.
850 // Also, convert to lower case, since case is significant in UNIX.
852 #if defined(__WXMAC__)
853 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
857 char thePath
[FILENAME_MAX
];
859 // convert the FSSpec to an FSRef
860 (void) FSpMakeFSRef( spec
, &theRef
);
861 // get the POSIX path associated with the FSRef
862 (void) FSRefMakePath( &theRef
, (UInt8
*)thePath
, sizeof(thePath
) );
864 // create path string for return value
865 wxString
result( thePath
) ;
870 // get length of path and allocate handle
871 FSpGetFullPath( spec
, &length
, &myPath
) ;
872 ::SetHandleSize( myPath
, length
+ 1 ) ;
874 (*myPath
)[length
] = 0 ;
875 if ((length
> 0) && ((*myPath
)[length
-1] == ':'))
876 (*myPath
)[length
-1] = 0 ;
878 // create path string for return value
879 wxString
result( (char*) *myPath
) ;
881 // free allocated handle
882 ::HUnlock( myPath
) ;
883 ::DisposeHandle( myPath
) ;
889 void wxMacFilename2FSSpec( const char *path
, FSSpec
*spec
)
894 // get the FSRef associated with the POSIX path
895 (void) FSPathMakeRef((const UInt8
*) path
, &theRef
, NULL
);
896 // convert the FSRef to an FSSpec
897 (void) FSGetCatalogInfo(&theRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
899 FSpLocationFromFullPath( strlen(path
) , path
, spec
) ;
904 // Mac file names are POSIX (Unix style) under Darwin
905 // therefore the conversion functions below are not needed
907 static char sMacFileNameConversion
[ 1000 ] ;
909 wxString
wxMac2UnixFilename (const char *str
)
911 char *s
= sMacFileNameConversion
;
915 memmove( s
+1 , s
,strlen( s
) + 1) ;
926 *s
= wxTolower(*s
); // Case INDEPENDENT
930 return wxString(sMacFileNameConversion
) ;
933 wxString
wxUnix2MacFilename (const char *str
)
935 char *s
= sMacFileNameConversion
;
941 // relative path , since it goes on with slash which is translated to a :
942 memmove( s
, s
+1 ,strlen( s
) ) ;
944 else if ( *s
== '/' )
946 // absolute path -> on mac just start with the drive name
947 memmove( s
, s
+1 ,strlen( s
) ) ;
951 wxASSERT_MSG( 1 , "unkown path beginning" ) ;
955 if (*s
== '/' || *s
== '\\')
957 // convert any back-directory situations
958 if ( *(s
+1) == '.' && *(s
+2) == '.' && ( (*(s
+3) == '/' || *(s
+3) == '\\') ) )
961 memmove( s
+1 , s
+3 ,strlen( s
+3 ) + 1 ) ;
969 return wxString (sMacFileNameConversion
) ;
972 wxString
wxMacFSSpec2UnixFilename( const FSSpec
*spec
)
974 return wxMac2UnixFilename( wxMacFSSpec2MacFilename( spec
) ) ;
977 void wxUnixFilename2FSSpec( const char *path
, FSSpec
*spec
)
979 wxString var
= wxUnix2MacFilename( path
) ;
980 wxMacFilename2FSSpec( var
, spec
) ;
982 #endif // ! __DARWIN__
987 wxDos2UnixFilename (char *s
)
996 *s
= wxTolower (*s
); // Case INDEPENDENT
1003 #if defined(__WXMSW__) || defined(__WXPM__)
1004 wxUnix2DosFilename (wxChar
*s
)
1006 wxUnix2DosFilename (wxChar
*WXUNUSED(s
) )
1009 // Yes, I really mean this to happen under DOS only! JACS
1010 #if defined(__WXMSW__) || defined(__WXPM__)
1021 // Concatenate two files to form third
1023 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
1026 if ( !wxGetTempFileName("cat", outfile
) )
1029 FILE *fp1
= (FILE *) NULL
;
1030 FILE *fp2
= (FILE *) NULL
;
1031 FILE *fp3
= (FILE *) NULL
;
1032 // Open the inputs and outputs
1033 if ((fp1
= wxFopen (OS_FILENAME( file1
), wxT("rb"))) == NULL
||
1034 (fp2
= wxFopen (OS_FILENAME( file2
), wxT("rb"))) == NULL
||
1035 (fp3
= wxFopen (OS_FILENAME( outfile
), wxT("wb"))) == NULL
)
1047 while ((ch
= getc (fp1
)) != EOF
)
1048 (void) putc (ch
, fp3
);
1051 while ((ch
= getc (fp2
)) != EOF
)
1052 (void) putc (ch
, fp3
);
1056 bool result
= wxRenameFile(outfile
, file3
);
1062 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1064 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1065 // CopyFile() copies file attributes and modification time too, so use it
1066 // instead of our code if available
1068 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1069 return ::CopyFile(file1
, file2
, !overwrite
) != 0;
1070 #elif defined(__WXPM__)
1071 if (::DosCopy(file2
, file2
, overwrite
? DCPY_EXISTING
: 0) == 0)
1078 // get permissions of file1
1079 if ( wxStat(OS_FILENAME(file1
), &fbuf
) != 0 )
1081 // the file probably doesn't exist or we haven't the rights to read
1083 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1088 // open file1 for reading
1089 wxFile
fileIn(file1
, wxFile::read
);
1090 if ( !fileIn
.IsOpened() )
1093 // remove file2, if it exists. This is needed for creating
1094 // file2 with the correct permissions in the next step
1095 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1097 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1103 // reset the umask as we want to create the file with exactly the same
1104 // permissions as the original one
1105 mode_t oldUmask
= umask( 0 );
1108 // create file2 with the same permissions than file1 and open it for
1111 if ( !fileOut
.Create(file2
, overwrite
, fbuf
.st_mode
& 0777) )
1115 /// restore the old umask
1119 // copy contents of file1 to file2
1124 count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1125 if ( fileIn
.Error() )
1132 if ( fileOut
.Write(buf
, count
) < count
)
1136 // we can expect fileIn to be closed successfully, but we should ensure
1137 // that fileOut was closed as some write errors (disk full) might not be
1138 // detected before doing this
1139 if ( !fileIn
.Close() || !fileOut
.Close() )
1142 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1143 // no chmod in VA. Should be some permission API for HPFS386 partitions
1145 if ( chmod(OS_FILENAME(file2
), fbuf
.st_mode
) != 0 )
1147 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1151 #endif // OS/2 || Mac
1154 #endif // __WXMSW__ && __WIN32__
1158 wxRenameFile (const wxString
& file1
, const wxString
& file2
)
1160 // Normal system call
1161 if ( wxRename (file1
, file2
) == 0 )
1165 if (wxCopyFile(file1
, file2
)) {
1166 wxRemoveFile(file1
);
1173 bool wxRemoveFile(const wxString
& file
)
1175 #if defined(__VISUALC__) \
1176 || defined(__BORLANDC__) \
1177 || defined(__WATCOMC__) \
1178 || defined(__GNUWIN32__)
1179 int res
= wxRemove(file
);
1181 int res
= unlink(OS_FILENAME(file
));
1187 bool wxMkdir(const wxString
& dir
, int perm
)
1189 #if defined(__WXMAC__) && !defined(__UNIX__)
1190 return (mkdir( dir
, 0 ) == 0);
1192 const wxChar
*dirname
= dir
.c_str();
1194 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1195 // for the GNU compiler
1196 #if (!(defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) || defined(__WXMICROWIN__)
1197 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1198 #elif defined(__WXPM__)
1199 if (::DosCreateDir((PSZ
)dirname
, NULL
) != 0) // enhance for EAB's??
1200 #else // !MSW and !OS/2 VAC++
1202 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1205 wxLogSysError(_("Directory '%s' couldn't be created"), dirname
);
1214 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1217 return FALSE
; //to be changed since rmdir exists in VMS7.x
1218 #elif defined(__WXPM__)
1219 return (::DosDeleteDir((PSZ
)dir
.c_str()) == 0);
1223 return FALSE
; // What to do?
1225 return (wxRmDir(OS_FILENAME(dir
)) == 0);
1231 // does the path exists? (may have or not '/' or '\\' at the end)
1232 bool wxPathExists(const wxChar
*pszPathName
)
1234 wxString
strPath(pszPathName
);
1236 // Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
1237 // so remove all trailing backslashes from the path - but don't do this for
1238 // the pathes "d:\" (which are different from "d:") nor for just "\"
1239 while ( wxEndsWithPathSeparator(strPath
) )
1241 size_t len
= strPath
.length();
1242 if ( len
== 1 || (len
== 3 && strPath
[len
- 2] == _T(':')) )
1245 strPath
.Truncate(len
- 1);
1247 #endif // __WINDOWS__
1249 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1250 // Stat can't cope with network paths
1251 DWORD ret
= GetFileAttributes(strPath
.c_str());
1252 DWORD isDir
= (ret
& FILE_ATTRIBUTE_DIRECTORY
);
1253 return ((ret
!= 0xffffffff) && (isDir
!= 0));
1257 #ifndef __VISAGECPP__
1258 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1259 ((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1261 // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
1262 return wxStat(wxFNSTRINGCAST strPath
.fn_str(), &st
) == 0 &&
1263 (st
.st_mode
== S_IFDIR
);
1269 // Get a temporary filename, opening and closing the file.
1270 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1272 wxString filename
= wxFileName::CreateTempFileName(prefix
);
1273 if ( filename
.empty() )
1277 wxStrcpy(buf
, filename
);
1279 buf
= copystring(filename
);
1284 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1286 buf
= wxFileName::CreateTempFileName(prefix
);
1288 return !buf
.empty();
1291 // Get first file name matching given wild card.
1293 #if defined(__UNIX__)
1295 // Get first file name matching given wild card.
1296 // Flags are reserved for future use.
1298 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1299 static DIR *gs_dirStream
= (DIR *) NULL
;
1300 static wxString gs_strFileSpec
;
1301 static int gs_findFlags
= 0;
1304 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1308 wxChar
*specvms
= NULL
;
1311 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1313 closedir(gs_dirStream
); // edz 941103: better housekeping
1315 gs_findFlags
= flags
;
1317 gs_strFileSpec
= spec
;
1319 // Find path only so we can concatenate
1320 // found file onto path
1321 wxString
path(wxPathOnly(gs_strFileSpec
));
1323 // special case: path is really "/"
1324 if ( !path
&& gs_strFileSpec
[0u] == wxT('/') )
1327 wxStrcpy( specvms
, wxT( "[000000]" ) );
1328 gs_strFileSpec
= specvms
;
1329 wxString
path_vms(wxPathOnly(gs_strFileSpec
));
1335 // path is empty => Local directory
1339 wxStrcpy( specvms
, wxT( "[]" ) );
1340 gs_strFileSpec
= specvms
;
1341 wxString
path_vms1(wxPathOnly(gs_strFileSpec
));
1348 gs_dirStream
= opendir(path
.fn_str());
1349 if ( !gs_dirStream
)
1351 wxLogSysError(_("Can not enumerate files in directory '%s'"),
1356 result
= wxFindNextFile();
1358 #endif // !VMS6.x or earlier
1363 wxString
wxFindNextFile()
1367 #if !defined( __VMS__ ) || ( __VMS_VER >= 70000000 )
1368 wxCHECK_MSG( gs_dirStream
, result
, wxT("must call wxFindFirstFile first") );
1370 // Find path only so we can concatenate
1371 // found file onto path
1372 wxString
path(wxPathOnly(gs_strFileSpec
));
1373 wxString
name(wxFileNameFromPath(gs_strFileSpec
));
1375 /* MATTHEW: special case: path is really "/" */
1376 if ( !path
&& gs_strFileSpec
[0u] == wxT('/'))
1380 struct dirent
*nextDir
;
1381 for ( nextDir
= readdir(gs_dirStream
);
1383 nextDir
= readdir(gs_dirStream
) )
1385 if (wxMatchWild(name
, nextDir
->d_name
, FALSE
) && // RR: added FALSE to find hidden files
1386 strcmp(nextDir
->d_name
, ".") &&
1387 strcmp(nextDir
->d_name
, "..") )
1390 if ( !path
.IsEmpty() )
1393 if ( path
!= wxT('/') )
1397 result
+= nextDir
->d_name
;
1399 // Only return "." and ".." when they match
1401 if ( (strcmp(nextDir
->d_name
, ".") == 0) ||
1402 (strcmp(nextDir
->d_name
, "..") == 0))
1404 if ( (gs_findFlags
& wxDIR
) != 0 )
1410 isdir
= wxDirExists(result
);
1412 // and only return directories when flags & wxDIR
1413 if ( !gs_findFlags
||
1414 ((gs_findFlags
& wxDIR
) && isdir
) ||
1415 ((gs_findFlags
& wxFILE
) && !isdir
) )
1422 result
.Empty(); // not found
1424 closedir(gs_dirStream
);
1425 gs_dirStream
= (DIR *) NULL
;
1426 #endif // !VMS6.2 or earlier
1431 #elif defined(__WXMAC__)
1433 struct MacDirectoryIterator
1441 static int g_iter_flags
;
1443 static MacDirectoryIterator g_iter
;
1444 wxString g_iter_spec
;
1446 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1450 g_iter_spec
= spec
;
1451 g_iter_spec
.MakeUpper() ;
1452 g_iter_flags
= flags
; /* MATTHEW: [5] Remember flags */
1454 // Find path only so we can concatenate found file onto path
1455 wxString
path(wxPathOnly(spec
));
1458 wxMacFilename2FSSpec( path
, &fsspec
) ;
1459 g_iter
.m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
1460 g_iter
.m_CPB
.hFileInfo
.ioNamePtr
= g_iter
.m_name
;
1461 g_iter
.m_index
= 0 ;
1464 FSpGetDirectoryID( &fsspec
, &g_iter
.m_dirId
, &isDir
) ;
1466 return wxEmptyString
;
1468 return wxFindNextFile( ) ;
1471 wxString
wxFindNextFile()
1480 while ( err
== noErr
)
1483 g_iter
.m_CPB
.dirInfo
.ioFDirIndex
= g_iter
.m_index
;
1484 g_iter
.m_CPB
.dirInfo
.ioDrDirID
= g_iter
.m_dirId
; /* we need to do this every time */
1485 err
= PBGetCatInfoSync((CInfoPBPtr
)&g_iter
.m_CPB
);
1489 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (g_iter_flags
& wxDIR
) ) // we have a directory
1492 if ( ( g_iter
.m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(g_iter_flags
& wxFILE
) )
1500 return wxEmptyString
;
1504 FSMakeFSSpecCompat(g_iter
.m_CPB
.hFileInfo
.ioVRefNum
,
1509 wxString name
= wxMacFSSpec2MacFilename( &spec
) ;
1510 if ( g_iter_spec
.Right(4)==(":*.*") || g_iter_spec
.Right(2)==(":*") || name
.Upper().Matches(g_iter_spec
) )
1513 return wxEmptyString
;
1516 #elif defined(__WXMSW__)
1519 static HANDLE gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1520 static WIN32_FIND_DATA gs_findDataStruct
;
1523 static struct ffblk gs_findDataStruct
;
1525 static struct _find_t gs_findDataStruct
;
1529 static wxString gs_strFileSpec
;
1530 static int gs_findFlags
= 0;
1532 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1536 gs_strFileSpec
= spec
;
1537 gs_findFlags
= flags
; /* MATTHEW: [5] Remember flags */
1539 // Find path only so we can concatenate found file onto path
1540 wxString
path(wxPathOnly(gs_strFileSpec
));
1541 if ( !path
.IsEmpty() )
1542 result
<< path
<< wxT('\\');
1545 if ( gs_hFileStruct
!= INVALID_HANDLE_VALUE
)
1546 FindClose(gs_hFileStruct
);
1548 gs_hFileStruct
= ::FindFirstFile(WXSTRINGCAST spec
, &gs_findDataStruct
);
1550 if ( gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1557 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1559 if (isdir
&& !(flags
& wxDIR
))
1560 return wxFindNextFile();
1561 else if (!isdir
&& flags
&& !(flags
& wxFILE
))
1562 return wxFindNextFile();
1564 result
+= gs_findDataStruct
.cFileName
;
1568 int flag
= _A_NORMAL
;
1573 if (findfirst(WXSTRINGCAST spec
, &gs_findDataStruct
, flag
) == 0)
1575 if (_dos_findfirst(WXSTRINGCAST spec
, flag
, &gs_findDataStruct
) == 0)
1581 attrib
= gs_findDataStruct
.ff_attrib
;
1583 attrib
= gs_findDataStruct
.attrib
;
1586 if (attrib
& _A_SUBDIR
) {
1587 if (!(gs_findFlags
& wxDIR
))
1588 return wxFindNextFile();
1589 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1590 return wxFindNextFile();
1594 gs_findDataStruct
.ff_name
1596 gs_findDataStruct
.name
1606 wxString
wxFindNextFile()
1610 // Find path only so we can concatenate found file onto path
1611 wxString
path(wxPathOnly(gs_strFileSpec
));
1616 if (gs_hFileStruct
== INVALID_HANDLE_VALUE
)
1619 bool success
= (FindNextFile(gs_hFileStruct
, &gs_findDataStruct
) != 0);
1622 FindClose(gs_hFileStruct
);
1623 gs_hFileStruct
= INVALID_HANDLE_VALUE
;
1627 bool isdir
= !!(gs_findDataStruct
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
);
1629 if (isdir
&& !(gs_findFlags
& wxDIR
))
1631 else if (!isdir
&& gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1634 if ( !path
.IsEmpty() )
1635 result
<< path
<< wxT('\\');
1636 result
<< gs_findDataStruct
.cFileName
;
1643 if (findnext(&gs_findDataStruct
) == 0)
1645 if (_dos_findnext(&gs_findDataStruct
) == 0)
1648 /* MATTHEW: [5] Check directory flag */
1652 attrib
= gs_findDataStruct
.ff_attrib
;
1654 attrib
= gs_findDataStruct
.attrib
;
1657 if (attrib
& _A_SUBDIR
) {
1658 if (!(gs_findFlags
& wxDIR
))
1660 } else if (gs_findFlags
&& !(gs_findFlags
& wxFILE
))
1666 gs_findDataStruct
.ff_name
1668 gs_findDataStruct
.name
1677 #elif defined(__WXPM__)
1679 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1684 // TODO: figure something out here for OS/2
1685 gs_strFileSpec = spec;
1686 gs_findFlags = flags;
1688 // Find path only so we can concatenate found file onto path
1689 wxString path(wxPathOnly(gs_strFileSpec));
1690 if ( !path.IsEmpty() )
1691 result << path << wxT('\\');
1693 int flag = _A_NORMAL;
1697 if (_dos_findfirst(WXSTRINGCAST spec, flag, &gs_findDataStruct) == 0)
1700 attrib = gs_findDataStruct.attrib;
1702 if (attrib & _A_SUBDIR) {
1703 if (!(gs_findFlags & wxDIR))
1704 return wxFindNextFile();
1705 } else if (gs_findFlags && !(gs_findFlags & wxFILE))
1706 return wxFindNextFile();
1708 result += gs_findDataStruct.name;
1714 wxString
wxFindNextFile()
1721 #else // generic implementation:
1723 static wxDir
*gs_dir
= NULL
;
1724 static wxString gs_dirPath
;
1726 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1728 gs_dirPath
= wxPathOnly(spec
);
1729 if ( gs_dirPath
.IsEmpty() )
1730 gs_dirPath
= wxT(".");
1731 if ( gs_dirPath
.Last() != wxFILE_SEP_PATH
)
1732 gs_dirPath
<< wxFILE_SEP_PATH
;
1736 gs_dir
= new wxDir(gs_dirPath
);
1738 if ( !gs_dir
->IsOpened() )
1740 wxLogSysError(_("Can not enumerate files '%s'"), spec
);
1741 return wxEmptyString
;
1747 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1748 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1749 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1753 gs_dir
->GetFirst(&result
, wxFileNameFromPath(spec
), dirFlags
);
1754 if ( result
.IsEmpty() )
1757 return gs_dirPath
+ result
;
1760 wxString
wxFindNextFile()
1762 wxASSERT_MSG( gs_dir
, wxT("You must call wxFindFirstFile before!") );
1765 gs_dir
->GetNext(&result
);
1767 if ( result
.IsEmpty() )
1770 return gs_dirPath
+ result
;
1773 #endif // Unix/Windows/OS/2
1775 // Get current working directory.
1776 // If buf is NULL, allocates space using new, else
1778 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1781 buf
= new wxChar
[sz
+1];
1783 char *cbuf
= new char[sz
+1];
1785 if (_getcwd(cbuf
, sz
) == NULL
) {
1786 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1789 SFSaveDisk
= 0x214, CurDirStore
= 0x398
1793 FSMakeFSSpec( - *(short *) SFSaveDisk
, *(long *) CurDirStore
, NULL
, &cwdSpec
) ;
1794 wxString res
= wxMacFSSpec2UnixFilename( &cwdSpec
) ;
1795 strcpy( buf
, res
) ;
1798 if (getcwd(cbuf
, sz
) == NULL
) {
1803 if (_getcwd(buf
, sz
) == NULL
) {
1804 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1809 pb
.ioNamePtr
= (StringPtr
) &fileName
;
1811 pb
.ioRefNum
= LMGetCurApRefNum();
1813 error
= PBGetFCBInfoSync(&pb
);
1814 if ( error
== noErr
)
1816 cwdSpec
.vRefNum
= pb
.ioFCBVRefNum
;
1817 cwdSpec
.parID
= pb
.ioFCBParID
;
1818 cwdSpec
.name
[0] = 0 ;
1819 wxString res
= wxMacFSSpec2MacFilename( &cwdSpec
) ;
1821 strcpy( buf
, res
) ;
1822 buf
[res
.length()]=0 ;
1827 this version will not always give back the application directory on mac
1830 SFSaveDisk = 0x214, CurDirStore = 0x398
1834 FSMakeFSSpec( - *(short *) SFSaveDisk , *(long *) CurDirStore , NULL , &cwdSpec ) ;
1835 wxString res = wxMacFSSpec2UnixFilename( &cwdSpec ) ;
1836 strcpy( buf , res ) ;
1839 #elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
1841 rc
= ::DosQueryCurrentDir( 0 // current drive
1847 if (getcwd(buf
, sz
) == NULL
) {
1855 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1864 static const size_t maxPathLen
= 1024;
1867 wxGetWorkingDirectory(str
.GetWriteBuf(maxPathLen
), maxPathLen
);
1868 str
.UngetWriteBuf();
1873 bool wxSetWorkingDirectory(const wxString
& d
)
1875 #if defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1876 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1877 #elif defined(__WXPM__)
1878 return (::DosSetCurrentDir((PSZ
)d
.c_str()) == 0);
1879 #elif defined(__WINDOWS__)
1882 return (bool)(SetCurrentDirectory(d
) != 0);
1884 // Must change drive, too.
1885 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1888 wxChar firstChar
= d
[0];
1892 firstChar
= firstChar
- 32;
1894 // To a drive number
1895 unsigned int driveNo
= firstChar
- 64;
1898 unsigned int noDrives
;
1899 _dos_setdrive(driveNo
, &noDrives
);
1902 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1910 // Get the OS directory if appropriate (such as the Windows directory).
1911 // On non-Windows platform, probably just return the empty string.
1912 wxString
wxGetOSDirectory()
1914 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1916 GetWindowsDirectory(buf
, 256);
1917 return wxString(buf
);
1919 return wxEmptyString
;
1923 bool wxEndsWithPathSeparator(const wxChar
*pszFileName
)
1925 size_t len
= wxStrlen(pszFileName
);
1929 return wxIsPathSeparator(pszFileName
[len
- 1]);
1932 // find a file in a list of directories, returns false if not found
1933 bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
)
1935 // we assume that it's not empty
1936 wxCHECK_MSG( !wxIsEmpty(pszFile
), FALSE
,
1937 _T("empty file name in wxFindFileInPath"));
1939 // skip path separator in the beginning of the file name if present
1940 if ( wxIsPathSeparator(*pszFile
) )
1943 // copy the path (strtok will modify it)
1944 wxChar
*szPath
= new wxChar
[wxStrlen(pszPath
) + 1];
1945 wxStrcpy(szPath
, pszPath
);
1948 wxChar
*pc
, *save_ptr
;
1949 for ( pc
= wxStrtok(szPath
, wxPATH_SEP
, &save_ptr
);
1951 pc
= wxStrtok((wxChar
*) NULL
, wxPATH_SEP
, &save_ptr
) )
1953 // search for the file in this directory
1955 if ( !wxEndsWithPathSeparator(pc
) )
1956 strFile
+= wxFILE_SEP_PATH
;
1959 if ( FileExists(strFile
) ) {
1965 // suppress warning about unused variable save_ptr when wxStrtok() is a
1966 // macro which throws away its third argument
1971 return pc
!= NULL
; // if true => we breaked from the loop
1974 void WXDLLEXPORT
wxSplitPath(const wxChar
*pszFileName
,
1979 // it can be empty, but it shouldn't be NULL
1980 wxCHECK_RET( pszFileName
, wxT("NULL file name in wxSplitPath") );
1982 wxFileName::SplitPath(pszFileName
, pstrPath
, pstrName
, pstrExt
);
1985 time_t WXDLLEXPORT
wxFileModificationTime(const wxString
& filename
)
1989 wxStat(filename
.fn_str(), &buf
);
1990 return buf
.st_mtime
;
1994 //------------------------------------------------------------------------
1995 // wild character routines
1996 //------------------------------------------------------------------------
1998 bool wxIsWild( const wxString
& pattern
)
2000 wxString tmp
= pattern
;
2001 wxChar
*pat
= WXSTRINGCAST(tmp
);
2004 case wxT('?'): case wxT('*'): case wxT('['): case wxT('{'):
2014 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
2016 #if defined(HAVE_FNMATCH_H)
2018 // this probably won't work well for multibyte chars in Unicode mode?
2020 return fnmatch(pat
.fn_str(), text
.fn_str(), FNM_PERIOD
) == 0;
2022 return fnmatch(pat
.fn_str(), text
.fn_str(), 0) == 0;
2026 // #pragma error Broken implementation of wxMatchWild() -- needs fixing!
2029 * WARNING: this code is broken!
2032 wxString tmp1
= pat
;
2033 wxChar
*pattern
= WXSTRINGCAST(tmp1
);
2034 wxString tmp2
= text
;
2035 wxChar
*str
= WXSTRINGCAST(tmp2
);
2038 bool done
= FALSE
, ret_code
, ok
;
2039 // Below is for vi fans
2040 const wxChar OB
= wxT('{'), CB
= wxT('}');
2042 // dot_special means '.' only matches '.'
2043 if (dot_special
&& *str
== wxT('.') && *pattern
!= *str
)
2046 while ((*pattern
!= wxT('\0')) && (!done
)
2047 && (((*str
==wxT('\0'))&&((*pattern
==OB
)||(*pattern
==wxT('*'))))||(*str
!=wxT('\0')))) {
2051 if (*pattern
!= wxT('\0'))
2057 while ((*str
!=wxT('\0'))
2058 && ((ret_code
=wxMatchWild(pattern
, str
++, FALSE
)) == 0))
2061 while (*str
!= wxT('\0'))
2063 while (*pattern
!= wxT('\0'))
2070 if ((*pattern
== wxT('\0')) || (*pattern
== wxT(']'))) {
2074 if (*pattern
== wxT('\\')) {
2076 if (*pattern
== wxT('\0')) {
2081 if (*(pattern
+ 1) == wxT('-')) {
2084 if (*pattern
== wxT(']')) {
2088 if (*pattern
== wxT('\\')) {
2090 if (*pattern
== wxT('\0')) {
2095 if ((*str
< c
) || (*str
> *pattern
)) {
2099 } else if (*pattern
!= *str
) {
2104 while ((*pattern
!= wxT(']')) && (*pattern
!= wxT('\0'))) {
2105 if ((*pattern
== wxT('\\')) && (*(pattern
+ 1) != wxT('\0')))
2109 if (*pattern
!= wxT('\0')) {
2119 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2122 while (ok
&& (*cp
!= wxT('\0')) && (*pattern
!= wxT('\0'))
2123 && (*pattern
!= wxT(',')) && (*pattern
!= CB
)) {
2124 if (*pattern
== wxT('\\'))
2126 ok
= (*pattern
++ == *cp
++);
2128 if (*pattern
== wxT('\0')) {
2134 while ((*pattern
!= CB
) && (*pattern
!= wxT('\0'))) {
2135 if (*++pattern
== wxT('\\')) {
2136 if (*++pattern
== CB
)
2141 while (*pattern
!=CB
&& *pattern
!=wxT(',') && *pattern
!=wxT('\0')) {
2142 if (*++pattern
== wxT('\\')) {
2143 if (*++pattern
== CB
|| *pattern
== wxT(','))
2148 if (*pattern
!= wxT('\0'))
2153 if (*str
== *pattern
) {
2160 while (*pattern
== wxT('*'))
2162 return ((*str
== wxT('\0')) && (*pattern
== wxT('\0')));
2168 #pragma warning(default:4706) // assignment within conditional expression