]>
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"
51 #include "wx/process.h"
52 #include "wx/txtstrm.h"
59 #if !defined(__WATCOMC__)
60 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
66 #include "wx/colordlg.h"
72 #include <sys/types.h>
81 #include "wx/msw/private.h"
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
89 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
90 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
93 // ============================================================================
95 // ============================================================================
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
102 int strcasecmp(const char *str_1
, const char *str_2
)
104 register char c1
, c2
;
106 c1
= tolower(*str_1
++);
107 c2
= tolower(*str_2
++);
108 } while ( c1
&& (c1
== c2
) );
113 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
116 register char c1
, c2
;
119 c1
= tolower(*str_1
++);
120 c2
= tolower(*str_2
++);
132 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
133 // we have no strI functions under VMS, therefore I have implemented
134 // an inefficient but portable version: convert copies of strings to lowercase
135 // and then use the normal comparison
136 static void myLowerString(char *s
)
139 if(isalpha(*s
)) *s
= (char)tolower(*s
);
144 int strcasecmp(const char *str_1
, const char *str_2
)
146 char *temp1
= new char[strlen(str_1
)+1];
147 char *temp2
= new char[strlen(str_2
)+1];
150 myLowerString(temp1
);
151 myLowerString(temp2
);
153 int result
= wxStrcmp(temp1
,temp2
);
160 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
162 char *temp1
= new char[strlen(str_1
)+1];
163 char *temp2
= new char[strlen(str_2
)+1];
166 myLowerString(temp1
);
167 myLowerString(temp2
);
169 int result
= strncmp(temp1
,temp2
,maxchar
);
181 #define strcasecmp stricmp
182 #define strncasecmp strnicmp
184 #define strcasecmp _stricmp
185 #define strncasecmp _strnicmp
192 #define strcasecmp stricmp
193 #define strncasecmp strnicmp
196 // This declaration is missing in SunOS!
197 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
198 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
201 int strcasecmp (const char *, const char *);
202 int strncasecmp (const char *, const char *, size_t);
205 #endif /* __WXMSW__ */
208 #define strcasecmp stricmp
209 #define strncasecmp strnicmp
213 copystring (const wxChar
*s
)
215 if (s
== NULL
) s
= wxT("");
216 size_t len
= wxStrlen (s
) + 1;
218 wxChar
*news
= new wxChar
[len
];
219 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
225 static long wxCurrentId
= 100;
230 return wxCurrentId
++;
234 wxGetCurrentId(void) { return wxCurrentId
; }
237 wxRegisterId (long id
)
239 if (id
>= wxCurrentId
)
240 wxCurrentId
= id
+ 1;
244 StringToFloat (wxChar
*s
, float *number
)
246 if (s
&& *s
&& number
)
247 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
251 StringToDouble (wxChar
*s
, double *number
)
253 if (s
&& *s
&& number
)
254 *number
= wxStrtod (s
, (wxChar
**) NULL
);
258 FloatToString (float number
, const wxChar
*fmt
)
260 static wxChar buf
[256];
262 // sprintf (buf, "%.2f", number);
263 wxSprintf (buf
, fmt
, number
);
268 DoubleToString (double number
, const wxChar
*fmt
)
270 static wxChar buf
[256];
272 wxSprintf (buf
, fmt
, number
);
277 StringToInt (wxChar
*s
, int *number
)
279 if (s
&& *s
&& number
)
280 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
284 StringToLong (wxChar
*s
, long *number
)
286 if (s
&& *s
&& number
)
287 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
291 IntToString (int number
)
293 static wxChar buf
[20];
295 wxSprintf (buf
, wxT("%d"), number
);
300 LongToString (long number
)
302 static wxChar buf
[20];
304 wxSprintf (buf
, wxT("%ld"), number
);
308 // Array used in DecToHex conversion routine.
309 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
311 // Convert 2-digit hex number to decimal
312 int wxHexToDec(const wxString
& buf
)
314 int firstDigit
, secondDigit
;
316 if (buf
.GetChar(0) >= wxT('A'))
317 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
319 firstDigit
= buf
.GetChar(0) - wxT('0');
321 if (buf
.GetChar(1) >= wxT('A'))
322 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
324 secondDigit
= buf
.GetChar(1) - wxT('0');
326 return firstDigit
* 16 + secondDigit
;
329 // Convert decimal integer to 2-character hex string
330 void wxDecToHex(int dec
, wxChar
*buf
)
332 int firstDigit
= (int)(dec
/16.0);
333 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
334 buf
[0] = hexArray
[firstDigit
];
335 buf
[1] = hexArray
[secondDigit
];
339 // Convert decimal integer to 2-character hex string
340 wxString
wxDecToHex(int dec
)
343 wxDecToHex(dec
, buf
);
344 return wxString(buf
);
347 // Match a string INDEPENDENT OF CASE
349 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
351 if (str1
== NULL
|| str2
== NULL
)
358 int len1
= strlen (str1
);
359 int len2
= strlen (str2
);
362 // Search for str1 in str2
363 // Slow .... but acceptable for short strings
364 for (i
= 0; i
<= len2
- len1
; i
++)
366 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
372 if (strcasecmp (str1
, str2
) == 0)
377 int len1
= strlen (str1
);
378 int len2
= strlen (str2
);
380 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
387 // Return the current date/time
391 time_t now
= time((time_t *) NULL
);
392 char *date
= ctime(&now
);
394 return wxString(date
);
399 // ----------------------------------------------------------------------------
400 // Menu accelerators related functions
401 // ----------------------------------------------------------------------------
403 wxChar
*wxStripMenuCodes (wxChar
*in
, wxChar
*out
)
406 return (wxChar
*) NULL
;
409 out
= copystring(in
);
411 wxChar
*tmpOut
= out
;
417 // Check && -> &, &x -> x
418 if (*++in
== wxT('&'))
421 else if (*in
== wxT('\t'))
423 // Remove all stuff after \t in X mode, and let the stuff as is
425 // Accelerators are handled in wx_item.cc for Motif, and are not
426 // YET supported in XView
438 wxString
wxStripMenuCodes(const wxString
& str
)
440 wxChar
*buf
= new wxChar
[str
.Length() + 1];
441 wxStripMenuCodes(WXSTRINGCAST str
, buf
);
449 // return wxAcceleratorEntry for the given menu string or NULL if none
451 wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
453 // check for accelerators: they are given after '\t'
454 int posTab
= label
.Find(wxT('\t'));
455 if ( posTab
!= wxNOT_FOUND
) {
456 // parse the accelerator string
458 int accelFlags
= wxACCEL_NORMAL
;
460 for ( size_t n
= (size_t)posTab
+ 1; n
< label
.Len(); n
++ ) {
461 if ( (label
[n
] == '+') || (label
[n
] == '-') ) {
462 if ( current
== _("ctrl") )
463 accelFlags
|= wxACCEL_CTRL
;
464 else if ( current
== _("alt") )
465 accelFlags
|= wxACCEL_ALT
;
466 else if ( current
== _("shift") )
467 accelFlags
|= wxACCEL_SHIFT
;
469 wxLogDebug(wxT("Unknown accel modifier: '%s'"),
476 current
+= wxTolower(label
[n
]);
480 if ( current
.IsEmpty() ) {
481 wxLogDebug(wxT("No accel key found, accel string ignored."));
484 if ( current
.Len() == 1 ) {
486 keyCode
= wxToupper(current
[0U]);
489 // is it a function key?
490 if ( current
[0U] == 'f' && isdigit(current
[1U]) &&
491 (current
.Len() == 2 ||
492 (current
.Len() == 3 && isdigit(current
[2U]))) ) {
494 wxSscanf(current
.c_str() + 1, wxT("%d"), &n
);
496 keyCode
= WXK_F1
+ n
- 1;
499 #if 0 // this is not supported by GTK+, apparently
500 // several special cases
502 if ( current
== wxT("DEL") ) {
505 else if ( current
== wxT("PGUP") ) {
508 else if ( current
== wxT("PGDN") ) {
514 wxLogDebug(wxT("Unrecognized accel key '%s', accel "
515 "string ignored."), current
.c_str());
522 // we do have something
523 return new wxAcceleratorEntry(accelFlags
, keyCode
);
527 return (wxAcceleratorEntry
*)NULL
;
530 #endif // wxUSE_ACCEL
532 // ----------------------------------------------------------------------------
533 // Window search functions
534 // ----------------------------------------------------------------------------
537 * If parent is non-NULL, look through children for a label or title
538 * matching the specified string. If NULL, look through all top-level windows.
543 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
547 return wxFindWindowByLabel1(title
, parent
);
551 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
553 node
= node
->GetNext() )
555 wxWindow
*win
= node
->GetData();
556 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
562 return (wxWindow
*) NULL
;
567 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
571 if (parent
->GetLabel() == title
)
577 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
579 node
= node
->GetNext() )
581 wxWindow
*win
= (wxWindow
*)node
->GetData();
582 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
589 return (wxWindow
*) NULL
; // Not found
593 * If parent is non-NULL, look through children for a name
594 * matching the specified string. If NULL, look through all top-level windows.
599 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
603 return wxFindWindowByName1 (title
, parent
);
607 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
609 node
= node
->GetNext() )
611 wxWindow
*win
= node
->GetData();
612 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
619 // Failed? Try by label instead.
620 return wxFindWindowByLabel(title
, parent
);
625 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
629 if ( parent
->GetName() == title
)
635 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
637 wxWindow
*win
= (wxWindow
*) node
->Data ();
638 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
645 return (wxWindow
*) NULL
; // Not found
649 // Returns menu item id or -1 if none.
651 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
653 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
656 return menuBar
->FindMenuItem (menuString
, itemString
);
662 On Fri, 21 Jul 1995, Paul Craven wrote:
664 > Is there a way to find the path of running program's executable? I can get
665 > my home directory, and the current directory, but I don't know how to get the
666 > executable directory.
669 The code below (warty as it is), does what you want on most Unix,
670 DOS, and Mac platforms (it's from the ALS Prolog main).
672 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
673 ||==== Voice: +1 (617)965-9191 Newton Centre,
674 || FAX: +1 (617)965-1636 MA 02159 USA
675 Email: ken@als.com WWW: http://www.als.com
676 ------------------------------------------------------------------------
679 // This code is commented out but it may be integrated with wxWin at
680 // a later date, after testing. Thanks Ken!
683 /*--------------------------------------------------------------------*
684 | whereami is given a filename f in the form: whereami(argv[0])
685 | It returns the directory in which the executable file (containing
686 | this code [main.c] ) may be found. A dot will be returned to indicate
687 | the current directory.
688 *--------------------------------------------------------------------*/
694 register char *cutoff
= NULL
; /* stifle -Wall */
701 * See if the file is accessible either through the current directory
702 * or through an absolute path.
705 if (access(name
, R_OK
) == 0) {
707 /*-------------------------------------------------------------*
708 * The file was accessible without any other work. But the current
709 * working directory might change on us, so if it was accessible
710 * through the cwd, then we should get it for later accesses.
711 *-------------------------------------------------------------*/
714 if (!absolute_pathname(name
)) {
715 #if defined(DOS) || defined(__WIN32__)
721 if (*(name
+ 1) == ':') {
722 if (*name
>= 'a' && *name
<= 'z')
723 drive
= (int) (*name
- 'a' + 1);
725 drive
= (int) (*name
- 'A' + 1);
727 *newrbuf
++ = *(name
+ 1);
728 *newrbuf
++ = DIR_SEPARATOR
;
732 *newrbuf
++ = DIR_SEPARATOR
;
734 if (getcwd(newrbuf
, drive
) == 0) { /* } */
736 if (getcwd(newrbuf
, 1024) == 0) { /* } */
740 if (getwd(imagedir
) == 0) { /* } */
741 #else /* !HAVE_GETWD */
742 if (getcwd(imagedir
, 1024) == 0) {
743 #endif /* !HAVE_GETWD */
745 fatal_error(FE_GETCWD
, 0);
747 for (; *t
; t
++) /* Set t to end of buffer */
749 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
754 cutoff
= t
; /* otherwise put one in */
755 *t
++ = DIR_SEPARATOR
;
758 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
760 (*t
++ = DIR_SEPARATOR
);
763 /*-------------------------------------------------------------*
764 * Copy the rest of the string and set the cutoff if it was not
765 * already set. If the first character of name is a slash, cutoff
766 * is not presently set but will be on the first iteration of the
768 *-------------------------------------------------------------*/
770 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
771 if (*s
== DIR_SEPARATOR
)
780 /*-------------------------------------------------------------*
781 * Get the path list from the environment. If the path list is
782 * inaccessible for any reason, leave with fatal error.
783 *-------------------------------------------------------------*/
786 if ((s
= getenv("Commands")) == (char *) 0)
788 if ((s
= getenv("PATH")) == (char *) 0)
790 fatal_error(FE_PATH
, 0);
793 * Copy path list into ebuf and set the source pointer to the
794 * beginning of this buffer.
802 while (*s
&& *s
!= PATH_SEPARATOR
)
804 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
805 ; /* do nothing -- slash already is in place */
807 *t
++ = DIR_SEPARATOR
; /* put in the slash */
808 cutoff
= t
- 1; /* set cutoff */
810 if (access(imagedir
, R_OK
) == 0)
814 s
++; /* advance source pointer */
816 fatal_error(FE_INFND
, 0);
821 /*-------------------------------------------------------------*
822 | At this point the full pathname should exist in imagedir and
823 | cutoff should be set to the final slash. We must now determine
824 | whether the file name is a symbolic link or not and chase it down
825 | if it is. Note that we reuse ebuf for getting the link.
826 *-------------------------------------------------------------*/
829 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
832 if (*s
== DIR_SEPARATOR
) {
839 if (*s
== DIR_SEPARATOR
)
840 cutoff
= t
; /* mark the last slash seen */
841 if (!(*t
++ = *s
++)) /* copy the character */
846 #endif /* HAVE_SYMLINK */
848 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
849 *(cutoff
+ 1) = 0; /* chop off the filename part */
856 // ----------------------------------------------------------------------------
858 // ----------------------------------------------------------------------------
861 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
862 * since otherwise the generic code may be pulled in unnecessarily.
865 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
866 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
868 wxMessageDialog
dialog(parent
, message
, caption
, style
);
870 int ans
= dialog
.ShowModal();
886 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
887 const wxString
& defaultValue
, wxWindow
*parent
,
888 int x
, int y
, bool WXUNUSED(centre
) )
891 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
892 if (dialog
.ShowModal() == wxID_OK
)
894 str
= dialog
.GetValue();
900 wxString
wxGetPasswordFromUser(const wxString
& message
,
901 const wxString
& caption
,
902 const wxString
& defaultValue
,
906 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
907 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
908 if ( dialog
.ShowModal() == wxID_OK
)
910 str
= dialog
.GetValue();
916 #endif // wxUSE_TEXTDLG
918 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
921 data
.SetChooseFull(TRUE
);
924 data
.SetColour((wxColour
&)colInit
); // const_cast
928 wxColourDialog
dialog(parent
, &data
);
929 if ( dialog
.ShowModal() == wxID_OK
)
931 colRet
= dialog
.GetColourData().GetColour();
933 //else: leave it invalid
938 // ----------------------------------------------------------------------------
939 // missing C RTL functions (FIXME shouldn't be here at all)
940 // ----------------------------------------------------------------------------
943 char *strdup(const char *s
)
945 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
950 return ( c
>= 0 && c
< 128 ) ;
954 // ----------------------------------------------------------------------------
955 // wxSafeYield and supporting functions
956 // ----------------------------------------------------------------------------
958 void wxEnableTopLevelWindows(bool enable
)
960 wxWindowList::Node
*node
;
961 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
962 node
->GetData()->Enable(enable
);
965 static void wxFindDisabledWindows(wxWindowList
& winDisabled
,
969 wxWindowList::Node
*node
;
970 for ( node
= win
->GetChildren().GetFirst(); node
; node
= node
->GetNext() )
972 wxWindow
*child
= node
->GetData();
973 if ( child
== winToSkip
)
976 wxFindDisabledWindows(winDisabled
, child
, winToSkip
);
978 if ( child
->IsEnabled() )
980 winDisabled
.Append(child
);
986 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
988 // remember all windows we're going to (temporarily) disable
989 m_winDisabled
= new wxWindowList
;
993 // and the top level window too
994 HWND hwndFG
= ::GetForegroundWindow();
995 m_winTop
= hwndFG
? wxFindWinFromHandle((WXHWND
)hwndFG
) : (wxWindow
*)NULL
;
997 HWND hwndFG
= ::GetTopWindow();
998 m_winTop
= hwndFG
? wxFindWinFromHandle((WXHWND
)hwndFG
) : (wxWindow
*)NULL
;
1002 wxWindowList::Node
*node
;
1003 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1005 wxWindow
*winTop
= node
->GetData();
1006 if ( winTop
!= winToSkip
&& winTop
->IsEnabled() )
1008 wxFindDisabledWindows(*m_winDisabled
, winTop
, winToSkip
);
1010 m_winDisabled
->Append(winTop
);
1016 wxWindowDisabler::~wxWindowDisabler()
1018 wxWindowList::Node
*node
;
1019 for ( node
= m_winDisabled
->GetFirst(); node
; node
= node
->GetNext() )
1021 node
->GetData()->Enable();
1024 delete m_winDisabled
;
1030 if ( !::SetForegroundWindow(GetHwndOf(m_winTop
)) )
1032 wxLogLastError("SetForegroundWindow");
1038 // 16-bit SetForegroundWindow() replacement
1040 GetWindowRect(m_winTop
, &reWin
);
1041 SetWindowPos (m_winTop
, HWND_TOP
,
1042 reWin
.left
, reWin
.top
,
1043 reWin
.right
- reWin
.left
, reWin
.bottom
,
1050 // Yield to other apps/messages and disable user input to all windows except
1052 bool wxSafeYield(wxWindow
*win
)
1054 wxWindowDisabler wd
;
1056 bool rc
= wxYield();
1061 // ----------------------------------------------------------------------------
1063 // ----------------------------------------------------------------------------
1065 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1066 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1069 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1071 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1077 // ----------------------------------------------------------------------------
1078 // network and user id functions
1079 // ----------------------------------------------------------------------------
1081 // Get Full RFC822 style email address
1082 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1084 wxString email
= wxGetEmailAddress();
1088 wxStrncpy(address
, email
, maxSize
- 1);
1089 address
[maxSize
- 1] = wxT('\0');
1094 wxString
wxGetEmailAddress()
1098 wxString host
= wxGetHostName();
1101 wxString user
= wxGetUserId();
1104 wxString
email(user
);
1105 email
<< wxT('@') << host
;
1112 wxString
wxGetUserId()
1114 static const int maxLoginLen
= 256; // FIXME arbitrary number
1117 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1118 buf
.UngetWriteBuf();
1126 wxString
wxGetUserName()
1128 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1131 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1132 buf
.UngetWriteBuf();
1140 wxString
wxGetHostName()
1142 static const size_t hostnameSize
= 257;
1145 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1147 buf
.UngetWriteBuf();
1155 wxString
wxGetFullHostName()
1157 static const size_t hostnameSize
= 257;
1160 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1162 buf
.UngetWriteBuf();
1170 wxString
wxGetHomeDir()
1173 wxGetHomeDir(&home
);
1180 wxString
wxGetCurrentDir()
1187 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1188 dir
.UngetWriteBuf();
1192 if ( errno
!= ERANGE
)
1194 wxLogSysError(_T("Failed to get current directory"));
1196 return wxEmptyString
;
1200 // buffer was too small, retry with a larger one
1212 // ----------------------------------------------------------------------------
1214 // ----------------------------------------------------------------------------
1216 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1218 // create a wxProcess which will capture the output
1219 wxProcess
*process
= new wxProcess
;
1220 process
->Redirect();
1222 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1225 wxInputStream
& is
= *process
->GetInputStream();
1226 wxTextInputStream
tis(is
);
1227 while ( !is
.Eof() && is
.IsOk() )
1229 wxString line
= tis
.ReadLine();
1230 if ( is
.LastError() )