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