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