]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
724f54de2a05e8435fcf737fba6c4aa6a7587a12
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/notebook.h"
73 #include "wx/statusbr.h"
74 #include "wx/toolbar.h"
80 #include <sys/types.h>
89 #include "wx/msw/private.h"
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
97 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
98 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
101 // ============================================================================
103 // ============================================================================
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 #if defined(__WXMAC__) && !defined(__DARWIN__)
110 int strcasecmp(const char *str_1
, const char *str_2
)
112 register char c1
, c2
;
114 c1
= tolower(*str_1
++);
115 c2
= tolower(*str_2
++);
116 } while ( c1
&& (c1
== c2
) );
121 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
124 register char c1
, c2
;
127 c1
= tolower(*str_1
++);
128 c2
= tolower(*str_2
++);
138 #endif // __WXMAC__ && !__DARWIN__
140 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
141 // we have no strI functions under VMS, therefore I have implemented
142 // an inefficient but portable version: convert copies of strings to lowercase
143 // and then use the normal comparison
144 static void myLowerString(char *s
)
147 if(isalpha(*s
)) *s
= (char)tolower(*s
);
152 int strcasecmp(const char *str_1
, const char *str_2
)
154 char *temp1
= new char[strlen(str_1
)+1];
155 char *temp2
= new char[strlen(str_2
)+1];
158 myLowerString(temp1
);
159 myLowerString(temp2
);
161 int result
= wxStrcmp(temp1
,temp2
);
168 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
170 char *temp1
= new char[strlen(str_1
)+1];
171 char *temp2
= new char[strlen(str_2
)+1];
174 myLowerString(temp1
);
175 myLowerString(temp2
);
177 int result
= strncmp(temp1
,temp2
,maxchar
);
185 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
189 #define strcasecmp stricmp
190 #define strncasecmp strnicmp
192 #define strcasecmp _stricmp
193 #define strncasecmp _strnicmp
200 #define strcasecmp stricmp
201 #define strncasecmp strnicmp
204 // This declaration is missing in SunOS!
205 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
206 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
209 int strcasecmp (const char *, const char *);
210 int strncasecmp (const char *, const char *, size_t);
213 #endif /* __WXMSW__ */
216 #define strcasecmp stricmp
217 #define strncasecmp strnicmp
221 copystring (const wxChar
*s
)
223 if (s
== NULL
) s
= wxT("");
224 size_t len
= wxStrlen (s
) + 1;
226 wxChar
*news
= new wxChar
[len
];
227 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
233 static long wxCurrentId
= 100;
238 return wxCurrentId
++;
242 wxGetCurrentId(void) { return wxCurrentId
; }
245 wxRegisterId (long id
)
247 if (id
>= wxCurrentId
)
248 wxCurrentId
= id
+ 1;
252 StringToFloat (wxChar
*s
, float *number
)
254 if (s
&& *s
&& number
)
255 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
259 StringToDouble (wxChar
*s
, double *number
)
261 if (s
&& *s
&& number
)
262 *number
= wxStrtod (s
, (wxChar
**) NULL
);
266 FloatToString (float number
, const wxChar
*fmt
)
268 static wxChar buf
[256];
270 wxSprintf (buf
, fmt
, number
);
275 DoubleToString (double number
, const wxChar
*fmt
)
277 static wxChar buf
[256];
279 wxSprintf (buf
, fmt
, number
);
284 StringToInt (wxChar
*s
, int *number
)
286 if (s
&& *s
&& number
)
287 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
291 StringToLong (wxChar
*s
, long *number
)
293 if (s
&& *s
&& number
)
294 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
298 IntToString (int number
)
300 static wxChar buf
[20];
302 wxSprintf (buf
, wxT("%d"), number
);
307 LongToString (long number
)
309 static wxChar buf
[20];
311 wxSprintf (buf
, wxT("%ld"), number
);
315 // Array used in DecToHex conversion routine.
316 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
318 // Convert 2-digit hex number to decimal
319 int wxHexToDec(const wxString
& buf
)
321 int firstDigit
, secondDigit
;
323 if (buf
.GetChar(0) >= wxT('A'))
324 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
326 firstDigit
= buf
.GetChar(0) - wxT('0');
328 if (buf
.GetChar(1) >= wxT('A'))
329 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
331 secondDigit
= buf
.GetChar(1) - wxT('0');
333 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
336 // Convert decimal integer to 2-character hex string
337 void wxDecToHex(int dec
, wxChar
*buf
)
339 int firstDigit
= (int)(dec
/16.0);
340 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
341 buf
[0] = hexArray
[firstDigit
];
342 buf
[1] = hexArray
[secondDigit
];
346 // Convert decimal integer to 2-character hex string
347 wxString
wxDecToHex(int dec
)
350 wxDecToHex(dec
, buf
);
351 return wxString(buf
);
354 // Match a string INDEPENDENT OF CASE
356 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
358 if (str1
== NULL
|| str2
== NULL
)
365 int len1
= strlen (str1
);
366 int len2
= strlen (str2
);
369 // Search for str1 in str2
370 // Slow .... but acceptable for short strings
371 for (i
= 0; i
<= len2
- len1
; i
++)
373 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
379 if (strcasecmp (str1
, str2
) == 0)
384 int len1
= strlen (str1
);
385 int len2
= strlen (str2
);
387 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
394 // Return the current date/time
398 time_t now
= time((time_t *) NULL
);
399 char *date
= ctime(&now
);
401 return wxString(date
);
408 // ----------------------------------------------------------------------------
409 // Menu accelerators related functions
410 // ----------------------------------------------------------------------------
412 wxChar
*wxStripMenuCodes(wxChar
*in
, wxChar
*out
)
414 wxString s
= wxMenuItem::GetLabelFromText(in
);
417 // go smash their buffer if it's not big enough - I love char * params
418 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
428 wxString
wxStripMenuCodes(const wxString
& in
)
432 size_t len
= in
.length();
435 for ( size_t n
= 0; n
< len
; n
++ )
440 // skip it, it is used to introduce the accel char (or to quote
441 // itself in which case it should still be skipped): note that it
442 // can't be the last character of the string
445 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
449 // use the next char instead
453 else if ( ch
== _T('\t') )
455 // everything after TAB is accel string, exit the loop
465 #endif // wxUSE_MENUS
467 // ----------------------------------------------------------------------------
468 // Window search functions
469 // ----------------------------------------------------------------------------
472 * If parent is non-NULL, look through children for a label or title
473 * matching the specified string. If NULL, look through all top-level windows.
478 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
482 return wxFindWindowByLabel1(title
, parent
);
486 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
488 node
= node
->GetNext() )
490 wxWindow
*win
= node
->GetData();
491 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
497 return (wxWindow
*) NULL
;
502 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
506 if (parent
->GetLabel() == title
)
512 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
514 node
= node
->GetNext() )
516 wxWindow
*win
= (wxWindow
*)node
->GetData();
517 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
524 return (wxWindow
*) NULL
; // Not found
528 * If parent is non-NULL, look through children for a name
529 * matching the specified string. If NULL, look through all top-level windows.
534 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
538 return wxFindWindowByName1 (title
, parent
);
542 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
544 node
= node
->GetNext() )
546 wxWindow
*win
= node
->GetData();
547 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
554 // Failed? Try by label instead.
555 return wxFindWindowByLabel(title
, parent
);
560 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
564 if ( parent
->GetName() == title
)
570 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
572 wxWindow
*win
= (wxWindow
*) node
->Data ();
573 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
580 return (wxWindow
*) NULL
; // Not found
584 // Returns menu item id or -1 if none.
586 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
589 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
591 return menuBar
->FindMenuItem (menuString
, itemString
);
592 #endif // wxUSE_MENUS
597 // Try to find the deepest child that contains 'pt'.
598 // We go backwards, to try to allow for controls that are spacially
599 // within other controls, but are still siblings (e.g. buttons within
600 // static boxes). Static boxes are likely to be created _before_ controls
601 // that sit inside them.
602 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
607 // Hack for wxNotebook case: at least in wxGTK, all pages
608 // claim to be shown, so we must only deal with the selected one.
609 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
611 wxNotebook
* nb
= (wxNotebook
*) win
;
612 int sel
= nb
->GetSelection();
615 wxWindow
* child
= nb
->GetPage(sel
);
616 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
623 else if (win->IsKindOf(CLASSINFO(wxFrame)))
625 // Pseudo-children that may not be mentioned in the child list
626 wxWindowList extraChildren;
627 wxFrame* frame = (wxFrame*) win;
628 if (frame->GetStatusBar())
629 extraChildren.Append(frame->GetStatusBar());
630 if (frame->GetToolBar())
631 extraChildren.Append(frame->GetToolBar());
633 wxNode* node = extraChildren.First();
636 wxWindow* child = (wxWindow*) node->Data();
637 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
645 wxNode
* node
= win
->GetChildren().Last();
648 wxWindow
* child
= (wxWindow
*) node
->Data();
649 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
652 node
= node
->Previous();
655 wxPoint pos
= win
->GetPosition();
656 wxSize sz
= win
->GetSize();
657 if (win
->GetParent())
659 pos
= win
->GetParent()->ClientToScreen(pos
);
662 wxRect
rect(pos
, sz
);
669 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
671 // Go backwards through the list since windows
672 // on top are likely to have been appended most
674 wxNode
* node
= wxTopLevelWindows
.Last();
677 wxWindow
* win
= (wxWindow
*) node
->Data();
678 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
681 node
= node
->Previous();
689 On Fri, 21 Jul 1995, Paul Craven wrote:
691 > Is there a way to find the path of running program's executable? I can get
692 > my home directory, and the current directory, but I don't know how to get the
693 > executable directory.
696 The code below (warty as it is), does what you want on most Unix,
697 DOS, and Mac platforms (it's from the ALS Prolog main).
699 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
700 ||==== Voice: +1 (617)965-9191 Newton Centre,
701 || FAX: +1 (617)965-1636 MA 02159 USA
702 Email: ken@als.com WWW: http://www.als.com
703 ------------------------------------------------------------------------
706 // This code is commented out but it may be integrated with wxWin at
707 // a later date, after testing. Thanks Ken!
710 /*--------------------------------------------------------------------*
711 | whereami is given a filename f in the form: whereami(argv[0])
712 | It returns the directory in which the executable file (containing
713 | this code [main.c] ) may be found. A dot will be returned to indicate
714 | the current directory.
715 *--------------------------------------------------------------------*/
721 register char *cutoff
= NULL
; /* stifle -Wall */
728 * See if the file is accessible either through the current directory
729 * or through an absolute path.
732 if (access(name
, R_OK
) == 0) {
734 /*-------------------------------------------------------------*
735 * The file was accessible without any other work. But the current
736 * working directory might change on us, so if it was accessible
737 * through the cwd, then we should get it for later accesses.
738 *-------------------------------------------------------------*/
741 if (!absolute_pathname(name
)) {
742 #if defined(DOS) || defined(__WIN32__)
748 if (*(name
+ 1) == ':') {
749 if (*name
>= 'a' && *name
<= 'z')
750 drive
= (int) (*name
- 'a' + 1);
752 drive
= (int) (*name
- 'A' + 1);
754 *newrbuf
++ = *(name
+ 1);
755 *newrbuf
++ = DIR_SEPARATOR
;
759 *newrbuf
++ = DIR_SEPARATOR
;
761 if (getcwd(newrbuf
, drive
) == 0) { /* } */
763 if (getcwd(newrbuf
, 1024) == 0) { /* } */
767 if (getwd(imagedir
) == 0) { /* } */
768 #else /* !HAVE_GETWD */
769 if (getcwd(imagedir
, 1024) == 0) {
770 #endif /* !HAVE_GETWD */
772 fatal_error(FE_GETCWD
, 0);
774 for (; *t
; t
++) /* Set t to end of buffer */
776 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
781 cutoff
= t
; /* otherwise put one in */
782 *t
++ = DIR_SEPARATOR
;
785 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
787 (*t
++ = DIR_SEPARATOR
);
790 /*-------------------------------------------------------------*
791 * Copy the rest of the string and set the cutoff if it was not
792 * already set. If the first character of name is a slash, cutoff
793 * is not presently set but will be on the first iteration of the
795 *-------------------------------------------------------------*/
797 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
798 if (*s
== DIR_SEPARATOR
)
807 /*-------------------------------------------------------------*
808 * Get the path list from the environment. If the path list is
809 * inaccessible for any reason, leave with fatal error.
810 *-------------------------------------------------------------*/
813 if ((s
= getenv("Commands")) == (char *) 0)
815 if ((s
= getenv("PATH")) == (char *) 0)
817 fatal_error(FE_PATH
, 0);
820 * Copy path list into ebuf and set the source pointer to the
821 * beginning of this buffer.
829 while (*s
&& *s
!= PATH_SEPARATOR
)
831 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
832 ; /* do nothing -- slash already is in place */
834 *t
++ = DIR_SEPARATOR
; /* put in the slash */
835 cutoff
= t
- 1; /* set cutoff */
837 if (access(imagedir
, R_OK
) == 0)
841 s
++; /* advance source pointer */
843 fatal_error(FE_INFND
, 0);
848 /*-------------------------------------------------------------*
849 | At this point the full pathname should exist in imagedir and
850 | cutoff should be set to the final slash. We must now determine
851 | whether the file name is a symbolic link or not and chase it down
852 | if it is. Note that we reuse ebuf for getting the link.
853 *-------------------------------------------------------------*/
856 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
859 if (*s
== DIR_SEPARATOR
) {
866 if (*s
== DIR_SEPARATOR
)
867 cutoff
= t
; /* mark the last slash seen */
868 if (!(*t
++ = *s
++)) /* copy the character */
873 #endif /* HAVE_SYMLINK */
875 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
876 *(cutoff
+ 1) = 0; /* chop off the filename part */
883 // ----------------------------------------------------------------------------
885 // ----------------------------------------------------------------------------
888 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
889 * since otherwise the generic code may be pulled in unnecessarily.
894 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
895 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
897 wxMessageDialog
dialog(parent
, message
, caption
, style
);
899 int ans
= dialog
.ShowModal();
912 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
917 #endif // wxUSE_MSGDLG
921 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
922 const wxString
& defaultValue
, wxWindow
*parent
,
923 int x
, int y
, bool WXUNUSED(centre
) )
926 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
927 if (dialog
.ShowModal() == wxID_OK
)
929 str
= dialog
.GetValue();
935 wxString
wxGetPasswordFromUser(const wxString
& message
,
936 const wxString
& caption
,
937 const wxString
& defaultValue
,
941 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
942 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
943 if ( dialog
.ShowModal() == wxID_OK
)
945 str
= dialog
.GetValue();
951 #endif // wxUSE_TEXTDLG
955 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
958 data
.SetChooseFull(TRUE
);
961 data
.SetColour((wxColour
&)colInit
); // const_cast
965 wxColourDialog
dialog(parent
, &data
);
966 if ( dialog
.ShowModal() == wxID_OK
)
968 colRet
= dialog
.GetColourData().GetColour();
970 //else: leave it invalid
975 #endif // wxUSE_COLOURDLG
977 // ----------------------------------------------------------------------------
978 // missing C RTL functions (FIXME shouldn't be here at all)
979 // ----------------------------------------------------------------------------
982 char *strdup(const char *s
)
984 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
989 return ( c
>= 0 && c
< 128 ) ;
993 // ----------------------------------------------------------------------------
994 // wxSafeYield and supporting functions
995 // ----------------------------------------------------------------------------
997 void wxEnableTopLevelWindows(bool enable
)
999 wxWindowList::Node
*node
;
1000 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1001 node
->GetData()->Enable(enable
);
1004 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1006 // remember the top level windows which were already disabled, so that we
1007 // don't reenable them later
1008 m_winDisabled
= NULL
;
1010 wxWindowList::Node
*node
;
1011 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1013 wxWindow
*winTop
= node
->GetData();
1014 if ( winTop
== winToSkip
)
1017 if ( winTop
->IsEnabled() )
1023 if ( !m_winDisabled
)
1025 m_winDisabled
= new wxWindowList
;
1028 m_winDisabled
->Append(winTop
);
1033 wxWindowDisabler::~wxWindowDisabler()
1035 wxWindowList::Node
*node
;
1036 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1038 wxWindow
*winTop
= node
->GetData();
1039 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1043 //else: had been already disabled, don't reenable
1046 delete m_winDisabled
;
1049 // Yield to other apps/messages and disable user input to all windows except
1051 bool wxSafeYield(wxWindow
*win
)
1053 wxWindowDisabler
wd(win
);
1055 bool rc
= wxYield();
1060 // ----------------------------------------------------------------------------
1062 // ----------------------------------------------------------------------------
1064 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1065 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1068 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1070 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1076 const wxChar
*wxGetInstallPrefix()
1080 if ( wxGetEnv(wxT("WX_PREFIX"), &prefix
) )
1081 return prefix
.c_str();
1083 #ifdef wxINSTALL_PREFIX
1084 return wxT(wxINSTALL_PREFIX
);
1091 // ----------------------------------------------------------------------------
1092 // network and user id functions
1093 // ----------------------------------------------------------------------------
1095 // Get Full RFC822 style email address
1096 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1098 wxString email
= wxGetEmailAddress();
1102 wxStrncpy(address
, email
, maxSize
- 1);
1103 address
[maxSize
- 1] = wxT('\0');
1108 wxString
wxGetEmailAddress()
1112 wxString host
= wxGetFullHostName();
1115 wxString user
= wxGetUserId();
1118 email
<< user
<< wxT('@') << host
;
1125 wxString
wxGetUserId()
1127 static const int maxLoginLen
= 256; // FIXME arbitrary number
1130 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1131 buf
.UngetWriteBuf();
1139 wxString
wxGetUserName()
1141 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1144 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1145 buf
.UngetWriteBuf();
1153 wxString
wxGetHostName()
1155 static const size_t hostnameSize
= 257;
1158 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1160 buf
.UngetWriteBuf();
1168 wxString
wxGetFullHostName()
1170 static const size_t hostnameSize
= 257;
1173 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1175 buf
.UngetWriteBuf();
1183 wxString
wxGetHomeDir()
1186 wxGetHomeDir(&home
);
1193 wxString
wxGetCurrentDir()
1200 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1201 dir
.UngetWriteBuf();
1205 if ( errno
!= ERANGE
)
1207 wxLogSysError(_T("Failed to get current directory"));
1209 return wxEmptyString
;
1213 // buffer was too small, retry with a larger one
1225 // ----------------------------------------------------------------------------
1227 // ----------------------------------------------------------------------------
1229 // this is a private function because it hasn't a clean interface: the first
1230 // array is passed by reference, the second by pointer - instead we have 2
1231 // public versions of wxExecute() below
1232 static long wxDoExecuteWithCapture(const wxString
& command
,
1233 wxArrayString
& output
,
1234 wxArrayString
* error
)
1237 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1241 // create a wxProcess which will capture the output
1242 wxProcess
*process
= new wxProcess
;
1243 process
->Redirect();
1245 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1250 wxInputStream
* is
= process
->GetInputStream();
1251 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1252 wxTextInputStream
tis(*is
);
1254 wxTextInputStream
*tes
= NULL
;
1255 wxInputStream
*es
= NULL
;
1258 es
= process
->GetErrorStream();
1260 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1262 tes
= new wxTextInputStream(*es
);
1270 if ( !is
->Eof() && is
->IsOk() )
1272 wxString line
= tis
.ReadLine();
1273 if ( is
->LastError() )
1281 if ( error
&& !es
->Eof() && es
->IsOk() )
1283 wxString line
= tes
->ReadLine();
1284 if ( es
->LastError() )
1296 #endif // wxUSE_STREAMS
1301 #endif // IO redirection supoprted
1304 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1306 return wxDoExecuteWithCapture(command
, output
, NULL
);
1309 long wxExecute(const wxString
& command
,
1310 wxArrayString
& output
,
1311 wxArrayString
& error
)
1313 return wxDoExecuteWithCapture(command
, output
, &error
);
1316 // ----------------------------------------------------------------------------
1317 // wxApp::Yield() wrappers for backwards compatibility
1318 // ----------------------------------------------------------------------------
1323 return wxTheApp
&& wxTheApp
->Yield();
1329 bool wxYieldIfNeeded()
1332 return wxTheApp
&& wxTheApp
->Yield(TRUE
);