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