]>
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"
44 #include "wx/textctrl.h" // for wxTE_PASSWORD
46 #include "wx/menuitem.h"
53 #include "wx/process.h"
54 #include "wx/txtstrm.h"
62 #if !defined(__WATCOMC__)
63 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
69 #include "wx/colordlg.h"
70 #include "wx/notebook.h"
72 #include "wx/statusbr.h"
73 #include "wx/toolbar.h"
79 #include <sys/types.h>
88 #include "wx/msw/private.h"
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
96 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
97 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
109 int strcasecmp(const char *str_1
, const char *str_2
)
111 register char c1
, c2
;
113 c1
= tolower(*str_1
++);
114 c2
= tolower(*str_2
++);
115 } while ( c1
&& (c1
== c2
) );
120 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
123 register char c1
, c2
;
126 c1
= tolower(*str_1
++);
127 c2
= tolower(*str_2
++);
139 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
140 // we have no strI functions under VMS, therefore I have implemented
141 // an inefficient but portable version: convert copies of strings to lowercase
142 // and then use the normal comparison
143 static void myLowerString(char *s
)
146 if(isalpha(*s
)) *s
= (char)tolower(*s
);
151 int strcasecmp(const char *str_1
, const char *str_2
)
153 char *temp1
= new char[strlen(str_1
)+1];
154 char *temp2
= new char[strlen(str_2
)+1];
157 myLowerString(temp1
);
158 myLowerString(temp2
);
160 int result
= wxStrcmp(temp1
,temp2
);
167 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
169 char *temp1
= new char[strlen(str_1
)+1];
170 char *temp2
= new char[strlen(str_2
)+1];
173 myLowerString(temp1
);
174 myLowerString(temp2
);
176 int result
= strncmp(temp1
,temp2
,maxchar
);
184 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
188 #define strcasecmp stricmp
189 #define strncasecmp strnicmp
191 #define strcasecmp _stricmp
192 #define strncasecmp _strnicmp
199 #define strcasecmp stricmp
200 #define strncasecmp strnicmp
203 // This declaration is missing in SunOS!
204 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
205 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
208 int strcasecmp (const char *, const char *);
209 int strncasecmp (const char *, const char *, size_t);
212 #endif /* __WXMSW__ */
215 #define strcasecmp stricmp
216 #define strncasecmp strnicmp
220 copystring (const wxChar
*s
)
222 if (s
== NULL
) s
= wxT("");
223 size_t len
= wxStrlen (s
) + 1;
225 wxChar
*news
= new wxChar
[len
];
226 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
232 static long wxCurrentId
= 100;
237 return wxCurrentId
++;
241 wxGetCurrentId(void) { return wxCurrentId
; }
244 wxRegisterId (long id
)
246 if (id
>= wxCurrentId
)
247 wxCurrentId
= id
+ 1;
251 StringToFloat (wxChar
*s
, float *number
)
253 if (s
&& *s
&& number
)
254 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
258 StringToDouble (wxChar
*s
, double *number
)
260 if (s
&& *s
&& number
)
261 *number
= wxStrtod (s
, (wxChar
**) NULL
);
265 FloatToString (float number
, const wxChar
*fmt
)
267 static wxChar buf
[256];
269 wxSprintf (buf
, fmt
, number
);
274 DoubleToString (double number
, const wxChar
*fmt
)
276 static wxChar buf
[256];
278 wxSprintf (buf
, fmt
, number
);
283 StringToInt (wxChar
*s
, int *number
)
285 if (s
&& *s
&& number
)
286 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
290 StringToLong (wxChar
*s
, long *number
)
292 if (s
&& *s
&& number
)
293 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
297 IntToString (int number
)
299 static wxChar buf
[20];
301 wxSprintf (buf
, wxT("%d"), number
);
306 LongToString (long number
)
308 static wxChar buf
[20];
310 wxSprintf (buf
, wxT("%ld"), number
);
314 // Array used in DecToHex conversion routine.
315 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
317 // Convert 2-digit hex number to decimal
318 int wxHexToDec(const wxString
& buf
)
320 int firstDigit
, secondDigit
;
322 if (buf
.GetChar(0) >= wxT('A'))
323 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
325 firstDigit
= buf
.GetChar(0) - wxT('0');
327 if (buf
.GetChar(1) >= wxT('A'))
328 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
330 secondDigit
= buf
.GetChar(1) - wxT('0');
332 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
335 // Convert decimal integer to 2-character hex string
336 void wxDecToHex(int dec
, wxChar
*buf
)
338 int firstDigit
= (int)(dec
/16.0);
339 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
340 buf
[0] = hexArray
[firstDigit
];
341 buf
[1] = hexArray
[secondDigit
];
345 // Convert decimal integer to 2-character hex string
346 wxString
wxDecToHex(int dec
)
349 wxDecToHex(dec
, buf
);
350 return wxString(buf
);
353 // Match a string INDEPENDENT OF CASE
355 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
357 if (str1
== NULL
|| str2
== NULL
)
364 int len1
= strlen (str1
);
365 int len2
= strlen (str2
);
368 // Search for str1 in str2
369 // Slow .... but acceptable for short strings
370 for (i
= 0; i
<= len2
- len1
; i
++)
372 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
378 if (strcasecmp (str1
, str2
) == 0)
383 int len1
= strlen (str1
);
384 int len2
= strlen (str2
);
386 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
393 // Return the current date/time
397 time_t now
= time((time_t *) NULL
);
398 char *date
= ctime(&now
);
400 return wxString(date
);
407 // ----------------------------------------------------------------------------
408 // Menu accelerators related functions
409 // ----------------------------------------------------------------------------
411 wxChar
*wxStripMenuCodes(wxChar
*in
, wxChar
*out
)
413 wxString s
= wxMenuItem::GetLabelFromText(in
);
416 // go smash their buffer if it's not big enough - I love char * params
417 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
427 wxString
wxStripMenuCodes(const wxString
& in
)
431 size_t len
= in
.length();
434 for ( size_t n
= 0; n
< len
; n
++ )
439 // skip it, it is used to introduce the accel char (or to quote
440 // itself in which case it should still be skipped): note that it
441 // can't be the last character of the string
444 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
448 // use the next char instead
452 else if ( ch
== _T('\t') )
454 // everything after TAB is accel string, exit the loop
464 #endif // wxUSE_MENUS
466 // ----------------------------------------------------------------------------
467 // Window search functions
468 // ----------------------------------------------------------------------------
471 * If parent is non-NULL, look through children for a label or title
472 * matching the specified string. If NULL, look through all top-level windows.
477 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
481 return wxFindWindowByLabel1(title
, parent
);
485 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
487 node
= node
->GetNext() )
489 wxWindow
*win
= node
->GetData();
490 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
496 return (wxWindow
*) NULL
;
501 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
505 if (parent
->GetLabel() == title
)
511 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxWindow
*win
= (wxWindow
*)node
->GetData();
516 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
523 return (wxWindow
*) NULL
; // Not found
527 * If parent is non-NULL, look through children for a name
528 * matching the specified string. If NULL, look through all top-level windows.
533 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
537 return wxFindWindowByName1 (title
, parent
);
541 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
543 node
= node
->GetNext() )
545 wxWindow
*win
= node
->GetData();
546 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
553 // Failed? Try by label instead.
554 return wxFindWindowByLabel(title
, parent
);
559 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
563 if ( parent
->GetName() == title
)
569 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
571 wxWindow
*win
= (wxWindow
*) node
->Data ();
572 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
579 return (wxWindow
*) NULL
; // Not found
583 // Returns menu item id or -1 if none.
585 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
588 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
590 return menuBar
->FindMenuItem (menuString
, itemString
);
591 #endif // wxUSE_MENUS
596 // Try to find the deepest child that contains 'pt'.
597 // We go backwards, to try to allow for controls that are spacially
598 // within other controls, but are still siblings (e.g. buttons within
599 // static boxes). Static boxes are likely to be created _before_ controls
600 // that sit inside them.
601 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
606 // Hack for wxNotebook case: at least in wxGTK, all pages
607 // claim to be shown, so we must only deal with the selected one.
608 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
610 wxNotebook
* nb
= (wxNotebook
*) win
;
611 int sel
= nb
->GetSelection();
614 wxWindow
* child
= nb
->GetPage(sel
);
615 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
622 else if (win->IsKindOf(CLASSINFO(wxFrame)))
624 // Pseudo-children that may not be mentioned in the child list
625 wxWindowList extraChildren;
626 wxFrame* frame = (wxFrame*) win;
627 if (frame->GetStatusBar())
628 extraChildren.Append(frame->GetStatusBar());
629 if (frame->GetToolBar())
630 extraChildren.Append(frame->GetToolBar());
632 wxNode* node = extraChildren.First();
635 wxWindow* child = (wxWindow*) node->Data();
636 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
644 wxNode
* node
= win
->GetChildren().Last();
647 wxWindow
* child
= (wxWindow
*) node
->Data();
648 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
651 node
= node
->Previous();
654 wxPoint pos
= win
->GetPosition();
655 wxSize sz
= win
->GetSize();
656 if (win
->GetParent())
658 pos
= win
->GetParent()->ClientToScreen(pos
);
661 wxRect
rect(pos
, sz
);
668 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
670 // Go backwards through the list since windows
671 // on top are likely to have been appended most
673 wxNode
* node
= wxTopLevelWindows
.Last();
676 wxWindow
* win
= (wxWindow
*) node
->Data();
677 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
680 node
= node
->Previous();
688 On Fri, 21 Jul 1995, Paul Craven wrote:
690 > Is there a way to find the path of running program's executable? I can get
691 > my home directory, and the current directory, but I don't know how to get the
692 > executable directory.
695 The code below (warty as it is), does what you want on most Unix,
696 DOS, and Mac platforms (it's from the ALS Prolog main).
698 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
699 ||==== Voice: +1 (617)965-9191 Newton Centre,
700 || FAX: +1 (617)965-1636 MA 02159 USA
701 Email: ken@als.com WWW: http://www.als.com
702 ------------------------------------------------------------------------
705 // This code is commented out but it may be integrated with wxWin at
706 // a later date, after testing. Thanks Ken!
709 /*--------------------------------------------------------------------*
710 | whereami is given a filename f in the form: whereami(argv[0])
711 | It returns the directory in which the executable file (containing
712 | this code [main.c] ) may be found. A dot will be returned to indicate
713 | the current directory.
714 *--------------------------------------------------------------------*/
720 register char *cutoff
= NULL
; /* stifle -Wall */
727 * See if the file is accessible either through the current directory
728 * or through an absolute path.
731 if (access(name
, R_OK
) == 0) {
733 /*-------------------------------------------------------------*
734 * The file was accessible without any other work. But the current
735 * working directory might change on us, so if it was accessible
736 * through the cwd, then we should get it for later accesses.
737 *-------------------------------------------------------------*/
740 if (!absolute_pathname(name
)) {
741 #if defined(DOS) || defined(__WIN32__)
747 if (*(name
+ 1) == ':') {
748 if (*name
>= 'a' && *name
<= 'z')
749 drive
= (int) (*name
- 'a' + 1);
751 drive
= (int) (*name
- 'A' + 1);
753 *newrbuf
++ = *(name
+ 1);
754 *newrbuf
++ = DIR_SEPARATOR
;
758 *newrbuf
++ = DIR_SEPARATOR
;
760 if (getcwd(newrbuf
, drive
) == 0) { /* } */
762 if (getcwd(newrbuf
, 1024) == 0) { /* } */
766 if (getwd(imagedir
) == 0) { /* } */
767 #else /* !HAVE_GETWD */
768 if (getcwd(imagedir
, 1024) == 0) {
769 #endif /* !HAVE_GETWD */
771 fatal_error(FE_GETCWD
, 0);
773 for (; *t
; t
++) /* Set t to end of buffer */
775 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
780 cutoff
= t
; /* otherwise put one in */
781 *t
++ = DIR_SEPARATOR
;
784 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
786 (*t
++ = DIR_SEPARATOR
);
789 /*-------------------------------------------------------------*
790 * Copy the rest of the string and set the cutoff if it was not
791 * already set. If the first character of name is a slash, cutoff
792 * is not presently set but will be on the first iteration of the
794 *-------------------------------------------------------------*/
796 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
797 if (*s
== DIR_SEPARATOR
)
806 /*-------------------------------------------------------------*
807 * Get the path list from the environment. If the path list is
808 * inaccessible for any reason, leave with fatal error.
809 *-------------------------------------------------------------*/
812 if ((s
= getenv("Commands")) == (char *) 0)
814 if ((s
= getenv("PATH")) == (char *) 0)
816 fatal_error(FE_PATH
, 0);
819 * Copy path list into ebuf and set the source pointer to the
820 * beginning of this buffer.
828 while (*s
&& *s
!= PATH_SEPARATOR
)
830 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
831 ; /* do nothing -- slash already is in place */
833 *t
++ = DIR_SEPARATOR
; /* put in the slash */
834 cutoff
= t
- 1; /* set cutoff */
836 if (access(imagedir
, R_OK
) == 0)
840 s
++; /* advance source pointer */
842 fatal_error(FE_INFND
, 0);
847 /*-------------------------------------------------------------*
848 | At this point the full pathname should exist in imagedir and
849 | cutoff should be set to the final slash. We must now determine
850 | whether the file name is a symbolic link or not and chase it down
851 | if it is. Note that we reuse ebuf for getting the link.
852 *-------------------------------------------------------------*/
855 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
858 if (*s
== DIR_SEPARATOR
) {
865 if (*s
== DIR_SEPARATOR
)
866 cutoff
= t
; /* mark the last slash seen */
867 if (!(*t
++ = *s
++)) /* copy the character */
872 #endif /* HAVE_SYMLINK */
874 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
875 *(cutoff
+ 1) = 0; /* chop off the filename part */
882 // ----------------------------------------------------------------------------
884 // ----------------------------------------------------------------------------
887 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
888 * since otherwise the generic code may be pulled in unnecessarily.
893 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
894 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
896 wxMessageDialog
dialog(parent
, message
, caption
, style
);
898 int ans
= dialog
.ShowModal();
911 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
916 #endif // wxUSE_MSGDLG
920 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
921 const wxString
& defaultValue
, wxWindow
*parent
,
922 int x
, int y
, bool WXUNUSED(centre
) )
925 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
926 if (dialog
.ShowModal() == wxID_OK
)
928 str
= dialog
.GetValue();
934 wxString
wxGetPasswordFromUser(const wxString
& message
,
935 const wxString
& caption
,
936 const wxString
& defaultValue
,
940 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
941 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
942 if ( dialog
.ShowModal() == wxID_OK
)
944 str
= dialog
.GetValue();
950 #endif // wxUSE_TEXTDLG
954 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
957 data
.SetChooseFull(TRUE
);
960 data
.SetColour((wxColour
&)colInit
); // const_cast
964 wxColourDialog
dialog(parent
, &data
);
965 if ( dialog
.ShowModal() == wxID_OK
)
967 colRet
= dialog
.GetColourData().GetColour();
969 //else: leave it invalid
974 #endif // wxUSE_COLOURDLG
976 // ----------------------------------------------------------------------------
977 // missing C RTL functions (FIXME shouldn't be here at all)
978 // ----------------------------------------------------------------------------
981 char *strdup(const char *s
)
983 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
988 return ( c
>= 0 && c
< 128 ) ;
992 // ----------------------------------------------------------------------------
993 // wxSafeYield and supporting functions
994 // ----------------------------------------------------------------------------
996 void wxEnableTopLevelWindows(bool enable
)
998 wxWindowList::Node
*node
;
999 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1000 node
->GetData()->Enable(enable
);
1003 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1005 // remember the top level windows which were already disabled, so that we
1006 // don't reenable them later
1007 m_winDisabled
= NULL
;
1009 wxWindowList::Node
*node
;
1010 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1012 wxWindow
*winTop
= node
->GetData();
1013 if ( winTop
== winToSkip
)
1016 if ( winTop
->IsEnabled() )
1022 if ( !m_winDisabled
)
1024 m_winDisabled
= new wxWindowList
;
1027 m_winDisabled
->Append(winTop
);
1032 wxWindowDisabler::~wxWindowDisabler()
1034 wxWindowList::Node
*node
;
1035 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1037 wxWindow
*winTop
= node
->GetData();
1038 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1042 //else: had been already disabled, don't reenable
1045 delete m_winDisabled
;
1048 // Yield to other apps/messages and disable user input to all windows except
1050 bool wxSafeYield(wxWindow
*win
)
1052 wxWindowDisabler
wd(win
);
1054 bool rc
= wxYield();
1059 // ----------------------------------------------------------------------------
1061 // ----------------------------------------------------------------------------
1063 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1064 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1067 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1069 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1075 const wxChar
*wxGetInstallPrefix()
1079 if ( wxGetEnv(wxT("WX_PREFIX"), &prefix
) )
1080 return prefix
.c_str();
1082 #ifdef wxINSTALL_PREFIX
1083 return wxT(wxINSTALL_PREFIX
);
1090 // ----------------------------------------------------------------------------
1091 // network and user id functions
1092 // ----------------------------------------------------------------------------
1094 // Get Full RFC822 style email address
1095 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1097 wxString email
= wxGetEmailAddress();
1101 wxStrncpy(address
, email
, maxSize
- 1);
1102 address
[maxSize
- 1] = wxT('\0');
1107 wxString
wxGetEmailAddress()
1111 wxString host
= wxGetFullHostName();
1114 wxString user
= wxGetUserId();
1117 email
<< user
<< wxT('@') << host
;
1124 wxString
wxGetUserId()
1126 static const int maxLoginLen
= 256; // FIXME arbitrary number
1129 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1130 buf
.UngetWriteBuf();
1138 wxString
wxGetUserName()
1140 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1143 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1144 buf
.UngetWriteBuf();
1152 wxString
wxGetHostName()
1154 static const size_t hostnameSize
= 257;
1157 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1159 buf
.UngetWriteBuf();
1167 wxString
wxGetFullHostName()
1169 static const size_t hostnameSize
= 257;
1172 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1174 buf
.UngetWriteBuf();
1182 wxString
wxGetHomeDir()
1185 wxGetHomeDir(&home
);
1192 wxString
wxGetCurrentDir()
1199 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1200 dir
.UngetWriteBuf();
1204 if ( errno
!= ERANGE
)
1206 wxLogSysError(_T("Failed to get current directory"));
1208 return wxEmptyString
;
1212 // buffer was too small, retry with a larger one
1224 // ----------------------------------------------------------------------------
1226 // ----------------------------------------------------------------------------
1228 // this is a private function because it hasn't a clean interface: the first
1229 // array is passed by reference, the second by pointer - instead we have 2
1230 // public versions of wxExecute() below
1231 static long wxDoExecuteWithCapture(const wxString
& command
,
1232 wxArrayString
& output
,
1233 wxArrayString
* error
)
1236 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1240 // create a wxProcess which will capture the output
1241 wxProcess
*process
= new wxProcess
;
1242 process
->Redirect();
1244 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1249 wxInputStream
* is
= process
->GetInputStream();
1250 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1251 wxTextInputStream
tis(*is
);
1253 wxTextInputStream
*tes
= NULL
;
1254 wxInputStream
*es
= NULL
;
1257 es
= process
->GetErrorStream();
1259 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1261 tes
= new wxTextInputStream(*es
);
1269 if ( !is
->Eof() && is
->IsOk() )
1271 wxString line
= tis
.ReadLine();
1272 if ( is
->LastError() )
1280 if ( error
&& !es
->Eof() && es
->IsOk() )
1282 wxString line
= tes
->ReadLine();
1283 if ( es
->LastError() )
1295 #endif // wxUSE_STREAMS
1300 #endif // IO redirection supoprted
1303 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1305 return wxDoExecuteWithCapture(command
, output
, NULL
);
1308 long wxExecute(const wxString
& command
,
1309 wxArrayString
& output
,
1310 wxArrayString
& error
)
1312 return wxDoExecuteWithCapture(command
, output
, &error
);