]> git.saurik.com Git - wxWidgets.git/blame - src/common/utilscmn.cpp
wxProcess fixes (Detach() added), cleared/corrected wxExecute() documentation
[wxWidgets.git] / src / common / utilscmn.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: utilscmn.cpp
3// Purpose: Miscellaneous utility functions and classes
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
3f4a0c5b 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
7007fcfc 13#pragma implementation "utils.h"
c801d85f
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/defs.h"
25#include "wx/utils.h"
26#include "wx/window.h"
27#include "wx/menu.h"
28#include "wx/frame.h"
dfad0599
JS
29#include "wx/msgdlg.h"
30#include "wx/textdlg.h"
c801d85f
KB
31#endif
32
3f4a0c5b
VZ
33#include "wx/ioswrap.h"
34
47d67540 35#if wxUSE_IOSTREAMH
3f4a0c5b 36 #include <fstream.h>
c801d85f 37#else
3f4a0c5b 38 #include <fstream>
c801d85f
KB
39#endif
40
c801d85f
KB
41#include <ctype.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#if !defined(__WATCOMC__)
3f4a0c5b
VZ
46 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
47 #include <errno.h>
48 #endif
c801d85f
KB
49#endif
50#include <time.h>
469e1e5c 51#ifndef __MWERKS__
c801d85f
KB
52#include <sys/types.h>
53#include <sys/stat.h>
469e1e5c 54#endif
c801d85f 55
ce3ed50d
JS
56#ifdef __SALFORDC__
57#include <clib.h>
58#endif
59
c801d85f
KB
60// Pattern matching code.
61// Yes, this path is deliberate (for Borland compilation)
62#ifdef wx_mac /* MATTHEW: [5] Mac doesn't like paths with "/" */
63#include "glob.inc"
64#else
65#include "../common/glob.inc"
66#endif
67
2049ba38 68#ifdef __WXMSW__
c801d85f
KB
69#include "windows.h"
70#endif
71
72#define _MAXPATHLEN 500
73
74extern char *wxBuffer;
75
17dff81c
SC
76#ifdef __WXMAC__
77int strcasecmp(const char *str_1, const char *str_2)
78{
79 register char c1, c2;
80 do {
81 c1 = tolower(*str_1++);
82 c2 = tolower(*str_2++);
83 } while ( c1 && (c1 == c2) );
84
85 return c1 - c2;
86}
87
88int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
89{
90
91 register char c1, c2;
3f4a0c5b 92 while( maxchar--)
17dff81c
SC
93 {
94 c1 = tolower(*str_1++);
95 c2 = tolower(*str_2++);
3f4a0c5b 96
17dff81c 97 if ( !c1 || c1!=c2 )
3f4a0c5b
VZ
98 return c1 - c2;
99
17dff81c
SC
100 } ;
101
102 return 0 ;
103
104}
105#endif
c801d85f
KB
106#ifdef __VMS__
107// we have no strI functions under VMS, therefore I have implemented
108// an inefficient but portable version: convert copies of strings to lowercase
109// and then use the normal comparison
110static void myLowerString(char *s)
111{
112 while(*s){
113 if(isalpha(*s)) *s = (char)tolower(*s);
114 s++;
115 }
116}
117
118int strcasecmp(const char *str_1, const char *str_2)
119{
120 char *temp1 = new char[strlen(str_1)+1];
121 char *temp2 = new char[strlen(str_2)+1];
122 strcpy(temp1,str_1);
123 strcpy(temp2,str_2);
124 myLowerString(temp1);
125 myLowerString(temp2);
126
127 int result = strcmp(temp1,temp2);
128 delete[] temp1;
129 delete[] temp2;
130
131 return(result);
132}
133
134int strncasecmp(const char *str_1, const char *str_2, size_t maxchar)
135{
136 char *temp1 = new char[strlen(str_1)+1];
137 char *temp2 = new char[strlen(str_2)+1];
138 strcpy(temp1,str_1);
139 strcpy(temp2,str_2);
140 myLowerString(temp1);
141 myLowerString(temp2);
142
143 int result = strncmp(temp1,temp2,maxchar);
144 delete[] temp1;
145 delete[] temp2;
146
147 return(result);
148}
149#endif
150
34138703 151#ifdef __WINDOWS__
c801d85f
KB
152
153#ifndef __GNUWIN32__
469e1e5c 154#ifndef __MWERKS__
c801d85f
KB
155#define strcasecmp stricmp
156#define strncasecmp strnicmp
469e1e5c
SC
157#else
158#define strcasecmp _stricmp
159#define strncasecmp _strnicmp
160#endif
c801d85f
KB
161#endif
162
c801d85f
KB
163#else
164// This declaration is missing in SunOS!
165// (Yes, I know it is NOT ANSI-C but its in BSD libc)
166#if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
167extern "C"
168{
169 int strcasecmp (const char *, const char *);
170 int strncasecmp (const char *, const char *, size_t);
171}
172#endif
3f4a0c5b 173#endif /* __WXMSW__ */
c801d85f
KB
174
175
176char *
177copystring (const char *s)
178{
179 if (s == NULL) s = "";
180 size_t len = strlen (s) + 1;
181
182 char *news = new char[len];
3f4a0c5b 183 memcpy (news, s, len); // Should be the fastest
c801d85f
KB
184
185 return news;
186}
187
188// Id generation
189static long wxCurrentId = 100;
190
3f4a0c5b 191long
c801d85f
KB
192wxNewId (void)
193{
194 return wxCurrentId++;
195}
196
197long
198wxGetCurrentId(void) { return wxCurrentId; }
199
3f4a0c5b 200void
c801d85f
KB
201wxRegisterId (long id)
202{
203 if (id >= wxCurrentId)
204 wxCurrentId = id + 1;
205}
206
3f4a0c5b 207void
c801d85f
KB
208StringToFloat (char *s, float *number)
209{
210 if (s && *s && number)
c67daf87 211 *number = (float) strtod (s, (char **) NULL);
c801d85f
KB
212}
213
3f4a0c5b 214void
c801d85f
KB
215StringToDouble (char *s, double *number)
216{
217 if (s && *s && number)
c67daf87 218 *number = strtod (s, (char **) NULL);
c801d85f
KB
219}
220
221char *
222FloatToString (float number, const char *fmt)
223{
224 static char buf[256];
225
226// sprintf (buf, "%.2f", number);
227 sprintf (buf, fmt, number);
228 return buf;
229}
230
231char *
232DoubleToString (double number, const char *fmt)
233{
234 static char buf[256];
235
236 sprintf (buf, fmt, number);
237 return buf;
238}
239
3f4a0c5b 240void
c801d85f
KB
241StringToInt (char *s, int *number)
242{
243 if (s && *s && number)
c67daf87 244 *number = (int) strtol (s, (char **) NULL, 10);
c801d85f
KB
245}
246
3f4a0c5b 247void
c801d85f
KB
248StringToLong (char *s, long *number)
249{
250 if (s && *s && number)
c67daf87 251 *number = strtol (s, (char **) NULL, 10);
c801d85f
KB
252}
253
254char *
255IntToString (int number)
256{
257 static char buf[20];
258
259 sprintf (buf, "%d", number);
260 return buf;
261}
262
263char *
264LongToString (long number)
265{
266 static char buf[20];
267
268 sprintf (buf, "%ld", number);
269 return buf;
270}
271
272// Array used in DecToHex conversion routine.
273static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
274 'C', 'D', 'E', 'F' };
275
276// Convert 2-digit hex number to decimal
fd71308f 277int wxHexToDec(const wxString& buf)
c801d85f
KB
278{
279 int firstDigit, secondDigit;
3f4a0c5b 280
fd71308f
JS
281 if (buf.GetChar(0) >= 'A')
282 firstDigit = buf.GetChar(0) - 'A' + 10;
c801d85f 283 else
fd71308f 284 firstDigit = buf.GetChar(0) - '0';
c801d85f 285
fd71308f
JS
286 if (buf.GetChar(1) >= 'A')
287 secondDigit = buf.GetChar(1) - 'A' + 10;
c801d85f 288 else
fd71308f 289 secondDigit = buf.GetChar(1) - '0';
3f4a0c5b 290
c801d85f
KB
291 return firstDigit * 16 + secondDigit;
292}
293
294// Convert decimal integer to 2-character hex string
295void wxDecToHex(int dec, char *buf)
296{
297 int firstDigit = (int)(dec/16.0);
298 int secondDigit = (int)(dec - (firstDigit*16.0));
299 buf[0] = hexArray[firstDigit];
300 buf[1] = hexArray[secondDigit];
301 buf[2] = 0;
302}
303
fd71308f
JS
304// Convert decimal integer to 2-character hex string
305wxString wxDecToHex(int dec)
306{
307 char buf[3];
308 wxDecToHex(dec, buf);
309 return wxString(buf);
310}
311
c801d85f 312// Match a string INDEPENDENT OF CASE
3f4a0c5b 313bool
c801d85f
KB
314StringMatch (char *str1, char *str2, bool subString, bool exact)
315{
316 if (str1 == NULL || str2 == NULL)
317 return FALSE;
318 if (str1 == str2)
319 return TRUE;
320
321 if (subString)
322 {
323 int len1 = strlen (str1);
324 int len2 = strlen (str2);
325 int i;
326
327 // Search for str1 in str2
328 // Slow .... but acceptable for short strings
329 for (i = 0; i <= len2 - len1; i++)
3f4a0c5b
VZ
330 {
331 if (strncasecmp (str1, str2 + i, len1) == 0)
332 return TRUE;
333 }
c801d85f
KB
334 }
335 else if (exact)
336 {
337 if (strcasecmp (str1, str2) == 0)
3f4a0c5b 338 return TRUE;
c801d85f
KB
339 }
340 else
341 {
342 int len1 = strlen (str1);
343 int len2 = strlen (str2);
344
345 if (strncasecmp (str1, str2, wxMin (len1, len2)) == 0)
3f4a0c5b 346 return TRUE;
c801d85f
KB
347 }
348
349 return FALSE;
350}
351
352// Return the current date/time
353// [volatile]
354wxString wxNow( void )
355{
c67daf87 356 time_t now = time((time_t *) NULL);
3f4a0c5b 357 char *date = ctime(&now);
c801d85f
KB
358 date[24] = '\0';
359 return wxString(date);
360}
361
362/* Get Full RFC822 style email address */
363bool
364wxGetEmailAddress (char *address, int maxSize)
365{
366 char host[65];
367 char user[65];
368
369 if (wxGetHostName(host, 64) == FALSE)
370 return FALSE;
371 if (wxGetUserId(user, 64) == FALSE)
372 return FALSE;
373
374 char tmp[130];
375 strcpy(tmp, user);
376 strcat(tmp, "@");
377 strcat(tmp, host);
378
379 strncpy(address, tmp, maxSize - 1);
380 address[maxSize-1] = '\0';
381 return TRUE;
382}
383
384/*
385 * Strip out any menu codes
386 */
387
388char *wxStripMenuCodes (char *in, char *out)
389{
390 if (!in)
c67daf87 391 return (char *) NULL;
3f4a0c5b 392
c801d85f
KB
393 if (!out)
394 out = copystring(in);
395
396 char *tmpOut = out;
3f4a0c5b 397
c801d85f
KB
398 while (*in)
399 {
400 if (*in == '&')
3f4a0c5b
VZ
401 {
402 // Check && -> &, &x -> x
403 if (*++in == '&')
404 *out++ = *in++;
405 }
c801d85f 406 else if (*in == '\t')
3f4a0c5b 407 {
c801d85f
KB
408 // Remove all stuff after \t in X mode, and let the stuff as is
409 // in Windows mode.
410 // Accelerators are handled in wx_item.cc for Motif, and are not
411 // YET supported in XView
3f4a0c5b
VZ
412 break;
413 }
c801d85f 414 else
3f4a0c5b
VZ
415 *out++ = *in++;
416 } // while
c801d85f
KB
417
418 *out = '\0';
419
420 return tmpOut;
421}
422
47bc1060
JS
423wxString wxStripMenuCodes(const wxString& str)
424{
425 char *buf = new char[str.Length() + 1];
426 wxStripMenuCodes((char*) (const char*) str, buf);
427 wxString str1(buf);
428 delete[] buf;
429 return str1;
430}
c801d85f
KB
431
432/*
433 * Window search functions
434 *
435 */
436
437/*
438 * If parent is non-NULL, look through children for a label or title
439 * matching the specified string. If NULL, look through all top-level windows.
440 *
441 */
442
443static wxWindow *wxFindWindowByLabel1 (const wxString& title, wxWindow * parent);
444
445wxWindow *
446wxFindWindowByLabel (const wxString& title, wxWindow * parent)
447{
448 if (parent)
449 {
450 return wxFindWindowByLabel1 (title, parent);
451 }
452 else
453 {
454 for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
3f4a0c5b
VZ
455 {
456 wxWindow *win = (wxWindow *) node->Data ();
457 wxWindow *retwin = wxFindWindowByLabel1 (title, win);
458 if (retwin)
459 return retwin;
460 } // for()
c801d85f
KB
461
462 }
c67daf87 463 return (wxWindow *) NULL;
c801d85f
KB
464}
465
466// Recursive
467static wxWindow *
468wxFindWindowByLabel1 (const wxString& title, wxWindow * parent)
469{
470 if (parent)
471 {
472 if (parent->GetLabel() == title)
3f4a0c5b 473 return parent;
c801d85f
KB
474 }
475
476 if (parent)
477 {
c0ed460c 478 for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
3f4a0c5b
VZ
479 {
480 wxWindow *win = (wxWindow *) node->Data ();
481 wxWindow *retwin = wxFindWindowByLabel1 (title, win);
482 if (retwin)
483 return retwin;
484 } // for()
c801d85f
KB
485
486 }
487
3f4a0c5b 488 return (wxWindow *) NULL; // Not found
c801d85f
KB
489
490}
491
492/*
493 * If parent is non-NULL, look through children for a name
494 * matching the specified string. If NULL, look through all top-level windows.
495 *
496 */
497
498static wxWindow *wxFindWindowByName1 (const wxString& title, wxWindow * parent);
499
500wxWindow *
501wxFindWindowByName (const wxString& title, wxWindow * parent)
502{
503 if (parent)
504 {
505 return wxFindWindowByName1 (title, parent);
506 }
507 else
508 {
509 for (wxNode * node = wxTopLevelWindows.First (); node; node = node->Next ())
3f4a0c5b
VZ
510 {
511 wxWindow *win = (wxWindow *) node->Data ();
512 wxWindow *retwin = wxFindWindowByName1 (title, win);
513 if (retwin)
514 return retwin;
515 } // for()
c801d85f
KB
516
517 }
518 // Failed? Try by label instead.
519 return wxFindWindowByLabel(title, parent);
520}
521
522// Recursive
523static wxWindow *
524wxFindWindowByName1 (const wxString& title, wxWindow * parent)
525{
526 if (parent)
527 {
3f4a0c5b
VZ
528 if ( parent->GetName() == title )
529 return parent;
c801d85f
KB
530 }
531
532 if (parent)
533 {
c0ed460c 534 for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
3f4a0c5b
VZ
535 {
536 wxWindow *win = (wxWindow *) node->Data ();
537 wxWindow *retwin = wxFindWindowByName1 (title, win);
538 if (retwin)
539 return retwin;
540 } // for()
c801d85f
KB
541
542 }
543
3f4a0c5b 544 return (wxWindow *) NULL; // Not found
c801d85f
KB
545
546}
547
548// Returns menu item id or -1 if none.
3f4a0c5b 549int
c801d85f
KB
550wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString)
551{
552 wxMenuBar *menuBar = frame->GetMenuBar ();
553 if (!menuBar)
554 return -1;
555 return menuBar->FindMenuItem (menuString, itemString);
556}
557
c801d85f
KB
558/*
559On Fri, 21 Jul 1995, Paul Craven wrote:
560
561> Is there a way to find the path of running program's executable? I can get
562> my home directory, and the current directory, but I don't know how to get the
563> executable directory.
3f4a0c5b 564>
c801d85f
KB
565
566The code below (warty as it is), does what you want on most Unix,
567DOS, and Mac platforms (it's from the ALS Prolog main).
568
3f4a0c5b 569|| Ken Bowen Applied Logic Systems, Inc. PO Box 180,
c801d85f
KB
570||==== Voice: +1 (617)965-9191 Newton Centre,
571|| FAX: +1 (617)965-1636 MA 02159 USA
572 Email: ken@als.com WWW: http://www.als.com
573------------------------------------------------------------------------
574*/
575
576// This code is commented out but it may be integrated with wxWin at
577// a later date, after testing. Thanks Ken!
578#if 0
579
580/*--------------------------------------------------------------------*
581 | whereami is given a filename f in the form: whereami(argv[0])
3f4a0c5b
VZ
582 | It returns the directory in which the executable file (containing
583 | this code [main.c] ) may be found. A dot will be returned to indicate
c801d85f
KB
584 | the current directory.
585 *--------------------------------------------------------------------*/
586
587static void
588whereami(name)
589 char *name;
590{
3f4a0c5b 591 register char *cutoff = NULL; /* stifle -Wall */
c801d85f
KB
592 register char *s;
593 register char *t;
594 int cc;
595 char ebuf[4096];
596
597 /*
598 * See if the file is accessible either through the current directory
599 * or through an absolute path.
600 */
601
602 if (access(name, R_OK) == 0) {
603
3f4a0c5b
VZ
604 /*-------------------------------------------------------------*
605 * The file was accessible without any other work. But the current
606 * working directory might change on us, so if it was accessible
607 * through the cwd, then we should get it for later accesses.
608 *-------------------------------------------------------------*/
c801d85f 609
3f4a0c5b
VZ
610 t = imagedir;
611 if (!absolute_pathname(name)) {
c801d85f 612#if defined(DOS) || defined(__WIN32__)
3f4a0c5b
VZ
613 int drive;
614 char *newrbuf;
c801d85f 615
3f4a0c5b 616 newrbuf = imagedir;
c801d85f 617#ifndef __DJGPP__
3f4a0c5b
VZ
618 if (*(name + 1) == ':') {
619 if (*name >= 'a' && *name <= 'z')
620 drive = (int) (*name - 'a' + 1);
621 else
622 drive = (int) (*name - 'A' + 1);
623 *newrbuf++ = *name;
624 *newrbuf++ = *(name + 1);
625 *newrbuf++ = DIR_SEPARATOR;
626 }
627 else {
628 drive = 0;
629 *newrbuf++ = DIR_SEPARATOR;
630 }
631 if (getcwd(newrbuf, drive) == 0) { /* } */
c801d85f 632#else
3f4a0c5b 633 if (getcwd(newrbuf, 1024) == 0) { /* } */
c801d85f
KB
634#endif
635#else /* DOS */
636#ifdef HAVE_GETWD
3f4a0c5b 637 if (getwd(imagedir) == 0) { /* } */
c801d85f 638#else /* !HAVE_GETWD */
3f4a0c5b 639 if (getcwd(imagedir, 1024) == 0) {
c801d85f
KB
640#endif /* !HAVE_GETWD */
641#endif /* DOS */
3f4a0c5b
VZ
642 fatal_error(FE_GETCWD, 0);
643 }
644 for (; *t; t++) /* Set t to end of buffer */
645 ;
646 if (*(t - 1) == DIR_SEPARATOR) /* leave slash if already
647 * last char
648 */
649 cutoff = t - 1;
650 else {
651 cutoff = t; /* otherwise put one in */
652 *t++ = DIR_SEPARATOR;
653 }
654 }
c801d85f 655#if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
3f4a0c5b
VZ
656 else
657 (*t++ = DIR_SEPARATOR);
c801d85f
KB
658#endif
659
3f4a0c5b
VZ
660 /*-------------------------------------------------------------*
661 * Copy the rest of the string and set the cutoff if it was not
662 * already set. If the first character of name is a slash, cutoff
663 * is not presently set but will be on the first iteration of the
664 * loop below.
665 *-------------------------------------------------------------*/
c801d85f 666
3f4a0c5b
VZ
667 for ((*name == DIR_SEPARATOR ? (s = name+1) : (s = name));;) {
668 if (*s == DIR_SEPARATOR)
669 cutoff = t;
670 if (!(*t++ = *s++))
671 break;
672 }
c801d85f
KB
673
674 }
675 else {
676
3f4a0c5b
VZ
677 /*-------------------------------------------------------------*
678 * Get the path list from the environment. If the path list is
679 * inaccessible for any reason, leave with fatal error.
680 *-------------------------------------------------------------*/
c801d85f
KB
681
682#ifdef __MAC__
3f4a0c5b 683 if ((s = getenv("Commands")) == (char *) 0)
c801d85f 684#else
3f4a0c5b 685 if ((s = getenv("PATH")) == (char *) 0)
c801d85f 686#endif
3f4a0c5b
VZ
687 fatal_error(FE_PATH, 0);
688
689 /*
690 * Copy path list into ebuf and set the source pointer to the
691 * beginning of this buffer.
692 */
693
694 strcpy(ebuf, s);
695 s = ebuf;
696
697 for (;;) {
698 t = imagedir;
699 while (*s && *s != PATH_SEPARATOR)
700 *t++ = *s++;
701 if (t > imagedir && *(t - 1) == DIR_SEPARATOR)
702 ; /* do nothing -- slash already is in place */
703 else
704 *t++ = DIR_SEPARATOR; /* put in the slash */
705 cutoff = t - 1; /* set cutoff */
706 strcpy(t, name);
707 if (access(imagedir, R_OK) == 0)
708 break;
709
710 if (*s)
711 s++; /* advance source pointer */
712 else
713 fatal_error(FE_INFND, 0);
714 }
c801d85f
KB
715
716 }
717
718 /*-------------------------------------------------------------*
719 | At this point the full pathname should exist in imagedir and
720 | cutoff should be set to the final slash. We must now determine
721 | whether the file name is a symbolic link or not and chase it down
722 | if it is. Note that we reuse ebuf for getting the link.
723 *-------------------------------------------------------------*/
724
725#ifdef HAVE_SYMLINK
726 while ((cc = readlink(imagedir, ebuf, 512)) != -1) {
3f4a0c5b
VZ
727 ebuf[cc] = 0;
728 s = ebuf;
729 if (*s == DIR_SEPARATOR) {
730 t = imagedir;
731 }
732 else {
733 t = cutoff + 1;
734 }
735 for (;;) {
736 if (*s == DIR_SEPARATOR)
737 cutoff = t; /* mark the last slash seen */
738 if (!(*t++ = *s++)) /* copy the character */
739 break;
740 }
c801d85f
KB
741 }
742
743#endif /* HAVE_SYMLINK */
744
3f4a0c5b
VZ
745 strcpy(imagename, cutoff + 1); /* keep the image name */
746 *(cutoff + 1) = 0; /* chop off the filename part */
c801d85f
KB
747}
748
749#endif
750
dfad0599
JS
751/*
752 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
753 * since otherwise the generic code may be pulled in unnecessarily.
754 */
755
756int wxMessageBox(const wxString& message, const wxString& caption, long style,
757 wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
758{
759 wxMessageDialog dialog(parent, message, caption, style);
760
761 int ans = dialog.ShowModal();
762 switch ( ans )
763 {
764 case wxID_OK:
765 return wxOK;
766 break;
767 case wxID_YES:
768 return wxYES;
769 break;
770 case wxID_NO:
771 return wxNO;
772 break;
773 default:
774 case wxID_CANCEL:
775 return wxCANCEL;
776 break;
777 }
778 return ans;
779}
780
781wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
782 const wxString& defaultValue, wxWindow *parent,
783 int x, int y, bool WXUNUSED(centre) )
784{
785 wxTextEntryDialog dialog(parent, message, caption, defaultValue, wxOK|wxCANCEL, wxPoint(x, y));
786 if (dialog.ShowModal() == wxID_OK)
787 return dialog.GetValue();
788 else
789 return wxString("");
790}
791
469e1e5c 792#ifdef __MWERKS__
3f4a0c5b 793char *strdup(const char *s)
469e1e5c 794{
3f4a0c5b 795 return strcpy( (char*) malloc( strlen( s ) + 1 ) , s ) ;
469e1e5c
SC
796}
797
3f4a0c5b 798int isascii( int c )
469e1e5c 799{
3f4a0c5b 800 return ( c >= 0 && c < 128 ) ;
469e1e5c 801}
f60d0f94 802#endif
e2a6f233
JS
803
804// Overloaded functions, taking a wxString
805bool wxGetHostName(wxString& name)
806{
807 bool success = wxGetHostName(wxBuffer, 500);
808 if (success)
809 {
810 name = wxBuffer;
811 return TRUE;
812 }
813 else
814 return FALSE;
815}
816
817bool wxGetUserId(wxString& buf)
818{
819 bool success = wxGetUserId(wxBuffer, 500);
820 if (success)
821 {
822 buf = wxBuffer;
823 return TRUE;
824 }
825 else
826 return FALSE;
827}
828
829bool wxGetUserName(wxString& buf)
830{
831 bool success = wxGetUserName(wxBuffer, 500);
832 if (success)
833 {
834 buf = wxBuffer;
835 return TRUE;
836 }
837 else
838 return FALSE;
839}
840