1 /////////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) 1998-2002 wxWindows dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "wxchar.h"
19 // ----------------------------------------------------------------------------
20 // first deal with Unicode setting: wxUSE_UNICODE should be defined as 0 or 1
21 // and is used by wxWindows, _UNICODE and/or UNICODE may be defined or used by
22 // the system headers so bring these settings in sync
23 // ----------------------------------------------------------------------------
25 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
26 #if defined(_UNICODE) || defined(UNICODE)
28 #define wxUSE_UNICODE 1
31 #define wxUSE_UNICODE 0
35 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
45 // check whether we have wchar_t
46 #if !defined(wxUSE_WCHAR_T)
47 #if defined(__WIN16__)
48 // no wchar_t under Win16 regadrless of compiler used
49 #define wxUSE_WCHAR_T 0
50 #elif defined(__UNIX__)
51 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
52 #define wxUSE_WCHAR_T 1
54 #define wxUSE_WCHAR_T 0
56 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
57 #define wxUSE_WCHAR_T 0
58 #elif defined(__WATCOMC__)
59 #define wxUSE_WCHAR_T 0
60 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
61 #define wxUSE_WCHAR_T 0
63 // add additional compiler checks if this fails
64 #define wxUSE_WCHAR_T 1
66 #endif // !defined(wxUSE_WCHAR_T)
68 // Unicode support requires wchar_t
69 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
70 #error "wchar_t must be available in Unicode build"
73 // ----------------------------------------------------------------------------
74 // standard headers we need here
76 // NB: don't include any wxWindows headers here because almost of them include
78 // ----------------------------------------------------------------------------
80 // Required for wxPrintf() etc
83 // Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac
84 // and VC++ for Windows CE don't provide it
85 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
86 // use #define, not inline wrapper, as it is tested with #ifndef below
87 #define wxStrdupA strdup
90 // non Unix compilers which do have wchar.h (but not tchar.h which is included
91 // below and which includes wchar.h anyhow).
92 // Actually MinGW has tchar.h, but it does not include wchar.h
93 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
101 // the current (as of Nov 2002) version of cygwin has a bug in its
102 // wchar.h -- there is no extern "C" around the declarations in it and
103 // this results in linking errors later; also, at least on some
104 // Cygwin versions, wchar.h requires sys/types.h
106 #include <sys/types.h>
113 #elif defined(HAVE_WCSTR_H)
114 // old compilers have relevant declarations here
116 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
117 // include stdlib.h for wchar_t
119 #endif // HAVE_WCHAR_H
120 #endif // wxUSE_WCHAR_T
122 // ----------------------------------------------------------------------------
123 // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
124 // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
125 // the function mapping _tfoo() -> foo() or wfoo()
126 // ----------------------------------------------------------------------------
128 // VC++ and BC++ starting with 5.2 have TCHAR support
130 #define wxHAVE_TCHAR_SUPPORT
131 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
132 #define wxHAVE_TCHAR_SUPPORT
134 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
135 #define wxHAVE_TCHAR_SUPPORT
139 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
140 // VZ: the old VisualAge definitions were completely wrong and had no
141 // chance at all to work in Unicode build anyhow so let's pretend that
142 // VisualAge does _not_ support TCHAR for the moment (as indicated by
143 // "0 &&" above) until someone really has time to delve into Unicode
146 // VisualAge 4.0+ supports TCHAR
147 #define wxHAVE_TCHAR_SUPPORT
148 #endif // compilers with (good) TCHAR support
154 #ifdef wxHAVE_TCHAR_SUPPORT
155 // get TCHAR definition if we've got it
158 // we surely do have wchar_t if we have TCHAR
159 #ifndef wxUSE_WCHAR_T
160 #define wxUSE_WCHAR_T 1
161 #endif // !defined(wxUSE_WCHAR_T)
163 // and we also do have wcslen()
167 #endif // wxHAVE_TCHAR_SUPPORT
169 // ----------------------------------------------------------------------------
170 // define wxChar type
171 // ----------------------------------------------------------------------------
173 // TODO: define wxCharInt to be equal to either int or wint_t?
177 typedef signed char wxSChar
;
178 typedef unsigned char wxUChar
;
180 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
181 // signed/unsigned version of it which (a) makes sense to me (unlike
182 // char wchar_t is always unsigned) and (b) was how the previous
183 // definitions worked so keep it like this
185 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
187 #if !defined(__WCHAR_TYPE__) || \
188 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
190 typedef wchar_t wxChar
;
191 typedef wchar_t wxSChar
;
192 typedef wchar_t wxUChar
;
193 #else // __WCHAR_TYPE__ and gcc < 2.96
194 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
195 // this doesn't work with new GCC 3.x compilers because wchar_t is
196 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
197 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
198 // have to define wxChar conditionally depending on detected
199 // compiler & compiler version.
200 // with old definition of wxChar.
201 typedef __WCHAR_TYPE__ wxChar
;
202 typedef __WCHAR_TYPE__ wxSChar
;
203 typedef __WCHAR_TYPE__ wxUChar
;
204 #endif // __WCHAR_TYPE__
205 #endif // ASCII/Unicode
207 // ----------------------------------------------------------------------------
208 // define _T() and related macros
209 // ----------------------------------------------------------------------------
211 // BSD systems define _T() to be something different in ctype.h, override it
212 #if defined(__FreeBSD__) || defined(__DARWIN__)
217 // could already be defined by tchar.h (it's quasi standard)
223 #endif // ASCII/Unicode
224 #endif // !defined(_T)
226 // although global macros with such names are normally bad, we want to have
227 // another name for _T() which should be used to avoid confusion between _T()
228 // and _() in wxWindows sources
231 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
233 #define __XFILE__(x) wxT(x)
234 #define __TFILE__ __XFILE__(__FILE__)
238 #define __XDATE__(x) wxT(x)
239 #define __TDATE__ __XDATE__(__DATE__)
243 #define __XTIME__(x) wxT(x)
244 #define __TTIME__ __XTIME__(__TIME__)
247 // ----------------------------------------------------------------------------
248 // define wxFoo() function for each standard foo() function whose signature
249 // (exceptionally including the return type) includes any mention of char:
250 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
251 // the same signature but with char replaced by wxChar which allows us to use
252 // it in Unicode build as well
253 // ----------------------------------------------------------------------------
255 #ifdef wxHAVE_TCHAR_SUPPORT
259 #define wxIsalnum _istalnum
260 #define wxIsalpha _istalpha
261 #define wxIsctrl _istctrl
262 #define wxIsdigit _istdigit
263 #define wxIsgraph _istgraph
264 #define wxIslower _istlower
265 #define wxIsprint _istprint
266 #define wxIspunct _istpunct
267 #define wxIsspace _istspace
268 #define wxIsupper _istupper
269 #define wxIsxdigit _istxdigit
270 #define wxTolower _totlower
271 #define wxToupper _totupper
274 #define wxSetlocale _tsetlocale
276 // string.h functions
277 #define wxStrcat _tcscat
278 #define wxStrchr _tcschr
279 #define wxStrcmp _tcscmp
280 #define wxStrcoll _tcscoll
281 #define wxStrcpy _tcscpy
282 #define wxStrcspn _tcscspn
283 #define wxStrdupW _wcsdup // notice the 'W'!
284 #define wxStrftime _tcsftime
285 #define wxStricmp _tcsicmp
286 #define wxStrnicmp _tcsnicmp
287 #define wxStrlen_ _tcslen // used in wxStrlen inline function
288 #define wxStrncat _tcsncat
289 #define wxStrncmp _tcsncmp
290 #define wxStrncpy _tcsncpy
291 #define wxStrpbrk _tcspbrk
292 #define wxStrrchr _tcsrchr
293 #define wxStrspn _tcsspn
294 #define wxStrstr _tcsstr
295 #define wxStrtod _tcstod
296 #define wxStrtol _tcstol
297 #define wxStrtoul _tcstoul
298 #define wxStrxfrm _tcsxfrm
301 #define wxFgetc _fgettc
302 #define wxFgetchar _fgettchar
303 #define wxFgets _fgetts
304 #define wxFopen _tfopen
305 #define wxFputc _fputtc
306 #define wxFputchar _fputtchar
307 #define wxFprintf _ftprintf
308 #define wxFputs _fputts
309 #define wxFreopen _tfreopen
310 #define wxFscanf _ftscanf
311 #define wxGetc _gettc
312 #define wxGetchar _gettchar
313 #define wxGets _getts
314 #define wxPerror _tperror
315 #define wxPrintf _tprintf
316 #define wxPutc _puttc
317 #define wxPutchar _puttchar
318 #define wxPuts _putts
319 #define wxScanf _tscanf
320 #define wxSprintf _stprintf
321 #define wxSscanf _stscanf
322 #define wxTmpnam _ttmpnam
323 #define wxUngetc _tungetc
324 #define wxVfprintf _vftprintf
325 #define wxVprintf _vtprintf
326 #define wxVsscanf _vstscanf
327 #define wxVsprintf _vstprintf
329 // special case: not all TCHAR-aware compilers have those
330 #if defined(__VISUALC__) || \
331 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
332 #define wxVsnprintf_ _vsntprintf
333 #define wxSnprintf_ _sntprintf
336 // special case: these functions are missing under Win9x with Unicows so we
337 // have to implement them ourselves
338 #if wxUSE_UNICODE_MSLU
339 #define wxRemove wxMSLU__tremove
340 #define wxRename wxMSLU__trename
342 #define wxRemove _tremove
343 #define wxRename _trename
346 // stdlib.h functions
349 // #define wxAtof _tttof -- notice that there is no such thing (why?)
350 #define wxGetenv _tgetenv
351 #define wxSystem _tsystem
354 #define wxAsctime _tasctime
355 #define wxCtime _tctime
356 #else // !TCHAR-aware compilers
360 // this is probably glibc-specific
361 #if defined(__WCHAR_TYPE__)
362 // ctype.h functions (wctype.h)
363 #define wxIsalnum iswalnum
364 #define wxIsalpha iswalpha
365 #define wxIsctrl iswcntrl
366 #define wxIsdigit iswdigit
367 #define wxIsgraph iswgraph
368 #define wxIslower iswlower
369 #define wxIsprint iswprint
370 #define wxIspunct iswpunct
371 #define wxIsspace iswspace
372 #define wxIsupper iswupper
373 #define wxIsxdigit iswxdigit
375 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
376 // /usr/include/wctype.h incorrectly declares translations
377 // tables which provokes tons of compile-time warnings -- try
379 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
380 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
382 #define wxTolower towlower
383 #define wxToupper towupper
386 // string.h functions (wchar.h)
387 #define wxStrcat wcscat
388 #define wxStrchr wcschr
389 #define wxStrcmp wcscmp
390 #define wxStrcoll wcscoll
391 #define wxStrcpy wcscpy
392 #define wxStrcspn wcscspn
393 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
394 #define wxStrncat wcsncat
395 #define wxStrncmp wcsncmp
396 #define wxStrncpy wcsncpy
397 #define wxStrpbrk wcspbrk
398 #define wxStrrchr wcsrchr
399 #define wxStrspn wcsspn
400 #define wxStrstr wcsstr
401 #define wxStrtod wcstod
402 #define wxStrtol wcstol
403 #define wxStrtoul wcstoul
404 #define wxStrxfrm wcsxfrm
406 #define wxFgetc fgetwc
407 #define wxFgetchar fgetwchar
408 #define wxFgets fgetws
409 #define wxFputc fputwc
410 #define wxFputchar fputwchar
412 #define wxGetchar getwchar
414 #define wxUngetc ungetwc
418 #define wxPutchar wputchar
420 #define wxFputs fputws
422 #define wxNEED_FPUTWC
426 int wxFputs(const wxChar
*ch
, FILE *stream
);
427 int wxPutc(wxChar ch
, FILE *stream
);
429 #define wxPuts(ws) wxFputs(ws, stdout)
430 #define wxPutchar(wch) wxPutc(wch, stdout)
433 // we need %s to %ls conversion for printf and scanf etc
434 #define wxNEED_PRINTF_CONVERSION
436 // glibc doesn't have wide char equivalents of the other stuff so
437 // use our own versions
438 #define wxNEED_WX_STDIO_H
439 #define wxNEED_WX_STDLIB_H
440 #define wxNEED_WX_TIME_H
441 #elif defined(__MWERKS__) && ( defined(macintosh) || defined(__MACH__) )
442 // ctype.h functions (wctype.h)
443 #define wxIsalnum iswalnum
444 #define wxIsalpha iswalpha
445 #define wxIsctrl iswcntrl
446 #define wxIsdigit iswdigit
447 #define wxIsgraph iswgraph
448 #define wxIslower iswlower
449 #define wxIsprint iswprint
450 #define wxIspunct iswpunct
451 #define wxIsspace iswspace
452 #define wxIsupper iswupper
453 #define wxIsxdigit iswxdigit
454 #define wxTolower towlower
455 #define wxToupper towupper
457 // string.h functions (wchar.h)
458 #define wxStrcat wcscat
459 #define wxStrchr wcschr
460 #define wxStrcmp wcscmp
461 #define wxStrcoll wcscoll
462 #define wxStrcpy wcscpy
463 #define wxStrcspn wcscspn
464 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
465 #define wxStrncat wcsncat
466 #define wxStrncmp wcsncmp
467 #define wxStrncpy wcsncpy
468 #define wxStrpbrk wcspbrk
469 #define wxStrrchr wcsrchr
470 #define wxStrspn wcsspn
471 #define wxStrstr wcsstr
472 #define wxStrtod wcstod
473 #define wxStrtol wcstol
474 #define wxStrtoul wcstoul
475 #define wxStrxfrm wcsxfrm
477 #define wxFgetc fgetwc
478 #define wxFgetchar fgetwchar
479 #define wxFgets fgetws
480 #define wxFputc fputwc
481 #define wxFputchar fputwchar
483 #define wxGetchar getwchar
485 #define wxUngetc ungetwc
487 #define wxNEED_PRINTF_CONVERSION
490 #define wxPutchar putwchar
491 #define wxFputs fputws
495 #define wxNEED_WX_STDIO_H
497 // stdlib.h functions
501 #define wxGetenv(a) ((wxChar*)NULL)
502 #define wxSystem(a) ((int)NULL)
505 #define wxAsctime wasciitime
506 #define wxCtime wctime
507 #define wxStrftime wcsftime
510 #define wxNEED_FPUTWC
514 int wxFputs(const wxChar *ch, FILE *stream);
515 int wxPutc(wxChar ch, FILE *stream);
517 #define wxPuts(ws) wxFputs(ws, stdout)
518 #define wxPutchar(wch) wxPutc(wch, stdout)
520 // we need %s to %ls conversion for printf and scanf etc
521 #define wxNEED_PRINTF_CONVERSION
522 // glibc doesn't have wide char equivalents of the other stuff so
523 // use our own versions
524 #define wxNEED_WX_STDIO_H
525 #define wxNEED_WX_STDLIB_H
526 #define wxNEED_WX_TIME_H
528 #else // !metrowerks for apple
529 #error "Please define wide character functions for your environment"
536 #define wxIsalnum isalnum
537 #define wxIsalpha isalpha
538 #define wxIsctrl isctrl
539 #define wxIsdigit isdigit
540 #define wxIsgraph isgraph
541 #define wxIslower islower
542 #define wxIsprint isprint
543 #define wxIspunct ispunct
544 #define wxIsspace isspace
545 #define wxIsupper isupper
546 #define wxIsxdigit isxdigit
547 #define wxTolower tolower
548 #define wxToupper toupper
551 #define wxSetlocale setlocale
553 // string.h functions
554 #define wxStrcat strcat
555 #define wxStrchr strchr
556 #define wxStrcmp strcmp
557 #define wxStrcoll strcoll
558 #define wxStrcpy strcpy
559 #define wxStrcspn strcspn
561 // wxStricmp and wxStrnicmp are defined below
562 #define wxStrlen_ strlen // used in wxStrlen inline function
563 #define wxStrncat strncat
564 #define wxStrncmp strncmp
565 #define wxStrncpy strncpy
566 #define wxStrpbrk strpbrk
567 #define wxStrrchr strrchr
568 #define wxStrspn strspn
569 #define wxStrstr strstr
570 #define wxStrtod strtod
572 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
574 #define wxStrtol strtol
575 #define wxStrtoul strtoul
576 #define wxStrxfrm strxfrm
579 #define wxFopen fopen
580 #define wxFreopen freopen
581 #define wxPerror perror
582 #define wxRemove remove
583 #define wxRename rename
584 #define wxTmpnam tmpnam
586 #define wxFgetc fgetc
587 #define wxFgetchar fgetchar
588 #define wxFgets fgets
589 #define wxFputc fputc
590 #define wxFputchar fputchar
591 #define wxFprintf fprintf
592 #define wxFscanf fscanf
594 #define wxGetchar getchar
596 #define wxPrintf printf
598 #define wxPutchar putchar
600 #define wxScanf scanf
601 #define wxSprintf sprintf
602 #define wxSscanf sscanf
603 #define wxUngetc ungetc
604 #define wxVfprintf vfprintf
605 #define wxVprintf vprintf
606 #define wxVsscanf vsscanf
607 #define wxVsprintf vsprintf
609 // stdlib.h functions
613 #define wxGetenv getenv
614 #define wxSystem system
617 #define wxAsctime asctime
618 #define wxCtime ctime
619 #define wxStrftime strftime
620 #endif // Unicode/ASCII
621 #endif // TCHAR-aware compilers/the others
623 // ----------------------------------------------------------------------------
624 // various special cases
625 // ----------------------------------------------------------------------------
627 // define wxStricmp and wxStrnicmp for various compilers
629 // note that in Unicode mode we definitely are going to need our own version
630 #if !defined(wxStricmp) && !wxUSE_UNICODE
631 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
632 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
633 defined(__EMX__) || defined(__DJGPP__)
634 #define wxStricmp stricmp
635 #define wxStrnicmp strnicmp
636 #elif defined(__SC__) || defined(__VISUALC__) || \
637 (defined(__MWERKS__) && defined(__INTEL__))
638 #define wxStricmp _stricmp
639 #define wxStrnicmp _strnicmp
640 #elif defined(__UNIX__) || defined(__GNUWIN32__)
641 #define wxStricmp strcasecmp
642 #define wxStrnicmp strncasecmp
643 // #else -- use wxWindows implementation
645 #endif // !defined(wxStricmp)
647 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
648 // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
649 // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
652 #define wxWcslen wcslen
654 inline size_t wxWcslen(const wchar_t *s
)
663 #endif // wxUSE_WCHAR_T
665 // checks whether the passed in pointer is NULL and if the string is empty
666 inline bool wxIsEmpty(const wxChar
*p
) { return !p
|| !*p
; }
668 // safe version of strlen() (returns 0 if passed NULL pointer)
669 inline size_t wxStrlen(const wxChar
*psz
) { return psz
? wxStrlen_(psz
) : 0; }
671 // each of strdup() and wcsdup() may or may not be available but we need both
672 // of them anyhow for wx/buffer.h so we define the missing one(s) in
673 // wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
674 // defined -- if this is somehow not the case in some situations, please
675 // correct that and not the lines here
677 #define wxStrdup wxStrdupW
679 #define wxStrdup wxStrdupA
682 WXDLLEXPORT
bool wxOKlibc(); // for internal use
684 // ----------------------------------------------------------------------------
685 // printf() family saga
686 // ----------------------------------------------------------------------------
689 For some systems vsnprintf() exists in the system libraries but not in the
690 headers, so we need to declare it ourselves to be able to use it.
692 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
694 int vsnprintf(char *str
, size_t size
, const char *format
, va_list ap
);
695 #endif // !HAVE_VSNPRINTF_DECL
698 First of all, we always want to define safe snprintf() function to be used
699 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
700 which we really need...), otherwise we implement it using our own printf()
703 We define function with a trailing underscore here because the real one is a
704 wrapper around it as explained below
708 #if defined(__MWERKS__)
709 #define HAVE_WCSRTOMBS 1
710 #define HAVE_VSWPRINTF 1
712 #if defined(HAVE__VSNWPRINTF)
713 #define wxVsnprintf_ _vsnwprintf
714 /* MinGW?MSVCRT has the wrong vswprintf */
715 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
716 #define wxVsnprintf_ vswprintf
719 // all versions of CodeWarrior supported by wxWindows apparently have
721 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
722 // assume we have snprintf() too if we have vsnprintf()
723 #define wxVsnprintf_ vsnprintf
724 #define wxSnprintf_ snprintf
727 #endif // wxVsnprintf_ not defined yet
730 // no [v]snprintf(), cook our own
731 WXDLLEXPORT
int wxSnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
,
732 ...) ATTRIBUTE_PRINTF_3
;
735 WXDLLEXPORT
int wxVsnprintf_(wxChar
*buf
, size_t len
, const wxChar
*format
,
740 In Unicode mode we need to have all standard functions such as wprintf() and
741 so on but not all systems have them so use our own implementations in this
744 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
745 #define wxNEED_WPRINTF
749 More Unicode complications: although both ANSI C and C++ define a number of
750 wide character functions such as wprintf(), not all environments have them.
751 Worse, those which do have different behaviours: under Windows, %s format
752 specifier changes its meaning in Unicode build and expects a Unicode string
753 while under Unix/POSIX it still means an ASCII string even for wprintf() and
754 %ls has to be used for wide strings.
756 We choose to always emulate Windows behaviour as more useful for us so even
757 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
759 However, if we don't have any vswprintf() at all we don't need to redefine
760 anything as our own wxVsnprintf_() already behaves as needed.
763 #undef wxNEED_PRINTF_CONVERSION
766 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
767 // we need to implement all wide character printf and scanf functions
768 // either because we don't have them at all or because they don't have the
771 #include <stdio.h> // for FILE
773 int wxScanf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
774 int wxSscanf( const wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
775 int wxFscanf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
776 int wxVsscanf( const wxChar
*str
, const wxChar
*format
, va_list ap
);
777 int wxPrintf( const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_1
;
778 int wxSprintf( wxChar
*str
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
779 int wxFprintf( FILE *stream
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_2
;
780 int wxVfprintf( FILE *stream
, const wxChar
*format
, va_list ap
);
781 int wxVprintf( const wxChar
*format
, va_list ap
);
782 int wxVsprintf( wxChar
*str
, const wxChar
*format
, va_list ap
);
783 #endif // wxNEED_PRINTF_CONVERSION
785 // these 2 can be simply mapped to the versions with underscore at the end
786 // if we don't have to do the conversion
787 #ifdef wxNEED_PRINTF_CONVERSION
788 int wxSnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, ... ) ATTRIBUTE_PRINTF_3
;
789 int wxVsnprintf( wxChar
*str
, size_t size
, const wxChar
*format
, va_list ap
);
791 #define wxSnprintf wxSnprintf_
792 #define wxVsnprintf wxVsnprintf_
795 // ----------------------------------------------------------------------------
796 // various functions which might not be available in libc and for which we
797 // provide our own replacements in wxchar.cpp
798 // ----------------------------------------------------------------------------
802 // VZ: note that this is never defined currently
803 #ifdef wxNEED_WX_CTYPE_H
804 WXDLLEXPORT
int wxIsalnum(wxChar ch
);
805 WXDLLEXPORT
int wxIsalpha(wxChar ch
);
806 WXDLLEXPORT
int wxIsctrl(wxChar ch
);
807 WXDLLEXPORT
int wxIsdigit(wxChar ch
);
808 WXDLLEXPORT
int wxIsgraph(wxChar ch
);
809 WXDLLEXPORT
int wxIslower(wxChar ch
);
810 WXDLLEXPORT
int wxIsprint(wxChar ch
);
811 WXDLLEXPORT
int wxIspunct(wxChar ch
);
812 WXDLLEXPORT
int wxIsspace(wxChar ch
);
813 WXDLLEXPORT
int wxIsupper(wxChar ch
);
814 WXDLLEXPORT
int wxIsxdigit(wxChar ch
);
815 WXDLLEXPORT
int wxTolower(wxChar ch
);
816 WXDLLEXPORT
int wxToupper(wxChar ch
);
817 #endif // wxNEED_WX_CTYPE_H
819 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
820 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
821 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
823 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
827 // string.h functions
829 // VZ: this is never defined neither currently
830 #ifdef wxNEED_WX_STRING_H
831 WXDLLEXPORT wxChar
* wxStrcat(wxChar
*dest
, const wxChar
*src
);
832 WXDLLEXPORT
const wxChar
* wxStrchr(const wxChar
*s
, wxChar c
);
833 WXDLLEXPORT wxChar
* wxStrchr(wxChar
*s
, wxChar c
)
834 { return (wxChar
*)wxStrchr((const wxChar
*)s
, c
); }
835 WXDLLEXPORT
int wxStrcmp(const wxChar
*s1
, const wxChar
*s2
);
836 WXDLLEXPORT
int wxStrcoll(const wxChar
*s1
, const wxChar
*s2
);
837 WXDLLEXPORT wxChar
* wxStrcpy(wxChar
*dest
, const wxChar
*src
);
838 WXDLLEXPORT
size_t wxStrcspn(const wxChar
*s
, const wxChar
*reject
);
839 WXDLLEXPORT
size_t wxStrlen(const wxChar
*s
);
840 WXDLLEXPORT wxChar
* wxStrncat(wxChar
*dest
, const wxChar
*src
, size_t n
);
841 WXDLLEXPORT
int wxStrncmp(const wxChar
*s1
, const wxChar
*s2
, size_t n
);
842 WXDLLEXPORT wxChar
* wxStrncpy(wxChar
*dest
, const wxChar
*src
, size_t n
);
843 WXDLLEXPORT
const wxChar
* wxStrpbrk(const wxChar
*s
, const wxChar
*accept
);
844 WXDLLEXPORT wxChar
* wxStrpbrk(wxChar
*s
, const wxChar
*accept
)
845 { return (wxChar
*)wxStrpbrk((const wxChar
*)s
, accept
); }
846 WXDLLEXPORT
const wxChar
* wxStrrchr(const wxChar
*s
, wxChar c
);
847 WXDLLEXPORT wxChar
* wxStrrchr(wxChar
*s
, wxChar c
)
848 { return (wxChar
*)wxStrrchr((const wxChar
*)s
, c
); }
849 WXDLLEXPORT
size_t wxStrspn(const wxChar
*s
, const wxChar
*accept
);
850 WXDLLEXPORT
const wxChar
* wxStrstr(const wxChar
*haystack
, const wxChar
*needle
);
851 WXDLLEXPORT wxChar
*wxStrstr(wxChar
*haystack
, const wxChar
*needle
)
852 { return (wxChar
*)wxStrstr((const wxChar
*)haystack
, needle
); }
853 WXDLLEXPORT
double wxStrtod(const wxChar
*nptr
, wxChar
**endptr
);
854 WXDLLEXPORT
long int wxStrtol(const wxChar
*nptr
, wxChar
**endptr
, int base
);
855 WXDLLEXPORT
unsigned long int wxStrtoul(const wxChar
*nptr
, wxChar
**endptr
, int base
);
856 WXDLLEXPORT
size_t wxStrxfrm(wxChar
*dest
, const wxChar
*src
, size_t n
);
857 #endif // wxNEED_WX_STRING_H
860 WXDLLEXPORT
char *wxStrdupA(const char *psz
);
864 WXDLLEXPORT
wchar_t *wxStrdupW(const wchar_t *pwz
);
868 WXDLLEXPORT
int wxStricmp(const wxChar
*psz1
, const wxChar
*psz2
);
872 WXDLLEXPORT
int wxStrnicmp(const wxChar
*psz1
, const wxChar
*psz2
, size_t len
);
876 WXDLLEXPORT wxChar
* wxStrtok(wxChar
*psz
, const wxChar
*delim
, wxChar
**save_ptr
);
880 class WXDLLEXPORT wxWCharBuffer
;
881 WXDLLEXPORT wxWCharBuffer
wxSetlocale(int category
, const wxChar
*locale
);
885 #ifdef wxNEED_WX_STDIO_H
887 WXDLLEXPORT
FILE * wxFopen(const wxChar
*path
, const wxChar
*mode
);
888 WXDLLEXPORT
FILE * wxFreopen(const wxChar
*path
, const wxChar
*mode
, FILE *stream
);
889 WXDLLEXPORT
int wxRemove(const wxChar
*path
);
890 WXDLLEXPORT
int wxRename(const wxChar
*oldpath
, const wxChar
*newpath
);
892 // *printf() family is handled separately
893 #endif // wxNEED_WX_STDIO_H
896 // stdlib.h functions
898 WXDLLEXPORT
double wxAtof(const wxChar
*psz
);
901 #ifdef wxNEED_WX_STDLIB_H
902 WXDLLEXPORT
int wxAtoi(const wxChar
*psz
);
903 WXDLLEXPORT
long wxAtol(const wxChar
*psz
);
904 WXDLLEXPORT wxChar
* wxGetenv(const wxChar
*name
);
905 WXDLLEXPORT
int wxSystem(const wxChar
*psz
);
910 #ifdef wxNEED_WX_TIME_H
911 #if defined(__MWERKS__) && defined(macintosh)
914 WXDLLEXPORT
size_t wxStrftime(wxChar
*s
, size_t max
,
915 const wxChar
*fmt
, const struct tm
*tm
);
916 #endif // wxNEED_WX_TIME_H
918 // ----------------------------------------------------------------------------
919 // multibyte to wide char conversion functions and macros
920 // ----------------------------------------------------------------------------
923 // multibyte<->widechar conversion
924 WXDLLEXPORT
size_t wxMB2WC(wchar_t *buf
, const char *psz
, size_t n
);
925 WXDLLEXPORT
size_t wxWC2MB(char *buf
, const wchar_t *psz
, size_t n
);
928 #define wxMB2WX wxMB2WC
929 #define wxWX2MB wxWC2MB
930 #define wxWC2WX wxStrncpy
931 #define wxWX2WC wxStrncpy
933 #define wxMB2WX wxStrncpy
934 #define wxWX2MB wxStrncpy
935 #define wxWC2WX wxWC2MB
936 #define wxWX2WC wxMB2WC
938 #else // !wxUSE_UNICODE
939 // No wxUSE_WCHAR_T: we have to do something (JACS)
940 #define wxMB2WC wxStrncpy
941 #define wxWC2MB wxStrncpy
942 #define wxMB2WX wxStrncpy
943 #define wxWX2MB wxStrncpy
944 #define wxWC2WX wxWC2MB
945 #define wxWX2WC wxMB2WC
948 #endif //_WX_WXCHAR_H_