1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 // #pragma implementation "utils.h" // Note: this is done in utilscmn.cpp now.
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/cursor.h"
37 #include "wx/msw/private.h" // includes <windows.h>
44 #if !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__SALFORDC__)
52 #if defined(__GNUWIN32__) && !defined(__TWIN32__)
53 #include <sys/unistd.h>
59 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
60 // this (3.1 I believe) and how to test for it.
61 // If this works for Borland 4.0 as well, then no worries.
65 // VZ: there is some code using NetXXX() functions to get the full user name:
66 // I don't think it's a good idea because they don't work under Win95 and
67 // seem to return the same as wxGetUserId() under NT. If you really want
68 // to use them, just #define USE_NET_API
75 #if defined(__WIN32__) && !defined(__WXWINE__)
87 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
93 //// BEGIN for console support: VC++ only
96 #include "wx/msw/msvcrt.h"
100 #include "wx/ioswrap.h"
103 // N.B. BC++ doesn't have istream.h, ostream.h
105 # include <fstream.h>
110 /* Need to undef new if including crtdbg.h */
119 # if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
120 # define new new(__FILE__,__LINE__)
125 /// END for console support
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 // In the WIN.INI file
132 static const wxChar WX_SECTION
[] = wxT("wxWindows");
133 static const wxChar eUSERNAME
[] = wxT("UserName");
135 // these are only used under Win16
137 static const wxChar eHOSTNAME
[] = wxT("HostName");
138 static const wxChar eUSERID
[] = wxT("UserId");
141 // ============================================================================
143 // ============================================================================
145 // ----------------------------------------------------------------------------
146 // get host name and related
147 // ----------------------------------------------------------------------------
149 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
150 bool wxGetHostName(wxChar
*buf
, int maxSize
)
152 #if defined(__WIN32__) && !defined(__TWIN32__)
153 // TODO should use GetComputerNameEx() when available
155 DWORD nSize
= maxSize
;
156 if ( !::GetComputerName(buf
, &nSize
) )
158 wxLogLastError("GetComputerName");
166 const wxChar
*default_host
= wxT("noname");
168 if ((sysname
= wxGetenv(wxT("SYSTEM_NAME"))) == NULL
) {
169 GetProfileString(WX_SECTION
, eHOSTNAME
, default_host
, buf
, maxSize
- 1);
171 wxStrncpy(buf
, sysname
, maxSize
- 1);
172 buf
[maxSize
] = wxT('\0');
173 return *buf
? TRUE
: FALSE
;
177 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
179 return wxGetHostName(buf
, maxSize
);
182 // Get user ID e.g. jacs
183 bool wxGetUserId(wxChar
*buf
, int maxSize
)
185 #if defined(__WIN32__) && !defined(__win32s__) && !defined(__TWIN32__)
186 DWORD nSize
= maxSize
;
187 if ( ::GetUserName(buf
, &nSize
) == 0 )
189 // actually, it does happen on Win9x if the user didn't log on
190 DWORD res
= ::GetEnvironmentVariable(wxT("username"), buf
, maxSize
);
199 #else // Win16 or Win32s
201 const wxChar
*default_id
= wxT("anonymous");
203 // Can't assume we have NIS (PC-NFS) or some other ID daemon
205 if ( (user
= wxGetenv(wxT("USER"))) == NULL
&&
206 (user
= wxGetenv(wxT("LOGNAME"))) == NULL
)
208 // Use wxWindows configuration data (comming soon)
209 GetProfileString(WX_SECTION
, eUSERID
, default_id
, buf
, maxSize
- 1);
213 wxStrncpy(buf
, user
, maxSize
- 1);
216 return *buf
? TRUE
: FALSE
;
220 // Get user name e.g. Julian Smart
221 bool wxGetUserName(wxChar
*buf
, int maxSize
)
223 #if wxUSE_PENWINDOWS && !defined(__WATCOMC__) && !defined(__GNUWIN32__)
224 extern HANDLE g_hPenWin
; // PenWindows Running?
227 // PenWindows Does have a user concept!
228 // Get the current owner of the recognizer
229 GetPrivateProfileString("Current", "User", default_name
, wxBuffer
, maxSize
- 1, "PENWIN.INI");
230 strncpy(buf
, wxBuffer
, maxSize
- 1);
236 CHAR szUserName
[256];
237 if ( !wxGetUserId(szUserName
, WXSIZEOF(szUserName
)) )
240 // TODO how to get the domain name?
243 // the code is based on the MSDN example (also see KB article Q119670)
244 WCHAR wszUserName
[256]; // Unicode user name
245 WCHAR wszDomain
[256];
248 USER_INFO_2
*ui2
; // User structure
250 // Convert ANSI user name and domain to Unicode
251 MultiByteToWideChar( CP_ACP
, 0, szUserName
, strlen(szUserName
)+1,
252 wszUserName
, WXSIZEOF(wszUserName
) );
253 MultiByteToWideChar( CP_ACP
, 0, szDomain
, strlen(szDomain
)+1,
254 wszDomain
, WXSIZEOF(wszDomain
) );
256 // Get the computer name of a DC for the domain.
257 if ( NetGetDCName( NULL
, wszDomain
, &ComputerName
) != NERR_Success
)
259 wxLogError(wxT("Can not find domain controller"));
264 // Look up the user on the DC
265 NET_API_STATUS status
= NetUserGetInfo( (LPWSTR
)ComputerName
,
266 (LPWSTR
)&wszUserName
,
267 2, // level - we want USER_INFO_2
275 case NERR_InvalidComputer
:
276 wxLogError(wxT("Invalid domain controller name."));
280 case NERR_UserNotFound
:
281 wxLogError(wxT("Invalid user name '%s'."), szUserName
);
286 wxLogSysError(wxT("Can't get information about user"));
291 // Convert the Unicode full name to ANSI
292 WideCharToMultiByte( CP_ACP
, 0, ui2
->usri2_full_name
, -1,
293 buf
, maxSize
, NULL
, NULL
);
298 wxLogError(wxT("Couldn't look up full user name."));
301 #else // !USE_NET_API
302 // Could use NIS, MS-Mail or other site specific programs
303 // Use wxWindows configuration data
304 bool ok
= GetProfileString(WX_SECTION
, eUSERNAME
, wxT(""), buf
, maxSize
- 1) != 0;
307 ok
= wxGetUserId(buf
, maxSize
);
312 wxStrncpy(buf
, wxT("Unknown User"), maxSize
);
320 const wxChar
* wxGetHomeDir(wxString
*pstr
)
322 wxString
& strDir
= *pstr
;
324 #if defined(__UNIX__) && !defined(__TWIN32__)
325 const wxChar
*szHome
= wxGetenv("HOME");
326 if ( szHome
== NULL
) {
328 wxLogWarning(_("can't find user's HOME, using current directory."));
334 // add a trailing slash if needed
335 if ( strDir
.Last() != wxT('/') )
339 const wxChar
*szHome
= wxGetenv(wxT("HOMEDRIVE"));
340 if ( szHome
!= NULL
)
342 szHome
= wxGetenv(wxT("HOMEPATH"));
343 if ( szHome
!= NULL
) {
346 // the idea is that under NT these variables have default values
347 // of "%systemdrive%:" and "\\". As we don't want to create our
348 // config files in the root directory of the system drive, we will
349 // create it in our program's dir. However, if the user took care
350 // to set HOMEPATH to something other than "\\", we suppose that he
351 // knows what he is doing and use the supplied value.
352 if ( wxStrcmp(szHome
, wxT("\\")) != 0 )
353 return strDir
.c_str();
357 // Win16 has no idea about home, so use the working directory instead
360 // 260 was taken from windef.h
366 ::GetModuleFileName(::GetModuleHandle(NULL
),
367 strPath
.GetWriteBuf(MAX_PATH
), MAX_PATH
);
368 strPath
.UngetWriteBuf();
370 // extract the dir name
371 wxSplitPath(strPath
, &strDir
, NULL
, NULL
);
375 return strDir
.c_str();
378 wxChar
*wxGetUserHome(const wxString
& user
)
380 // VZ: the old code here never worked for user != "" anyhow! Moreover, it
381 // returned sometimes a malloc()'d pointer, sometimes a pointer to a
382 // static buffer and sometimes I don't even know what.
383 static wxString s_home
;
385 return (wxChar
*)wxGetHomeDir(&s_home
);
388 bool wxDirExists(const wxString
& dir
)
390 #if defined(__WIN32__)
391 WIN32_FIND_DATA fileInfo
;
394 struct ffblk fileInfo
;
396 struct find_t fileInfo
;
400 #if defined(__WIN32__)
401 HANDLE h
= ::FindFirstFile(dir
, &fileInfo
);
403 if ( h
== INVALID_HANDLE_VALUE
)
405 wxLogLastError("FindFirstFile");
412 return (fileInfo
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) != 0;
414 // In Borland findfirst has a different argument
415 // ordering from _dos_findfirst. But _dos_findfirst
416 // _should_ be ok in both MS and Borland... why not?
418 return (findfirst(dir
, &fileInfo
, _A_SUBDIR
) == 0 &&
419 (fileInfo
.ff_attrib
& _A_SUBDIR
) != 0);
421 return (_dos_findfirst(dir
, _A_SUBDIR
, &fileInfo
) == 0) &&
422 ((fileInfo
.attrib
& _A_SUBDIR
) != 0);
427 // ----------------------------------------------------------------------------
428 // process management
429 // ----------------------------------------------------------------------------
431 int wxKill(long pid
, int sig
)
433 // TODO use SendMessage(WM_QUIT) and TerminateProcess() if needed
438 // Execute a program in an Interactive Shell
439 bool wxShell(const wxString
& command
)
441 wxChar
*shell
= wxGetenv(wxT("COMSPEC"));
443 shell
= wxT("\\COMMAND.COM");
453 // pass the command to execute to the command processor
454 cmd
.Printf(wxT("%s /c %s"), shell
, command
.c_str());
457 return wxExecute(cmd
, FALSE
) != 0;
460 // ----------------------------------------------------------------------------
462 // ----------------------------------------------------------------------------
464 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
465 long wxGetFreeMemory()
467 #if defined(__WIN32__) && !defined(__BORLANDC__) && !defined(__TWIN32__)
468 MEMORYSTATUS memStatus
;
469 memStatus
.dwLength
= sizeof(MEMORYSTATUS
);
470 GlobalMemoryStatus(&memStatus
);
471 return memStatus
.dwAvailPhys
;
473 return (long)GetFreeSpace(0);
480 ::MessageBeep((UINT
)-1); // default sound
483 wxString
wxGetOsDescription()
491 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
492 if ( ::GetVersionEx(&info
) )
494 switch ( info
.dwPlatformId
)
496 case VER_PLATFORM_WIN32s
:
497 str
= _("Win32s on Windows 3.1");
500 case VER_PLATFORM_WIN32_WINDOWS
:
501 str
.Printf(_("Windows 9%c"),
502 info
.dwMinorVersion
== 0 ? _T('5') : _T('9'));
503 if ( !wxIsEmpty(info
.szCSDVersion
) )
505 str
<< _T(" (") << info
.szCSDVersion
<< _T(')');
509 case VER_PLATFORM_WIN32_NT
:
510 str
.Printf(_T("Windows NT %lu.%lu (build %lu"),
514 if ( !wxIsEmpty(info
.szCSDVersion
) )
516 str
<< _T(", ") << info
.szCSDVersion
;
524 wxFAIL_MSG( _T("GetVersionEx() failed") ); // should never happen
529 return _("Windows 3.1");
533 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
535 #if defined(__WIN32__) && !defined(__SC__)
539 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
540 if ( ::GetVersionEx(&info
) )
543 *majorVsn
= info
.dwMajorVersion
;
545 *minorVsn
= info
.dwMinorVersion
;
547 switch ( info
.dwPlatformId
)
549 case VER_PLATFORM_WIN32s
:
552 case VER_PLATFORM_WIN32_WINDOWS
:
555 case VER_PLATFORM_WIN32_NT
:
560 return wxWINDOWS
; // error if we get here, return generic value
562 int retValue
= wxWINDOWS
;
563 #ifdef __WINDOWS_386__
566 #if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS
567 extern HANDLE g_hPenWin
;
568 retValue
= g_hPenWin
? wxPENWINDOWS
: wxWINDOWS
;
581 // ----------------------------------------------------------------------------
583 // ----------------------------------------------------------------------------
587 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
588 static bool gs_inTimer
= FALSE
;
590 class wxSleepTimer
: public wxTimer
593 virtual void Notify()
600 static wxTimer
*wxTheSleepTimer
= NULL
;
602 void wxUsleep(unsigned long milliseconds
)
605 ::Sleep(milliseconds
);
610 wxTheSleepTimer
= new wxSleepTimer
;
612 wxTheSleepTimer
->Start(milliseconds
);
615 if (wxTheApp
->Pending())
616 wxTheApp
->Dispatch();
618 delete wxTheSleepTimer
;
619 wxTheSleepTimer
= NULL
;
623 void wxSleep(int nSecs
)
628 wxTheSleepTimer
= new wxSleepTimer
;
630 wxTheSleepTimer
->Start(nSecs
*1000);
633 if (wxTheApp
->Pending())
634 wxTheApp
->Dispatch();
636 delete wxTheSleepTimer
;
637 wxTheSleepTimer
= NULL
;
640 // Consume all events until no more left
646 #elif defined(__WIN32__) // wxUSE_GUI
648 void wxUsleep(unsigned long milliseconds
)
650 ::Sleep(milliseconds
);
653 void wxSleep(int nSecs
)
655 wxUsleep(1000*nSecs
);
658 #endif // wxUSE_GUI/!wxUSE_GUI
660 // ----------------------------------------------------------------------------
661 // deprecated (in favour of wxLog) log functions
662 // ----------------------------------------------------------------------------
666 // Output a debug mess., in a system dependent fashion.
667 void wxDebugMsg(const wxChar
*fmt
...)
670 static wxChar buffer
[512];
672 if (!wxTheApp
->GetWantDebugOutput())
677 wvsprintf(buffer
,fmt
,ap
) ;
678 OutputDebugString((LPCTSTR
)buffer
) ;
683 // Non-fatal error: pop up message box and (possibly) continue
684 void wxError(const wxString
& msg
, const wxString
& title
)
686 wxSprintf(wxBuffer
, wxT("%s\nContinue?"), WXSTRINGCAST msg
);
687 if (MessageBox(NULL
, (LPCTSTR
)wxBuffer
, (LPCTSTR
)WXSTRINGCAST title
,
688 MB_ICONSTOP
| MB_YESNO
) == IDNO
)
692 // Fatal error: pop up message box and abort
693 void wxFatalError(const wxString
& msg
, const wxString
& title
)
695 wxSprintf(wxBuffer
, wxT("%s: %s"), WXSTRINGCAST title
, WXSTRINGCAST msg
);
696 FatalAppExit(0, (LPCTSTR
)wxBuffer
);
699 // ----------------------------------------------------------------------------
700 // functions to work with .INI files
701 // ----------------------------------------------------------------------------
703 // Reading and writing resources (eg WIN.INI, .Xdefaults)
705 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
708 // Don't know what the correct cast should be, but it doesn't
709 // compile in BC++/16-bit without this cast.
710 #if !defined(__WIN32__)
711 return (WritePrivateProfileString((const char*) section
, (const char*) entry
, (const char*) value
, (const char*) file
) != 0);
713 return (WritePrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)value
, (LPCTSTR
)WXSTRINGCAST file
) != 0);
716 return (WriteProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)WXSTRINGCAST value
) != 0);
719 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
722 buf
.Printf(wxT("%.4f"), value
);
724 return wxWriteResource(section
, entry
, buf
, file
);
727 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
730 buf
.Printf(wxT("%ld"), value
);
732 return wxWriteResource(section
, entry
, buf
, file
);
735 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
738 buf
.Printf(wxT("%d"), value
);
740 return wxWriteResource(section
, entry
, buf
, file
);
743 bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
)
745 static const wxChar defunkt
[] = wxT("$$default");
748 int n
= GetPrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
749 (LPTSTR
)wxBuffer
, 1000, (LPCTSTR
)WXSTRINGCAST file
);
750 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
755 int n
= GetProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
756 (LPTSTR
)wxBuffer
, 1000);
757 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
760 if (*value
) delete[] (*value
);
761 *value
= copystring(wxBuffer
);
765 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
768 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
771 *value
= (float)wxStrtod(s
, NULL
);
778 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
781 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
784 *value
= wxStrtol(s
, NULL
, 10);
791 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
794 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
797 *value
= (int)wxStrtol(s
, NULL
, 10);
803 #endif // wxUSE_RESOURCES
805 // ---------------------------------------------------------------------------
806 // helper functions for showing a "busy" cursor
807 // ---------------------------------------------------------------------------
809 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
810 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
811 static int gs_wxBusyCursorCount
= 0;
813 // Set the cursor to the busy cursor for all windows
814 void wxBeginBusyCursor(wxCursor
*cursor
)
816 if ( gs_wxBusyCursorCount
++ == 0 )
818 gs_wxBusyCursor
= (HCURSOR
)cursor
->GetHCURSOR();
819 gs_wxBusyCursorOld
= ::SetCursor(gs_wxBusyCursor
);
821 //else: nothing to do, already set
824 // Restore cursor to normal
825 void wxEndBusyCursor()
827 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
828 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
830 if ( --gs_wxBusyCursorCount
== 0 )
832 ::SetCursor(gs_wxBusyCursorOld
);
834 gs_wxBusyCursorOld
= 0;
838 // TRUE if we're between the above two calls
841 return (gs_wxBusyCursorCount
> 0);
844 // Check whether this window wants to process messages, e.g. Stop button
845 // in long calculations.
846 bool wxCheckForInterrupt(wxWindow
*wnd
)
848 wxCHECK( wnd
, FALSE
);
851 while ( ::PeekMessage(&msg
, GetHwndOf(wnd
), 0, 0, PM_REMOVE
) )
853 ::TranslateMessage(&msg
);
854 ::DispatchMessage(&msg
);
862 // MSW only: get user-defined resource from the .res file.
863 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
865 wxChar
*wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
)
867 HRSRC hResource
= ::FindResource(wxGetInstance(), resourceName
, resourceType
);
868 if ( hResource
== 0 )
871 HGLOBAL hData
= ::LoadResource(wxGetInstance(), hResource
);
875 wxChar
*theText
= (wxChar
*)::LockResource(hData
);
879 // Not all compilers put a zero at the end of the resource (e.g. BC++ doesn't).
880 // so we need to find the length of the resource.
881 int len
= ::SizeofResource(wxGetInstance(), hResource
);
882 wxChar
*s
= new wxChar
[len
+1];
883 wxStrncpy(s
,theText
,len
);
886 // wxChar *s = copystring(theText);
890 UnlockResource(hData
);
894 // GlobalFree(hData);
899 // ----------------------------------------------------------------------------
901 // ----------------------------------------------------------------------------
903 void wxGetMousePosition( int* x
, int* y
)
906 GetCursorPos( & pt
);
911 // Return TRUE if we have a colour display
912 bool wxColourDisplay()
915 int noCols
= GetDeviceCaps(dc
, NUMCOLORS
);
917 return (noCols
== -1) || (noCols
> 2);
920 // Returns depth of screen
924 return GetDeviceCaps(dc
, PLANES
) * GetDeviceCaps(dc
, BITSPIXEL
);
927 // Get size of display
928 void wxDisplaySize(int *width
, int *height
)
932 if ( width
) *width
= GetDeviceCaps(dc
, HORZRES
);
933 if ( height
) *height
= GetDeviceCaps(dc
, VERTRES
);
936 // ---------------------------------------------------------------------------
937 // window information functions
938 // ---------------------------------------------------------------------------
940 wxString WXDLLEXPORT
wxGetWindowText(WXHWND hWnd
)
943 int len
= GetWindowTextLength((HWND
)hWnd
) + 1;
944 GetWindowText((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
950 wxString WXDLLEXPORT
wxGetWindowClass(WXHWND hWnd
)
954 int len
= 256; // some starting value
958 // as we've #undefined GetClassName we must now manually choose the
959 // right function to call
972 #endif // Twin32/!Twin32
973 #endif // Unicode/ANSI
975 ((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
980 // the class name might have been truncated, retry with larger
993 WXWORD WXDLLEXPORT
wxGetWindowId(WXHWND hWnd
)
996 return GetWindowWord((HWND
)hWnd
, GWW_ID
);
998 return GetWindowLong((HWND
)hWnd
, GWL_ID
);
1003 //------------------------------------------------------------------------
1004 // wild character routines
1005 //------------------------------------------------------------------------
1007 bool wxIsWild( const wxString
& pattern
)
1009 wxString tmp
= pattern
;
1010 char *pat
= WXSTRINGCAST(tmp
);
1013 case '?': case '*': case '[': case '{':
1024 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1026 wxString tmp1
= pat
;
1027 char *pattern
= WXSTRINGCAST(tmp1
);
1028 wxString tmp2
= text
;
1029 char *str
= WXSTRINGCAST(tmp2
);
1032 bool done
= FALSE
, ret_code
, ok
;
1033 // Below is for vi fans
1034 const char OB
= '{', CB
= '}';
1036 // dot_special means '.' only matches '.'
1037 if (dot_special
&& *str
== '.' && *pattern
!= *str
)
1040 while ((*pattern
!= '\0') && (!done
)
1041 && (((*str
=='\0')&&((*pattern
==OB
)||(*pattern
=='*')))||(*str
!='\0'))) {
1045 if (*pattern
!= '\0')
1052 && (!(ret_code
=wxMatchWild(pattern
, str
++, FALSE
))))
1055 while (*str
!= '\0')
1057 while (*pattern
!= '\0')
1064 if ((*pattern
== '\0') || (*pattern
== ']')) {
1068 if (*pattern
== '\\') {
1070 if (*pattern
== '\0') {
1075 if (*(pattern
+ 1) == '-') {
1078 if (*pattern
== ']') {
1082 if (*pattern
== '\\') {
1084 if (*pattern
== '\0') {
1089 if ((*str
< c
) || (*str
> *pattern
)) {
1093 } else if (*pattern
!= *str
) {
1098 while ((*pattern
!= ']') && (*pattern
!= '\0')) {
1099 if ((*pattern
== '\\') && (*(pattern
+ 1) != '\0'))
1103 if (*pattern
!= '\0') {
1113 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1116 while (ok
&& (*cp
!= '\0') && (*pattern
!= '\0')
1117 && (*pattern
!= ',') && (*pattern
!= CB
)) {
1118 if (*pattern
== '\\')
1120 ok
= (*pattern
++ == *cp
++);
1122 if (*pattern
== '\0') {
1128 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1129 if (*++pattern
== '\\') {
1130 if (*++pattern
== CB
)
1135 while (*pattern
!=CB
&& *pattern
!=',' && *pattern
!='\0') {
1136 if (*++pattern
== '\\') {
1137 if (*++pattern
== CB
|| *pattern
== ',')
1142 if (*pattern
!= '\0')
1147 if (*str
== *pattern
) {
1154 while (*pattern
== '*')
1156 return ((*str
== '\0') && (*pattern
== '\0'));
1163 // maximum mumber of lines the output console should have
1164 static const WORD MAX_CONSOLE_LINES
= 500;
1166 BOOL WINAPI
MyConsoleHandler( DWORD dwCtrlType
) { // control signal type
1171 void wxRedirectIOToConsole()
1175 CONSOLE_SCREEN_BUFFER_INFO coninfo
;
1178 // allocate a console for this app
1181 // set the screen buffer to be big enough to let us scroll text
1182 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
),
1184 coninfo
.dwSize
.Y
= MAX_CONSOLE_LINES
;
1185 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE
),
1188 // redirect unbuffered STDOUT to the console
1189 lStdHandle
= (long)GetStdHandle(STD_OUTPUT_HANDLE
);
1190 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1191 if(hConHandle
<= 0) return;
1192 fp
= _fdopen( hConHandle
, "w" );
1194 setvbuf( stdout
, NULL
, _IONBF
, 0 );
1196 // redirect unbuffered STDIN to the console
1197 lStdHandle
= (long)GetStdHandle(STD_INPUT_HANDLE
);
1198 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1199 if(hConHandle
<= 0) return;
1200 fp
= _fdopen( hConHandle
, "r" );
1202 setvbuf( stdin
, NULL
, _IONBF
, 0 );
1204 // redirect unbuffered STDERR to the console
1205 lStdHandle
= (long)GetStdHandle(STD_ERROR_HANDLE
);
1206 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1207 if(hConHandle
<= 0) return;
1208 fp
= _fdopen( hConHandle
, "w" );
1210 setvbuf( stderr
, NULL
, _IONBF
, 0 );
1212 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
1213 // point to console as well
1214 ios::sync_with_stdio();
1216 SetConsoleCtrlHandler(MyConsoleHandler
, TRUE
);
1220 void wxRedirectIOToConsole()