]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "utils.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
40 #include "wx/window.h"
43 #include "wx/msgdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/textctrl.h" // for wxTE_PASSWORD
47 #include "wx/menuitem.h"
54 #include "wx/process.h"
55 #include "wx/txtstrm.h"
63 #if !defined(__WATCOMC__)
64 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
70 #include "wx/colordlg.h"
71 #include "wx/fontdlg.h"
72 #include "wx/notebook.h"
74 #include "wx/statusbr.h"
80 #include <sys/types.h>
89 #include "wx/msw/private.h"
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 #if WXWIN_COMPATIBILITY_2_2
97 const wxChar
*wxInternalErrorStr
= wxT("wxWindows Internal Error");
98 const wxChar
*wxFatalErrorStr
= wxT("wxWindows Fatal Error");
99 #endif // WXWIN_COMPATIBILITY_2_2
101 // ----------------------------------------------------------------------------
102 // function protoypes
103 // ----------------------------------------------------------------------------
105 // ============================================================================
107 // ============================================================================
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 #if defined(__WXMAC__) && !defined(__DARWIN__)
114 int strcasecmp(const char *str_1
, const char *str_2
)
116 register char c1
, c2
;
118 c1
= tolower(*str_1
++);
119 c2
= tolower(*str_2
++);
120 } while ( c1
&& (c1
== c2
) );
125 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
128 register char c1
, c2
;
131 c1
= tolower(*str_1
++);
132 c2
= tolower(*str_2
++);
142 #endif // __WXMAC__ && !__DARWIN__
144 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
145 // we have no strI functions under VMS, therefore I have implemented
146 // an inefficient but portable version: convert copies of strings to lowercase
147 // and then use the normal comparison
148 static void myLowerString(char *s
)
151 if(isalpha(*s
)) *s
= (char)tolower(*s
);
156 int strcasecmp(const char *str_1
, const char *str_2
)
158 char *temp1
= new char[strlen(str_1
)+1];
159 char *temp2
= new char[strlen(str_2
)+1];
162 myLowerString(temp1
);
163 myLowerString(temp2
);
165 int result
= wxStrcmp(temp1
,temp2
);
172 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
174 char *temp1
= new char[strlen(str_1
)+1];
175 char *temp2
= new char[strlen(str_2
)+1];
178 myLowerString(temp1
);
179 myLowerString(temp2
);
181 int result
= strncmp(temp1
,temp2
,maxchar
);
189 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) && !defined(__WXWINE__)
193 #define strcasecmp stricmp
194 #define strncasecmp strnicmp
196 #define strcasecmp _stricmp
197 #define strncasecmp _strnicmp
204 #define strcasecmp stricmp
205 #define strncasecmp strnicmp
208 // This declaration is missing in SunOS!
209 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
210 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
213 int strcasecmp (const char *, const char *);
214 int strncasecmp (const char *, const char *, size_t);
217 #endif /* __WXMSW__ */
220 #define strcasecmp stricmp
221 #define strncasecmp strnicmp
225 #define strcasecmp stricmp
226 #define strncasecmp strnicmp
230 copystring (const wxChar
*s
)
232 if (s
== NULL
) s
= wxT("");
233 size_t len
= wxStrlen (s
) + 1;
235 wxChar
*news
= new wxChar
[len
];
236 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
242 static long wxCurrentId
= 100;
247 return wxCurrentId
++;
251 wxGetCurrentId(void) { return wxCurrentId
; }
254 wxRegisterId (long id
)
256 if (id
>= wxCurrentId
)
257 wxCurrentId
= id
+ 1;
261 StringToFloat (const wxChar
*s
, float *number
)
263 if (s
&& *s
&& number
)
264 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
268 StringToDouble (const wxChar
*s
, double *number
)
270 if (s
&& *s
&& number
)
271 *number
= wxStrtod (s
, (wxChar
**) NULL
);
275 FloatToString (float number
, const wxChar
*fmt
)
277 static wxChar buf
[256];
279 wxSprintf (buf
, fmt
, number
);
284 DoubleToString (double number
, const wxChar
*fmt
)
286 static wxChar buf
[256];
288 wxSprintf (buf
, fmt
, number
);
293 StringToInt (const wxChar
*s
, int *number
)
295 if (s
&& *s
&& number
)
296 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
300 StringToLong (const wxChar
*s
, long *number
)
302 if (s
&& *s
&& number
)
303 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
307 IntToString (int number
)
309 static wxChar buf
[20];
311 wxSprintf (buf
, wxT("%d"), number
);
316 LongToString (long number
)
318 static wxChar buf
[20];
320 wxSprintf (buf
, wxT("%ld"), number
);
324 // Array used in DecToHex conversion routine.
325 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
327 // Convert 2-digit hex number to decimal
328 int wxHexToDec(const wxString
& buf
)
330 int firstDigit
, secondDigit
;
332 if (buf
.GetChar(0) >= wxT('A'))
333 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
335 firstDigit
= buf
.GetChar(0) - wxT('0');
337 if (buf
.GetChar(1) >= wxT('A'))
338 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
340 secondDigit
= buf
.GetChar(1) - wxT('0');
342 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
345 // Convert decimal integer to 2-character hex string
346 void wxDecToHex(int dec
, wxChar
*buf
)
348 int firstDigit
= (int)(dec
/16.0);
349 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
350 buf
[0] = hexArray
[firstDigit
];
351 buf
[1] = hexArray
[secondDigit
];
355 // Convert decimal integer to 2-character hex string
356 wxString
wxDecToHex(int dec
)
359 wxDecToHex(dec
, buf
);
360 return wxString(buf
);
363 // Match a string INDEPENDENT OF CASE
365 StringMatch (const char *str1
, const char *str2
, bool subString
, bool exact
)
367 if (str1
== NULL
|| str2
== NULL
)
374 int len1
= strlen (str1
);
375 int len2
= strlen (str2
);
378 // Search for str1 in str2
379 // Slow .... but acceptable for short strings
380 for (i
= 0; i
<= len2
- len1
; i
++)
382 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
388 if (strcasecmp (str1
, str2
) == 0)
393 int len1
= strlen (str1
);
394 int len2
= strlen (str2
);
396 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
403 // Return the current date/time
407 time_t now
= time((time_t *) NULL
);
408 char *date
= ctime(&now
);
410 return wxString(date
);
417 // ----------------------------------------------------------------------------
418 // Menu accelerators related functions
419 // ----------------------------------------------------------------------------
421 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
423 wxString s
= wxMenuItem::GetLabelFromText(in
);
426 // go smash their buffer if it's not big enough - I love char * params
427 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
437 wxString
wxStripMenuCodes(const wxString
& in
)
441 size_t len
= in
.length();
444 for ( size_t n
= 0; n
< len
; n
++ )
449 // skip it, it is used to introduce the accel char (or to quote
450 // itself in which case it should still be skipped): note that it
451 // can't be the last character of the string
454 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
458 // use the next char instead
462 else if ( ch
== _T('\t') )
464 // everything after TAB is accel string, exit the loop
474 #endif // wxUSE_MENUS
476 // ----------------------------------------------------------------------------
477 // Window search functions
478 // ----------------------------------------------------------------------------
481 * If parent is non-NULL, look through children for a label or title
482 * matching the specified string. If NULL, look through all top-level windows.
487 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
489 return wxWindow::FindWindowByLabel( title
, parent
);
494 * If parent is non-NULL, look through children for a name
495 * matching the specified string. If NULL, look through all top-level windows.
500 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
502 return wxWindow::FindWindowByName( name
, parent
);
505 // Returns menu item id or -1 if none.
507 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
510 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
512 return menuBar
->FindMenuItem (menuString
, itemString
);
513 #endif // wxUSE_MENUS
518 // Try to find the deepest child that contains 'pt'.
519 // We go backwards, to try to allow for controls that are spacially
520 // within other controls, but are still siblings (e.g. buttons within
521 // static boxes). Static boxes are likely to be created _before_ controls
522 // that sit inside them.
523 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
528 // Hack for wxNotebook case: at least in wxGTK, all pages
529 // claim to be shown, so we must only deal with the selected one.
531 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
533 wxNotebook
* nb
= (wxNotebook
*) win
;
534 int sel
= nb
->GetSelection();
537 wxWindow
* child
= nb
->GetPage(sel
);
538 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
547 else if (win->IsKindOf(CLASSINFO(wxFrame)))
549 // Pseudo-children that may not be mentioned in the child list
550 wxWindowList extraChildren;
551 wxFrame* frame = (wxFrame*) win;
552 if (frame->GetStatusBar())
553 extraChildren.Append(frame->GetStatusBar());
554 if (frame->GetToolBar())
555 extraChildren.Append(frame->GetToolBar());
557 wxNode* node = extraChildren.First();
560 wxWindow* child = (wxWindow*) node->Data();
561 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
569 wxNode
* node
= win
->GetChildren().Last();
572 wxWindow
* child
= (wxWindow
*) node
->Data();
573 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
576 node
= node
->Previous();
579 wxPoint pos
= win
->GetPosition();
580 wxSize sz
= win
->GetSize();
581 if (win
->GetParent())
583 pos
= win
->GetParent()->ClientToScreen(pos
);
586 wxRect
rect(pos
, sz
);
593 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
595 // Go backwards through the list since windows
596 // on top are likely to have been appended most
598 wxNode
* node
= wxTopLevelWindows
.Last();
601 wxWindow
* win
= (wxWindow
*) node
->Data();
602 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
605 node
= node
->Previous();
613 On Fri, 21 Jul 1995, Paul Craven wrote:
615 > Is there a way to find the path of running program's executable? I can get
616 > my home directory, and the current directory, but I don't know how to get the
617 > executable directory.
620 The code below (warty as it is), does what you want on most Unix,
621 DOS, and Mac platforms (it's from the ALS Prolog main).
623 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
624 ||==== Voice: +1 (617)965-9191 Newton Centre,
625 || FAX: +1 (617)965-1636 MA 02159 USA
626 Email: ken@als.com WWW: http://www.als.com
627 ------------------------------------------------------------------------
630 // This code is commented out but it may be integrated with wxWin at
631 // a later date, after testing. Thanks Ken!
634 /*--------------------------------------------------------------------*
635 | whereami is given a filename f in the form: whereami(argv[0])
636 | It returns the directory in which the executable file (containing
637 | this code [main.c] ) may be found. A dot will be returned to indicate
638 | the current directory.
639 *--------------------------------------------------------------------*/
645 register char *cutoff
= NULL
; /* stifle -Wall */
652 * See if the file is accessible either through the current directory
653 * or through an absolute path.
656 if (access(name
, R_OK
) == 0) {
658 /*-------------------------------------------------------------*
659 * The file was accessible without any other work. But the current
660 * working directory might change on us, so if it was accessible
661 * through the cwd, then we should get it for later accesses.
662 *-------------------------------------------------------------*/
665 if (!absolute_pathname(name
)) {
666 #if defined(__DOS__) || defined(__WIN32__)
672 if (*(name
+ 1) == ':') {
673 if (*name
>= 'a' && *name
<= 'z')
674 drive
= (int) (*name
- 'a' + 1);
676 drive
= (int) (*name
- 'A' + 1);
678 *newrbuf
++ = *(name
+ 1);
679 *newrbuf
++ = DIR_SEPARATOR
;
683 *newrbuf
++ = DIR_SEPARATOR
;
685 if (getcwd(newrbuf
, drive
) == 0) { /* } */
687 if (getcwd(newrbuf
, 1024) == 0) { /* } */
691 if (getwd(imagedir
) == 0) { /* } */
692 #else /* !HAVE_GETWD */
693 if (getcwd(imagedir
, 1024) == 0) {
694 #endif /* !HAVE_GETWD */
696 fatal_error(FE_GETCWD
, 0);
698 for (; *t
; t
++) /* Set t to end of buffer */
700 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
705 cutoff
= t
; /* otherwise put one in */
706 *t
++ = DIR_SEPARATOR
;
709 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
711 (*t
++ = DIR_SEPARATOR
);
714 /*-------------------------------------------------------------*
715 * Copy the rest of the string and set the cutoff if it was not
716 * already set. If the first character of name is a slash, cutoff
717 * is not presently set but will be on the first iteration of the
719 *-------------------------------------------------------------*/
721 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
722 if (*s
== DIR_SEPARATOR
)
731 /*-------------------------------------------------------------*
732 * Get the path list from the environment. If the path list is
733 * inaccessible for any reason, leave with fatal error.
734 *-------------------------------------------------------------*/
737 if ((s
= getenv("Commands")) == (char *) 0)
739 if ((s
= getenv("PATH")) == (char *) 0)
741 fatal_error(FE_PATH
, 0);
744 * Copy path list into ebuf and set the source pointer to the
745 * beginning of this buffer.
753 while (*s
&& *s
!= PATH_SEPARATOR
)
755 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
756 ; /* do nothing -- slash already is in place */
758 *t
++ = DIR_SEPARATOR
; /* put in the slash */
759 cutoff
= t
- 1; /* set cutoff */
761 if (access(imagedir
, R_OK
) == 0)
765 s
++; /* advance source pointer */
767 fatal_error(FE_INFND
, 0);
772 /*-------------------------------------------------------------*
773 | At this point the full pathname should exist in imagedir and
774 | cutoff should be set to the final slash. We must now determine
775 | whether the file name is a symbolic link or not and chase it down
776 | if it is. Note that we reuse ebuf for getting the link.
777 *-------------------------------------------------------------*/
780 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
783 if (*s
== DIR_SEPARATOR
) {
790 if (*s
== DIR_SEPARATOR
)
791 cutoff
= t
; /* mark the last slash seen */
792 if (!(*t
++ = *s
++)) /* copy the character */
797 #endif /* HAVE_SYMLINK */
799 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
800 *(cutoff
+ 1) = 0; /* chop off the filename part */
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
812 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
813 * since otherwise the generic code may be pulled in unnecessarily.
818 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
819 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
821 wxMessageDialog
dialog(parent
, message
, caption
, style
);
823 int ans
= dialog
.ShowModal();
836 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
841 #endif // wxUSE_MSGDLG
845 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
846 const wxString
& defaultValue
, wxWindow
*parent
,
847 int x
, int y
, bool WXUNUSED(centre
) )
850 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
851 if (dialog
.ShowModal() == wxID_OK
)
853 str
= dialog
.GetValue();
859 wxString
wxGetPasswordFromUser(const wxString
& message
,
860 const wxString
& caption
,
861 const wxString
& defaultValue
,
865 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
866 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
867 if ( dialog
.ShowModal() == wxID_OK
)
869 str
= dialog
.GetValue();
875 #endif // wxUSE_TEXTDLG
879 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
882 data
.SetChooseFull(TRUE
);
885 data
.SetColour((wxColour
&)colInit
); // const_cast
889 wxColourDialog
dialog(parent
, &data
);
890 if ( dialog
.ShowModal() == wxID_OK
)
892 colRet
= dialog
.GetColourData().GetColour();
894 //else: leave it invalid
899 #endif // wxUSE_COLOURDLG
903 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
)
908 data
.SetInitialFont(fontInit
);
912 wxFontDialog
dialog(parent
, data
);
913 if ( dialog
.ShowModal() == wxID_OK
)
915 fontRet
= dialog
.GetFontData().GetChosenFont();
917 //else: leave it invalid
922 #endif // wxUSE_FONTDLG
923 // ----------------------------------------------------------------------------
924 // missing C RTL functions (FIXME shouldn't be here at all)
925 // ----------------------------------------------------------------------------
929 char *strdup(const char *s
)
931 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
936 return ( c
>= 0 && c
< 128 ) ;
940 // ----------------------------------------------------------------------------
941 // wxSafeYield and supporting functions
942 // ----------------------------------------------------------------------------
944 void wxEnableTopLevelWindows(bool enable
)
946 wxWindowList::Node
*node
;
947 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
948 node
->GetData()->Enable(enable
);
951 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
953 // remember the top level windows which were already disabled, so that we
954 // don't reenable them later
955 m_winDisabled
= NULL
;
957 wxWindowList::Node
*node
;
958 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
960 wxWindow
*winTop
= node
->GetData();
961 if ( winTop
== winToSkip
)
964 if ( winTop
->IsEnabled() )
970 if ( !m_winDisabled
)
972 m_winDisabled
= new wxWindowList
;
975 m_winDisabled
->Append(winTop
);
980 wxWindowDisabler::~wxWindowDisabler()
982 wxWindowList::Node
*node
;
983 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
985 wxWindow
*winTop
= node
->GetData();
986 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
990 //else: had been already disabled, don't reenable
993 delete m_winDisabled
;
996 // Yield to other apps/messages and disable user input to all windows except
998 bool wxSafeYield(wxWindow
*win
)
1000 wxWindowDisabler
wd(win
);
1002 bool rc
= wxYield();
1007 // ----------------------------------------------------------------------------
1009 // ----------------------------------------------------------------------------
1011 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1012 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1015 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1017 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1023 const wxChar
*wxGetInstallPrefix()
1027 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
1028 return prefix
.c_str();
1030 #ifdef wxINSTALL_PREFIX
1031 return wxT(wxINSTALL_PREFIX
);
1037 wxString
wxGetDataDir()
1039 wxString format
= wxGetInstallPrefix();
1040 format
<< wxFILE_SEP_PATH
1041 << wxT("share") << wxFILE_SEP_PATH
1042 << wxT("wx") << wxFILE_SEP_PATH
1045 dir
.Printf(format
.c_str(), wxMAJOR_VERSION
, wxMINOR_VERSION
);
1050 // ----------------------------------------------------------------------------
1051 // network and user id functions
1052 // ----------------------------------------------------------------------------
1054 // Get Full RFC822 style email address
1055 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1057 wxString email
= wxGetEmailAddress();
1061 wxStrncpy(address
, email
, maxSize
- 1);
1062 address
[maxSize
- 1] = wxT('\0');
1067 wxString
wxGetEmailAddress()
1071 wxString host
= wxGetFullHostName();
1074 wxString user
= wxGetUserId();
1077 email
<< user
<< wxT('@') << host
;
1084 wxString
wxGetUserId()
1086 static const int maxLoginLen
= 256; // FIXME arbitrary number
1089 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1090 buf
.UngetWriteBuf();
1098 wxString
wxGetUserName()
1100 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1103 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1104 buf
.UngetWriteBuf();
1112 wxString
wxGetHostName()
1114 static const size_t hostnameSize
= 257;
1117 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1119 buf
.UngetWriteBuf();
1127 wxString
wxGetFullHostName()
1129 static const size_t hostnameSize
= 257;
1132 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1134 buf
.UngetWriteBuf();
1142 wxString
wxGetHomeDir()
1145 wxGetHomeDir(&home
);
1152 wxString
wxGetCurrentDir()
1159 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1160 dir
.UngetWriteBuf();
1164 if ( errno
!= ERANGE
)
1166 wxLogSysError(_T("Failed to get current directory"));
1168 return wxEmptyString
;
1172 // buffer was too small, retry with a larger one
1184 // ----------------------------------------------------------------------------
1186 // ----------------------------------------------------------------------------
1188 // this is a private function because it hasn't a clean interface: the first
1189 // array is passed by reference, the second by pointer - instead we have 2
1190 // public versions of wxExecute() below
1191 static long wxDoExecuteWithCapture(const wxString
& command
,
1192 wxArrayString
& output
,
1193 wxArrayString
* error
)
1196 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1200 // create a wxProcess which will capture the output
1201 wxProcess
*process
= new wxProcess
;
1202 process
->Redirect();
1204 long rc
= wxExecute(command
, wxEXEC_SYNC
, process
);
1209 wxInputStream
* is
= process
->GetInputStream();
1210 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1211 wxTextInputStream
tis(*is
);
1213 wxTextInputStream
*tes
= NULL
;
1214 wxInputStream
*es
= NULL
;
1217 es
= process
->GetErrorStream();
1219 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1221 tes
= new wxTextInputStream(*es
);
1229 if ( !is
->Eof() && is
->IsOk() )
1231 wxString line
= tis
.ReadLine();
1232 if ( is
->LastError() )
1240 if ( error
&& !es
->Eof() && es
->IsOk() )
1242 wxString line
= tes
->ReadLine();
1243 if ( es
->LastError() )
1255 #endif // wxUSE_STREAMS
1260 #endif // IO redirection supoprted
1263 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1265 return wxDoExecuteWithCapture(command
, output
, NULL
);
1268 long wxExecute(const wxString
& command
,
1269 wxArrayString
& output
,
1270 wxArrayString
& error
)
1272 return wxDoExecuteWithCapture(command
, output
, &error
);
1275 // ----------------------------------------------------------------------------
1276 // wxApp::Yield() wrappers for backwards compatibility
1277 // ----------------------------------------------------------------------------
1282 return wxTheApp
&& wxTheApp
->Yield();
1288 bool wxYieldIfNeeded()
1291 return wxTheApp
&& wxTheApp
->Yield(TRUE
);