]>
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"
39 #include "wx/window.h"
42 #include "wx/msgdlg.h"
43 #include "wx/textdlg.h"
45 #include "wx/menuitem.h"
52 #include "wx/process.h"
53 #include "wx/txtstrm.h"
61 #if !defined(__WATCOMC__)
62 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
68 #include "wx/colordlg.h"
69 #include "wx/notebook.h"
71 #include "wx/statusbr.h"
72 #include "wx/toolbar.h"
78 #include <sys/types.h>
87 #include "wx/msw/private.h"
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
95 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
96 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
108 int strcasecmp(const char *str_1
, const char *str_2
)
110 register char c1
, c2
;
112 c1
= tolower(*str_1
++);
113 c2
= tolower(*str_2
++);
114 } while ( c1
&& (c1
== c2
) );
119 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
122 register char c1
, c2
;
125 c1
= tolower(*str_1
++);
126 c2
= tolower(*str_2
++);
138 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
139 // we have no strI functions under VMS, therefore I have implemented
140 // an inefficient but portable version: convert copies of strings to lowercase
141 // and then use the normal comparison
142 static void myLowerString(char *s
)
145 if(isalpha(*s
)) *s
= (char)tolower(*s
);
150 int strcasecmp(const char *str_1
, const char *str_2
)
152 char *temp1
= new char[strlen(str_1
)+1];
153 char *temp2
= new char[strlen(str_2
)+1];
156 myLowerString(temp1
);
157 myLowerString(temp2
);
159 int result
= wxStrcmp(temp1
,temp2
);
166 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
168 char *temp1
= new char[strlen(str_1
)+1];
169 char *temp2
= new char[strlen(str_2
)+1];
172 myLowerString(temp1
);
173 myLowerString(temp2
);
175 int result
= strncmp(temp1
,temp2
,maxchar
);
187 #define strcasecmp stricmp
188 #define strncasecmp strnicmp
190 #define strcasecmp _stricmp
191 #define strncasecmp _strnicmp
198 #define strcasecmp stricmp
199 #define strncasecmp strnicmp
202 // This declaration is missing in SunOS!
203 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
204 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
207 int strcasecmp (const char *, const char *);
208 int strncasecmp (const char *, const char *, size_t);
211 #endif /* __WXMSW__ */
214 #define strcasecmp stricmp
215 #define strncasecmp strnicmp
219 copystring (const wxChar
*s
)
221 if (s
== NULL
) s
= wxT("");
222 size_t len
= wxStrlen (s
) + 1;
224 wxChar
*news
= new wxChar
[len
];
225 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
231 static long wxCurrentId
= 100;
236 return wxCurrentId
++;
240 wxGetCurrentId(void) { return wxCurrentId
; }
243 wxRegisterId (long id
)
245 if (id
>= wxCurrentId
)
246 wxCurrentId
= id
+ 1;
250 StringToFloat (wxChar
*s
, float *number
)
252 if (s
&& *s
&& number
)
253 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
257 StringToDouble (wxChar
*s
, double *number
)
259 if (s
&& *s
&& number
)
260 *number
= wxStrtod (s
, (wxChar
**) NULL
);
264 FloatToString (float number
, const wxChar
*fmt
)
266 static wxChar buf
[256];
268 wxSprintf (buf
, fmt
, number
);
273 DoubleToString (double number
, const wxChar
*fmt
)
275 static wxChar buf
[256];
277 wxSprintf (buf
, fmt
, number
);
282 StringToInt (wxChar
*s
, int *number
)
284 if (s
&& *s
&& number
)
285 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
289 StringToLong (wxChar
*s
, long *number
)
291 if (s
&& *s
&& number
)
292 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
296 IntToString (int number
)
298 static wxChar buf
[20];
300 wxSprintf (buf
, wxT("%d"), number
);
305 LongToString (long number
)
307 static wxChar buf
[20];
309 wxSprintf (buf
, wxT("%ld"), number
);
313 // Array used in DecToHex conversion routine.
314 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
316 // Convert 2-digit hex number to decimal
317 int wxHexToDec(const wxString
& buf
)
319 int firstDigit
, secondDigit
;
321 if (buf
.GetChar(0) >= wxT('A'))
322 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
324 firstDigit
= buf
.GetChar(0) - wxT('0');
326 if (buf
.GetChar(1) >= wxT('A'))
327 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
329 secondDigit
= buf
.GetChar(1) - wxT('0');
331 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
334 // Convert decimal integer to 2-character hex string
335 void wxDecToHex(int dec
, wxChar
*buf
)
337 int firstDigit
= (int)(dec
/16.0);
338 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
339 buf
[0] = hexArray
[firstDigit
];
340 buf
[1] = hexArray
[secondDigit
];
344 // Convert decimal integer to 2-character hex string
345 wxString
wxDecToHex(int dec
)
348 wxDecToHex(dec
, buf
);
349 return wxString(buf
);
352 // Match a string INDEPENDENT OF CASE
354 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
356 if (str1
== NULL
|| str2
== NULL
)
363 int len1
= strlen (str1
);
364 int len2
= strlen (str2
);
367 // Search for str1 in str2
368 // Slow .... but acceptable for short strings
369 for (i
= 0; i
<= len2
- len1
; i
++)
371 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
377 if (strcasecmp (str1
, str2
) == 0)
382 int len1
= strlen (str1
);
383 int len2
= strlen (str2
);
385 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
392 // Return the current date/time
396 time_t now
= time((time_t *) NULL
);
397 char *date
= ctime(&now
);
399 return wxString(date
);
406 // ----------------------------------------------------------------------------
407 // Menu accelerators related functions
408 // ----------------------------------------------------------------------------
410 wxChar
*wxStripMenuCodes(wxChar
*in
, wxChar
*out
)
412 wxString s
= wxMenuItem::GetLabelFromText(in
);
415 // go smash their buffer if it's not big enough - I love char * params
416 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
426 wxString
wxStripMenuCodes(const wxString
& in
)
430 size_t len
= in
.length();
433 for ( size_t n
= 0; n
< len
; n
++ )
438 // skip it, it is used to introduce the accel char (or to quote
439 // itself in which case it should still be skipped): note that it
440 // can't be the last character of the string
443 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
447 // use the next char instead
451 else if ( ch
== _T('\t') )
453 // everything after TAB is accel string, exit the loop
463 #endif // wxUSE_MENUS
465 // ----------------------------------------------------------------------------
466 // Window search functions
467 // ----------------------------------------------------------------------------
470 * If parent is non-NULL, look through children for a label or title
471 * matching the specified string. If NULL, look through all top-level windows.
476 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
480 return wxFindWindowByLabel1(title
, parent
);
484 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
486 node
= node
->GetNext() )
488 wxWindow
*win
= node
->GetData();
489 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
495 return (wxWindow
*) NULL
;
500 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
504 if (parent
->GetLabel() == title
)
510 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
512 node
= node
->GetNext() )
514 wxWindow
*win
= (wxWindow
*)node
->GetData();
515 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
522 return (wxWindow
*) NULL
; // Not found
526 * If parent is non-NULL, look through children for a name
527 * matching the specified string. If NULL, look through all top-level windows.
532 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
536 return wxFindWindowByName1 (title
, parent
);
540 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
542 node
= node
->GetNext() )
544 wxWindow
*win
= node
->GetData();
545 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
552 // Failed? Try by label instead.
553 return wxFindWindowByLabel(title
, parent
);
558 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
562 if ( parent
->GetName() == title
)
568 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
570 wxWindow
*win
= (wxWindow
*) node
->Data ();
571 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
578 return (wxWindow
*) NULL
; // Not found
582 // Returns menu item id or -1 if none.
584 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
587 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
589 return menuBar
->FindMenuItem (menuString
, itemString
);
590 #endif // wxUSE_MENUS
595 // Try to find the deepest child that contains 'pt'.
596 // We go backwards, to try to allow for controls that are spacially
597 // within other controls, but are still siblings (e.g. buttons within
598 // static boxes). Static boxes are likely to be created _before_ controls
599 // that sit inside them.
600 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
605 // Hack for wxNotebook case: at least in wxGTK, all pages
606 // claim to be shown, so we must only deal with the selected one.
607 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
609 wxNotebook
* nb
= (wxNotebook
*) win
;
610 int sel
= nb
->GetSelection();
613 wxWindow
* child
= nb
->GetPage(sel
);
614 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
621 else if (win->IsKindOf(CLASSINFO(wxFrame)))
623 // Pseudo-children that may not be mentioned in the child list
624 wxWindowList extraChildren;
625 wxFrame* frame = (wxFrame*) win;
626 if (frame->GetStatusBar())
627 extraChildren.Append(frame->GetStatusBar());
628 if (frame->GetToolBar())
629 extraChildren.Append(frame->GetToolBar());
631 wxNode* node = extraChildren.First();
634 wxWindow* child = (wxWindow*) node->Data();
635 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
643 wxNode
* node
= win
->GetChildren().Last();
646 wxWindow
* child
= (wxWindow
*) node
->Data();
647 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
650 node
= node
->Previous();
653 wxPoint pos
= win
->GetPosition();
654 wxSize sz
= win
->GetSize();
655 if (win
->GetParent())
657 pos
= win
->GetParent()->ClientToScreen(pos
);
660 wxRect
rect(pos
, sz
);
667 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
669 // Go backwards through the list since windows
670 // on top are likely to have been appended most
672 wxNode
* node
= wxTopLevelWindows
.Last();
675 wxWindow
* win
= (wxWindow
*) node
->Data();
676 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
679 node
= node
->Previous();
687 On Fri, 21 Jul 1995, Paul Craven wrote:
689 > Is there a way to find the path of running program's executable? I can get
690 > my home directory, and the current directory, but I don't know how to get the
691 > executable directory.
694 The code below (warty as it is), does what you want on most Unix,
695 DOS, and Mac platforms (it's from the ALS Prolog main).
697 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
698 ||==== Voice: +1 (617)965-9191 Newton Centre,
699 || FAX: +1 (617)965-1636 MA 02159 USA
700 Email: ken@als.com WWW: http://www.als.com
701 ------------------------------------------------------------------------
704 // This code is commented out but it may be integrated with wxWin at
705 // a later date, after testing. Thanks Ken!
708 /*--------------------------------------------------------------------*
709 | whereami is given a filename f in the form: whereami(argv[0])
710 | It returns the directory in which the executable file (containing
711 | this code [main.c] ) may be found. A dot will be returned to indicate
712 | the current directory.
713 *--------------------------------------------------------------------*/
719 register char *cutoff
= NULL
; /* stifle -Wall */
726 * See if the file is accessible either through the current directory
727 * or through an absolute path.
730 if (access(name
, R_OK
) == 0) {
732 /*-------------------------------------------------------------*
733 * The file was accessible without any other work. But the current
734 * working directory might change on us, so if it was accessible
735 * through the cwd, then we should get it for later accesses.
736 *-------------------------------------------------------------*/
739 if (!absolute_pathname(name
)) {
740 #if defined(DOS) || defined(__WIN32__)
746 if (*(name
+ 1) == ':') {
747 if (*name
>= 'a' && *name
<= 'z')
748 drive
= (int) (*name
- 'a' + 1);
750 drive
= (int) (*name
- 'A' + 1);
752 *newrbuf
++ = *(name
+ 1);
753 *newrbuf
++ = DIR_SEPARATOR
;
757 *newrbuf
++ = DIR_SEPARATOR
;
759 if (getcwd(newrbuf
, drive
) == 0) { /* } */
761 if (getcwd(newrbuf
, 1024) == 0) { /* } */
765 if (getwd(imagedir
) == 0) { /* } */
766 #else /* !HAVE_GETWD */
767 if (getcwd(imagedir
, 1024) == 0) {
768 #endif /* !HAVE_GETWD */
770 fatal_error(FE_GETCWD
, 0);
772 for (; *t
; t
++) /* Set t to end of buffer */
774 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
779 cutoff
= t
; /* otherwise put one in */
780 *t
++ = DIR_SEPARATOR
;
783 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
785 (*t
++ = DIR_SEPARATOR
);
788 /*-------------------------------------------------------------*
789 * Copy the rest of the string and set the cutoff if it was not
790 * already set. If the first character of name is a slash, cutoff
791 * is not presently set but will be on the first iteration of the
793 *-------------------------------------------------------------*/
795 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
796 if (*s
== DIR_SEPARATOR
)
805 /*-------------------------------------------------------------*
806 * Get the path list from the environment. If the path list is
807 * inaccessible for any reason, leave with fatal error.
808 *-------------------------------------------------------------*/
811 if ((s
= getenv("Commands")) == (char *) 0)
813 if ((s
= getenv("PATH")) == (char *) 0)
815 fatal_error(FE_PATH
, 0);
818 * Copy path list into ebuf and set the source pointer to the
819 * beginning of this buffer.
827 while (*s
&& *s
!= PATH_SEPARATOR
)
829 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
830 ; /* do nothing -- slash already is in place */
832 *t
++ = DIR_SEPARATOR
; /* put in the slash */
833 cutoff
= t
- 1; /* set cutoff */
835 if (access(imagedir
, R_OK
) == 0)
839 s
++; /* advance source pointer */
841 fatal_error(FE_INFND
, 0);
846 /*-------------------------------------------------------------*
847 | At this point the full pathname should exist in imagedir and
848 | cutoff should be set to the final slash. We must now determine
849 | whether the file name is a symbolic link or not and chase it down
850 | if it is. Note that we reuse ebuf for getting the link.
851 *-------------------------------------------------------------*/
854 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
857 if (*s
== DIR_SEPARATOR
) {
864 if (*s
== DIR_SEPARATOR
)
865 cutoff
= t
; /* mark the last slash seen */
866 if (!(*t
++ = *s
++)) /* copy the character */
871 #endif /* HAVE_SYMLINK */
873 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
874 *(cutoff
+ 1) = 0; /* chop off the filename part */
881 // ----------------------------------------------------------------------------
883 // ----------------------------------------------------------------------------
886 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
887 * since otherwise the generic code may be pulled in unnecessarily.
892 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
893 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
895 wxMessageDialog
dialog(parent
, message
, caption
, style
);
897 int ans
= dialog
.ShowModal();
910 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
915 #endif // wxUSE_MSGDLG
919 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
920 const wxString
& defaultValue
, wxWindow
*parent
,
921 int x
, int y
, bool WXUNUSED(centre
) )
924 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
925 if (dialog
.ShowModal() == wxID_OK
)
927 str
= dialog
.GetValue();
933 wxString
wxGetPasswordFromUser(const wxString
& message
,
934 const wxString
& caption
,
935 const wxString
& defaultValue
,
939 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
940 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
941 if ( dialog
.ShowModal() == wxID_OK
)
943 str
= dialog
.GetValue();
949 #endif // wxUSE_TEXTDLG
953 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
956 data
.SetChooseFull(TRUE
);
959 data
.SetColour((wxColour
&)colInit
); // const_cast
963 wxColourDialog
dialog(parent
, &data
);
964 if ( dialog
.ShowModal() == wxID_OK
)
966 colRet
= dialog
.GetColourData().GetColour();
968 //else: leave it invalid
973 #endif // wxUSE_COLOURDLG
975 // ----------------------------------------------------------------------------
976 // missing C RTL functions (FIXME shouldn't be here at all)
977 // ----------------------------------------------------------------------------
980 char *strdup(const char *s
)
982 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
987 return ( c
>= 0 && c
< 128 ) ;
991 // ----------------------------------------------------------------------------
992 // wxSafeYield and supporting functions
993 // ----------------------------------------------------------------------------
995 void wxEnableTopLevelWindows(bool enable
)
997 wxWindowList::Node
*node
;
998 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
999 node
->GetData()->Enable(enable
);
1002 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1004 // remember the top level windows which were already disabled, so that we
1005 // don't reenable them later
1006 m_winDisabled
= NULL
;
1008 wxWindowList::Node
*node
;
1009 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1011 wxWindow
*winTop
= node
->GetData();
1012 if ( winTop
== winToSkip
)
1015 if ( winTop
->IsEnabled() )
1021 if ( !m_winDisabled
)
1023 m_winDisabled
= new wxWindowList
;
1026 m_winDisabled
->Append(winTop
);
1031 wxWindowDisabler::~wxWindowDisabler()
1033 wxWindowList::Node
*node
;
1034 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1036 wxWindow
*winTop
= node
->GetData();
1037 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1041 //else: had been already disabled, don't reenable
1044 delete m_winDisabled
;
1047 // Yield to other apps/messages and disable user input to all windows except
1049 bool wxSafeYield(wxWindow
*win
)
1051 wxWindowDisabler
wd(win
);
1053 bool rc
= wxYield();
1058 // ----------------------------------------------------------------------------
1060 // ----------------------------------------------------------------------------
1062 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1063 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1066 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1068 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1074 // ----------------------------------------------------------------------------
1075 // network and user id functions
1076 // ----------------------------------------------------------------------------
1078 // Get Full RFC822 style email address
1079 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1081 wxString email
= wxGetEmailAddress();
1085 wxStrncpy(address
, email
, maxSize
- 1);
1086 address
[maxSize
- 1] = wxT('\0');
1091 wxString
wxGetEmailAddress()
1095 wxString host
= wxGetFullHostName();
1098 wxString user
= wxGetUserId();
1101 email
<< user
<< wxT('@') << host
;
1108 wxString
wxGetUserId()
1110 static const int maxLoginLen
= 256; // FIXME arbitrary number
1113 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1114 buf
.UngetWriteBuf();
1122 wxString
wxGetUserName()
1124 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1127 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1128 buf
.UngetWriteBuf();
1136 wxString
wxGetHostName()
1138 static const size_t hostnameSize
= 257;
1141 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1143 buf
.UngetWriteBuf();
1151 wxString
wxGetFullHostName()
1153 static const size_t hostnameSize
= 257;
1156 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1158 buf
.UngetWriteBuf();
1166 wxString
wxGetHomeDir()
1169 wxGetHomeDir(&home
);
1176 wxString
wxGetCurrentDir()
1183 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1184 dir
.UngetWriteBuf();
1188 if ( errno
!= ERANGE
)
1190 wxLogSysError(_T("Failed to get current directory"));
1192 return wxEmptyString
;
1196 // buffer was too small, retry with a larger one
1208 // ----------------------------------------------------------------------------
1210 // ----------------------------------------------------------------------------
1212 // this is a private function because it hasn't a clean interface: the first
1213 // array is passed by reference, the second by pointer - instead we have 2
1214 // public versions of wxExecute() below
1215 static long wxDoExecuteWithCapture(const wxString
& command
,
1216 wxArrayString
& output
,
1217 wxArrayString
* error
)
1220 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1224 // create a wxProcess which will capture the output
1225 wxProcess
*process
= new wxProcess
;
1226 process
->Redirect();
1228 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1233 wxInputStream
* is
= process
->GetInputStream();
1234 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1235 wxTextInputStream
tis(*is
);
1237 wxTextInputStream
*tes
= NULL
;
1238 wxInputStream
*es
= NULL
;
1241 es
= process
->GetErrorStream();
1243 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1245 tes
= new wxTextInputStream(*es
);
1253 if ( !is
->Eof() && is
->IsOk() )
1255 wxString line
= tis
.ReadLine();
1256 if ( is
->LastError() )
1264 if ( error
&& !es
->Eof() && es
->IsOk() )
1266 wxString line
= tes
->ReadLine();
1267 if ( es
->LastError() )
1279 #endif // wxUSE_STREAMS
1284 #endif // IO redirection supoprted
1287 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1289 return wxDoExecuteWithCapture(command
, output
, NULL
);
1292 long wxExecute(const wxString
& command
,
1293 wxArrayString
& output
,
1294 wxArrayString
& error
)
1296 return wxDoExecuteWithCapture(command
, output
, &error
);