3 * Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
8 * Copyright: (c) 1998-2002 Joel Farley, Ove Kåven, Robert Roebling, Ron Lee
9 * Licence: wxWindows licence
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "wxchar.h"
21 #include "wx/defs.h" /* for wxUSE_UNICODE */
23 #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
24 char *strtok_r(char *, const char *, char **);
27 /* check whether we have wchar_t and which size it is if we do */
28 #if !defined(wxUSE_WCHAR_T)
30 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
31 #define wxUSE_WCHAR_T 1
33 #define wxUSE_WCHAR_T 0
35 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
36 #define wxUSE_WCHAR_T 0
37 #elif defined(__WATCOMC__)
38 #define wxUSE_WCHAR_T 0
39 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
40 #define wxUSE_WCHAR_T 0
42 /* add additional compiler checks if this fails */
43 #define wxUSE_WCHAR_T 1
45 #endif /* !defined(wxUSE_WCHAR_T) */
47 /* Unicode support requires wchar_t */
48 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
49 #error "wchar_t must be available in Unicode build"
53 Standard headers we need here.
55 NB: don't include any wxWidgets headers here because almost of them include
59 /* Required for wxPrintf() etc */
62 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
63 /* and VC++ for Windows CE don't provide it */
64 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
65 /* use #define, not inline wrapper, as it is tested with #ifndef below */
66 #define wxStrdupA strdup
70 non Unix compilers which do have wchar.h (but not tchar.h which is included
71 below and which includes wchar.h anyhow).
73 Actually MinGW has tchar.h, but it does not include wchar.h
75 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
80 #if defined(__MWERKS__) && !defined(__MACH__)
88 /* the current (as of Nov 2002) version of cygwin has a bug in its */
89 /* wchar.h -- there is no extern "C" around the declarations in it and */
90 /* this results in linking errors later; also, at least on some */
91 /* Cygwin versions, wchar.h requires sys/types.h */
93 #include <sys/types.h>
101 #if defined(__CYGWIN__) && defined(__cplusplus)
103 #endif /* Cygwin and C++ */
105 #elif defined(HAVE_WCSTR_H)
106 /* old compilers have relevant declarations here */
108 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
109 /* include stdlib.h for wchar_t */
111 #endif /* HAVE_WCHAR_H */
112 #endif /* wxUSE_WCHAR_T */
114 /* ---------------------------------------------------------------------------- */
115 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
116 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
117 /* the function mapping _tfoo() -> foo() or wfoo() */
118 /* ---------------------------------------------------------------------------- */
120 /* VC++ and BC++ starting with 5.2 have TCHAR support */
122 #define wxHAVE_TCHAR_SUPPORT
123 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
124 #define wxHAVE_TCHAR_SUPPORT
126 #elif defined(__WATCOMC__)
127 #define wxHAVE_TCHAR_SUPPORT
128 #elif defined(__DMC__)
129 #define wxHAVE_TCHAR_SUPPORT
130 #elif defined(__WXPALMOS__)
132 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
133 #define wxHAVE_TCHAR_SUPPORT
137 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
138 /* VZ: the old VisualAge definitions were completely wrong and had no */
139 /* chance at all to work in Unicode build anyhow so let's pretend that */
140 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
141 /* "0 &&" above) until someone really has time to delve into Unicode */
142 /* issues under OS/2 */
144 /* VisualAge 4.0+ supports TCHAR */
145 #define wxHAVE_TCHAR_SUPPORT
146 #endif /* compilers with (good) TCHAR support */
152 #ifdef wxHAVE_TCHAR_SUPPORT
153 /* get TCHAR definition if we've got it */
156 /* we surely do have wchar_t if we have TCHAR */
157 #ifndef wxUSE_WCHAR_T
158 #define wxUSE_WCHAR_T 1
159 #endif /* !defined(wxUSE_WCHAR_T) */
161 /* and we also do have wcslen() */
165 #endif /* wxHAVE_TCHAR_SUPPORT */
167 /* ---------------------------------------------------------------------------- */
168 /* define wxChar type */
169 /* ---------------------------------------------------------------------------- */
171 /* TODO: define wxCharInt to be equal to either int or wint_t? */
175 typedef signed char wxSChar
;
176 typedef unsigned char wxUChar
;
178 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
179 /* signed/unsigned version of it which (a) makes sense to me (unlike */
180 /* char wchar_t is always unsigned) and (b) was how the previous */
181 /* definitions worked so keep it like this */
183 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
185 #if !defined(__WCHAR_TYPE__) || \
186 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
188 typedef wchar_t wxChar
;
189 typedef wchar_t wxSChar
;
190 typedef wchar_t wxUChar
;
191 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
192 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. However, */
193 /* this doesn't work with new GCC 3.x compilers because wchar_t is */
194 /* C++'s builtin type in the new standard. OTOH, old compilers (GCC */
195 /* 2.x) won't accept new definition of wx{S,U}Char, therefore we */
196 /* have to define wxChar conditionally depending on detected */
197 /* compiler & compiler version. */
198 /* with old definition of wxChar. */
199 typedef __WCHAR_TYPE__ wxChar
;
200 typedef __WCHAR_TYPE__ wxSChar
;
201 typedef __WCHAR_TYPE__ wxUChar
;
202 #endif /* __WCHAR_TYPE__ */
203 #endif /* ASCII/Unicode */
205 /* ---------------------------------------------------------------------------- */
206 /* define _T() and related macros */
207 /* ---------------------------------------------------------------------------- */
209 /* BSD systems define _T() to be something different in ctype.h, override it */
210 #if defined(__FreeBSD__) || defined(__DARWIN__)
215 /* could already be defined by tchar.h (it's quasi standard) */
221 #endif /* ASCII/Unicode */
222 #endif /* !defined(_T) */
224 /* although global macros with such names are normally bad, we want to have */
225 /* another name for _T() which should be used to avoid confusion between _T() */
226 /* and _() in wxWidgets sources */
229 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
231 #define __XFILE__(x) wxT(x)
232 #define __TFILE__ __XFILE__(__FILE__)
236 #define __XDATE__(x) wxT(x)
237 #define __TDATE__ __XDATE__(__DATE__)
241 #define __XTIME__(x) wxT(x)
242 #define __TTIME__ __XTIME__(__TIME__)
246 define wxFoo() function for each standard foo() function whose signature
247 (exceptionally including the return type) includes any mention of char:
248 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
249 the same signature but with char replaced by wxChar which allows us to use
250 it in Unicode build as well
253 #ifdef wxHAVE_TCHAR_SUPPORT
256 #if defined(__WATCOMC__) && defined(UNICODE)
257 #define WXWCHAR_T_CAST(c) (wint_t)(c)
259 #define WXWCHAR_T_CAST(c) c
262 /* ctype.h functions */
263 #define wxIsalnum(c) _istalnum(WXWCHAR_T_CAST(c))
264 #define wxIsalpha(c) _istalpha(WXWCHAR_T_CAST(c))
265 #define wxIscntrl(c) _istcntrl(WXWCHAR_T_CAST(c))
266 #define wxIsdigit(c) _istdigit(WXWCHAR_T_CAST(c))
267 #define wxIsgraph(c) _istgraph(WXWCHAR_T_CAST(c))
268 #define wxIslower(c) _istlower(WXWCHAR_T_CAST(c))
269 #define wxIsprint(c) _istprint(WXWCHAR_T_CAST(c))
270 #define wxIspunct(c) _istpunct(WXWCHAR_T_CAST(c))
271 #define wxIsspace(c) _istspace(WXWCHAR_T_CAST(c))
272 #define wxIsupper(c) _istupper(WXWCHAR_T_CAST(c))
273 #define wxIsxdigit(c) _istxdigit(WXWCHAR_T_CAST(c))
276 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
277 signed chars < 0, so "fix" it here.
279 #define wxTolower(c) _totlower((wxUChar)(c))
280 #define wxToupper(c) _totupper((wxUChar)(c))
282 /* locale.h functons */
283 #define wxSetlocale _tsetlocale
285 /* string.h functions */
286 #define wxStrcat _tcscat
287 #define wxStrchr _tcschr
288 #define wxStrcmp _tcscmp
289 #define wxStrcoll _tcscoll
290 #define wxStrcpy _tcscpy
291 #define wxStrcspn _tcscspn
292 #define wxStrdupW _wcsdup /* notice the 'W'! */
293 #define wxStrftime _tcsftime
294 #define wxStricmp _tcsicmp
295 #define wxStrnicmp _tcsnicmp
296 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
297 #define wxStrncat _tcsncat
298 #define wxStrncmp _tcsncmp
299 #define wxStrncpy _tcsncpy
300 #define wxStrpbrk _tcspbrk
301 #define wxStrrchr _tcsrchr
302 #define wxStrspn _tcsspn
303 #define wxStrstr _tcsstr
304 #define wxStrtod _tcstod
305 #define wxStrtol _tcstol
306 #define wxStrtoul _tcstoul
307 #define wxStrxfrm _tcsxfrm
309 /* stdio.h functions */
310 #define wxFgetc _fgettc
311 #define wxFgetchar _fgettchar
312 #define wxFgets _fgetts
313 #if wxUSE_UNICODE_MSLU
314 #define wxFopen wxMSLU__tfopen
316 #define wxFopen _tfopen
318 #define wxFputc _fputtc
319 #define wxFputchar _fputtchar
320 #define wxFprintf _ftprintf
321 #define wxFputs _fputts
322 #define wxFreopen _tfreopen
323 #define wxFscanf _ftscanf
324 #define wxGetc _gettc
325 #define wxGetchar _gettchar
326 #define wxGets _getts
327 #define wxPerror _tperror
328 #define wxPrintf _tprintf
329 #define wxPutc(c,f) _puttc(WXWCHAR_T_CAST(c),f)
330 #define wxPutchar _puttchar
331 #define wxPuts _putts
332 #define wxScanf _tscanf
335 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
336 int wxSprintf (wchar_t * __RESTRICT s
, const wchar_t * __RESTRICT format
, ... ) ;
338 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
339 #define wxSprintf sprintf
342 #define wxSprintf _stprintf
345 #define wxSscanf _stscanf
346 #define wxTmpnam _ttmpnam
347 #define wxUngetc _tungetc
348 #define wxVfprintf _vftprintf
349 #define wxVprintf _vtprintf
350 #define wxVsscanf _vstscanf
351 #define wxVsprintf _vstprintf
353 /* special case: not all TCHAR-aware compilers have those */
354 #if defined(__VISUALC__) || \
355 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
356 #define wxVsnprintf_ _vsntprintf
357 #define wxSnprintf_ _sntprintf
360 /* special case: these functions are missing under Win9x with Unicows so we */
361 /* have to implement them ourselves */
362 #if wxUSE_UNICODE_MSLU
363 #define wxRemove wxMSLU__tremove
364 #define wxRename wxMSLU__trename
367 /* carefully: wxRemove() must return 0 on success while DeleteFile()
368 returns 0 on error, so don't just define one as the other */
369 int wxRemove(const wxChar
*path
);
371 #define wxRemove _tremove
372 #define wxRename _trename
376 /* stdlib.h functions */
379 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
380 /* there are no env vars at all under CE, so no _tgetenv neither */
382 /* can't define as inline function as this is a C file... */
383 #define wxGetenv(name) ((wxChar *)NULL)
385 #define wxGetenv _tgetenv
387 #define wxSystem _tsystem
389 /* time.h functions */
390 #define wxAsctime _tasctime
391 #define wxCtime _tctime
393 #define wxMbstowcs mbstowcs
394 #define wxWcstombs wcstombs
395 #else /* !TCHAR-aware compilers */
397 #if !defined(__MWERKS__) && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
398 /* even though they are defined and "implemented", they are bad and just
399 stubs so we need our own - we need these even in ANSI builds!! */
400 WXDLLIMPEXP_BASE
size_t wxMbstowcs (wchar_t *, const char *, size_t);
401 WXDLLIMPEXP_BASE
size_t wxWcstombs (char *, const wchar_t *, size_t);
403 #define wxMbstowcs mbstowcs
404 #define wxWcstombs wcstombs
407 /* No UNICODE in the c library except wchar_t typedef on mac OSX 10.2 and less - roll our own */
408 #if !defined(__MWERKS__) && wxUSE_UNICODE && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
410 /* we need everything! */
411 #define wxNEED_WX_STRING_H
412 #define wxNEED_WX_CTYPE_H
414 #define wxFgetchar(c) wxFgetc(c, stdin)
415 #define wxFputc wxPutc
416 #define wxFputchar(c) wxPutc(c, stdout)
417 #define wxGetc wxFgetc
418 #define wxGetchar(c) wxFgetc(c, stdin)
425 #define wxNEED_UNGETC
431 int wxFputs(const wxChar
*ch
, FILE *stream
);
432 int wxPuts(const wxChar
*ws
);
433 int wxPutc(wxChar ch
, FILE *stream
);
438 WXDLLIMPEXP_BASE
size_t wxStrlen_(const wxChar
*s
);
443 #define wxPutchar(wch) wxPutc(wch, stdout)
445 #define wxNEED_PRINTF_CONVERSION
446 #define wxNEED_WX_STDIO_H
447 #define wxNEED_WX_STDLIB_H
448 #define wxNEED_WX_TIME_H
453 /* this is probably glibc-specific */
454 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
455 /* ctype.h functions (wctype.h) */
456 #define wxIsalnum iswalnum
457 #define wxIsalpha iswalpha
458 #define wxIscntrl iswcntrl
459 #define wxIsdigit iswdigit
460 #define wxIsgraph iswgraph
461 #define wxIslower iswlower
462 #define wxIsprint iswprint
463 #define wxIspunct iswpunct
464 #define wxIsspace iswspace
465 #define wxIsupper iswupper
466 #define wxIsxdigit iswxdigit
468 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
469 /* /usr/include/wctype.h incorrectly declares translations */
470 /* tables which provokes tons of compile-time warnings -- try */
471 /* to correct this */
472 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
473 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
474 #else /* !glibc 2.0 */
475 #define wxTolower towlower
476 #define wxToupper towupper
477 #endif /* gcc/!gcc */
479 /* string.h functions (wchar.h) */
480 #define wxStrcat wcscat
481 #define wxStrchr wcschr
482 #define wxStrcmp wcscmp
483 #define wxStrcoll wcscoll
484 #define wxStrcpy wcscpy
485 #define wxStrcspn wcscspn
486 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
487 #define wxStrncat wcsncat
488 #define wxStrncmp wcsncmp
489 #define wxStrncpy wcsncpy
490 #define wxStrpbrk wcspbrk
491 #define wxStrrchr wcsrchr
492 #define wxStrspn wcsspn
493 #define wxStrstr wcsstr
494 #define wxStrtod wcstod
495 #define wxStrtol wcstol
496 #define wxStrtoul wcstoul
497 #define wxStrxfrm wcsxfrm
499 #define wxFgetc fgetwc
500 #define wxFgetchar fgetwchar
501 #define wxFgets fgetws
502 #define wxFputc fputwc
503 #define wxFputchar fputwchar
505 #define wxGetchar getwchar
507 #define wxUngetc ungetwc
510 #define wxFputs fputws
514 int wxFputs(const wxChar
*ch
, FILE *stream
);
522 int wxPutc(wxChar ch
, FILE *stream
);
526 #define wxPutchar wputchar
528 #define wxPutchar(wch) wxPutc(wch, stdout)
535 int wxPuts(const wxChar
*ws
);
538 /* we need %s to %ls conversion for printf and scanf etc */
539 #define wxNEED_PRINTF_CONVERSION
541 /* glibc doesn't have wide char equivalents of the other stuff so */
542 /* use our own versions */
543 #define wxNEED_WX_STDIO_H
544 #define wxNEED_WX_STDLIB_H
545 #define wxNEED_WX_TIME_H
546 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
547 /* ctype.h functions (wctype.h) */
548 #define wxIsalnum iswalnum
549 #define wxIsalpha iswalpha
550 #define wxIscntrl iswcntrl
551 #define wxIsdigit iswdigit
552 #define wxIsgraph iswgraph
553 #define wxIslower iswlower
554 #define wxIsprint iswprint
555 #define wxIspunct iswpunct
556 #define wxIsspace iswspace
557 #define wxIsupper iswupper
558 #define wxIsxdigit iswxdigit
559 #define wxTolower towlower
560 #define wxToupper towupper
562 /* string.h functions (wchar.h) */
563 #define wxStrcat wcscat
564 #define wxStrchr wcschr
565 #define wxStrcmp wcscmp
566 #define wxStrcoll wcscoll
567 #define wxStrcpy wcscpy
568 #define wxStrcspn wcscspn
569 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
570 #define wxStrncat wcsncat
571 #define wxStrncmp wcsncmp
572 #define wxStrncpy wcsncpy
573 #define wxStrpbrk wcspbrk
574 #define wxStrrchr wcsrchr
575 #define wxStrspn wcsspn
576 #define wxStrstr wcsstr
577 #define wxStrtod wcstod
578 #define wxStrtol wcstol
579 #define wxStrtoul wcstoul
580 #define wxStrxfrm wcsxfrm
582 #define wxFgetc fgetwc
583 #define wxFgetchar fgetwchar
584 #define wxFgets fgetws
585 #define wxFputc fputwc
586 #define wxFputchar fputwchar
588 #define wxGetchar getwchar
590 #define wxUngetc ungetwc
592 #define wxNEED_PRINTF_CONVERSION
595 #define wxPutchar putwchar
596 #define wxFputs fputws
598 /* stdio.h functions */
600 #define wxNEED_WX_STDIO_H
602 /* stdlib.h functions */
604 #define wxNEED_WX_STDLIB_H
609 #define wxGetenv(a) ((wxChar*)NULL)
610 #define wxSystem(a) ((int)NULL)
612 /* time.h functions */
613 #define wxAsctime wasciitime
614 #define wxCtime wctime
615 /* #define wxStrftime wcsftime */
617 #define wxNEED_WX_TIME_H
618 #else /* !metrowerks for apple */
619 #error "Please define wide character functions for your environment"
625 /* ctype.h functions */
626 #define wxIsalnum isalnum
627 #define wxIsalpha isalpha
628 #define wxIscntrl iscntrl
629 #define wxIsdigit isdigit
630 #define wxIsgraph isgraph
631 #define wxIslower islower
632 #define wxIsprint isprint
633 #define wxIspunct ispunct
634 #define wxIsspace isspace
635 #define wxIsupper isupper
636 #define wxIsxdigit isxdigit
637 #define wxTolower tolower
638 #define wxToupper toupper
640 /* locale.h functons */
641 #define wxSetlocale setlocale
643 /* string.h functions */
644 #define wxStrcat strcat
645 #define wxStrchr strchr
646 #define wxStrcmp strcmp
647 #define wxStrcoll strcoll
648 #define wxStrcpy strcpy
649 #define wxStrcspn strcspn
651 /* wxStricmp and wxStrnicmp are defined below */
652 #define wxStrlen_ strlen /* used in wxStrlen inline function */
653 #define wxStrncat strncat
654 #define wxStrncmp strncmp
655 #define wxStrncpy strncpy
656 #define wxStrpbrk strpbrk
657 #define wxStrrchr strrchr
658 #define wxStrspn strspn
659 #define wxStrstr strstr
660 #define wxStrtod strtod
662 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
664 #define wxStrtol strtol
665 #define wxStrtoul strtoul
666 #define wxStrxfrm strxfrm
668 /* stdio.h functions */
669 #define wxFopen fopen
670 #define wxFreopen freopen
671 #define wxRemove remove
672 #define wxRename rename
674 #define wxPerror perror
675 #define wxTmpnam tmpnam
677 #define wxFgetc fgetc
678 #define wxFgetchar fgetchar
679 #define wxFgets fgets
680 #define wxFputc fputc
681 #define wxFputs fputs
682 #define wxFputchar fputchar
683 #define wxFprintf fprintf
684 #define wxFscanf fscanf
686 #define wxGetchar getchar
688 #define wxPrintf printf
690 #define wxPutchar putchar
692 #define wxScanf scanf
693 #define wxSprintf sprintf
694 #define wxSscanf sscanf
695 #define wxUngetc ungetc
696 #define wxVfprintf vfprintf
697 #define wxVprintf vprintf
698 #define wxVsscanf vsscanf
699 #define wxVsprintf vsprintf
701 /* stdlib.h functions */
705 #define wxGetenv getenv
706 #define wxSystem system
708 /* time.h functions */
709 #define wxAsctime asctime
710 #define wxCtime ctime
711 #define wxStrftime strftime
712 #endif /* Unicode/ASCII */
713 #endif /* TCHAR-aware compilers/the others */
716 various special cases
719 /* define wxStricmp and wxStrnicmp for various compilers */
721 /* note that in Unicode mode we definitely are going to need our own version */
722 #if !defined(wxStricmp) && !wxUSE_UNICODE
723 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
724 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
725 defined(__EMX__) || defined(__DJGPP__)
726 #define wxStricmp stricmp
727 #define wxStrnicmp strnicmp
728 #elif defined(__WXPALMOS__)
729 /* FIXME: There is no equivalent to strnicmp in the Palm OS API. This
730 * quick hack should do until one can be written.
732 #define wxStricmp StrCaselessCompare
733 #define wxStrnicmp strnicmp
734 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
735 (defined(__MWERKS__) && defined(__INTEL__))
736 #define wxStricmp _stricmp
737 #define wxStrnicmp _strnicmp
738 #elif defined(__UNIX__) || defined(__GNUWIN32__)
739 #define wxStricmp strcasecmp
740 #define wxStrnicmp strncasecmp
741 /* #else -- use wxWidgets implementation */
743 #endif /* !defined(wxStricmp) */
745 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
746 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
747 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
750 #define wxWcslen wcslen
752 WXDLLIMPEXP_BASE
size_t wxWcslen(const wchar_t *s
);
754 #endif /* wxUSE_WCHAR_T */
757 /* checks whether the passed in pointer is NULL and if the string is empty */
758 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
760 /* safe version of strlen() (returns 0 if passed NULL pointer) */
761 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
765 each of strdup() and wcsdup() may or may not be available but we need both
766 of them anyhow for wx/buffer.h so we define the missing one(s) in
767 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
768 defined -- if this is somehow not the case in some situations, please
769 correct that and not the lines here
772 #define wxStrdup wxStrdupW
774 #define wxStrdup wxStrdupA
778 WXDLLIMPEXP_BASE
bool wxOKlibc(); /* for internal use */
781 /* printf() family saga */
784 For some systems vsnprintf() exists in the system libraries but not in the
785 headers, so we need to declare it ourselves to be able to use it.
787 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
793 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
794 #endif /* !HAVE_VSNPRINTF_DECL */
797 First of all, we always want to define safe snprintf() function to be used
798 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
799 which we really need...), otherwise we implement it using our own printf()
802 We define function with a trailing underscore here because the real one is a
803 wrapper around it as explained below
807 #if defined(__MWERKS__)
808 #define HAVE_WCSRTOMBS 1
809 #define HAVE_VSWPRINTF 1
811 #if defined(__WATCOMC__)
812 #define wxVsnprintf_ _vsnwprintf
813 #define wxSnprintf_ _snwprintf
815 #if defined(HAVE__VSNWPRINTF)
816 #define wxVsnprintf_ _vsnwprintf
817 /* MinGW?MSVCRT has the wrong vswprintf */
818 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
819 #define wxVsnprintf_ vswprintf
822 /* all versions of CodeWarrior supported by wxWidgets apparently have */
824 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
825 /* assume we have snprintf() too if we have vsnprintf() */
826 #define wxVsnprintf_ vsnprintf
827 #define wxSnprintf_ snprintf
830 #endif /* wxVsnprintf_ not defined yet */
833 /* no [v]snprintf(), cook our own */
834 WXDLLIMPEXP_BASE
int wxSnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
,
835 ...) ATTRIBUTE_PRINTF_3
;
838 WXDLLIMPEXP_BASE
int wxVsnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
,
843 In Unicode mode we need to have all standard functions such as wprintf() and
844 so on but not all systems have them so use our own implementations in this
847 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
848 #define wxNEED_WPRINTF
852 More Unicode complications: although both ANSI C and C++ define a number of
853 wide character functions such as wprintf(), not all environments have them.
854 Worse, those which do have different behaviours: under Windows, %s format
855 specifier changes its meaning in Unicode build and expects a Unicode string
856 while under Unix/POSIX it still means an ASCII string even for wprintf() and
857 %ls has to be used for wide strings.
859 We choose to always emulate Windows behaviour as more useful for us so even
860 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
864 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
866 we need to implement all wide character printf and scanf functions
867 either because we don't have them at all or because they don't have the
871 #include <stdio.h> /* for FILE */
873 int wxScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
874 int wxSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
875 int wxFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
876 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
877 int wxPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
878 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
879 int wxFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
880 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
881 int wxVprintf( const wxChar
*format
, va_list ap
);
882 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
883 #endif /* wxNEED_PRINTF_CONVERSION */
885 /* these 2 can be simply mapped to the versions with underscore at the end */
886 /* if we don't have to do the conversion */
888 However, if we don't have any vswprintf() at all we don't need to redefine
889 anything as our own wxVsnprintf_() already behaves as needed.
891 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
892 int wxSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
893 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
895 #define wxSnprintf wxSnprintf_
896 #define wxVsnprintf wxVsnprintf_
900 various functions which might not be available in libc and for which we
901 provide our own replacements in wxchar.cpp
904 /* ctype.h functions */
906 /* RN: Used only under OSX <= 10.2 currently */
907 #ifdef wxNEED_WX_CTYPE_H
908 WXDLLIMPEXP_BASE
int wxIsalnum(wxChar ch
);
909 WXDLLIMPEXP_BASE
int wxIsalpha(wxChar ch
);
910 WXDLLIMPEXP_BASE
int wxIscntrl(wxChar ch
);
911 WXDLLIMPEXP_BASE
int wxIsdigit(wxChar ch
);
912 WXDLLIMPEXP_BASE
int wxIsgraph(wxChar ch
);
913 WXDLLIMPEXP_BASE
int wxIslower(wxChar ch
);
914 WXDLLIMPEXP_BASE
int wxIsprint(wxChar ch
);
915 WXDLLIMPEXP_BASE
int wxIspunct(wxChar ch
);
916 WXDLLIMPEXP_BASE
int wxIsspace(wxChar ch
);
917 WXDLLIMPEXP_BASE
int wxIsupper(wxChar ch
);
918 WXDLLIMPEXP_BASE
int wxIsxdigit(wxChar ch
);
919 WXDLLIMPEXP_BASE
int wxTolower(wxChar ch
);
920 WXDLLIMPEXP_BASE
int wxToupper(wxChar ch
);
921 #endif /* wxNEED_WX_CTYPE_H */
923 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
924 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
925 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
927 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
931 a few compilers don't have the (non standard but common) isascii function,
932 define it ourselves for them
935 #if defined(__MWERKS__)
936 #define wxNEED_ISASCII
937 #elif defined(_WIN32_WCE)
938 #if _WIN32_WCE <= 211
939 #define wxNEED_ISASCII
944 #ifdef wxNEED_ISASCII
945 inline int isascii(int c
) { return (unsigned)c
< 0x80; }
949 #if _WIN32_WCE <= 211
950 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
952 #endif /* _WIN32_WCE */
955 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
956 initial versions of this header -- now it is too late to remove it so
957 although we fixed the function/macro name above, still provide the
958 backwards-compatible synonym.
960 #define wxIsctrl wxIscntrl
962 /* string.h functions */
964 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
965 #define wxNEED_STRDUP
966 #elif defined(__WXWINCE__)
967 #if _WIN32_WCE <= 211
968 #define wxNEED_STRDUP
974 WXDLLIMPEXP_BASE
char *strdup(const char* s
);
977 /* RN: Used only under OSX <= 10.2 currently
978 The __cplusplus ifdefs are messy, but they are required to build
979 the regex library, since c does not support function overloading
981 #ifdef wxNEED_WX_STRING_H
985 WXDLLIMPEXP_BASE wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
986 WXDLLIMPEXP_BASE
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
987 WXDLLIMPEXP_BASE
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
988 WXDLLIMPEXP_BASE
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
989 WXDLLIMPEXP_BASE wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
990 WXDLLIMPEXP_BASE
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
991 WXDLLIMPEXP_BASE wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
992 WXDLLIMPEXP_BASE
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
993 WXDLLIMPEXP_BASE wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
994 WXDLLIMPEXP_BASE
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
995 WXDLLIMPEXP_BASE
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
996 WXDLLIMPEXP_BASE
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
997 WXDLLIMPEXP_BASE
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
1002 /* These functions use C++, so we can't c extern them */
1003 WXDLLIMPEXP_BASE
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
1004 WXDLLIMPEXP_BASE
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1005 WXDLLIMPEXP_BASE
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
1006 WXDLLIMPEXP_BASE
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
1008 /* inlined versions */
1010 inline wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
1011 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
1012 inline wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
1013 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
1014 inline wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
1015 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
1016 inline wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
1017 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
1020 #endif /* wxNEED_WX_STRING_H */
1023 WXDLLIMPEXP_BASE
char *wxStrdupA(const char *psz
);
1027 WXDLLIMPEXP_BASE
wchar_t *wxStrdupW(const wchar_t *pwz
);
1031 WXDLLIMPEXP_BASE
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
1035 WXDLLIMPEXP_BASE
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
1039 WXDLLIMPEXP_BASE wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
1044 class WXDLLIMPEXP_BASE wxWCharBuffer
;
1045 WXDLLIMPEXP_BASE wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
1049 /* stdio.h functions */
1050 #ifdef wxNEED_WX_STDIO_H
1052 WXDLLIMPEXP_BASE
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
1053 WXDLLIMPEXP_BASE
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
1054 WXDLLIMPEXP_BASE
int wxRemove(const wxChar
*path
);
1055 WXDLLIMPEXP_BASE
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
1057 /* *printf() family is handled separately */
1058 #endif /* wxNEED_WX_STDIO_H */
1061 /* stdlib.h functions */
1063 WXDLLIMPEXP_BASE
double wxAtof(const wxChar
*psz
);
1066 #ifdef wxNEED_WX_STDLIB_H
1067 WXDLLIMPEXP_BASE
int wxAtoi(const wxChar
*psz
);
1068 WXDLLIMPEXP_BASE
long wxAtol(const wxChar
*psz
);
1069 WXDLLIMPEXP_BASE wxChar
* wxGetenv(const wxChar
*name
);
1070 WXDLLIMPEXP_BASE
int wxSystem(const wxChar
*psz
);
1074 /* time.h functions */
1075 #ifdef wxNEED_WX_TIME_H
1076 #if defined(__MWERKS__) && defined(macintosh)
1079 /*silent gabby compilers*/
1081 WXDLLIMPEXP_BASE
size_t wxStrftime(wxChar
*s
, size_t max
,
1082 const wxChar
*fmt
, const struct tm
*tm
);
1083 #endif /* wxNEED_WX_TIME_H */
1087 WXDLLIMPEXP_BASE wxChar
*wxCtime(const time_t *timep
);
1091 /* missing functions in some WinCE versions */
1093 #if (_WIN32_WCE < 300)
1094 WXDLLIMPEXP_BASE
void *calloc( size_t num
, size_t size
);
1096 #endif /* _WIN32_WCE */
1098 /* multibyte to wide char conversion functions and macros */
1101 /* multibyte<->widechar conversion */
1102 WXDLLIMPEXP_BASE
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
1103 WXDLLIMPEXP_BASE
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
1106 #define wxMB2WX wxMB2WC
1107 #define wxWX2MB wxWC2MB
1108 #define wxWC2WX wxStrncpy
1109 #define wxWX2WC wxStrncpy
1111 #define wxMB2WX wxStrncpy
1112 #define wxWX2MB wxStrncpy
1113 #define wxWC2WX wxWC2MB
1114 #define wxWX2WC wxMB2WC
1116 #else /* !wxUSE_UNICODE */
1117 /* Why is this here?
1119 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1120 #define wxMB2WC wxStrncpy
1121 #define wxWC2MB wxStrncpy
1122 #define wxMB2WX wxStrncpy
1123 #define wxWX2MB wxStrncpy
1124 #define wxWC2WX wxWC2MB
1125 #define wxWX2WC wxMB2WC
1129 RN: The following are not normal versions of memcpy et al., rather
1130 these are either char or widechar versions depending on
1131 if unicode is used or not.
1137 // RN: We could do the usual tricky compiler detection here,
1138 // and use their variant (such as wmemchr, etc.). The problem
1139 // is that these functions are quite rare, even though they are
1140 // part of the current POSIX standard. In addition, most compilers
1141 // (including even MSC) inline them just like we do right in their
1145 #include <string.h> //for mem funcs
1147 //implement our own wmem variants
1148 inline wxChar
* wxTmemchr(const wxChar
* s
, wxChar c
, size_t l
)
1150 for(;l
&& *s
!= c
;--l
, ++s
) {}
1157 inline int wxTmemcmp(const wxChar
* sz1
, const wxChar
* sz2
, size_t len
)
1159 for(; *sz1
== *sz2
&& len
; --len
, ++sz1
, ++sz2
) {}
1162 return *sz1
< *sz2
? -1 : *sz1
> *sz2
;
1167 inline wxChar
* wxTmemcpy(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1169 return (wxChar
*) memcpy(szOut
, szIn
, len
* sizeof(wxChar
));
1172 inline wxChar
* wxTmemmove(wxChar
* szOut
, const wxChar
* szIn
, size_t len
)
1174 return (wxChar
*) memmove(szOut
, szIn
, len
* sizeof(wxChar
));
1177 inline wxChar
* wxTmemset(wxChar
* szOut
, const wxChar cIn
, size_t len
)
1179 wxChar
* szRet
= szOut
;
1187 #else //!wxUSE_UNICODE
1188 # define wxTmemchr memchr
1189 # define wxTmemcmp memcmp
1190 # define wxTmemcpy memcpy
1191 # define wxTmemmove memmove
1192 # define wxTmemset memset
1195 #endif /*__cplusplus*/
1198 #endif /* _WX_WXCHAR_H_ */