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