]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
BSD systems define _T to something different in ctype.h, therefore include
[wxWidgets.git] / include / wx / wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wxchar.h
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 // Author: Joel Farley, Ove Kåven
5 // Modified by: Vadim Zeitlin, Robert Roebling
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998-2002 wxWindows dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXCHAR_H_
13 #define _WX_WXCHAR_H_
14
15 #ifdef __GNUG__
16 #pragma interface "wxchar.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // first deal with Unicode setting: wxUSE_UNICODE should be defined as 0 or 1
21 // and is used by wxWindows, _UNICODE and/or UNICODE may be defined or used by
22 // the system headers so bring these settings in sync
23 // ----------------------------------------------------------------------------
24
25 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
26 #if defined(_UNICODE) || defined(UNICODE)
27 #undef wxUSE_UNICODE
28 #define wxUSE_UNICODE 1
29 #else
30 #ifndef wxUSE_UNICODE
31 #define wxUSE_UNICODE 0
32 #endif
33 #endif // Unicode
34
35 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
36 #if wxUSE_UNICODE
37 #ifndef _UNICODE
38 #define _UNICODE
39 #endif
40 #ifndef UNICODE
41 #define UNICODE
42 #endif
43 #endif // Unicode
44
45 // check whether we have wchar_t
46 #if !defined(wxUSE_WCHAR_T)
47 #if defined(__WIN16__)
48 // no wchar_t under Win16 regadrless of compiler used
49 #define wxUSE_WCHAR_T 0
50 #elif defined(__UNIX__)
51 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
52 #define wxUSE_WCHAR_T 1
53 #else
54 #define wxUSE_WCHAR_T 0
55 #endif
56 #elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
57 #define wxUSE_WCHAR_T 0
58 #elif defined(__WATCOMC__)
59 #define wxUSE_WCHAR_T 0
60 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
61 #define wxUSE_WCHAR_T 0
62 #else
63 // add additional compiler checks if this fails
64 #define wxUSE_WCHAR_T 1
65 #endif
66 #endif // !defined(wxUSE_WCHAR_T)
67
68 // Unicode support requires wchar_t
69 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
70 #error "wchar_t must be available in Unicode build"
71 #endif // Unicode
72
73 // ----------------------------------------------------------------------------
74 // standard headers we need here
75 //
76 // NB: don't include any wxWindows headers here because almost of them include
77 // this one!
78 // ----------------------------------------------------------------------------
79
80 // Required for wxPrintf() etc
81 #include <stdarg.h>
82
83 #if defined(__CYGWIN__)
84 #ifndef HAVE_WCSLEN
85 #define HAVE_WCSLEN
86 #endif // !HAVE_WCSLEN
87 #include <stddef.h>
88 #endif
89
90 // non Unix compilers which do have wchar.h (but not tchar.h which is included
91 // below and which includes wchar.h anyhow)
92 #if defined(__MWERKS__) || defined(__VISAGECPP__)
93 #ifndef HAVE_WCHAR_H
94 #define HAVE_WCHAR_H
95 #endif
96 #endif
97
98 #if wxUSE_WCHAR_T
99 #ifdef HAVE_WCHAR_H
100 // include wchar.h to get wcslen() declaration used by wx/buffer.h
101 #include <wchar.h>
102 #elif defined(HAVE_WCSTR_H)
103 // old compilers have wcslen() here
104 #include <wcstr.h>
105 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
106 // include stdlib.h for wchar_t, wcslen is provided in wxchar.cpp
107 #include <stdlib.h>
108 size_t WXDLLEXPORT wcslen(const wchar_t *s);
109 #endif // HAVE_WCHAR_H
110 #endif // wxUSE_WCHAR_T
111
112 // ----------------------------------------------------------------------------
113 // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
114 // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
115 // the function mapping _tfoo() -> foo() or wfoo()
116 // ----------------------------------------------------------------------------
117
118 // VC++ and BC++ starting with 5.2 have TCHAR support
119 #ifdef __VISUALC__
120 #define wxHAVE_TCHAR_SUPPORT
121 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
122 #define wxHAVE_TCHAR_SUPPORT
123 #include <ctype.h>
124 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
125 #define wxHAVE_TCHAR_SUPPORT
126 #include <stddef.h>
127 #include <string.h>
128 #include <ctype.h>
129 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
130 // VZ: the old VisualAge definitions were completely wrong and had no
131 // chance at all to work in Unicode build anyhow so let's pretend that
132 // VisualAge does _not_ support TCHAR for the moment (as indicated by
133 // "0 &&" above) until someone really has time to delve into Unicode
134 // issues under OS/2
135
136 // VisualAge 4.0+ supports TCHAR
137 #define wxHAVE_TCHAR_SUPPORT
138 #endif // compilers with (good) TCHAR support
139
140 #ifdef wxHAVE_TCHAR_SUPPORT
141 // get TCHAR definition if we've got it
142 #include <tchar.h>
143
144 // we surely do have wchar_t if we have TCHAR
145 #ifndef wxUSE_WCHAR_T
146 #define wxUSE_WCHAR_T 1
147 #endif // !defined(wxUSE_WCHAR_T)
148
149 // and we also do have wcslen()
150 #ifndef HAVE_WCSLEN
151 #define HAVE_WCSLEN
152 #endif
153 #endif // wxHAVE_TCHAR_SUPPORT
154
155 // ----------------------------------------------------------------------------
156 // define wxChar type
157 // ----------------------------------------------------------------------------
158
159 // TODO: define wxCharInt to be equal to either int or wint_t?
160
161 #if !wxUSE_UNICODE
162 typedef char wxChar;
163 typedef signed char wxSChar;
164 typedef unsigned char wxUChar;
165 #else // Unicode
166 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
167 // signed/unsigned version of it which (a) makes sense to me (unlike
168 // char wchar_t is always unsigned) and (b) was how the previous
169 // definitions worked so keep it like this
170
171 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
172 // comment below
173 #if !defined(__WCHAR_TYPE__) || \
174 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
175 // standard case
176 typedef wchar_t wxChar;
177 typedef wchar_t wxSChar;
178 typedef wchar_t wxUChar;
179 #else // __WCHAR_TYPE__ and gcc < 2.96
180 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
181 // this doesn't work with new GCC 3.x compilers because wchar_t is
182 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
183 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
184 // have to define wxChar conditionally depending on detected
185 // compiler & compiler version.
186 // with old definition of wxChar.
187 typedef __WCHAR_TYPE__ wxChar;
188 typedef __WCHAR_TYPE__ wxSChar;
189 typedef __WCHAR_TYPE__ wxUChar;
190 #endif // __WCHAR_TYPE__
191 #endif // ASCII/Unicode
192
193 // ----------------------------------------------------------------------------
194 // define _T() and related macros
195 // ----------------------------------------------------------------------------
196
197 // BSD systems define _T() to be something different in ctype.h, override it
198 #if defined(__FreeBSD__) || defined(__DARWIN__)
199 #include <ctype.h>
200 #undef _T
201 #endif
202
203 // could already be defined by tchar.h (it's quasi standard)
204 #ifndef _T
205 #if !wxUSE_UNICODE
206 #define _T(x) x
207 #else // Unicode
208 #define _T(x) L ## x
209 #endif // ASCII/Unicode
210 #endif // !defined(_T)
211
212 // although global macros with such names are normally bad, we want to have
213 // another name for _T() which should be used to avoid confusion between _T()
214 // and _() in wxWindows sources
215 #define wxT(x) _T(x)
216
217 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
218 #ifndef __TFILE__
219 #define __XFILE__(x) wxT(x)
220 #define __TFILE__ __XFILE__(__FILE__)
221 #endif
222
223 #ifndef __TDATE__
224 #define __XDATE__(x) wxT(x)
225 #define __TDATE__ __XDATE__(__DATE__)
226 #endif
227
228 #ifndef __TTIME__
229 #define __XTIME__(x) wxT(x)
230 #define __TTIME__ __XTIME__(__TIME__)
231 #endif
232
233 // ----------------------------------------------------------------------------
234 // define wxFoo() function for each standard foo() function whose signature
235 // (exceptionally including the return type) includes any mention of char:
236 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
237 // the same signature but with char replaced by wxChar which allows us to use
238 // it in Unicode build as well
239 // ----------------------------------------------------------------------------
240
241 #ifdef wxHAVE_TCHAR_SUPPORT
242 // ctype.h functions
243 #define wxIsalnum _istalnum
244 #define wxIsalpha _istalpha
245 #define wxIsctrl _istctrl
246 #define wxIsdigit _istdigit
247 #define wxIsgraph _istgraph
248 #define wxIslower _istlower
249 #define wxIsprint _istprint
250 #define wxIspunct _istpunct
251 #define wxIsspace _istspace
252 #define wxIsupper _istupper
253 #define wxIsxdigit _istxdigit
254 #define wxTolower _totlower
255 #define wxToupper _totupper
256
257 // locale.h functons
258 #define wxSetlocale _tsetlocale
259
260 // string.h functions
261 #define wxStrcat _tcscat
262 #define wxStrchr _tcschr
263 #define wxStrcmp _tcscmp
264 #define wxStrcoll _tcscoll
265 #define wxStrcpy _tcscpy
266 #define wxStrcspn _tcscspn
267 #define wxStrftime _tcsftime
268 #define wxStricmp _tcsicmp
269 #define wxStrnicmp _tcsnicmp
270 #define wxStrlen_ _tcslen // used in wxStrlen inline function
271 #define wxStrncat _tcsncat
272 #define wxStrncmp _tcsncmp
273 #define wxStrncpy _tcsncpy
274 #define wxStrpbrk _tcspbrk
275 #define wxStrrchr _tcsrchr
276 #define wxStrspn _tcsspn
277 #define wxStrstr _tcsstr
278 #define wxStrtod _tcstod
279 #define wxStrtol _tcstol
280 #define wxStrtoul _tcstoul
281 #define wxStrxfrm _tcsxfrm
282
283 // stdio.h functions
284 #define wxFgetc _fgettc
285 #define wxFgetchar _fgettchar
286 #define wxFgets _fgetts
287 #define wxFopen _tfopen
288 #define wxFputc _fputtc
289 #define wxFputchar _fputtchar
290 #define wxFprintf _ftprintf
291 #define wxFputs _fputts
292 #define wxFreopen _tfreopen
293 #define wxFscanf _ftscanf
294 #define wxGetc _gettc
295 #define wxGetchar _gettchar
296 #define wxGets _getts
297 #define wxPerror _tperror
298 #define wxPrintf _tprintf
299 #define wxPutc _puttc
300 #define wxPutchar _puttchar
301 #define wxPuts _putts
302 #define wxScanf _tscanf
303 #define wxSprintf _stprintf
304 #define wxSscanf _stscanf
305 #define wxTmpnam _ttmpnam
306 #define wxUngetc _tungetc
307 #define wxVfprintf _vftprintf
308 #define wxVprintf _vtprintf
309 #define wxVsscanf _vstscanf
310 #define wxVsprintf _vstprintf
311
312 // special case: these functions are missing under Win9x with Unicows so we
313 // have to implement them ourselves
314 #if wxUSE_UNICODE_MSLU
315 #define wxRemove wxMSLU__tremove
316 #define wxRename wxMSLU__trename
317 #else
318 #define wxRemove _tremove
319 #define wxRename _trename
320 #endif
321
322 // stdlib.h functions
323 #define wxAtoi _ttoi
324 #define wxAtol _ttol
325 // #define wxAtof _tttof -- notice that there is no such thing (why?)
326 #define wxGetenv _tgetenv
327 #define wxSystem _tsystem
328
329 // time.h functions
330 #define wxAsctime _tasctime
331 #define wxCtime _tctime
332 #else // !TCHAR-aware compilers
333 #if wxUSE_UNICODE
334 #include <wctype.h>
335
336 // this is probably glibc-specific
337 #if defined(__WCHAR_TYPE__)
338 // ctype.h functions (wctype.h)
339 #define wxIsalnum iswalnum
340 #define wxIsalpha iswalpha
341 #define wxIsctrl iswcntrl
342 #define wxIsdigit iswdigit
343 #define wxIsgraph iswgraph
344 #define wxIslower iswlower
345 #define wxIsprint iswprint
346 #define wxIspunct iswpunct
347 #define wxIsspace iswspace
348 #define wxIsupper iswupper
349 #define wxIsxdigit iswxdigit
350
351 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
352 // /usr/include/wctype.h incorrectly declares translations
353 // tables which provokes tons of compile-time warnings -- try
354 // to correct this
355 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
356 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
357 #else // !glibc 2.0
358 #define wxTolower towlower
359 #define wxToupper towupper
360 #endif // gcc/!gcc
361
362 // string.h functions (wchar.h)
363 #define wxStrcat wcscat
364 #define wxStrchr wcschr
365 #define wxStrcmp wcscmp
366 #define wxStrcoll wcscoll
367 #define wxStrcpy wcscpy
368 #define wxStrcspn wcscspn
369 #define wxStrlen_ wcslen // used in wxStrlen inline function
370 #define wxStrncat wcsncat
371 #define wxStrncmp wcsncmp
372 #define wxStrncpy wcsncpy
373 #define wxStrpbrk wcspbrk
374 #define wxStrrchr wcsrchr
375 #define wxStrspn wcsspn
376 #define wxStrstr wcsstr
377 #define wxStrtod wcstod
378 #define wxStrtok wcstok
379 #define wxStrtol wcstol
380 #define wxStrtoul wcstoul
381 #define wxStrxfrm wcsxfrm
382
383 #define wxFgetc fgetwc
384 #define wxFgetchar fgetwchar
385 #define wxFgets fgetws
386 #define wxFputc fputwc
387 #define wxFputchar fputwchar
388 #define wxGetc getwc
389 #define wxGetchar getwchar
390 #define wxGets getws
391 #define wxUngetc ungetwc
392
393 #ifdef HAVE_FPUTWC
394 #define wxPutc wputc
395 #define wxPutchar wputchar
396 #define wxPuts putws
397 #define wxFputs fputws
398 #else
399 #include <stdio.h>
400
401 int wxFputs(const wxChar *ch, FILE *stream);
402 int wxPutc(wxChar ch, FILE *stream);
403
404 #define wxPuts(ws) wxFputs(ws, stdout)
405 #define wxPutchar(wch) wxPutc(wch, stdout)
406 #endif
407
408 // we need %s to %ls conversion for printf and scanf etc
409 #define wxNEED_PRINTF_CONVERSION
410
411 // glibc doesn't have wide char equivalents of the other stuff so
412 // use our own versions
413 #define wxNEED_WX_STDIO_H
414 #define wxNEED_WX_STDLIB_H
415 #define wxNEED_WX_TIME_H
416 #else // !glibc
417 #error "Please define wide character functions for your environment"
418 #endif
419 #else // ASCII
420 #include <ctype.h>
421 #include <string.h>
422
423 // ctype.h functions
424 #define wxIsalnum isalnum
425 #define wxIsalpha isalpha
426 #define wxIsctrl isctrl
427 #define wxIsdigit isdigit
428 #define wxIsgraph isgraph
429 #define wxIslower islower
430 #define wxIsprint isprint
431 #define wxIspunct ispunct
432 #define wxIsspace isspace
433 #define wxIsupper isupper
434 #define wxIsxdigit isxdigit
435 #define wxTolower tolower
436 #define wxToupper toupper
437
438 // locale.h functons
439 #define wxSetlocale setlocale
440
441 // string.h functions
442 #define wxStrcat strcat
443 #define wxStrchr strchr
444 #define wxStrcmp strcmp
445 #define wxStrcoll strcoll
446 #define wxStrcpy strcpy
447 #define wxStrcspn strcspn
448 #if !defined(__MWERKS__) || !defined(__WXMAC__)
449 #define wxStrdup strdup
450 #endif
451 // wxStricmp and wxStrnicmp are defined below
452 #define wxStrlen_ strlen // used in wxStrlen inline function
453 #define wxStrncat strncat
454 #define wxStrncmp strncmp
455 #define wxStrncpy strncpy
456 #define wxStrpbrk strpbrk
457 #define wxStrrchr strrchr
458 #define wxStrspn strspn
459 #define wxStrstr strstr
460 #define wxStrtod strtod
461 #ifdef HAVE_STRTOK_R
462 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
463 #else
464 #define wxStrtok(str, sep, last) strtok(str, sep)
465 #endif
466 #define wxStrtol strtol
467 #define wxStrtoul strtoul
468 #define wxStrxfrm strxfrm
469
470 // stdio.h functions
471 #define wxFopen fopen
472 #define wxFreopen freopen
473 #define wxPerror perror
474 #define wxRemove remove
475 #define wxRename rename
476 #define wxTmpnam tmpnam
477
478 #define wxFgetc fgetc
479 #define wxFgetchar fgetchar
480 #define wxFgets fgets
481 #define wxFputc fputc
482 #define wxFputchar fputchar
483 #define wxFprintf fprintf
484 #define wxFscanf fscanf
485 #define wxGetc getc
486 #define wxGetchar getchar
487 #define wxGets gets
488 #define wxPrintf printf
489 #define wxPutc putc
490 #define wxPutchar putchar
491 #define wxPuts puts
492 #define wxScanf scanf
493 #define wxSprintf sprintf
494 #define wxSscanf sscanf
495 #define wxUngetc ungetc
496 #define wxVfprintf vfprintf
497 #define wxVprintf vprintf
498 #define wxVsscanf vsscanf
499 #define wxVsprintf vsprintf
500
501 // stdlib.h functions
502 #define wxAtof atof
503 #define wxAtoi atoi
504 #define wxAtol atol
505 #define wxGetenv getenv
506 #define wxSystem system
507
508 // time.h functions
509 #define wxAsctime asctime
510 #define wxCtime ctime
511 #define wxStrftime strftime
512 #endif // Unicode/ASCII
513 #endif // TCHAR-aware compilers/the others
514
515 // ----------------------------------------------------------------------------
516 // various special cases
517 // ----------------------------------------------------------------------------
518
519 // define wxStricmp and wxStrnicmp for various compilers
520 //
521 // note that in Unicode mode we definitely are going to need our own version
522 #if !defined(wxStricmp) && !wxUSE_UNICODE
523 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
524 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
525 defined(__EMX__) || defined(__DJGPP__)
526 #define wxStricmp stricmp
527 #define wxStrnicmp strnicmp
528 #elif defined(__SC__) || defined(__VISUALC__) || \
529 (defined(__MWERKS__) && defined(__INTEL__))
530 #define wxStricmp _stricmp
531 #define wxStrnicmp _strnicmp
532 #elif defined(__UNIX__) || defined(__GNUWIN32__)
533 #define wxStricmp strcasecmp
534 #define wxStrnicmp strncasecmp
535 // #else -- use wxWindows implementation
536 #endif
537 #endif // !defined(wxStricmp)
538
539 // checks whether the passed in pointer is NULL and if the string is empty
540 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
541
542 // safe version of strlen() (returns 0 if passed NULL pointer)
543 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
544
545 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
546 // it's used in wx/buffer.h)
547 #if wxUSE_WCHAR_T
548 #ifdef HAVE_WCSLEN
549 #define wxWcslen wcslen
550 #else
551 inline size_t wxWcslen(const wchar_t *s)
552 {
553 size_t n = 0;
554 while ( *s++ )
555 n++;
556
557 return n;
558 }
559 #endif
560 #endif // wxUSE_WCHAR_T
561
562 WXDLLEXPORT bool wxOKlibc(); // for internal use
563
564 // ----------------------------------------------------------------------------
565 // printf() family saga
566 // ----------------------------------------------------------------------------
567
568 /*
569 First of all, we always want to define safe snprintf() function to be used
570 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
571 which we really need...), otherwise we implement it using our own printf()
572 code.
573
574 We define function with a trailing underscore here because the real one is a
575 wrapper around it as explained below
576 */
577 #ifdef wxHAVE_TCHAR_SUPPORT
578 #define wxVsnprintf_ _vsntprintf
579 #define wxSnprintf_ _sntprintf
580 #else // !TCHAR
581 #if wxUSE_UNICODE
582 #if defined(HAVE_VSWPRINTF)
583 #define wxVsnprintf_ vswprintf
584 #endif
585 #else // ASCII
586 #if (defined(HAVE_VSNPRINTF) || defined(__WXMAC__))
587 // assume we have snprintf() too if we have vsnprintf()
588 #define wxVsnprintf_ vsnprintf
589 #define wxSnprintf_ snprintf
590 #endif
591 #endif
592 #endif // TCHAR/!TCHAR
593
594 #ifndef wxVsnprintf_
595 // no [v]snprintf(), cook our own
596 WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
597 ...) ATTRIBUTE_PRINTF_3;
598 WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
599 va_list argptr);
600 #endif
601
602 /*
603 In Unicode mode we need to have all standard functions such as wprintf() and
604 so on but not all systems have them so use our own implementations in this
605 case.
606 */
607 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
608 #define wxNEED_WPRINTF
609 #endif
610
611 /*
612 More Unicode complications: although both ANSI C and C++ define a number of
613 wide character functions such as wprintf(), not all environments have them.
614 Worse, those which do have different behaviours: under Windows, %s format
615 specifier changes its meaning in Unicode build and expects a Unicode string
616 while under Unix/POSIX it still means an ASCII string even for wprintf() and
617 %ls has to be used for wide strings.
618
619 We choose to always emulate Windows behaviour as more useful for us so even
620 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
621
622 However, if we don't have any vswprintf() at all we don't need to redefine
623 anything as our own wxVsnprintf_() already behaves as needed.
624 */
625 #ifndef wxVsnprintf_
626 #undef wxNEED_PRINTF_CONVERSION
627 #endif
628
629 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
630 // we need to implement all wide character printf and scanf functions
631 // either because we don't have them at all or because they don't have the
632 // semantics we need
633
634 #include <stdio.h> // for FILE
635
636 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
637 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
638 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
639 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
640 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
641 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
642 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
643 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
644 int wxVprintf( const wxChar *format, va_list ap );
645 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
646
647 // these 2 can be simply mapped to the versions with underscore at the end
648 // if we don't have to do the conversion
649 #ifdef wxNEED_PRINTF_CONVERSION
650 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_4;
651 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
652 #else
653 #define wxSnprintf wxSnprintf_
654 #define wxVsnprintf wxVsnprintf_
655 #endif
656 #endif // wxNEED_PRINTF_CONVERSION
657
658 // ----------------------------------------------------------------------------
659 // various functions which might not be available in libc and for which we
660 // provide our own replacements in wxchar.cpp
661 // ----------------------------------------------------------------------------
662
663 // ctype.h functions
664 //
665 // VZ: note that this is never defined currently
666 #ifdef wxNEED_WX_CTYPE_H
667 WXDLLEXPORT int wxIsalnum(wxChar ch);
668 WXDLLEXPORT int wxIsalpha(wxChar ch);
669 WXDLLEXPORT int wxIsctrl(wxChar ch);
670 WXDLLEXPORT int wxIsdigit(wxChar ch);
671 WXDLLEXPORT int wxIsgraph(wxChar ch);
672 WXDLLEXPORT int wxIslower(wxChar ch);
673 WXDLLEXPORT int wxIsprint(wxChar ch);
674 WXDLLEXPORT int wxIspunct(wxChar ch);
675 WXDLLEXPORT int wxIsspace(wxChar ch);
676 WXDLLEXPORT int wxIsupper(wxChar ch);
677 WXDLLEXPORT int wxIsxdigit(wxChar ch);
678 WXDLLEXPORT int wxTolower(wxChar ch);
679 WXDLLEXPORT int wxToupper(wxChar ch);
680 #endif // wxNEED_WX_CTYPE_H
681
682 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
683 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
684 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
685 #undef wxIsspace
686 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
687 #endif // VC++
688
689
690 // string.h functions
691 //
692 // VZ: this is never defined neither currently
693 #ifdef wxNEED_WX_STRING_H
694 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
695 WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
696 WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
697 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
698 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
699 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
700 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
701 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
702 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
703 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
704 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
705 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
706 WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
707 WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
708 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
709 WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
710 WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
711 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
712 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
713 WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
714 WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
715 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
716 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
717 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
718 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
719 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
720 #endif // wxNEED_WX_STRING_H
721
722 #ifndef wxStrdup
723 WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
724 #endif
725
726 #ifndef wxStricmp
727 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
728 #endif
729
730 #ifndef wxStrnicmp
731 WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
732 #endif
733
734 #ifndef wxStrtok
735 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
736 #endif
737
738 #ifndef wxSetlocale
739 class WXDLLEXPORT wxWCharBuffer;
740 WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
741 #endif
742
743 // stdio.h functions
744 #ifdef wxNEED_WX_STDIO_H
745 #include <stdio.h>
746 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
747 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
748 WXDLLEXPORT int wxRemove(const wxChar *path);
749 WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath);
750
751 // *printf() family is handled separately
752 #endif // wxNEED_WX_STDIO_H
753
754
755 // stdlib.h functions
756 #ifndef wxAtof
757 WXDLLEXPORT double wxAtof(const wxChar *psz);
758 #endif
759
760 #ifdef wxNEED_WX_STDLIB_H
761 WXDLLEXPORT int wxAtoi(const wxChar *psz);
762 WXDLLEXPORT long wxAtol(const wxChar *psz);
763 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
764 WXDLLEXPORT int wxSystem(const wxChar *psz);
765 #endif
766
767
768 // time.h functions
769 #ifdef wxNEED_WX_TIME_H
770 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
771 const wxChar *fmt, const struct tm *tm);
772 #endif // wxNEED_WX_TIME_H
773
774 // ----------------------------------------------------------------------------
775 // multibyte to wide char conversion functions and macros
776 // ----------------------------------------------------------------------------
777
778 #if wxUSE_WCHAR_T
779 // multibyte<->widechar conversion
780 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
781 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
782
783 #if wxUSE_UNICODE
784 #define wxMB2WX wxMB2WC
785 #define wxWX2MB wxWC2MB
786 #define wxWC2WX wxStrncpy
787 #define wxWX2WC wxStrncpy
788 #else
789 #define wxMB2WX wxStrncpy
790 #define wxWX2MB wxStrncpy
791 #define wxWC2WX wxWC2MB
792 #define wxWX2WC wxMB2WC
793 #endif
794 #else // !wxUSE_UNICODE
795 // No wxUSE_WCHAR_T: we have to do something (JACS)
796 #define wxMB2WC wxStrncpy
797 #define wxWC2MB wxStrncpy
798 #define wxMB2WX wxStrncpy
799 #define wxWX2MB wxStrncpy
800 #define wxWC2WX wxWC2MB
801 #define wxWX2WC wxMB2WC
802 #endif
803
804 #endif //_WX_WXCHAR_H_
805