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