]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "utils.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
39 #include "wx/window.h"
42 #include "wx/msgdlg.h"
43 #include "wx/textdlg.h"
45 #include "wx/menuitem.h"
52 #include "wx/process.h"
53 #include "wx/txtstrm.h"
61 #if !defined(__WATCOMC__)
62 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
68 #include "wx/colordlg.h"
74 #include <sys/types.h>
83 #include "wx/msw/private.h"
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
91 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
92 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
104 int strcasecmp(const char *str_1
, const char *str_2
)
106 register char c1
, c2
;
108 c1
= tolower(*str_1
++);
109 c2
= tolower(*str_2
++);
110 } while ( c1
&& (c1
== c2
) );
115 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
118 register char c1
, c2
;
121 c1
= tolower(*str_1
++);
122 c2
= tolower(*str_2
++);
134 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
135 // we have no strI functions under VMS, therefore I have implemented
136 // an inefficient but portable version: convert copies of strings to lowercase
137 // and then use the normal comparison
138 static void myLowerString(char *s
)
141 if(isalpha(*s
)) *s
= (char)tolower(*s
);
146 int strcasecmp(const char *str_1
, const char *str_2
)
148 char *temp1
= new char[strlen(str_1
)+1];
149 char *temp2
= new char[strlen(str_2
)+1];
152 myLowerString(temp1
);
153 myLowerString(temp2
);
155 int result
= wxStrcmp(temp1
,temp2
);
162 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
164 char *temp1
= new char[strlen(str_1
)+1];
165 char *temp2
= new char[strlen(str_2
)+1];
168 myLowerString(temp1
);
169 myLowerString(temp2
);
171 int result
= strncmp(temp1
,temp2
,maxchar
);
183 #define strcasecmp stricmp
184 #define strncasecmp strnicmp
186 #define strcasecmp _stricmp
187 #define strncasecmp _strnicmp
194 #define strcasecmp stricmp
195 #define strncasecmp strnicmp
198 // This declaration is missing in SunOS!
199 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
200 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
203 int strcasecmp (const char *, const char *);
204 int strncasecmp (const char *, const char *, size_t);
207 #endif /* __WXMSW__ */
210 #define strcasecmp stricmp
211 #define strncasecmp strnicmp
215 copystring (const wxChar
*s
)
217 if (s
== NULL
) s
= wxT("");
218 size_t len
= wxStrlen (s
) + 1;
220 wxChar
*news
= new wxChar
[len
];
221 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
227 static long wxCurrentId
= 100;
232 return wxCurrentId
++;
236 wxGetCurrentId(void) { return wxCurrentId
; }
239 wxRegisterId (long id
)
241 if (id
>= wxCurrentId
)
242 wxCurrentId
= id
+ 1;
246 StringToFloat (wxChar
*s
, float *number
)
248 if (s
&& *s
&& number
)
249 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
253 StringToDouble (wxChar
*s
, double *number
)
255 if (s
&& *s
&& number
)
256 *number
= wxStrtod (s
, (wxChar
**) NULL
);
260 FloatToString (float number
, const wxChar
*fmt
)
262 static wxChar buf
[256];
264 // sprintf (buf, "%.2f", number);
265 wxSprintf (buf
, fmt
, number
);
270 DoubleToString (double number
, const wxChar
*fmt
)
272 static wxChar buf
[256];
274 wxSprintf (buf
, fmt
, number
);
279 StringToInt (wxChar
*s
, int *number
)
281 if (s
&& *s
&& number
)
282 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
286 StringToLong (wxChar
*s
, long *number
)
288 if (s
&& *s
&& number
)
289 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
293 IntToString (int number
)
295 static wxChar buf
[20];
297 wxSprintf (buf
, wxT("%d"), number
);
302 LongToString (long number
)
304 static wxChar buf
[20];
306 wxSprintf (buf
, wxT("%ld"), number
);
310 // Array used in DecToHex conversion routine.
311 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
313 // Convert 2-digit hex number to decimal
314 int wxHexToDec(const wxString
& buf
)
316 int firstDigit
, secondDigit
;
318 if (buf
.GetChar(0) >= wxT('A'))
319 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
321 firstDigit
= buf
.GetChar(0) - wxT('0');
323 if (buf
.GetChar(1) >= wxT('A'))
324 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
326 secondDigit
= buf
.GetChar(1) - wxT('0');
328 return firstDigit
* 16 + secondDigit
;
331 // Convert decimal integer to 2-character hex string
332 void wxDecToHex(int dec
, wxChar
*buf
)
334 int firstDigit
= (int)(dec
/16.0);
335 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
336 buf
[0] = hexArray
[firstDigit
];
337 buf
[1] = hexArray
[secondDigit
];
341 // Convert decimal integer to 2-character hex string
342 wxString
wxDecToHex(int dec
)
345 wxDecToHex(dec
, buf
);
346 return wxString(buf
);
349 // Match a string INDEPENDENT OF CASE
351 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
353 if (str1
== NULL
|| str2
== NULL
)
360 int len1
= strlen (str1
);
361 int len2
= strlen (str2
);
364 // Search for str1 in str2
365 // Slow .... but acceptable for short strings
366 for (i
= 0; i
<= len2
- len1
; i
++)
368 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
374 if (strcasecmp (str1
, str2
) == 0)
379 int len1
= strlen (str1
);
380 int len2
= strlen (str2
);
382 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
389 // Return the current date/time
393 time_t now
= time((time_t *) NULL
);
394 char *date
= ctime(&now
);
396 return wxString(date
);
401 // ----------------------------------------------------------------------------
402 // Menu accelerators related functions
403 // ----------------------------------------------------------------------------
405 wxChar
*wxStripMenuCodes (wxChar
*in
, wxChar
*out
)
408 return (wxChar
*) NULL
;
411 out
= copystring(in
);
413 wxChar
*tmpOut
= out
;
419 // Check && -> &, &x -> x
420 if (*++in
== wxT('&'))
423 else if (*in
== wxT('\t'))
425 // Remove all stuff after \t in X mode, and let the stuff as is
427 // Accelerators are handled in wx_item.cc for Motif, and are not
428 // YET supported in XView
440 wxString
wxStripMenuCodes(const wxString
& str
)
442 wxChar
*buf
= new wxChar
[str
.Length() + 1];
443 wxStripMenuCodes(WXSTRINGCAST str
, buf
);
451 // return wxAcceleratorEntry for the given menu string or NULL if none
453 wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
455 // check for accelerators: they are given after '\t'
456 int posTab
= label
.Find(wxT('\t'));
457 if ( posTab
!= wxNOT_FOUND
) {
458 // parse the accelerator string
460 int accelFlags
= wxACCEL_NORMAL
;
462 for ( size_t n
= (size_t)posTab
+ 1; n
< label
.Len(); n
++ ) {
463 if ( (label
[n
] == '+') || (label
[n
] == '-') ) {
464 if ( current
== _("ctrl") )
465 accelFlags
|= wxACCEL_CTRL
;
466 else if ( current
== _("alt") )
467 accelFlags
|= wxACCEL_ALT
;
468 else if ( current
== _("shift") )
469 accelFlags
|= wxACCEL_SHIFT
;
471 wxLogDebug(wxT("Unknown accel modifier: '%s'"),
478 current
+= wxTolower(label
[n
]);
482 if ( current
.IsEmpty() ) {
483 wxLogDebug(wxT("No accel key found, accel string ignored."));
486 if ( current
.Len() == 1 ) {
488 keyCode
= wxToupper(current
[0U]);
491 // is it a function key?
492 if ( current
[0U] == 'f' && isdigit(current
[1U]) &&
493 (current
.Len() == 2 ||
494 (current
.Len() == 3 && isdigit(current
[2U]))) ) {
496 wxSscanf(current
.c_str() + 1, wxT("%d"), &n
);
498 keyCode
= WXK_F1
+ n
- 1;
501 // several special cases
503 if ( current
== wxT("DEL") ) {
504 keyCode
= WXK_DELETE
;
506 else if ( current
== wxT("DELETE") ) {
507 keyCode
= WXK_DELETE
;
509 else if ( current
== wxT("INS") ) {
510 keyCode
= WXK_INSERT
;
512 else if ( current
== wxT("INSERT") ) {
513 keyCode
= WXK_INSERT
;
516 else if ( current
== wxT("PGUP") ) {
519 else if ( current
== wxT("PGDN") ) {
525 wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."),
533 // we do have something
534 return new wxAcceleratorEntry(accelFlags
, keyCode
);
538 return (wxAcceleratorEntry
*)NULL
;
541 #endif // wxUSE_ACCEL
543 // ----------------------------------------------------------------------------
544 // Window search functions
545 // ----------------------------------------------------------------------------
548 * If parent is non-NULL, look through children for a label or title
549 * matching the specified string. If NULL, look through all top-level windows.
554 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
558 return wxFindWindowByLabel1(title
, parent
);
562 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
564 node
= node
->GetNext() )
566 wxWindow
*win
= node
->GetData();
567 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
573 return (wxWindow
*) NULL
;
578 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
582 if (parent
->GetLabel() == title
)
588 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
590 node
= node
->GetNext() )
592 wxWindow
*win
= (wxWindow
*)node
->GetData();
593 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
600 return (wxWindow
*) NULL
; // Not found
604 * If parent is non-NULL, look through children for a name
605 * matching the specified string. If NULL, look through all top-level windows.
610 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
614 return wxFindWindowByName1 (title
, parent
);
618 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
620 node
= node
->GetNext() )
622 wxWindow
*win
= node
->GetData();
623 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
630 // Failed? Try by label instead.
631 return wxFindWindowByLabel(title
, parent
);
636 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
640 if ( parent
->GetName() == title
)
646 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
648 wxWindow
*win
= (wxWindow
*) node
->Data ();
649 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
656 return (wxWindow
*) NULL
; // Not found
660 // Returns menu item id or -1 if none.
662 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
664 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
667 return menuBar
->FindMenuItem (menuString
, itemString
);
670 // Try to find the deepest child that contains 'pt'
671 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
673 wxNode
* node
= win
->GetChildren().First();
676 wxWindow
* child
= (wxWindow
*) node
->Data();
677 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
683 wxPoint pos
= win
->GetPosition();
684 wxSize sz
= win
->GetSize();
685 if (win
->GetParent())
687 pos
= win
->GetParent()->ClientToScreen(pos
);
690 wxRect
rect(pos
, sz
);
697 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
699 // Go backwards through the list since windows
700 // on top are likely to have been appended most
702 wxNode
* node
= wxTopLevelWindows
.Last();
705 wxWindow
* win
= (wxWindow
*) node
->Data();
706 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
709 node
= node
->Previous();
717 On Fri, 21 Jul 1995, Paul Craven wrote:
719 > Is there a way to find the path of running program's executable? I can get
720 > my home directory, and the current directory, but I don't know how to get the
721 > executable directory.
724 The code below (warty as it is), does what you want on most Unix,
725 DOS, and Mac platforms (it's from the ALS Prolog main).
727 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
728 ||==== Voice: +1 (617)965-9191 Newton Centre,
729 || FAX: +1 (617)965-1636 MA 02159 USA
730 Email: ken@als.com WWW: http://www.als.com
731 ------------------------------------------------------------------------
734 // This code is commented out but it may be integrated with wxWin at
735 // a later date, after testing. Thanks Ken!
738 /*--------------------------------------------------------------------*
739 | whereami is given a filename f in the form: whereami(argv[0])
740 | It returns the directory in which the executable file (containing
741 | this code [main.c] ) may be found. A dot will be returned to indicate
742 | the current directory.
743 *--------------------------------------------------------------------*/
749 register char *cutoff
= NULL
; /* stifle -Wall */
756 * See if the file is accessible either through the current directory
757 * or through an absolute path.
760 if (access(name
, R_OK
) == 0) {
762 /*-------------------------------------------------------------*
763 * The file was accessible without any other work. But the current
764 * working directory might change on us, so if it was accessible
765 * through the cwd, then we should get it for later accesses.
766 *-------------------------------------------------------------*/
769 if (!absolute_pathname(name
)) {
770 #if defined(DOS) || defined(__WIN32__)
776 if (*(name
+ 1) == ':') {
777 if (*name
>= 'a' && *name
<= 'z')
778 drive
= (int) (*name
- 'a' + 1);
780 drive
= (int) (*name
- 'A' + 1);
782 *newrbuf
++ = *(name
+ 1);
783 *newrbuf
++ = DIR_SEPARATOR
;
787 *newrbuf
++ = DIR_SEPARATOR
;
789 if (getcwd(newrbuf
, drive
) == 0) { /* } */
791 if (getcwd(newrbuf
, 1024) == 0) { /* } */
795 if (getwd(imagedir
) == 0) { /* } */
796 #else /* !HAVE_GETWD */
797 if (getcwd(imagedir
, 1024) == 0) {
798 #endif /* !HAVE_GETWD */
800 fatal_error(FE_GETCWD
, 0);
802 for (; *t
; t
++) /* Set t to end of buffer */
804 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
809 cutoff
= t
; /* otherwise put one in */
810 *t
++ = DIR_SEPARATOR
;
813 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
815 (*t
++ = DIR_SEPARATOR
);
818 /*-------------------------------------------------------------*
819 * Copy the rest of the string and set the cutoff if it was not
820 * already set. If the first character of name is a slash, cutoff
821 * is not presently set but will be on the first iteration of the
823 *-------------------------------------------------------------*/
825 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
826 if (*s
== DIR_SEPARATOR
)
835 /*-------------------------------------------------------------*
836 * Get the path list from the environment. If the path list is
837 * inaccessible for any reason, leave with fatal error.
838 *-------------------------------------------------------------*/
841 if ((s
= getenv("Commands")) == (char *) 0)
843 if ((s
= getenv("PATH")) == (char *) 0)
845 fatal_error(FE_PATH
, 0);
848 * Copy path list into ebuf and set the source pointer to the
849 * beginning of this buffer.
857 while (*s
&& *s
!= PATH_SEPARATOR
)
859 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
860 ; /* do nothing -- slash already is in place */
862 *t
++ = DIR_SEPARATOR
; /* put in the slash */
863 cutoff
= t
- 1; /* set cutoff */
865 if (access(imagedir
, R_OK
) == 0)
869 s
++; /* advance source pointer */
871 fatal_error(FE_INFND
, 0);
876 /*-------------------------------------------------------------*
877 | At this point the full pathname should exist in imagedir and
878 | cutoff should be set to the final slash. We must now determine
879 | whether the file name is a symbolic link or not and chase it down
880 | if it is. Note that we reuse ebuf for getting the link.
881 *-------------------------------------------------------------*/
884 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
887 if (*s
== DIR_SEPARATOR
) {
894 if (*s
== DIR_SEPARATOR
)
895 cutoff
= t
; /* mark the last slash seen */
896 if (!(*t
++ = *s
++)) /* copy the character */
901 #endif /* HAVE_SYMLINK */
903 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
904 *(cutoff
+ 1) = 0; /* chop off the filename part */
911 // ----------------------------------------------------------------------------
913 // ----------------------------------------------------------------------------
916 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
917 * since otherwise the generic code may be pulled in unnecessarily.
920 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
921 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
923 wxMessageDialog
dialog(parent
, message
, caption
, style
);
925 int ans
= dialog
.ShowModal();
938 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
944 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
945 const wxString
& defaultValue
, wxWindow
*parent
,
946 int x
, int y
, bool WXUNUSED(centre
) )
949 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
950 if (dialog
.ShowModal() == wxID_OK
)
952 str
= dialog
.GetValue();
958 wxString
wxGetPasswordFromUser(const wxString
& message
,
959 const wxString
& caption
,
960 const wxString
& defaultValue
,
964 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
965 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
966 if ( dialog
.ShowModal() == wxID_OK
)
968 str
= dialog
.GetValue();
974 #endif // wxUSE_TEXTDLG
976 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
979 data
.SetChooseFull(TRUE
);
982 data
.SetColour((wxColour
&)colInit
); // const_cast
986 wxColourDialog
dialog(parent
, &data
);
987 if ( dialog
.ShowModal() == wxID_OK
)
989 colRet
= dialog
.GetColourData().GetColour();
991 //else: leave it invalid
996 // ----------------------------------------------------------------------------
997 // missing C RTL functions (FIXME shouldn't be here at all)
998 // ----------------------------------------------------------------------------
1001 char *strdup(const char *s
)
1003 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
1006 int isascii( int c
)
1008 return ( c
>= 0 && c
< 128 ) ;
1010 #endif // __MWERKS__
1012 // ----------------------------------------------------------------------------
1013 // wxSafeYield and supporting functions
1014 // ----------------------------------------------------------------------------
1016 void wxEnableTopLevelWindows(bool enable
)
1018 wxWindowList::Node
*node
;
1019 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1020 node
->GetData()->Enable(enable
);
1023 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1027 // and the top level window too
1028 HWND hwndFG
= ::GetForegroundWindow();
1029 m_winTop
= hwndFG
? wxFindWinFromHandle((WXHWND
)hwndFG
) : (wxWindow
*)NULL
;
1031 HWND hwndFG
= ::GetTopWindow(0);
1032 m_winTop
= hwndFG
? wxFindWinFromHandle((WXHWND
)hwndFG
) : (wxWindow
*)NULL
;
1036 // remember the top level windows which were already disabled, so that we
1037 // don't reenable them later
1038 m_winDisabled
= NULL
;
1040 wxWindowList::Node
*node
;
1041 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1043 wxWindow
*winTop
= node
->GetData();
1044 if ( winTop
== winToSkip
)
1047 if ( winTop
->IsEnabled() )
1053 if ( !m_winDisabled
)
1055 m_winDisabled
= new wxWindowList
;
1058 m_winDisabled
->Append(winTop
);
1063 wxWindowDisabler::~wxWindowDisabler()
1065 wxWindowList::Node
*node
;
1066 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1068 wxWindow
*winTop
= node
->GetData();
1069 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1073 //else: had been already disabled, don't reenable
1076 delete m_winDisabled
;
1082 if ( !::SetForegroundWindow(GetHwndOf(m_winTop
)) )
1084 wxLogLastError(wxT("SetForegroundWindow"));
1090 // 16-bit SetForegroundWindow() replacement
1092 GetWindowRect((HWND
) m_winTop
, &reWin
);
1093 SetWindowPos ((HWND
) m_winTop
, HWND_TOP
,
1094 reWin
.left
, reWin
.top
,
1095 reWin
.right
- reWin
.left
, reWin
.bottom
,
1102 // Yield to other apps/messages and disable user input to all windows except
1104 bool wxSafeYield(wxWindow
*win
)
1106 wxWindowDisabler
wd(win
);
1108 bool rc
= wxYield();
1113 // ----------------------------------------------------------------------------
1115 // ----------------------------------------------------------------------------
1117 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1118 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1121 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1123 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1129 // ----------------------------------------------------------------------------
1130 // network and user id functions
1131 // ----------------------------------------------------------------------------
1133 // Get Full RFC822 style email address
1134 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1136 wxString email
= wxGetEmailAddress();
1140 wxStrncpy(address
, email
, maxSize
- 1);
1141 address
[maxSize
- 1] = wxT('\0');
1146 wxString
wxGetEmailAddress()
1150 wxString host
= wxGetFullHostName();
1153 wxString user
= wxGetUserId();
1156 email
<< user
<< wxT('@') << host
;
1163 wxString
wxGetUserId()
1165 static const int maxLoginLen
= 256; // FIXME arbitrary number
1168 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1169 buf
.UngetWriteBuf();
1177 wxString
wxGetUserName()
1179 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1182 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1183 buf
.UngetWriteBuf();
1191 wxString
wxGetHostName()
1193 static const size_t hostnameSize
= 257;
1196 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1198 buf
.UngetWriteBuf();
1206 wxString
wxGetFullHostName()
1208 static const size_t hostnameSize
= 257;
1211 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1213 buf
.UngetWriteBuf();
1221 wxString
wxGetHomeDir()
1224 wxGetHomeDir(&home
);
1231 wxString
wxGetCurrentDir()
1238 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1239 dir
.UngetWriteBuf();
1243 if ( errno
!= ERANGE
)
1245 wxLogSysError(_T("Failed to get current directory"));
1247 return wxEmptyString
;
1251 // buffer was too small, retry with a larger one
1263 // ----------------------------------------------------------------------------
1265 // ----------------------------------------------------------------------------
1267 // this is a private function because it hasn't a clean interface: the first
1268 // array is passed by reference, the second by pointer - instead we have 2
1269 // public versions of wxExecute() below
1270 static long wxDoExecuteWithCapture(const wxString
& command
,
1271 wxArrayString
& output
,
1272 wxArrayString
* error
)
1275 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1279 // create a wxProcess which will capture the output
1280 wxProcess
*process
= new wxProcess
;
1281 process
->Redirect();
1283 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1288 wxInputStream
* is
= process
->GetInputStream();
1289 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1290 wxTextInputStream
tis(*is
);
1292 wxTextInputStream
*tes
= NULL
;
1293 wxInputStream
*es
= NULL
;
1296 es
= process
->GetErrorStream();
1298 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1300 tes
= new wxTextInputStream(*es
);
1308 if ( !is
->Eof() && is
->IsOk() )
1310 wxString line
= tis
.ReadLine();
1311 if ( is
->LastError() )
1319 if ( error
&& !es
->Eof() && es
->IsOk() )
1321 wxString line
= tes
->ReadLine();
1322 if ( es
->LastError() )
1334 #endif // wxUSE_STREAMS
1339 #endif // IO redirection supoprted
1342 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1344 return wxDoExecuteWithCapture(command
, output
, NULL
);
1347 long wxExecute(const wxString
& command
,
1348 wxArrayString
& output
,
1349 wxArrayString
& error
)
1351 return wxDoExecuteWithCapture(command
, output
, &error
);