]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
0b3a697e5034f38d43bf11a3e37b24cc6140c094
[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, Ron Lee
6 * Created: 1998/06/12
7 * RCS-ID: $Id$
8 * Copyright: (c) 1998-2002 wxWidgets dev team
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCHAR_H_
15 #define _WX_WXCHAR_H_
16
17 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "wxchar.h"
19 #endif
20
21 #include "wx/defs.h" /* for wxUSE_UNICODE */
22
23 /* check whether we have wchar_t and which size it is if we do */
24 #if !defined(wxUSE_WCHAR_T)
25 #if defined(__UNIX__)
26 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
27 #define wxUSE_WCHAR_T 1
28 #else
29 #define wxUSE_WCHAR_T 0
30 #endif
31 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
32 #define wxUSE_WCHAR_T 0
33 #elif defined(__WATCOMC__)
34 #define wxUSE_WCHAR_T 0
35 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
36 #define wxUSE_WCHAR_T 0
37 #else
38 /* add additional compiler checks if this fails */
39 #define wxUSE_WCHAR_T 1
40 #endif
41 #endif /* !defined(wxUSE_WCHAR_T) */
42
43 /* Unicode support requires wchar_t */
44 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
45 #error "wchar_t must be available in Unicode build"
46 #endif /* Unicode */
47
48 /*
49 Standard headers we need here.
50
51 NB: don't include any wxWidgets headers here because almost of them include
52 this one!
53 */
54
55 /* Required for wxPrintf() etc */
56 #include <stdarg.h>
57
58 /* Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac */
59 /* and VC++ for Windows CE don't provide it */
60 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
61 /* use #define, not inline wrapper, as it is tested with #ifndef below */
62 #define wxStrdupA strdup
63 #endif
64
65 /*
66 non Unix compilers which do have wchar.h (but not tchar.h which is included
67 below and which includes wchar.h anyhow).
68
69 Actually MinGW has tchar.h, but it does not include wchar.h
70 */
71 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
72 #ifndef HAVE_WCHAR_H
73 #define HAVE_WCHAR_H
74 #endif
75 #endif
76 #if defined(__MWERKS__) && !defined(__MACH__)
77 #ifndef HAVE_WCSLEN
78 #define HAVE_WCSLEN
79 #endif
80 #endif
81
82 #if wxUSE_WCHAR_T
83 #ifdef HAVE_WCHAR_H
84 /* the current (as of Nov 2002) version of cygwin has a bug in its */
85 /* wchar.h -- there is no extern "C" around the declarations in it and */
86 /* this results in linking errors later; also, at least on some */
87 /* Cygwin versions, wchar.h requires sys/types.h */
88 #ifdef __CYGWIN__
89 #include <sys/types.h>
90 extern "C" {
91 #endif /* Cygwin */
92 #include <wchar.h>
93 #ifdef __CYGWIN__
94 }
95 #endif /* Cygwin */
96 #elif defined(HAVE_WCSTR_H)
97 /* old compilers have relevant declarations here */
98 #include <wcstr.h>
99 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
100 /* include stdlib.h for wchar_t */
101 #include <stdlib.h>
102 #endif /* HAVE_WCHAR_H */
103 #endif /* wxUSE_WCHAR_T */
104
105 /* ---------------------------------------------------------------------------- */
106 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
107 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and have */
108 /* the function mapping _tfoo() -> foo() or wfoo() */
109 /* ---------------------------------------------------------------------------- */
110
111 /* VC++ and BC++ starting with 5.2 have TCHAR support */
112 #ifdef __VISUALC__
113 #define wxHAVE_TCHAR_SUPPORT
114 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
115 #define wxHAVE_TCHAR_SUPPORT
116 #include <ctype.h>
117 #elif defined(__WATCOMC__)
118 #define wxHAVE_TCHAR_SUPPORT
119 #elif defined(__DMC__)
120 #define wxHAVE_TCHAR_SUPPORT
121 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
122 #define wxHAVE_TCHAR_SUPPORT
123 #include <stddef.h>
124 #include <string.h>
125 #include <ctype.h>
126 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
127 /* VZ: the old VisualAge definitions were completely wrong and had no */
128 /* chance at all to work in Unicode build anyhow so let's pretend that */
129 /* VisualAge does _not_ support TCHAR for the moment (as indicated by */
130 /* "0 &&" above) until someone really has time to delve into Unicode */
131 /* issues under OS/2 */
132
133 /* VisualAge 4.0+ supports TCHAR */
134 #define wxHAVE_TCHAR_SUPPORT
135 #endif /* compilers with (good) TCHAR support */
136
137 #ifdef __MWERKS__
138 #define HAVE_WPRINTF
139 #endif
140
141 #ifdef wxHAVE_TCHAR_SUPPORT
142 /* get TCHAR definition if we've got it */
143 #include <tchar.h>
144
145 /* we surely do have wchar_t if we have TCHAR */
146 #ifndef wxUSE_WCHAR_T
147 #define wxUSE_WCHAR_T 1
148 #endif /* !defined(wxUSE_WCHAR_T) */
149
150 /* and we also do have wcslen() */
151 #ifndef HAVE_WCSLEN
152 #define HAVE_WCSLEN
153 #endif
154 #endif /* wxHAVE_TCHAR_SUPPORT */
155
156 /* ---------------------------------------------------------------------------- */
157 /* define wxChar type */
158 /* ---------------------------------------------------------------------------- */
159
160 /* TODO: define wxCharInt to be equal to either int or wint_t? */
161
162 #if !wxUSE_UNICODE
163 typedef char wxChar;
164 typedef signed char wxSChar;
165 typedef unsigned char wxUChar;
166 #else /* Unicode */
167 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
168 /* signed/unsigned version of it which (a) makes sense to me (unlike */
169 /* char wchar_t is always unsigned) and (b) was how the previous */
170 /* definitions worked so keep it like this */
171
172 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
173 /* comment below */
174 #if !defined(__WCHAR_TYPE__) || \
175 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
176 /* standard case */
177 typedef wchar_t wxChar;
178 typedef wchar_t wxSChar;
179 typedef wchar_t wxUChar;
180 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
181 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. However, */
182 /* this doesn't work with new GCC 3.x compilers because wchar_t is */
183 /* C++'s builtin type in the new standard. OTOH, old compilers (GCC */
184 /* 2.x) won't accept new definition of wx{S,U}Char, therefore we */
185 /* have to define wxChar conditionally depending on detected */
186 /* compiler & compiler version. */
187 /* with old definition of wxChar. */
188 typedef __WCHAR_TYPE__ wxChar;
189 typedef __WCHAR_TYPE__ wxSChar;
190 typedef __WCHAR_TYPE__ wxUChar;
191 #endif /* __WCHAR_TYPE__ */
192 #endif /* ASCII/Unicode */
193
194 /* ---------------------------------------------------------------------------- */
195 /* define _T() and related macros */
196 /* ---------------------------------------------------------------------------- */
197
198 /* BSD systems define _T() to be something different in ctype.h, override it */
199 #if defined(__FreeBSD__) || defined(__DARWIN__)
200 #include <ctype.h>
201 #undef _T
202 #endif
203
204 /* could already be defined by tchar.h (it's quasi standard) */
205 #ifndef _T
206 #if !wxUSE_UNICODE
207 #define _T(x) x
208 #else /* Unicode */
209 #define _T(x) L ## x
210 #endif /* ASCII/Unicode */
211 #endif /* !defined(_T) */
212
213 /* although global macros with such names are normally bad, we want to have */
214 /* another name for _T() which should be used to avoid confusion between _T() */
215 /* and _() in wxWidgets sources */
216 #define wxT(x) _T(x)
217
218 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
219 #ifndef __TFILE__
220 #define __XFILE__(x) wxT(x)
221 #define __TFILE__ __XFILE__(__FILE__)
222 #endif
223
224 #ifndef __TDATE__
225 #define __XDATE__(x) wxT(x)
226 #define __TDATE__ __XDATE__(__DATE__)
227 #endif
228
229 #ifndef __TTIME__
230 #define __XTIME__(x) wxT(x)
231 #define __TTIME__ __XTIME__(__TIME__)
232 #endif
233
234 /*
235 define wxFoo() function for each standard foo() function whose signature
236 (exceptionally including the return type) includes any mention of char:
237 wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
238 the same signature but with char replaced by wxChar which allows us to use
239 it in Unicode build as well
240 */
241
242 #ifdef wxHAVE_TCHAR_SUPPORT
243 #include <ctype.h>
244
245 /* ctype.h functions */
246 #define wxIsalnum _istalnum
247 #define wxIsalpha _istalpha
248 #define wxIscntrl _istcntrl
249 #define wxIsdigit _istdigit
250 #define wxIsgraph _istgraph
251 #define wxIslower _istlower
252 #define wxIsprint _istprint
253 #define wxIspunct _istpunct
254 #define wxIsspace _istspace
255 #define wxIsupper _istupper
256 #define wxIsxdigit _istxdigit
257
258 /*
259 There is a bug in VC6 C RTL: toxxx() functions dosn't do anything with
260 signed chars < 0, so "fix" it here.
261 */
262 #define wxTolower(c) _totlower((wxUChar)(c))
263 #define wxToupper(c) _totupper((wxUChar)(c))
264
265 /* locale.h functons */
266 #define wxSetlocale _tsetlocale
267
268 /* string.h functions */
269 #define wxStrcat _tcscat
270 #define wxStrchr _tcschr
271 #define wxStrcmp _tcscmp
272 #define wxStrcoll _tcscoll
273 #define wxStrcpy _tcscpy
274 #define wxStrcspn _tcscspn
275 #define wxStrdupW _wcsdup /* notice the 'W'! */
276 #define wxStrftime _tcsftime
277 #define wxStricmp _tcsicmp
278 #define wxStrnicmp _tcsnicmp
279 #define wxStrlen_ _tcslen /* used in wxStrlen inline function */
280 #define wxStrncat _tcsncat
281 #define wxStrncmp _tcsncmp
282 #define wxStrncpy _tcsncpy
283 #define wxStrpbrk _tcspbrk
284 #define wxStrrchr _tcsrchr
285 #define wxStrspn _tcsspn
286 #define wxStrstr _tcsstr
287 #define wxStrtod _tcstod
288 #define wxStrtol _tcstol
289 #define wxStrtoul _tcstoul
290 #define wxStrxfrm _tcsxfrm
291
292 /* stdio.h functions */
293 #define wxFgetc _fgettc
294 #define wxFgetchar _fgettchar
295 #define wxFgets _fgetts
296 #define wxFopen _tfopen
297 #define wxFputc _fputtc
298 #define wxFputchar _fputtchar
299 #define wxFprintf _ftprintf
300 #define wxFputs _fputts
301 #define wxFreopen _tfreopen
302 #define wxFscanf _ftscanf
303 #define wxGetc _gettc
304 #define wxGetchar _gettchar
305 #define wxGets _getts
306 #define wxPerror _tperror
307 #define wxPrintf _tprintf
308 #define wxPutc _puttc
309 #define wxPutchar _puttchar
310 #define wxPuts _putts
311 #define wxScanf _tscanf
312 #if defined(__DMC__)
313 #if wxUSE_UNICODE
314 /* Digital Mars adds count to _stprintf (C99) so prototype conversion see wxchar.cpp */
315 int wxSprintf (wchar_t * __RESTRICT s, const wchar_t * __RESTRICT format, ... ) ;
316 #else
317 /* and there is a bug in D Mars tchar.h prior to 8.39.4n, so define as sprintf */
318 #define wxSprintf sprintf
319 #endif
320 #else
321 #define wxSprintf _stprintf
322 #endif
323
324 #define wxSscanf _stscanf
325 #define wxTmpnam _ttmpnam
326 #define wxUngetc _tungetc
327 #define wxVfprintf _vftprintf
328 #define wxVprintf _vtprintf
329 #define wxVsscanf _vstscanf
330 #define wxVsprintf _vstprintf
331
332 /* special case: not all TCHAR-aware compilers have those */
333 #if defined(__VISUALC__) || \
334 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
335 #define wxVsnprintf_ _vsntprintf
336 #define wxSnprintf_ _sntprintf
337 #endif
338
339 /* special case: these functions are missing under Win9x with Unicows so we */
340 /* have to implement them ourselves */
341 #if wxUSE_UNICODE_MSLU
342 #define wxRemove wxMSLU__tremove
343 #define wxRename wxMSLU__trename
344 #else
345 #ifdef __WXWINCE__
346 #define wxRemove DeleteFile
347 #else
348 #define wxRemove _tremove
349 #define wxRename _trename
350 #endif
351 #endif
352
353 /* stdlib.h functions */
354 #define wxAtoi _ttoi
355 #define wxAtol _ttol
356 /* #define wxAtof _tttof -- notice that there is no such thing (why?) */
357 #define wxGetenv _tgetenv
358 #define wxSystem _tsystem
359
360 /* time.h functions */
361 #define wxAsctime _tasctime
362 #define wxCtime _tctime
363 #else /* !TCHAR-aware compilers */
364
365 #if !defined(__MWERKS__) && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
366 /* even though they are defined and "implemented", they are bad and just
367 stubs so we need our own - we need these even in ANSI builds!! */
368 #define mbstowcs wxInternalMbstowcs
369 #define wcstombs wxInternalWcstombs
370
371 WXDLLIMPEXP_BASE size_t wxInternalMbstowcs (wchar_t *, const char *, size_t);
372 WXDLLIMPEXP_BASE size_t wxInternalWcstombs (char *, const wchar_t *, size_t);
373 #endif
374
375 /* No UNICODE in the c library except wchar_t typedef on mac OSX 10.2 and less - roll our own */
376 #if !defined(__MWERKS__) && wxUSE_UNICODE && defined(__DARWIN__) && ( MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2 )
377
378 /* we need everything! */
379 #define wxNEED_WX_STRING_H
380 #define wxNEED_WX_CTYPE_H
381
382 #define wxFgetchar(c) wxFgetc(c, stdin)
383 #define wxFputc wxPutc
384 #define wxFputchar(c) wxPutc(c, stdout)
385 #define wxGetc wxFgetc
386 #define wxGetchar(c) wxFgetc(c, stdin)
387
388 #include <stdio.h>
389
390 #define wxNEED_FGETC
391 #define wxNEED_FGETS
392 #define wxNEED_GETS
393 #define wxNEED_UNGETC
394
395 #define wxNEED_FPUTS
396 #define wxNEED_PUTC
397
398 int wxFputs(const wxChar *ch, FILE *stream);
399 int wxPutc(wxChar ch, FILE *stream);
400
401 WXDLLIMPEXP_BASE size_t wxStrlen_(const wxChar *s);
402
403 #define wxPutchar(wch) wxPutc(wch, stdout)
404 #define wxPuts(ws) wxFputs(ws, stdout)
405
406 #define wxNEED_PRINTF_CONVERSION
407 #define wxNEED_WX_STDIO_H
408 #define wxNEED_WX_STDLIB_H
409 #define wxNEED_WX_TIME_H
410
411 #elif wxUSE_UNICODE
412 #include <wctype.h>
413
414 /* this is probably glibc-specific */
415 #if defined(__WCHAR_TYPE__) && !defined(__MWERKS__)
416 /* ctype.h functions (wctype.h) */
417 #define wxIsalnum iswalnum
418 #define wxIsalpha iswalpha
419 #define wxIscntrl iswcntrl
420 #define wxIsdigit iswdigit
421 #define wxIsgraph iswgraph
422 #define wxIslower iswlower
423 #define wxIsprint iswprint
424 #define wxIspunct iswpunct
425 #define wxIsspace iswspace
426 #define wxIsupper iswupper
427 #define wxIsxdigit iswxdigit
428
429 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
430 /* /usr/include/wctype.h incorrectly declares translations */
431 /* tables which provokes tons of compile-time warnings -- try */
432 /* to correct this */
433 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
434 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
435 #else /* !glibc 2.0 */
436 #define wxTolower towlower
437 #define wxToupper towupper
438 #endif /* gcc/!gcc */
439
440 /* string.h functions (wchar.h) */
441 #define wxStrcat wcscat
442 #define wxStrchr wcschr
443 #define wxStrcmp wcscmp
444 #define wxStrcoll wcscoll
445 #define wxStrcpy wcscpy
446 #define wxStrcspn wcscspn
447 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
448 #define wxStrncat wcsncat
449 #define wxStrncmp wcsncmp
450 #define wxStrncpy wcsncpy
451 #define wxStrpbrk wcspbrk
452 #define wxStrrchr wcsrchr
453 #define wxStrspn wcsspn
454 #define wxStrstr wcsstr
455 #define wxStrtod wcstod
456 #define wxStrtol wcstol
457 #define wxStrtoul wcstoul
458 #define wxStrxfrm wcsxfrm
459
460 #define wxFgetc fgetwc
461 #define wxFgetchar fgetwchar
462 #define wxFgets fgetws
463 #define wxFputc fputwc
464 #define wxFputchar fputwchar
465 #define wxGetc getwc
466 #define wxGetchar getwchar
467 #define wxGets getws
468 #define wxUngetc ungetwc
469
470 #ifdef HAVE_FPUTWS
471 #define wxFputs fputws
472 #else
473 #define wxNEED_FPUTS
474 #include <stdio.h>
475 int wxFputs(const wxChar *ch, FILE *stream);
476 #endif
477
478 #ifdef HAVE_WPUTC
479 #define wxPutc wputc
480 #else
481 #define wxNEED_PUTC
482 #include <stdio.h>
483 int wxPutc(wxChar ch, FILE *stream);
484 #endif
485
486 #ifdef HAVE_WPUTCHAR
487 #define wxPutchar wputchar
488 #else
489 #define wxPutchar(wch) wxPutc(wch, stdout)
490 #endif
491
492 #ifdef HAVE_PUTWS
493 #define wxPuts putws
494 #else
495 #define wxPuts(ws) wxFputs(ws, stdout)
496 #endif
497
498 /* we need %s to %ls conversion for printf and scanf etc */
499 #define wxNEED_PRINTF_CONVERSION
500
501 /* glibc doesn't have wide char equivalents of the other stuff so */
502 /* use our own versions */
503 #define wxNEED_WX_STDIO_H
504 #define wxNEED_WX_STDLIB_H
505 #define wxNEED_WX_TIME_H
506 #elif defined(__MWERKS__) && ( defined(__MSL__) || defined(__MACH__) )
507 /* ctype.h functions (wctype.h) */
508 #define wxIsalnum iswalnum
509 #define wxIsalpha iswalpha
510 #define wxIscntrl iswcntrl
511 #define wxIsdigit iswdigit
512 #define wxIsgraph iswgraph
513 #define wxIslower iswlower
514 #define wxIsprint iswprint
515 #define wxIspunct iswpunct
516 #define wxIsspace iswspace
517 #define wxIsupper iswupper
518 #define wxIsxdigit iswxdigit
519 #define wxTolower towlower
520 #define wxToupper towupper
521
522 /* string.h functions (wchar.h) */
523 #define wxStrcat wcscat
524 #define wxStrchr wcschr
525 #define wxStrcmp wcscmp
526 #define wxStrcoll wcscoll
527 #define wxStrcpy wcscpy
528 #define wxStrcspn wcscspn
529 #define wxStrlen_ wxWcslen /* wxStrlen_() is used in wxStrlen() */
530 #define wxStrncat wcsncat
531 #define wxStrncmp wcsncmp
532 #define wxStrncpy wcsncpy
533 #define wxStrpbrk wcspbrk
534 #define wxStrrchr wcsrchr
535 #define wxStrspn wcsspn
536 #define wxStrstr wcsstr
537 #define wxStrtod wcstod
538 #define wxStrtol wcstol
539 #define wxStrtoul wcstoul
540 #define wxStrxfrm wcsxfrm
541
542 #define wxFgetc fgetwc
543 #define wxFgetchar fgetwchar
544 #define wxFgets fgetws
545 #define wxFputc fputwc
546 #define wxFputchar fputwchar
547 #define wxGetc getwc
548 #define wxGetchar getwchar
549 #define wxGets getws
550 #define wxUngetc ungetwc
551
552 #define wxNEED_PRINTF_CONVERSION
553
554 #define wxPutc putwc
555 #define wxPutchar putwchar
556 #define wxFputs fputws
557
558 /* stdio.h functions */
559
560 #define wxNEED_WX_STDIO_H
561
562 /* stdlib.h functions */
563 #ifdef __MACH__
564 #define wxNEED_WX_STDLIB_H
565 #else
566 #define wxAtof watof
567 #define wxAtoi watoi
568 #define wxAtol watol
569 #define wxGetenv(a) ((wxChar*)NULL)
570 #define wxSystem(a) ((int)NULL)
571 #endif
572 /* time.h functions */
573 #define wxAsctime wasciitime
574 #define wxCtime wctime
575 /* #define wxStrftime wcsftime */
576
577 #define wxNEED_WX_TIME_H
578 #else /* !metrowerks for apple */
579 #error "Please define wide character functions for your environment"
580 #endif
581 #else /* ASCII */
582 #include <ctype.h>
583 #include <string.h>
584
585 /* ctype.h functions */
586 #define wxIsalnum isalnum
587 #define wxIsalpha isalpha
588 #define wxIscntrl iscntrl
589 #define wxIsdigit isdigit
590 #define wxIsgraph isgraph
591 #define wxIslower islower
592 #define wxIsprint isprint
593 #define wxIspunct ispunct
594 #define wxIsspace isspace
595 #define wxIsupper isupper
596 #define wxIsxdigit isxdigit
597 #define wxTolower tolower
598 #define wxToupper toupper
599
600 /* locale.h functons */
601 #define wxSetlocale setlocale
602
603 /* string.h functions */
604 #define wxStrcat strcat
605 #define wxStrchr strchr
606 #define wxStrcmp strcmp
607 #define wxStrcoll strcoll
608 #define wxStrcpy strcpy
609 #define wxStrcspn strcspn
610
611 /* wxStricmp and wxStrnicmp are defined below */
612 #define wxStrlen_ strlen /* used in wxStrlen inline function */
613 #define wxStrncat strncat
614 #define wxStrncmp strncmp
615 #define wxStrncpy strncpy
616 #define wxStrpbrk strpbrk
617 #define wxStrrchr strrchr
618 #define wxStrspn strspn
619 #define wxStrstr strstr
620 #define wxStrtod strtod
621 #ifdef HAVE_STRTOK_R
622 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
623 #endif
624 #define wxStrtol strtol
625 #define wxStrtoul strtoul
626 #define wxStrxfrm strxfrm
627
628 /* stdio.h functions */
629 #define wxFopen fopen
630 #define wxFreopen freopen
631 #define wxRemove remove
632 #define wxRename rename
633
634 #define wxPerror perror
635 #define wxTmpnam tmpnam
636
637 #define wxFgetc fgetc
638 #define wxFgetchar fgetchar
639 #define wxFgets fgets
640 #define wxFputc fputc
641 #define wxFputs fputs
642 #define wxFputchar fputchar
643 #define wxFprintf fprintf
644 #define wxFscanf fscanf
645 #define wxGetc getc
646 #define wxGetchar getchar
647 #define wxGets gets
648 #define wxPrintf printf
649 #define wxPutc putc
650 #define wxPutchar putchar
651 #define wxPuts puts
652 #define wxScanf scanf
653 #define wxSprintf sprintf
654 #define wxSscanf sscanf
655 #define wxUngetc ungetc
656 #define wxVfprintf vfprintf
657 #define wxVprintf vprintf
658 #define wxVsscanf vsscanf
659 #define wxVsprintf vsprintf
660
661 /* stdlib.h functions */
662 #define wxAtof atof
663 #define wxAtoi atoi
664 #define wxAtol atol
665 #define wxGetenv getenv
666 #define wxSystem system
667
668 /* time.h functions */
669 #define wxAsctime asctime
670 #define wxCtime ctime
671 #define wxStrftime strftime
672 #endif /* Unicode/ASCII */
673 #endif /* TCHAR-aware compilers/the others */
674
675 /*
676 various special cases
677 */
678
679 /* define wxStricmp and wxStrnicmp for various compilers */
680
681 /* note that in Unicode mode we definitely are going to need our own version */
682 #if !defined(wxStricmp) && !wxUSE_UNICODE
683 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
684 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
685 defined(__EMX__) || defined(__DJGPP__)
686 #define wxStricmp stricmp
687 #define wxStrnicmp strnicmp
688 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
689 (defined(__MWERKS__) && defined(__INTEL__))
690 #define wxStricmp _stricmp
691 #define wxStrnicmp _strnicmp
692 #elif defined(__UNIX__) || defined(__GNUWIN32__)
693 #define wxStricmp strcasecmp
694 #define wxStrnicmp strncasecmp
695 /* #else -- use wxWidgets implementation */
696 #endif
697 #endif /* !defined(wxStricmp) */
698
699 /* define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as */
700 /* it's used in wx/buffer.h -- and also might be used just below by wxStrlen() */
701 /* when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen) */
702 #if wxUSE_WCHAR_T
703 #ifdef HAVE_WCSLEN
704 #define wxWcslen wcslen
705 #else
706 #if defined( __WXMAC_XCODE__ ) && !defined( __cplusplus )
707 /* xcode native targets are giving multiply defined symbols on regex */
708 static
709 #endif
710 inline size_t wxWcslen(const wchar_t *s)
711 {
712 size_t n = 0;
713 while ( *s++ )
714 n++;
715
716 return n;
717 }
718 #endif
719 #endif /* wxUSE_WCHAR_T */
720
721 #ifdef __cplusplus
722 /* checks whether the passed in pointer is NULL and if the string is empty */
723 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
724
725 /* safe version of strlen() (returns 0 if passed NULL pointer) */
726 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
727 #endif
728
729 /*
730 each of strdup() and wcsdup() may or may not be available but we need both
731 of them anyhow for wx/buffer.h so we define the missing one(s) in
732 wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
733 defined -- if this is somehow not the case in some situations, please
734 correct that and not the lines here
735 */
736 #if wxUSE_UNICODE
737 #define wxStrdup wxStrdupW
738 #else
739 #define wxStrdup wxStrdupA
740 #endif
741
742 #ifdef __cplusplus
743 WXDLLIMPEXP_BASE bool wxOKlibc(); /* for internal use */
744 #endif
745
746 /* printf() family saga */
747
748 /*
749 For some systems vsnprintf() exists in the system libraries but not in the
750 headers, so we need to declare it ourselves to be able to use it.
751 */
752 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
753 extern "C"
754 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
755 #endif /* !HAVE_VSNPRINTF_DECL */
756
757 /*
758 First of all, we always want to define safe snprintf() function to be used
759 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
760 which we really need...), otherwise we implement it using our own printf()
761 code.
762
763 We define function with a trailing underscore here because the real one is a
764 wrapper around it as explained below
765 */
766 #ifndef wxVsnprintf_
767 #if wxUSE_UNICODE
768 #if defined(__MWERKS__)
769 #define HAVE_WCSRTOMBS 1
770 #define HAVE_VSWPRINTF 1
771 #endif
772 #if defined(__WATCOMC__)
773 #define wxVsnprintf_ _vsnwprintf
774 #define wxSnprintf_ _snwprintf
775 #endif
776 #if defined(HAVE__VSNWPRINTF)
777 #define wxVsnprintf_ _vsnwprintf
778 /* MinGW?MSVCRT has the wrong vswprintf */
779 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
780 #define wxVsnprintf_ vswprintf
781 #endif
782 #else /* ASCII */
783 /* all versions of CodeWarrior supported by wxWidgets apparently have */
784 /* vsnprintf() */
785 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__) || defined(__WATCOMC__)
786 /* assume we have snprintf() too if we have vsnprintf() */
787 #define wxVsnprintf_ vsnprintf
788 #define wxSnprintf_ snprintf
789 #endif
790 #endif
791 #endif /* wxVsnprintf_ not defined yet */
792
793 #ifndef wxSnprintf_
794 /* no [v]snprintf(), cook our own */
795 WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
796 ...) ATTRIBUTE_PRINTF_3;
797 #endif
798 #ifndef wxVsnprintf_
799 WXDLLIMPEXP_BASE int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
800 va_list argptr);
801 #endif
802
803 /*
804 In Unicode mode we need to have all standard functions such as wprintf() and
805 so on but not all systems have them so use our own implementations in this
806 case.
807 */
808 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
809 #define wxNEED_WPRINTF
810 #endif
811
812 /*
813 More Unicode complications: although both ANSI C and C++ define a number of
814 wide character functions such as wprintf(), not all environments have them.
815 Worse, those which do have different behaviours: under Windows, %s format
816 specifier changes its meaning in Unicode build and expects a Unicode string
817 while under Unix/POSIX it still means an ASCII string even for wprintf() and
818 %ls has to be used for wide strings.
819
820 We choose to always emulate Windows behaviour as more useful for us so even
821 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
822
823 */
824
825 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
826 /*
827 we need to implement all wide character printf and scanf functions
828 either because we don't have them at all or because they don't have the
829 semantics we need
830 */
831
832 #include <stdio.h> /* for FILE */
833
834 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
835 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
836 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
837 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
838 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
839 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
840 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
841 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
842 int wxVprintf( const wxChar *format, va_list ap );
843 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
844 #endif /* wxNEED_PRINTF_CONVERSION */
845
846 /* these 2 can be simply mapped to the versions with underscore at the end */
847 /* if we don't have to do the conversion */
848 /*
849 However, if we don't have any vswprintf() at all we don't need to redefine
850 anything as our own wxVsnprintf_() already behaves as needed.
851 */
852 #if defined(wxNEED_PRINTF_CONVERSION) && defined(wxVsnprintf_)
853 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
854 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
855 #else
856 #define wxSnprintf wxSnprintf_
857 #define wxVsnprintf wxVsnprintf_
858 #endif
859
860 /*
861 various functions which might not be available in libc and for which we
862 provide our own replacements in wxchar.cpp
863 */
864
865 /* ctype.h functions */
866
867 /* RN: Used only under OSX <= 10.2 currently */
868 #ifdef wxNEED_WX_CTYPE_H
869 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
870 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
871 WXDLLIMPEXP_BASE int wxIscntrl(wxChar ch);
872 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
873 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
874 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
875 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
876 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
877 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
878 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
879 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
880 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
881 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
882 #endif /* wxNEED_WX_CTYPE_H */
883
884 /* under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks */
885 /* the file parsing -- this may be true for 5.0 as well, update #ifdef then */
886 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
887 #undef wxIsspace
888 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
889 #endif /* VC++ */
890
891 /*
892 a few compilers don't have the (non standard but common) isascii function,
893 define it ourselves for them
894 */
895 #ifndef isascii
896 #if defined(__MWERKS__)
897 #define wxNEED_ISASCII
898 #elif defined(_WIN32_WCE)
899 #if _WIN32_WCE <= 211
900 #define wxNEED_ISASCII
901 #endif
902 #endif
903 #endif /* isascii */
904
905 #ifdef wxNEED_ISASCII
906 inline int isascii(int c) { return (unsigned)c < 0x80; }
907 #endif
908
909 #ifdef _WIN32_WCE
910 #if _WIN32_WCE <= 211
911 #define isspace(c) ((c) == _T(' ') || (c) == _T('\t'))
912 #endif
913 #endif /* _WIN32_WCE */
914
915 /*
916 we had goofed and defined wxIsctrl() instead of (correct) wxIscntrl() in the
917 initial versions of this header -- now it is too late to remove it so
918 although we fixed the function/macro name above, still provide the
919 backwards-compatible synonym.
920 */
921 #define wxIsctrl wxIscntrl
922
923 /* string.h functions */
924 #ifndef strdup
925 #if defined(__MWERKS__) && !defined(__MACH__) && (__MSL__ < 0x00008000)
926 #define wxNEED_STRDUP
927 #elif defined(__WXWINCE__)
928 #if _WIN32_WCE <= 211
929 #define wxNEED_STRDUP
930 #endif
931 #endif
932 #endif /* strdup */
933
934 #ifdef wxNEED_STRDUP
935 WXDLLIMPEXP_BASE char *strdup(const char* s);
936 #endif
937
938 /* RN: Used only under OSX <= 10.2 currently */
939 #ifdef wxNEED_WX_STRING_H
940 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
941 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
942 inline wxChar * wxStrchr(wxChar *s, wxChar c)
943 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
944 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
945 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
946 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
947 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
948 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
949 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
950 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
951 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
952 inline wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
953 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
954 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
955 inline wxChar * wxStrrchr(wxChar *s, wxChar c)
956 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
957 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
958 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
959 inline wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
960 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
961 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
962 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
963 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
964 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
965 #endif /* wxNEED_WX_STRING_H */
966
967 #ifndef wxStrdupA
968 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
969 #endif
970
971 #ifndef wxStrdupW
972 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
973 #endif
974
975 #ifndef wxStricmp
976 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
977 #endif
978
979 #ifndef wxStrnicmp
980 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
981 #endif
982
983 #ifndef wxStrtok
984 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
985 #endif
986
987 #ifdef __cplusplus
988 #ifndef wxSetlocale
989 class WXDLLIMPEXP_BASE wxWCharBuffer;
990 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
991 #endif
992 #endif
993
994 /* stdio.h functions */
995 #ifdef wxNEED_WX_STDIO_H
996 #include <stdio.h>
997 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
998 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
999 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
1000 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
1001
1002 /* *printf() family is handled separately */
1003 #endif /* wxNEED_WX_STDIO_H */
1004
1005
1006 /* stdlib.h functions */
1007 #ifndef wxAtof
1008 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
1009 #endif
1010
1011 #ifdef wxNEED_WX_STDLIB_H
1012 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
1013 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
1014 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
1015 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
1016 #endif
1017
1018
1019 /* time.h functions */
1020 #ifdef wxNEED_WX_TIME_H
1021 #if defined(__MWERKS__) && defined(macintosh)
1022 #include <time.h>
1023 #endif
1024 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
1025 const wxChar *fmt, const struct tm *tm);
1026 #endif /* wxNEED_WX_TIME_H */
1027
1028 #ifndef wxCtime
1029 #include <time.h>
1030 WXDLLIMPEXP_BASE wxChar *wxCtime(const time_t *timep);
1031 #endif
1032
1033
1034 /* missing functions in some WinCE versions */
1035 #ifdef _WIN32_WCE
1036 #if (_WIN32_WCE < 300)
1037 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
1038 #endif
1039 #endif /* _WIN32_WCE */
1040
1041 /* multibyte to wide char conversion functions and macros */
1042
1043 #if wxUSE_WCHAR_T
1044 /* multibyte<->widechar conversion */
1045 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
1046 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
1047
1048 #if wxUSE_UNICODE
1049 #define wxMB2WX wxMB2WC
1050 #define wxWX2MB wxWC2MB
1051 #define wxWC2WX wxStrncpy
1052 #define wxWX2WC wxStrncpy
1053 #else
1054 #define wxMB2WX wxStrncpy
1055 #define wxWX2MB wxStrncpy
1056 #define wxWC2WX wxWC2MB
1057 #define wxWX2WC wxMB2WC
1058 #endif
1059 #else /* !wxUSE_UNICODE */
1060 #error ha
1061 /* No wxUSE_WCHAR_T: we have to do something (JACS) */
1062 #define wxMB2WC wxStrncpy
1063 #define wxWC2MB wxStrncpy
1064 #define wxMB2WX wxStrncpy
1065 #define wxWX2MB wxStrncpy
1066 #define wxWC2WX wxWC2MB
1067 #define wxWX2WC wxMB2WC
1068 #endif
1069
1070 //
1071 // RN: The following are not normal versions of memcpy et al., rather
1072 // these are either char or widechar versions depending on
1073 // if unicode is used or not.
1074 //
1075
1076 #ifdef __cplusplus
1077
1078 //
1079 // RN: We could do the usual tricky compiler detection here,
1080 // and use their variant (such as wmemchr, etc.). The problem
1081 // is that these functions are quite rare, even though they are
1082 // part of the current POSIX standard. In addition, most compilers
1083 // (including even MSC) inline them just like we do right in their
1084 // headers.
1085 //
1086 #if wxUSE_UNICODE
1087 #include <string.h> //for mem funcs
1088
1089 //implement our own wmem variants
1090 inline wxChar* wxMemchr(const wxChar* s, wxChar c, size_t l)
1091 {
1092 for(;l && *s != c;--l, ++s) {}
1093
1094 if(l)
1095 return (wxChar*)s;
1096 return NULL;
1097 }
1098
1099 inline int wxMemcmp(const wxChar* sz1, const wxChar* sz2, size_t len)
1100 {
1101 for(; *sz1 == *sz2 && len; --len, ++sz1, ++sz2) {}
1102
1103 if(len)
1104 return *sz1 < *sz2 ? -1 : *sz1 > *sz2;
1105 else
1106 return 0;
1107 }
1108
1109 inline wxChar* wxMemcpy(wxChar* szOut, const wxChar* szIn, size_t len)
1110 {
1111 return (wxChar*) memcpy(szOut, szIn, len * sizeof(wxChar));
1112 }
1113
1114 inline wxChar* wxMemmove(wxChar* szOut, const wxChar* szIn, size_t len)
1115 {
1116 return (wxChar*) memmove(szOut, szIn, len * sizeof(wxChar));
1117 }
1118
1119 inline wxChar* wxMemset(wxChar* szOut, const wxChar cIn, size_t len)
1120 {
1121 wxChar* szRet = szOut;
1122
1123 while (len--)
1124 *szOut++ = cIn;
1125
1126 return szRet;
1127 }
1128
1129 #else //!wxUSE_UNICODE
1130 # define wxMemchr memchr
1131 # define wxMemcmp memcmp
1132 # define wxMemcpy memcpy
1133 # define wxMemmove memmove
1134 # define wxMemset memset
1135 #endif
1136
1137 #endif /*__cplusplus*/
1138
1139
1140 #endif /* _WX_WXCHAR_H_ */
1141