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