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