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