]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "utils.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
40 #include "wx/window.h"
43 #include "wx/msgdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/textctrl.h" // for wxTE_PASSWORD
47 #include "wx/menuitem.h"
54 #include "wx/process.h"
55 #include "wx/txtstrm.h"
63 #if !defined(__WATCOMC__)
64 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
70 #include "wx/colordlg.h"
71 #include "wx/fontdlg.h"
72 #include "wx/notebook.h"
74 #include "wx/statusbr.h"
80 #include <sys/types.h>
89 #include "wx/msw/private.h"
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 #if WXWIN_COMPATIBILITY_2_2
97 const wxChar
*wxInternalErrorStr
= wxT("wxWindows Internal Error");
98 const wxChar
*wxFatalErrorStr
= wxT("wxWindows Fatal Error");
99 #endif // WXWIN_COMPATIBILITY_2_2
101 // ----------------------------------------------------------------------------
102 // function protoypes
103 // ----------------------------------------------------------------------------
106 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
107 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
110 // ============================================================================
112 // ============================================================================
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 #if defined(__WXMAC__) && !defined(__DARWIN__)
119 int strcasecmp(const char *str_1
, const char *str_2
)
121 register char c1
, c2
;
123 c1
= tolower(*str_1
++);
124 c2
= tolower(*str_2
++);
125 } while ( c1
&& (c1
== c2
) );
130 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
133 register char c1
, c2
;
136 c1
= tolower(*str_1
++);
137 c2
= tolower(*str_2
++);
147 #endif // __WXMAC__ && !__DARWIN__
149 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
150 // we have no strI functions under VMS, therefore I have implemented
151 // an inefficient but portable version: convert copies of strings to lowercase
152 // and then use the normal comparison
153 static void myLowerString(char *s
)
156 if(isalpha(*s
)) *s
= (char)tolower(*s
);
161 int strcasecmp(const char *str_1
, const char *str_2
)
163 char *temp1
= new char[strlen(str_1
)+1];
164 char *temp2
= new char[strlen(str_2
)+1];
167 myLowerString(temp1
);
168 myLowerString(temp2
);
170 int result
= wxStrcmp(temp1
,temp2
);
177 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
179 char *temp1
= new char[strlen(str_1
)+1];
180 char *temp2
= new char[strlen(str_2
)+1];
183 myLowerString(temp1
);
184 myLowerString(temp2
);
186 int result
= strncmp(temp1
,temp2
,maxchar
);
194 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
198 #define strcasecmp stricmp
199 #define strncasecmp strnicmp
201 #define strcasecmp _stricmp
202 #define strncasecmp _strnicmp
209 #define strcasecmp stricmp
210 #define strncasecmp strnicmp
213 // This declaration is missing in SunOS!
214 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
215 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
218 int strcasecmp (const char *, const char *);
219 int strncasecmp (const char *, const char *, size_t);
222 #endif /* __WXMSW__ */
225 #define strcasecmp stricmp
226 #define strncasecmp strnicmp
230 #define strcasecmp stricmp
231 #define strncasecmp strnicmp
235 copystring (const wxChar
*s
)
237 if (s
== NULL
) s
= wxT("");
238 size_t len
= wxStrlen (s
) + 1;
240 wxChar
*news
= new wxChar
[len
];
241 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
247 static long wxCurrentId
= 100;
252 return wxCurrentId
++;
256 wxGetCurrentId(void) { return wxCurrentId
; }
259 wxRegisterId (long id
)
261 if (id
>= wxCurrentId
)
262 wxCurrentId
= id
+ 1;
266 StringToFloat (const wxChar
*s
, float *number
)
268 if (s
&& *s
&& number
)
269 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
273 StringToDouble (const wxChar
*s
, double *number
)
275 if (s
&& *s
&& number
)
276 *number
= wxStrtod (s
, (wxChar
**) NULL
);
280 FloatToString (float number
, const wxChar
*fmt
)
282 static wxChar buf
[256];
284 wxSprintf (buf
, fmt
, number
);
289 DoubleToString (double number
, const wxChar
*fmt
)
291 static wxChar buf
[256];
293 wxSprintf (buf
, fmt
, number
);
298 StringToInt (const wxChar
*s
, int *number
)
300 if (s
&& *s
&& number
)
301 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
305 StringToLong (const wxChar
*s
, long *number
)
307 if (s
&& *s
&& number
)
308 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
312 IntToString (int number
)
314 static wxChar buf
[20];
316 wxSprintf (buf
, wxT("%d"), number
);
321 LongToString (long number
)
323 static wxChar buf
[20];
325 wxSprintf (buf
, wxT("%ld"), number
);
329 // Array used in DecToHex conversion routine.
330 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
332 // Convert 2-digit hex number to decimal
333 int wxHexToDec(const wxString
& buf
)
335 int firstDigit
, secondDigit
;
337 if (buf
.GetChar(0) >= wxT('A'))
338 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
340 firstDigit
= buf
.GetChar(0) - wxT('0');
342 if (buf
.GetChar(1) >= wxT('A'))
343 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
345 secondDigit
= buf
.GetChar(1) - wxT('0');
347 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
350 // Convert decimal integer to 2-character hex string
351 void wxDecToHex(int dec
, wxChar
*buf
)
353 int firstDigit
= (int)(dec
/16.0);
354 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
355 buf
[0] = hexArray
[firstDigit
];
356 buf
[1] = hexArray
[secondDigit
];
360 // Convert decimal integer to 2-character hex string
361 wxString
wxDecToHex(int dec
)
364 wxDecToHex(dec
, buf
);
365 return wxString(buf
);
368 // Match a string INDEPENDENT OF CASE
370 StringMatch (const char *str1
, const char *str2
, bool subString
, bool exact
)
372 if (str1
== NULL
|| str2
== NULL
)
379 int len1
= strlen (str1
);
380 int len2
= strlen (str2
);
383 // Search for str1 in str2
384 // Slow .... but acceptable for short strings
385 for (i
= 0; i
<= len2
- len1
; i
++)
387 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
393 if (strcasecmp (str1
, str2
) == 0)
398 int len1
= strlen (str1
);
399 int len2
= strlen (str2
);
401 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
408 // Return the current date/time
412 time_t now
= time((time_t *) NULL
);
413 char *date
= ctime(&now
);
415 return wxString(date
);
422 // ----------------------------------------------------------------------------
423 // Menu accelerators related functions
424 // ----------------------------------------------------------------------------
426 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
428 wxString s
= wxMenuItem::GetLabelFromText(in
);
431 // go smash their buffer if it's not big enough - I love char * params
432 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
442 wxString
wxStripMenuCodes(const wxString
& in
)
446 size_t len
= in
.length();
449 for ( size_t n
= 0; n
< len
; n
++ )
454 // skip it, it is used to introduce the accel char (or to quote
455 // itself in which case it should still be skipped): note that it
456 // can't be the last character of the string
459 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
463 // use the next char instead
467 else if ( ch
== _T('\t') )
469 // everything after TAB is accel string, exit the loop
479 #endif // wxUSE_MENUS
481 // ----------------------------------------------------------------------------
482 // Window search functions
483 // ----------------------------------------------------------------------------
486 * If parent is non-NULL, look through children for a label or title
487 * matching the specified string. If NULL, look through all top-level windows.
492 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
496 return wxFindWindowByLabel1(title
, parent
);
500 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
502 node
= node
->GetNext() )
504 wxWindow
*win
= node
->GetData();
505 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
511 return (wxWindow
*) NULL
;
516 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
520 if (parent
->GetLabel() == title
)
526 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
528 node
= node
->GetNext() )
530 wxWindow
*win
= (wxWindow
*)node
->GetData();
531 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
538 return (wxWindow
*) NULL
; // Not found
542 * If parent is non-NULL, look through children for a name
543 * matching the specified string. If NULL, look through all top-level windows.
548 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
552 return wxFindWindowByName1 (title
, parent
);
556 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
558 node
= node
->GetNext() )
560 wxWindow
*win
= node
->GetData();
561 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
568 // Failed? Try by label instead.
569 return wxFindWindowByLabel(title
, parent
);
574 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
578 if ( parent
->GetName() == title
)
584 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
586 wxWindow
*win
= (wxWindow
*) node
->Data ();
587 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
594 return (wxWindow
*) NULL
; // Not found
598 // Returns menu item id or -1 if none.
600 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
603 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
605 return menuBar
->FindMenuItem (menuString
, itemString
);
606 #endif // wxUSE_MENUS
611 // Try to find the deepest child that contains 'pt'.
612 // We go backwards, to try to allow for controls that are spacially
613 // within other controls, but are still siblings (e.g. buttons within
614 // static boxes). Static boxes are likely to be created _before_ controls
615 // that sit inside them.
616 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
621 // Hack for wxNotebook case: at least in wxGTK, all pages
622 // claim to be shown, so we must only deal with the selected one.
624 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
626 wxNotebook
* nb
= (wxNotebook
*) win
;
627 int sel
= nb
->GetSelection();
630 wxWindow
* child
= nb
->GetPage(sel
);
631 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
640 else if (win->IsKindOf(CLASSINFO(wxFrame)))
642 // Pseudo-children that may not be mentioned in the child list
643 wxWindowList extraChildren;
644 wxFrame* frame = (wxFrame*) win;
645 if (frame->GetStatusBar())
646 extraChildren.Append(frame->GetStatusBar());
647 if (frame->GetToolBar())
648 extraChildren.Append(frame->GetToolBar());
650 wxNode* node = extraChildren.First();
653 wxWindow* child = (wxWindow*) node->Data();
654 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
662 wxNode
* node
= win
->GetChildren().Last();
665 wxWindow
* child
= (wxWindow
*) node
->Data();
666 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
669 node
= node
->Previous();
672 wxPoint pos
= win
->GetPosition();
673 wxSize sz
= win
->GetSize();
674 if (win
->GetParent())
676 pos
= win
->GetParent()->ClientToScreen(pos
);
679 wxRect
rect(pos
, sz
);
686 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
688 // Go backwards through the list since windows
689 // on top are likely to have been appended most
691 wxNode
* node
= wxTopLevelWindows
.Last();
694 wxWindow
* win
= (wxWindow
*) node
->Data();
695 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
698 node
= node
->Previous();
706 On Fri, 21 Jul 1995, Paul Craven wrote:
708 > Is there a way to find the path of running program's executable? I can get
709 > my home directory, and the current directory, but I don't know how to get the
710 > executable directory.
713 The code below (warty as it is), does what you want on most Unix,
714 DOS, and Mac platforms (it's from the ALS Prolog main).
716 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
717 ||==== Voice: +1 (617)965-9191 Newton Centre,
718 || FAX: +1 (617)965-1636 MA 02159 USA
719 Email: ken@als.com WWW: http://www.als.com
720 ------------------------------------------------------------------------
723 // This code is commented out but it may be integrated with wxWin at
724 // a later date, after testing. Thanks Ken!
727 /*--------------------------------------------------------------------*
728 | whereami is given a filename f in the form: whereami(argv[0])
729 | It returns the directory in which the executable file (containing
730 | this code [main.c] ) may be found. A dot will be returned to indicate
731 | the current directory.
732 *--------------------------------------------------------------------*/
738 register char *cutoff
= NULL
; /* stifle -Wall */
745 * See if the file is accessible either through the current directory
746 * or through an absolute path.
749 if (access(name
, R_OK
) == 0) {
751 /*-------------------------------------------------------------*
752 * The file was accessible without any other work. But the current
753 * working directory might change on us, so if it was accessible
754 * through the cwd, then we should get it for later accesses.
755 *-------------------------------------------------------------*/
758 if (!absolute_pathname(name
)) {
759 #if defined(__DOS__) || defined(__WIN32__)
765 if (*(name
+ 1) == ':') {
766 if (*name
>= 'a' && *name
<= 'z')
767 drive
= (int) (*name
- 'a' + 1);
769 drive
= (int) (*name
- 'A' + 1);
771 *newrbuf
++ = *(name
+ 1);
772 *newrbuf
++ = DIR_SEPARATOR
;
776 *newrbuf
++ = DIR_SEPARATOR
;
778 if (getcwd(newrbuf
, drive
) == 0) { /* } */
780 if (getcwd(newrbuf
, 1024) == 0) { /* } */
784 if (getwd(imagedir
) == 0) { /* } */
785 #else /* !HAVE_GETWD */
786 if (getcwd(imagedir
, 1024) == 0) {
787 #endif /* !HAVE_GETWD */
789 fatal_error(FE_GETCWD
, 0);
791 for (; *t
; t
++) /* Set t to end of buffer */
793 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
798 cutoff
= t
; /* otherwise put one in */
799 *t
++ = DIR_SEPARATOR
;
802 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
804 (*t
++ = DIR_SEPARATOR
);
807 /*-------------------------------------------------------------*
808 * Copy the rest of the string and set the cutoff if it was not
809 * already set. If the first character of name is a slash, cutoff
810 * is not presently set but will be on the first iteration of the
812 *-------------------------------------------------------------*/
814 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
815 if (*s
== DIR_SEPARATOR
)
824 /*-------------------------------------------------------------*
825 * Get the path list from the environment. If the path list is
826 * inaccessible for any reason, leave with fatal error.
827 *-------------------------------------------------------------*/
830 if ((s
= getenv("Commands")) == (char *) 0)
832 if ((s
= getenv("PATH")) == (char *) 0)
834 fatal_error(FE_PATH
, 0);
837 * Copy path list into ebuf and set the source pointer to the
838 * beginning of this buffer.
846 while (*s
&& *s
!= PATH_SEPARATOR
)
848 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
849 ; /* do nothing -- slash already is in place */
851 *t
++ = DIR_SEPARATOR
; /* put in the slash */
852 cutoff
= t
- 1; /* set cutoff */
854 if (access(imagedir
, R_OK
) == 0)
858 s
++; /* advance source pointer */
860 fatal_error(FE_INFND
, 0);
865 /*-------------------------------------------------------------*
866 | At this point the full pathname should exist in imagedir and
867 | cutoff should be set to the final slash. We must now determine
868 | whether the file name is a symbolic link or not and chase it down
869 | if it is. Note that we reuse ebuf for getting the link.
870 *-------------------------------------------------------------*/
873 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
876 if (*s
== DIR_SEPARATOR
) {
883 if (*s
== DIR_SEPARATOR
)
884 cutoff
= t
; /* mark the last slash seen */
885 if (!(*t
++ = *s
++)) /* copy the character */
890 #endif /* HAVE_SYMLINK */
892 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
893 *(cutoff
+ 1) = 0; /* chop off the filename part */
900 // ----------------------------------------------------------------------------
902 // ----------------------------------------------------------------------------
905 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
906 * since otherwise the generic code may be pulled in unnecessarily.
911 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
912 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
914 wxMessageDialog
dialog(parent
, message
, caption
, style
);
916 int ans
= dialog
.ShowModal();
929 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
934 #endif // wxUSE_MSGDLG
938 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
939 const wxString
& defaultValue
, wxWindow
*parent
,
940 int x
, int y
, bool WXUNUSED(centre
) )
943 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
944 if (dialog
.ShowModal() == wxID_OK
)
946 str
= dialog
.GetValue();
952 wxString
wxGetPasswordFromUser(const wxString
& message
,
953 const wxString
& caption
,
954 const wxString
& defaultValue
,
958 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
959 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
960 if ( dialog
.ShowModal() == wxID_OK
)
962 str
= dialog
.GetValue();
968 #endif // wxUSE_TEXTDLG
972 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
975 data
.SetChooseFull(TRUE
);
978 data
.SetColour((wxColour
&)colInit
); // const_cast
982 wxColourDialog
dialog(parent
, &data
);
983 if ( dialog
.ShowModal() == wxID_OK
)
985 colRet
= dialog
.GetColourData().GetColour();
987 //else: leave it invalid
992 #endif // wxUSE_COLOURDLG
996 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
)
1001 data
.SetInitialFont(fontInit
);
1005 wxFontDialog
dialog(parent
, &data
);
1006 if ( dialog
.ShowModal() == wxID_OK
)
1008 fontRet
= dialog
.GetFontData().GetChosenFont();
1010 //else: leave it invalid
1015 #endif // wxUSE_FONTDLG
1016 // ----------------------------------------------------------------------------
1017 // missing C RTL functions (FIXME shouldn't be here at all)
1018 // ----------------------------------------------------------------------------
1021 #if __MSL__ < 0x7000
1022 char *strdup(const char *s
)
1024 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
1027 int isascii( int c
)
1029 return ( c
>= 0 && c
< 128 ) ;
1031 #endif // __MWERKS__
1033 // ----------------------------------------------------------------------------
1034 // wxSafeYield and supporting functions
1035 // ----------------------------------------------------------------------------
1037 void wxEnableTopLevelWindows(bool enable
)
1039 wxWindowList::Node
*node
;
1040 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1041 node
->GetData()->Enable(enable
);
1044 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1046 // remember the top level windows which were already disabled, so that we
1047 // don't reenable them later
1048 m_winDisabled
= NULL
;
1050 wxWindowList::Node
*node
;
1051 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1053 wxWindow
*winTop
= node
->GetData();
1054 if ( winTop
== winToSkip
)
1057 if ( winTop
->IsEnabled() )
1063 if ( !m_winDisabled
)
1065 m_winDisabled
= new wxWindowList
;
1068 m_winDisabled
->Append(winTop
);
1073 wxWindowDisabler::~wxWindowDisabler()
1075 wxWindowList::Node
*node
;
1076 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1078 wxWindow
*winTop
= node
->GetData();
1079 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1083 //else: had been already disabled, don't reenable
1086 delete m_winDisabled
;
1089 // Yield to other apps/messages and disable user input to all windows except
1091 bool wxSafeYield(wxWindow
*win
)
1093 wxWindowDisabler
wd(win
);
1095 bool rc
= wxYield();
1100 // ----------------------------------------------------------------------------
1102 // ----------------------------------------------------------------------------
1104 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1105 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1108 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1110 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1116 const wxChar
*wxGetInstallPrefix()
1120 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
1121 return prefix
.c_str();
1123 #ifdef wxINSTALL_PREFIX
1124 return wxT(wxINSTALL_PREFIX
);
1130 wxString
wxGetDataDir()
1132 wxString format
= wxGetInstallPrefix();
1133 format
<< wxFILE_SEP_PATH
1134 << wxT("share") << wxFILE_SEP_PATH
1135 << wxT("wx") << wxFILE_SEP_PATH
1138 dir
.Printf(format
.c_str(), wxMAJOR_VERSION
, wxMINOR_VERSION
);
1143 // ----------------------------------------------------------------------------
1144 // network and user id functions
1145 // ----------------------------------------------------------------------------
1147 // Get Full RFC822 style email address
1148 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1150 wxString email
= wxGetEmailAddress();
1154 wxStrncpy(address
, email
, maxSize
- 1);
1155 address
[maxSize
- 1] = wxT('\0');
1160 wxString
wxGetEmailAddress()
1164 wxString host
= wxGetFullHostName();
1167 wxString user
= wxGetUserId();
1170 email
<< user
<< wxT('@') << host
;
1177 wxString
wxGetUserId()
1179 static const int maxLoginLen
= 256; // FIXME arbitrary number
1182 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1183 buf
.UngetWriteBuf();
1191 wxString
wxGetUserName()
1193 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1196 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1197 buf
.UngetWriteBuf();
1205 wxString
wxGetHostName()
1207 static const size_t hostnameSize
= 257;
1210 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1212 buf
.UngetWriteBuf();
1220 wxString
wxGetFullHostName()
1222 static const size_t hostnameSize
= 257;
1225 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1227 buf
.UngetWriteBuf();
1235 wxString
wxGetHomeDir()
1238 wxGetHomeDir(&home
);
1245 wxString
wxGetCurrentDir()
1252 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1253 dir
.UngetWriteBuf();
1257 if ( errno
!= ERANGE
)
1259 wxLogSysError(_T("Failed to get current directory"));
1261 return wxEmptyString
;
1265 // buffer was too small, retry with a larger one
1277 // ----------------------------------------------------------------------------
1279 // ----------------------------------------------------------------------------
1281 // this is a private function because it hasn't a clean interface: the first
1282 // array is passed by reference, the second by pointer - instead we have 2
1283 // public versions of wxExecute() below
1284 static long wxDoExecuteWithCapture(const wxString
& command
,
1285 wxArrayString
& output
,
1286 wxArrayString
* error
)
1289 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1293 // create a wxProcess which will capture the output
1294 wxProcess
*process
= new wxProcess
;
1295 process
->Redirect();
1297 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1302 wxInputStream
* is
= process
->GetInputStream();
1303 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1304 wxTextInputStream
tis(*is
);
1306 wxTextInputStream
*tes
= NULL
;
1307 wxInputStream
*es
= NULL
;
1310 es
= process
->GetErrorStream();
1312 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1314 tes
= new wxTextInputStream(*es
);
1322 if ( !is
->Eof() && is
->IsOk() )
1324 wxString line
= tis
.ReadLine();
1325 if ( is
->LastError() )
1333 if ( error
&& !es
->Eof() && es
->IsOk() )
1335 wxString line
= tes
->ReadLine();
1336 if ( es
->LastError() )
1348 #endif // wxUSE_STREAMS
1353 #endif // IO redirection supoprted
1356 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1358 return wxDoExecuteWithCapture(command
, output
, NULL
);
1361 long wxExecute(const wxString
& command
,
1362 wxArrayString
& output
,
1363 wxArrayString
& error
)
1365 return wxDoExecuteWithCapture(command
, output
, &error
);
1368 // ----------------------------------------------------------------------------
1369 // wxApp::Yield() wrappers for backwards compatibility
1370 // ----------------------------------------------------------------------------
1375 return wxTheApp
&& wxTheApp
->Yield();
1381 bool wxYieldIfNeeded()
1384 return wxTheApp
&& wxTheApp
->Yield(TRUE
);