]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
added wxSplitterWindow to XRC
[wxWidgets.git] / include / wx / wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wxchar.h
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
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2002 wxWindows dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXCHAR_H_
13 #define _WX_WXCHAR_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "wxchar.h"
17 #endif
18
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 // ----------------------------------------------------------------------------
24
25 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
26 #if defined(_UNICODE) || defined(UNICODE)
27 #undef wxUSE_UNICODE
28 #define wxUSE_UNICODE 1
29 #else
30 #ifndef wxUSE_UNICODE
31 #define wxUSE_UNICODE 0
32 #endif
33 #endif // Unicode
34
35 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
36 #if wxUSE_UNICODE
37 #ifndef _UNICODE
38 #define _UNICODE
39 #endif
40 #ifndef UNICODE
41 #define UNICODE
42 #endif
43 #endif // Unicode
44
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
53 #else
54 #define wxUSE_WCHAR_T 0
55 #endif
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
62 #else
63 // add additional compiler checks if this fails
64 #define wxUSE_WCHAR_T 1
65 #endif
66 #endif // !defined(wxUSE_WCHAR_T)
67
68 // Unicode support requires wchar_t
69 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
70 #error "wchar_t must be available in Unicode build"
71 #endif // Unicode
72
73 // ----------------------------------------------------------------------------
74 // standard headers we need here
75 //
76 // NB: don't include any wxWindows headers here because almost of them include
77 // this one!
78 // ----------------------------------------------------------------------------
79
80 // Required for wxPrintf() etc
81 #include <stdarg.h>
82
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
88 #endif
89
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__)
94 #ifndef HAVE_WCHAR_H
95 #define HAVE_WCHAR_H
96 #endif
97 #endif
98
99 #if wxUSE_WCHAR_T
100 #ifdef HAVE_WCHAR_H
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
105 #ifdef __CYGWIN__
106 #include <sys/types.h>
107 extern "C" {
108 #endif // Cygwin
109 #include <wchar.h>
110 #ifdef __CYGWIN__
111 }
112 #endif // Cygwin
113 #elif defined(HAVE_WCSTR_H)
114 // old compilers have relevant declarations here
115 #include <wcstr.h>
116 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
117 // include stdlib.h for wchar_t
118 #include <stdlib.h>
119 #endif // HAVE_WCHAR_H
120 #endif // wxUSE_WCHAR_T
121
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 // ----------------------------------------------------------------------------
127
128 // VC++ and BC++ starting with 5.2 have TCHAR support
129 #ifdef __VISUALC__
130 #define wxHAVE_TCHAR_SUPPORT
131 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
132 #define wxHAVE_TCHAR_SUPPORT
133 #include <ctype.h>
134 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
135 #define wxHAVE_TCHAR_SUPPORT
136 #include <stddef.h>
137 #include <string.h>
138 #include <ctype.h>
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
144 // issues under OS/2
145
146 // VisualAge 4.0+ supports TCHAR
147 #define wxHAVE_TCHAR_SUPPORT
148 #endif // compilers with (good) TCHAR support
149
150 #ifdef wxHAVE_TCHAR_SUPPORT
151 // get TCHAR definition if we've got it
152 #include <tchar.h>
153
154 // we surely do have wchar_t if we have TCHAR
155 #ifndef wxUSE_WCHAR_T
156 #define wxUSE_WCHAR_T 1
157 #endif // !defined(wxUSE_WCHAR_T)
158
159 // and we also do have wcslen()
160 #ifndef HAVE_WCSLEN
161 #define HAVE_WCSLEN
162 #endif
163 #endif // wxHAVE_TCHAR_SUPPORT
164
165 // ----------------------------------------------------------------------------
166 // define wxChar type
167 // ----------------------------------------------------------------------------
168
169 // TODO: define wxCharInt to be equal to either int or wint_t?
170
171 #if !wxUSE_UNICODE
172 typedef char wxChar;
173 typedef signed char wxSChar;
174 typedef unsigned char wxUChar;
175 #else // Unicode
176 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
177 // signed/unsigned version of it which (a) makes sense to me (unlike
178 // char wchar_t is always unsigned) and (b) was how the previous
179 // definitions worked so keep it like this
180
181 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
182 // comment below
183 #if !defined(__WCHAR_TYPE__) || \
184 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
185 // standard case
186 typedef wchar_t wxChar;
187 typedef wchar_t wxSChar;
188 typedef wchar_t wxUChar;
189 #else // __WCHAR_TYPE__ and gcc < 2.96
190 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
191 // this doesn't work with new GCC 3.x compilers because wchar_t is
192 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
193 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
194 // have to define wxChar conditionally depending on detected
195 // compiler & compiler version.
196 // with old definition of wxChar.
197 typedef __WCHAR_TYPE__ wxChar;
198 typedef __WCHAR_TYPE__ wxSChar;
199 typedef __WCHAR_TYPE__ wxUChar;
200 #endif // __WCHAR_TYPE__
201 #endif // ASCII/Unicode
202
203 // ----------------------------------------------------------------------------
204 // define _T() and related macros
205 // ----------------------------------------------------------------------------
206
207 // BSD systems define _T() to be something different in ctype.h, override it
208 #if defined(__FreeBSD__) || defined(__DARWIN__)
209 #include <ctype.h>
210 #undef _T
211 #endif
212
213 // could already be defined by tchar.h (it's quasi standard)
214 #ifndef _T
215 #if !wxUSE_UNICODE
216 #define _T(x) x
217 #else // Unicode
218 #define _T(x) L ## x
219 #endif // ASCII/Unicode
220 #endif // !defined(_T)
221
222 // although global macros with such names are normally bad, we want to have
223 // another name for _T() which should be used to avoid confusion between _T()
224 // and _() in wxWindows sources
225 #define wxT(x) _T(x)
226
227 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
228 #ifndef __TFILE__
229 #define __XFILE__(x) wxT(x)
230 #define __TFILE__ __XFILE__(__FILE__)
231 #endif
232
233 #ifndef __TDATE__
234 #define __XDATE__(x) wxT(x)
235 #define __TDATE__ __XDATE__(__DATE__)
236 #endif
237
238 #ifndef __TTIME__
239 #define __XTIME__(x) wxT(x)
240 #define __TTIME__ __XTIME__(__TIME__)
241 #endif
242
243 // ----------------------------------------------------------------------------
244 // define wxFoo() function for each standard foo() function whose signature
245 // (exceptionally including the return type) includes any mention of char:
246 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
247 // the same signature but with char replaced by wxChar which allows us to use
248 // it in Unicode build as well
249 // ----------------------------------------------------------------------------
250
251 #ifdef wxHAVE_TCHAR_SUPPORT
252 #include <ctype.h>
253
254 // ctype.h functions
255 #define wxIsalnum _istalnum
256 #define wxIsalpha _istalpha
257 #define wxIsctrl _istctrl
258 #define wxIsdigit _istdigit
259 #define wxIsgraph _istgraph
260 #define wxIslower _istlower
261 #define wxIsprint _istprint
262 #define wxIspunct _istpunct
263 #define wxIsspace _istspace
264 #define wxIsupper _istupper
265 #define wxIsxdigit _istxdigit
266 #define wxTolower _totlower
267 #define wxToupper _totupper
268
269 // locale.h functons
270 #define wxSetlocale _tsetlocale
271
272 // string.h functions
273 #define wxStrcat _tcscat
274 #define wxStrchr _tcschr
275 #define wxStrcmp _tcscmp
276 #define wxStrcoll _tcscoll
277 #define wxStrcpy _tcscpy
278 #define wxStrcspn _tcscspn
279 #define wxStrdupW _wcsdup // notice the 'W'!
280 #define wxStrftime _tcsftime
281 #define wxStricmp _tcsicmp
282 #define wxStrnicmp _tcsnicmp
283 #define wxStrlen_ _tcslen // used in wxStrlen inline function
284 #define wxStrncat _tcsncat
285 #define wxStrncmp _tcsncmp
286 #define wxStrncpy _tcsncpy
287 #define wxStrpbrk _tcspbrk
288 #define wxStrrchr _tcsrchr
289 #define wxStrspn _tcsspn
290 #define wxStrstr _tcsstr
291 #define wxStrtod _tcstod
292 #define wxStrtol _tcstol
293 #define wxStrtoul _tcstoul
294 #define wxStrxfrm _tcsxfrm
295
296 // stdio.h functions
297 #define wxFgetc _fgettc
298 #define wxFgetchar _fgettchar
299 #define wxFgets _fgetts
300 #define wxFopen _tfopen
301 #define wxFputc _fputtc
302 #define wxFputchar _fputtchar
303 #define wxFprintf _ftprintf
304 #define wxFputs _fputts
305 #define wxFreopen _tfreopen
306 #define wxFscanf _ftscanf
307 #define wxGetc _gettc
308 #define wxGetchar _gettchar
309 #define wxGets _getts
310 #define wxPerror _tperror
311 #define wxPrintf _tprintf
312 #define wxPutc _puttc
313 #define wxPutchar _puttchar
314 #define wxPuts _putts
315 #define wxScanf _tscanf
316 #define wxSprintf _stprintf
317 #define wxSscanf _stscanf
318 #define wxTmpnam _ttmpnam
319 #define wxUngetc _tungetc
320 #define wxVfprintf _vftprintf
321 #define wxVprintf _vtprintf
322 #define wxVsscanf _vstscanf
323 #define wxVsprintf _vstprintf
324
325 // special case: not all TCHAR-aware compilers have those
326 #if defined(__VISUALC__) || \
327 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
328 #define wxVsnprintf_ _vsntprintf
329 #define wxSnprintf_ _sntprintf
330 #endif
331
332 // special case: these functions are missing under Win9x with Unicows so we
333 // have to implement them ourselves
334 #if wxUSE_UNICODE_MSLU
335 #define wxRemove wxMSLU__tremove
336 #define wxRename wxMSLU__trename
337 #else
338 #define wxRemove _tremove
339 #define wxRename _trename
340 #endif
341
342 // stdlib.h functions
343 #define wxAtoi _ttoi
344 #define wxAtol _ttol
345 // #define wxAtof _tttof -- notice that there is no such thing (why?)
346 #define wxGetenv _tgetenv
347 #define wxSystem _tsystem
348
349 // time.h functions
350 #define wxAsctime _tasctime
351 #define wxCtime _tctime
352 #else // !TCHAR-aware compilers
353 #if wxUSE_UNICODE
354 #include <wctype.h>
355
356 // this is probably glibc-specific
357 #if defined(__WCHAR_TYPE__)
358 // ctype.h functions (wctype.h)
359 #define wxIsalnum iswalnum
360 #define wxIsalpha iswalpha
361 #define wxIsctrl iswcntrl
362 #define wxIsdigit iswdigit
363 #define wxIsgraph iswgraph
364 #define wxIslower iswlower
365 #define wxIsprint iswprint
366 #define wxIspunct iswpunct
367 #define wxIsspace iswspace
368 #define wxIsupper iswupper
369 #define wxIsxdigit iswxdigit
370
371 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
372 // /usr/include/wctype.h incorrectly declares translations
373 // tables which provokes tons of compile-time warnings -- try
374 // to correct this
375 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
376 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
377 #else // !glibc 2.0
378 #define wxTolower towlower
379 #define wxToupper towupper
380 #endif // gcc/!gcc
381
382 // string.h functions (wchar.h)
383 #define wxStrcat wcscat
384 #define wxStrchr wcschr
385 #define wxStrcmp wcscmp
386 #define wxStrcoll wcscoll
387 #define wxStrcpy wcscpy
388 #define wxStrcspn wcscspn
389 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
390 #define wxStrncat wcsncat
391 #define wxStrncmp wcsncmp
392 #define wxStrncpy wcsncpy
393 #define wxStrpbrk wcspbrk
394 #define wxStrrchr wcsrchr
395 #define wxStrspn wcsspn
396 #define wxStrstr wcsstr
397 #define wxStrtod wcstod
398 #define wxStrtol wcstol
399 #define wxStrtoul wcstoul
400 #define wxStrxfrm wcsxfrm
401
402 #define wxFgetc fgetwc
403 #define wxFgetchar fgetwchar
404 #define wxFgets fgetws
405 #define wxFputc fputwc
406 #define wxFputchar fputwchar
407 #define wxGetc getwc
408 #define wxGetchar getwchar
409 #define wxGets getws
410 #define wxUngetc ungetwc
411
412 #ifdef HAVE_FPUTWC
413 #define wxPutc wputc
414 #define wxPutchar wputchar
415 #define wxPuts putws
416 #define wxFputs fputws
417 #else
418 #define wxNEED_FPUTWC
419
420 #include <stdio.h>
421
422 int wxFputs(const wxChar *ch, FILE *stream);
423 int wxPutc(wxChar ch, FILE *stream);
424
425 #define wxPuts(ws) wxFputs(ws, stdout)
426 #define wxPutchar(wch) wxPutc(wch, stdout)
427 #endif
428
429 // we need %s to %ls conversion for printf and scanf etc
430 #define wxNEED_PRINTF_CONVERSION
431
432 // glibc doesn't have wide char equivalents of the other stuff so
433 // use our own versions
434 #define wxNEED_WX_STDIO_H
435 #define wxNEED_WX_STDLIB_H
436 #define wxNEED_WX_TIME_H
437 #else // !glibc
438 #error "Please define wide character functions for your environment"
439 #endif
440 #else // ASCII
441 #include <ctype.h>
442 #include <string.h>
443
444 // ctype.h functions
445 #define wxIsalnum isalnum
446 #define wxIsalpha isalpha
447 #define wxIsctrl isctrl
448 #define wxIsdigit isdigit
449 #define wxIsgraph isgraph
450 #define wxIslower islower
451 #define wxIsprint isprint
452 #define wxIspunct ispunct
453 #define wxIsspace isspace
454 #define wxIsupper isupper
455 #define wxIsxdigit isxdigit
456 #define wxTolower tolower
457 #define wxToupper toupper
458
459 // locale.h functons
460 #define wxSetlocale setlocale
461
462 // string.h functions
463 #define wxStrcat strcat
464 #define wxStrchr strchr
465 #define wxStrcmp strcmp
466 #define wxStrcoll strcoll
467 #define wxStrcpy strcpy
468 #define wxStrcspn strcspn
469
470 // wxStricmp and wxStrnicmp are defined below
471 #define wxStrlen_ strlen // used in wxStrlen inline function
472 #define wxStrncat strncat
473 #define wxStrncmp strncmp
474 #define wxStrncpy strncpy
475 #define wxStrpbrk strpbrk
476 #define wxStrrchr strrchr
477 #define wxStrspn strspn
478 #define wxStrstr strstr
479 #define wxStrtod strtod
480 #ifdef HAVE_STRTOK_R
481 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
482 #endif
483 #define wxStrtol strtol
484 #define wxStrtoul strtoul
485 #define wxStrxfrm strxfrm
486
487 // stdio.h functions
488 #define wxFopen fopen
489 #define wxFreopen freopen
490 #define wxPerror perror
491 #define wxRemove remove
492 #define wxRename rename
493 #define wxTmpnam tmpnam
494
495 #define wxFgetc fgetc
496 #define wxFgetchar fgetchar
497 #define wxFgets fgets
498 #define wxFputc fputc
499 #define wxFputchar fputchar
500 #define wxFprintf fprintf
501 #define wxFscanf fscanf
502 #define wxGetc getc
503 #define wxGetchar getchar
504 #define wxGets gets
505 #define wxPrintf printf
506 #define wxPutc putc
507 #define wxPutchar putchar
508 #define wxPuts puts
509 #define wxScanf scanf
510 #define wxSprintf sprintf
511 #define wxSscanf sscanf
512 #define wxUngetc ungetc
513 #define wxVfprintf vfprintf
514 #define wxVprintf vprintf
515 #define wxVsscanf vsscanf
516 #define wxVsprintf vsprintf
517
518 // stdlib.h functions
519 #define wxAtof atof
520 #define wxAtoi atoi
521 #define wxAtol atol
522 #define wxGetenv getenv
523 #define wxSystem system
524
525 // time.h functions
526 #define wxAsctime asctime
527 #define wxCtime ctime
528 #define wxStrftime strftime
529 #endif // Unicode/ASCII
530 #endif // TCHAR-aware compilers/the others
531
532 // ----------------------------------------------------------------------------
533 // various special cases
534 // ----------------------------------------------------------------------------
535
536 // define wxStricmp and wxStrnicmp for various compilers
537 //
538 // note that in Unicode mode we definitely are going to need our own version
539 #if !defined(wxStricmp) && !wxUSE_UNICODE
540 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
541 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
542 defined(__EMX__) || defined(__DJGPP__)
543 #define wxStricmp stricmp
544 #define wxStrnicmp strnicmp
545 #elif defined(__SC__) || defined(__VISUALC__) || \
546 (defined(__MWERKS__) && defined(__INTEL__))
547 #define wxStricmp _stricmp
548 #define wxStrnicmp _strnicmp
549 #elif defined(__UNIX__) || defined(__GNUWIN32__)
550 #define wxStricmp strcasecmp
551 #define wxStrnicmp strncasecmp
552 // #else -- use wxWindows implementation
553 #endif
554 #endif // !defined(wxStricmp)
555
556 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
557 // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
558 // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
559 #if wxUSE_WCHAR_T
560 #ifdef HAVE_WCSLEN
561 #define wxWcslen wcslen
562 #else
563 inline size_t wxWcslen(const wchar_t *s)
564 {
565 size_t n = 0;
566 while ( *s++ )
567 n++;
568
569 return n;
570 }
571 #endif
572 #endif // wxUSE_WCHAR_T
573
574 // checks whether the passed in pointer is NULL and if the string is empty
575 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
576
577 // safe version of strlen() (returns 0 if passed NULL pointer)
578 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
579
580 // each of strdup() and wcsdup() may or may not be available but we need both
581 // of them anyhow for wx/buffer.h so we define the missing one(s) in
582 // wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
583 // defined -- if this is somehow not the case in some situations, please
584 // correct that and not the lines here
585 #if wxUSE_UNICODE
586 #define wxStrdup wxStrdupW
587 #else
588 #define wxStrdup wxStrdupA
589 #endif
590
591 WXDLLEXPORT bool wxOKlibc(); // for internal use
592
593 // ----------------------------------------------------------------------------
594 // printf() family saga
595 // ----------------------------------------------------------------------------
596
597 /*
598 For some systems vsnprintf() exists in the system libraries but not in the
599 headers, so we need to declare it ourselves to be able to use it.
600 */
601 #ifndef HAVE_VSNPRINTF_DECL
602 extern "C"
603 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
604 #endif // !HAVE_VSNPRINTF_DECL
605
606 /*
607 First of all, we always want to define safe snprintf() function to be used
608 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
609 which we really need...), otherwise we implement it using our own printf()
610 code.
611
612 We define function with a trailing underscore here because the real one is a
613 wrapper around it as explained below
614 */
615 #ifndef wxVsnprintf_
616 #if wxUSE_UNICODE
617 #if defined(HAVE__VSNWPRINTF)
618 #define wxVsnprintf_ _vsnwprintf
619 /* MinGW?MSVCRT has the wrong vswprintf */
620 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
621 #define wxVsnprintf_ vswprintf
622 #endif
623 #else // ASCII
624 // all versions of CodeWarrior supported by wxWindows apparently have
625 // vsnprintf()
626 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
627 // assume we have snprintf() too if we have vsnprintf()
628 #define wxVsnprintf_ vsnprintf
629 #define wxSnprintf_ snprintf
630 #endif
631 #endif
632 #endif // wxVsnprintf_ not defined yet
633
634 #ifndef wxSnprintf_
635 // no [v]snprintf(), cook our own
636 WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
637 ...) ATTRIBUTE_PRINTF_3;
638 #endif
639 #ifndef wxVsnprintf_
640 WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
641 va_list argptr);
642 #endif
643
644 /*
645 In Unicode mode we need to have all standard functions such as wprintf() and
646 so on but not all systems have them so use our own implementations in this
647 case.
648 */
649 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
650 #define wxNEED_WPRINTF
651 #endif
652
653 /*
654 More Unicode complications: although both ANSI C and C++ define a number of
655 wide character functions such as wprintf(), not all environments have them.
656 Worse, those which do have different behaviours: under Windows, %s format
657 specifier changes its meaning in Unicode build and expects a Unicode string
658 while under Unix/POSIX it still means an ASCII string even for wprintf() and
659 %ls has to be used for wide strings.
660
661 We choose to always emulate Windows behaviour as more useful for us so even
662 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
663
664 However, if we don't have any vswprintf() at all we don't need to redefine
665 anything as our own wxVsnprintf_() already behaves as needed.
666 */
667 #ifndef wxVsnprintf_
668 #undef wxNEED_PRINTF_CONVERSION
669 #endif
670
671 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
672 // we need to implement all wide character printf and scanf functions
673 // either because we don't have them at all or because they don't have the
674 // semantics we need
675
676 #include <stdio.h> // for FILE
677
678 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
679 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
680 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
681 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
682 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
683 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
684 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
685 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
686 int wxVprintf( const wxChar *format, va_list ap );
687 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
688 #endif // wxNEED_PRINTF_CONVERSION
689
690 // these 2 can be simply mapped to the versions with underscore at the end
691 // if we don't have to do the conversion
692 #ifdef wxNEED_PRINTF_CONVERSION
693 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
694 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
695 #else
696 #define wxSnprintf wxSnprintf_
697 #define wxVsnprintf wxVsnprintf_
698 #endif
699
700 // ----------------------------------------------------------------------------
701 // various functions which might not be available in libc and for which we
702 // provide our own replacements in wxchar.cpp
703 // ----------------------------------------------------------------------------
704
705 // ctype.h functions
706 //
707 // VZ: note that this is never defined currently
708 #ifdef wxNEED_WX_CTYPE_H
709 WXDLLEXPORT int wxIsalnum(wxChar ch);
710 WXDLLEXPORT int wxIsalpha(wxChar ch);
711 WXDLLEXPORT int wxIsctrl(wxChar ch);
712 WXDLLEXPORT int wxIsdigit(wxChar ch);
713 WXDLLEXPORT int wxIsgraph(wxChar ch);
714 WXDLLEXPORT int wxIslower(wxChar ch);
715 WXDLLEXPORT int wxIsprint(wxChar ch);
716 WXDLLEXPORT int wxIspunct(wxChar ch);
717 WXDLLEXPORT int wxIsspace(wxChar ch);
718 WXDLLEXPORT int wxIsupper(wxChar ch);
719 WXDLLEXPORT int wxIsxdigit(wxChar ch);
720 WXDLLEXPORT int wxTolower(wxChar ch);
721 WXDLLEXPORT int wxToupper(wxChar ch);
722 #endif // wxNEED_WX_CTYPE_H
723
724 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
725 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
726 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
727 #undef wxIsspace
728 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
729 #endif // VC++
730
731
732 // string.h functions
733 //
734 // VZ: this is never defined neither currently
735 #ifdef wxNEED_WX_STRING_H
736 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
737 WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
738 WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
739 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
740 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
741 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
742 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
743 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
744 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
745 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
746 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
747 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
748 WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
749 WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
750 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
751 WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
752 WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
753 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
754 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
755 WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
756 WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
757 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
758 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
759 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
760 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
761 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
762 #endif // wxNEED_WX_STRING_H
763
764 #ifndef wxStrdupA
765 WXDLLEXPORT char *wxStrdupA(const char *psz);
766 #endif
767
768 #ifndef wxStrdupW
769 WXDLLEXPORT wchar_t *wxStrdupW(const wchar_t *pwz);
770 #endif
771
772 #ifndef wxStricmp
773 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
774 #endif
775
776 #ifndef wxStrnicmp
777 WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
778 #endif
779
780 #ifndef wxStrtok
781 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
782 #endif
783
784 #ifndef wxSetlocale
785 class WXDLLEXPORT wxWCharBuffer;
786 WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
787 #endif
788
789 // stdio.h functions
790 #ifdef wxNEED_WX_STDIO_H
791 #include <stdio.h>
792 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
793 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
794 WXDLLEXPORT int wxRemove(const wxChar *path);
795 WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath);
796
797 // *printf() family is handled separately
798 #endif // wxNEED_WX_STDIO_H
799
800
801 // stdlib.h functions
802 #ifndef wxAtof
803 WXDLLEXPORT double wxAtof(const wxChar *psz);
804 #endif
805
806 #ifdef wxNEED_WX_STDLIB_H
807 WXDLLEXPORT int wxAtoi(const wxChar *psz);
808 WXDLLEXPORT long wxAtol(const wxChar *psz);
809 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
810 WXDLLEXPORT int wxSystem(const wxChar *psz);
811 #endif
812
813
814 // time.h functions
815 #ifdef wxNEED_WX_TIME_H
816 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
817 const wxChar *fmt, const struct tm *tm);
818 #endif // wxNEED_WX_TIME_H
819
820 // ----------------------------------------------------------------------------
821 // multibyte to wide char conversion functions and macros
822 // ----------------------------------------------------------------------------
823
824 #if wxUSE_WCHAR_T
825 // multibyte<->widechar conversion
826 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
827 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
828
829 #if wxUSE_UNICODE
830 #define wxMB2WX wxMB2WC
831 #define wxWX2MB wxWC2MB
832 #define wxWC2WX wxStrncpy
833 #define wxWX2WC wxStrncpy
834 #else
835 #define wxMB2WX wxStrncpy
836 #define wxWX2MB wxStrncpy
837 #define wxWC2WX wxWC2MB
838 #define wxWX2WC wxMB2WC
839 #endif
840 #else // !wxUSE_UNICODE
841 // No wxUSE_WCHAR_T: we have to do something (JACS)
842 #define wxMB2WC wxStrncpy
843 #define wxWC2MB wxStrncpy
844 #define wxMB2WX wxStrncpy
845 #define wxWX2MB wxStrncpy
846 #define wxWC2WX wxWC2MB
847 #define wxWX2WC wxMB2WC
848 #endif
849
850 #endif //_WX_WXCHAR_H_
851