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