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 // Chris Breeze 27/5/98: revised WIN32 code to
484 // detect WindowsNT correctly
485 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
487 if (majorVsn
) *majorVsn
= 0;
488 if (minorVsn
) *minorVsn
= 0;
490 #if defined(__WIN32__) && !defined(__SC__)
492 memset(&info
, 0, sizeof(OSVERSIONINFO
));
493 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
494 if (GetVersionEx(&info
))
496 if (majorVsn
) *majorVsn
= info
.dwMajorVersion
;
497 if (minorVsn
) *minorVsn
= info
.dwMinorVersion
;
498 switch (info
.dwPlatformId
)
500 case VER_PLATFORM_WIN32s
:
503 case VER_PLATFORM_WIN32_WINDOWS
:
506 case VER_PLATFORM_WIN32_NT
:
511 return wxWINDOWS
; // error if we get here, return generic value
515 # ifdef __WINDOWS_386__
518 # if !defined(__WATCOMC__) && !defined(GNUWIN32) && wxUSE_PENWINDOWS
519 extern HANDLE g_hPenWin
;
520 retValue
= g_hPenWin
? wxPENWINDOWS
: wxWINDOWS
;
523 // @@@@ To be completed. I don't have the manual here...
524 if (majorVsn
) *majorVsn
= 3 ;
525 if (minorVsn
) *minorVsn
= 1 ;
530 // ----------------------------------------------------------------------------
532 // ----------------------------------------------------------------------------
536 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
537 static bool gs_inTimer
= FALSE
;
539 class wxSleepTimer
: public wxTimer
542 virtual void Notify()
549 static wxTimer
*wxTheSleepTimer
= NULL
;
551 void wxUsleep(unsigned long milliseconds
)
554 ::Sleep(milliseconds
);
559 wxTheSleepTimer
= new wxSleepTimer
;
561 wxTheSleepTimer
->Start(milliseconds
);
564 if (wxTheApp
->Pending())
565 wxTheApp
->Dispatch();
567 delete wxTheSleepTimer
;
568 wxTheSleepTimer
= NULL
;
572 void wxSleep(int nSecs
)
577 wxTheSleepTimer
= new wxSleepTimer
;
579 wxTheSleepTimer
->Start(nSecs
*1000);
582 if (wxTheApp
->Pending())
583 wxTheApp
->Dispatch();
585 delete wxTheSleepTimer
;
586 wxTheSleepTimer
= NULL
;
589 // Consume all events until no more left
595 #elif defined(__WIN32__) // wxUSE_GUI
597 void wxUsleep(unsigned long milliseconds
)
599 ::Sleep(milliseconds
);
602 void wxSleep(int nSecs
)
604 wxUsleep(1000*nSecs
);
607 #endif // wxUSE_GUI/!wxUSE_GUI
609 // ----------------------------------------------------------------------------
610 // deprecated (in favour of wxLog) log functions
611 // ----------------------------------------------------------------------------
615 // Output a debug mess., in a system dependent fashion.
616 void wxDebugMsg(const wxChar
*fmt
...)
619 static wxChar buffer
[512];
621 if (!wxTheApp
->GetWantDebugOutput())
626 wvsprintf(buffer
,fmt
,ap
) ;
627 OutputDebugString((LPCTSTR
)buffer
) ;
632 // Non-fatal error: pop up message box and (possibly) continue
633 void wxError(const wxString
& msg
, const wxString
& title
)
635 wxSprintf(wxBuffer
, wxT("%s\nContinue?"), WXSTRINGCAST msg
);
636 if (MessageBox(NULL
, (LPCTSTR
)wxBuffer
, (LPCTSTR
)WXSTRINGCAST title
,
637 MB_ICONSTOP
| MB_YESNO
) == IDNO
)
641 // Fatal error: pop up message box and abort
642 void wxFatalError(const wxString
& msg
, const wxString
& title
)
644 wxSprintf(wxBuffer
, wxT("%s: %s"), WXSTRINGCAST title
, WXSTRINGCAST msg
);
645 FatalAppExit(0, (LPCTSTR
)wxBuffer
);
648 // ----------------------------------------------------------------------------
649 // functions to work with .INI files
650 // ----------------------------------------------------------------------------
652 // Reading and writing resources (eg WIN.INI, .Xdefaults)
654 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
657 // Don't know what the correct cast should be, but it doesn't
658 // compile in BC++/16-bit without this cast.
659 #if !defined(__WIN32__)
660 return (WritePrivateProfileString((const char*) section
, (const char*) entry
, (const char*) value
, (const char*) file
) != 0);
662 return (WritePrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)value
, (LPCTSTR
)WXSTRINGCAST file
) != 0);
665 return (WriteProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)WXSTRINGCAST value
) != 0);
668 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
671 buf
.Printf(wxT("%.4f"), value
);
673 return wxWriteResource(section
, entry
, buf
, file
);
676 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
679 buf
.Printf(wxT("%ld"), value
);
681 return wxWriteResource(section
, entry
, buf
, file
);
684 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
687 buf
.Printf(wxT("%d"), value
);
689 return wxWriteResource(section
, entry
, buf
, file
);
692 bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
)
694 static const wxChar defunkt
[] = wxT("$$default");
697 int n
= GetPrivateProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
698 (LPTSTR
)wxBuffer
, 1000, (LPCTSTR
)WXSTRINGCAST file
);
699 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
704 int n
= GetProfileString((LPCTSTR
)WXSTRINGCAST section
, (LPCTSTR
)WXSTRINGCAST entry
, (LPCTSTR
)defunkt
,
705 (LPTSTR
)wxBuffer
, 1000);
706 if (n
== 0 || wxStrcmp(wxBuffer
, defunkt
) == 0)
709 if (*value
) delete[] (*value
);
710 *value
= copystring(wxBuffer
);
714 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
717 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
720 *value
= (float)wxStrtod(s
, NULL
);
727 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
730 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
733 *value
= wxStrtol(s
, NULL
, 10);
740 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
743 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
746 *value
= (int)wxStrtol(s
, NULL
, 10);
752 #endif // wxUSE_RESOURCES
754 // ---------------------------------------------------------------------------
755 // helper functions for showing a "busy" cursor
756 // ---------------------------------------------------------------------------
758 HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
759 HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
760 static int gs_wxBusyCursorCount
= 0;
762 // Set the cursor to the busy cursor for all windows
763 void wxBeginBusyCursor(wxCursor
*cursor
)
765 if ( gs_wxBusyCursorCount
++ == 0 )
767 gs_wxBusyCursor
= (HCURSOR
)cursor
->GetHCURSOR();
768 gs_wxBusyCursorOld
= ::SetCursor(gs_wxBusyCursor
);
770 //else: nothing to do, already set
773 // Restore cursor to normal
774 void wxEndBusyCursor()
776 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
777 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
779 if ( --gs_wxBusyCursorCount
== 0 )
781 ::SetCursor(gs_wxBusyCursorOld
);
783 gs_wxBusyCursorOld
= 0;
787 // TRUE if we're between the above two calls
790 return (gs_wxBusyCursorCount
> 0);
793 // Check whether this window wants to process messages, e.g. Stop button
794 // in long calculations.
795 bool wxCheckForInterrupt(wxWindow
*wnd
)
797 wxCHECK( wnd
, FALSE
);
800 while ( ::PeekMessage(&msg
, GetHwndOf(wnd
), 0, 0, PM_REMOVE
) )
802 ::TranslateMessage(&msg
);
803 ::DispatchMessage(&msg
);
811 // MSW only: get user-defined resource from the .res file.
812 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
814 wxChar
*wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
)
816 HRSRC hResource
= ::FindResource(wxGetInstance(), resourceName
, resourceType
);
817 if ( hResource
== 0 )
820 HGLOBAL hData
= ::LoadResource(wxGetInstance(), hResource
);
824 wxChar
*theText
= (wxChar
*)::LockResource(hData
);
828 wxChar
*s
= copystring(theText
);
832 UnlockResource(hData
);
836 // GlobalFree(hData);
841 // ----------------------------------------------------------------------------
843 // ----------------------------------------------------------------------------
845 void wxGetMousePosition( int* x
, int* y
)
848 GetCursorPos( & pt
);
853 // Return TRUE if we have a colour display
854 bool wxColourDisplay()
857 int noCols
= GetDeviceCaps(dc
, NUMCOLORS
);
859 return (noCols
== -1) || (noCols
> 2);
862 // Returns depth of screen
866 return GetDeviceCaps(dc
, PLANES
) * GetDeviceCaps(dc
, BITSPIXEL
);
869 // Get size of display
870 void wxDisplaySize(int *width
, int *height
)
874 if ( width
) *width
= GetDeviceCaps(dc
, HORZRES
);
875 if ( height
) *height
= GetDeviceCaps(dc
, VERTRES
);
878 // ---------------------------------------------------------------------------
879 // window information functions
880 // ---------------------------------------------------------------------------
882 wxString WXDLLEXPORT
wxGetWindowText(WXHWND hWnd
)
885 int len
= GetWindowTextLength((HWND
)hWnd
) + 1;
886 GetWindowText((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
892 wxString WXDLLEXPORT
wxGetWindowClass(WXHWND hWnd
)
896 int len
= 256; // some starting value
900 // as we've #undefined GetClassName we must now manually choose the
901 // right function to call
914 #endif // Twin32/!Twin32
915 #endif // Unicode/ANSI
917 ((HWND
)hWnd
, str
.GetWriteBuf(len
), len
);
922 // the class name might have been truncated, retry with larger
935 WXWORD WXDLLEXPORT
wxGetWindowId(WXHWND hWnd
)
938 return GetWindowWord((HWND
)hWnd
, GWW_ID
);
940 return GetWindowLong((HWND
)hWnd
, GWL_ID
);
945 //------------------------------------------------------------------------
946 // wild character routines
947 //------------------------------------------------------------------------
949 bool wxIsWild( const wxString
& pattern
)
951 wxString tmp
= pattern
;
952 char *pat
= WXSTRINGCAST(tmp
);
955 case '?': case '*': case '[': case '{':
966 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
969 char *pattern
= WXSTRINGCAST(tmp1
);
970 wxString tmp2
= text
;
971 char *str
= WXSTRINGCAST(tmp2
);
974 bool done
= FALSE
, ret_code
, ok
;
975 // Below is for vi fans
976 const char OB
= '{', CB
= '}';
978 // dot_special means '.' only matches '.'
979 if (dot_special
&& *str
== '.' && *pattern
!= *str
)
982 while ((*pattern
!= '\0') && (!done
)
983 && (((*str
=='\0')&&((*pattern
==OB
)||(*pattern
=='*')))||(*str
!='\0'))) {
987 if (*pattern
!= '\0')
994 && (!(ret_code
=wxMatchWild(pattern
, str
++, FALSE
))))
999 while (*pattern
!= '\0')
1006 if ((*pattern
== '\0') || (*pattern
== ']')) {
1010 if (*pattern
== '\\') {
1012 if (*pattern
== '\0') {
1017 if (*(pattern
+ 1) == '-') {
1020 if (*pattern
== ']') {
1024 if (*pattern
== '\\') {
1026 if (*pattern
== '\0') {
1031 if ((*str
< c
) || (*str
> *pattern
)) {
1035 } else if (*pattern
!= *str
) {
1040 while ((*pattern
!= ']') && (*pattern
!= '\0')) {
1041 if ((*pattern
== '\\') && (*(pattern
+ 1) != '\0'))
1045 if (*pattern
!= '\0') {
1055 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1058 while (ok
&& (*cp
!= '\0') && (*pattern
!= '\0')
1059 && (*pattern
!= ',') && (*pattern
!= CB
)) {
1060 if (*pattern
== '\\')
1062 ok
= (*pattern
++ == *cp
++);
1064 if (*pattern
== '\0') {
1070 while ((*pattern
!= CB
) && (*pattern
!= '\0')) {
1071 if (*++pattern
== '\\') {
1072 if (*++pattern
== CB
)
1077 while (*pattern
!=CB
&& *pattern
!=',' && *pattern
!='\0') {
1078 if (*++pattern
== '\\') {
1079 if (*++pattern
== CB
|| *pattern
== ',')
1084 if (*pattern
!= '\0')
1089 if (*str
== *pattern
) {
1096 while (*pattern
== '*')
1098 return ((*str
== '\0') && (*pattern
== '\0'));
1105 // maximum mumber of lines the output console should have
1106 static const WORD MAX_CONSOLE_LINES
= 500;
1108 BOOL WINAPI
MyConsoleHandler( DWORD dwCtrlType
) { // control signal type
1113 void wxRedirectIOToConsole()
1117 CONSOLE_SCREEN_BUFFER_INFO coninfo
;
1120 // allocate a console for this app
1123 // set the screen buffer to be big enough to let us scroll text
1124 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
),
1126 coninfo
.dwSize
.Y
= MAX_CONSOLE_LINES
;
1127 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE
),
1130 // redirect unbuffered STDOUT to the console
1131 lStdHandle
= (long)GetStdHandle(STD_OUTPUT_HANDLE
);
1132 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1133 if(hConHandle
<= 0) return;
1134 fp
= _fdopen( hConHandle
, "w" );
1136 setvbuf( stdout
, NULL
, _IONBF
, 0 );
1138 // redirect unbuffered STDIN to the console
1139 lStdHandle
= (long)GetStdHandle(STD_INPUT_HANDLE
);
1140 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1141 if(hConHandle
<= 0) return;
1142 fp
= _fdopen( hConHandle
, "r" );
1144 setvbuf( stdin
, NULL
, _IONBF
, 0 );
1146 // redirect unbuffered STDERR to the console
1147 lStdHandle
= (long)GetStdHandle(STD_ERROR_HANDLE
);
1148 hConHandle
= _open_osfhandle(lStdHandle
, _O_TEXT
);
1149 if(hConHandle
<= 0) return;
1150 fp
= _fdopen( hConHandle
, "w" );
1152 setvbuf( stderr
, NULL
, _IONBF
, 0 );
1154 // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
1155 // point to console as well
1156 ios::sync_with_stdio();
1158 SetConsoleCtrlHandler(MyConsoleHandler
, TRUE
);
1162 void wxRedirectIOToConsole()