]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
Added #include <ctype.h> since it seems to have
[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__) // 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 #include <ctype.h>
243
244 // ctype.h functions
245 #define wxIsalnum _istalnum
246 #define wxIsalpha _istalpha
247 #define wxIsctrl _istctrl
248 #define wxIsdigit _istdigit
249 #define wxIsgraph _istgraph
250 #define wxIslower _istlower
251 #define wxIsprint _istprint
252 #define wxIspunct _istpunct
253 #define wxIsspace _istspace
254 #define wxIsupper _istupper
255 #define wxIsxdigit _istxdigit
256 #define wxTolower _totlower
257 #define wxToupper _totupper
258
259 // locale.h functons
260 #define wxSetlocale _tsetlocale
261
262 // string.h functions
263 #define wxStrcat _tcscat
264 #define wxStrchr _tcschr
265 #define wxStrcmp _tcscmp
266 #define wxStrcoll _tcscoll
267 #define wxStrcpy _tcscpy
268 #define wxStrcspn _tcscspn
269 #define wxStrftime _tcsftime
270 #define wxStricmp _tcsicmp
271 #define wxStrnicmp _tcsnicmp
272 #define wxStrlen_ _tcslen // used in wxStrlen inline function
273 #define wxStrncat _tcsncat
274 #define wxStrncmp _tcsncmp
275 #define wxStrncpy _tcsncpy
276 #define wxStrpbrk _tcspbrk
277 #define wxStrrchr _tcsrchr
278 #define wxStrspn _tcsspn
279 #define wxStrstr _tcsstr
280 #define wxStrtod _tcstod
281 #define wxStrtol _tcstol
282 #define wxStrtoul _tcstoul
283 #define wxStrxfrm _tcsxfrm
284
285 // stdio.h functions
286 #define wxFgetc _fgettc
287 #define wxFgetchar _fgettchar
288 #define wxFgets _fgetts
289 #define wxFopen _tfopen
290 #define wxFputc _fputtc
291 #define wxFputchar _fputtchar
292 #define wxFprintf _ftprintf
293 #define wxFputs _fputts
294 #define wxFreopen _tfreopen
295 #define wxFscanf _ftscanf
296 #define wxGetc _gettc
297 #define wxGetchar _gettchar
298 #define wxGets _getts
299 #define wxPerror _tperror
300 #define wxPrintf _tprintf
301 #define wxPutc _puttc
302 #define wxPutchar _puttchar
303 #define wxPuts _putts
304 #define wxScanf _tscanf
305 #define wxSprintf _stprintf
306 #define wxSscanf _stscanf
307 #define wxTmpnam _ttmpnam
308 #define wxUngetc _tungetc
309 #define wxVfprintf _vftprintf
310 #define wxVprintf _vtprintf
311 #define wxVsscanf _vstscanf
312 #define wxVsprintf _vstprintf
313
314 // special case: not all TCHAR-aware compilers have those
315 #if defined(__VISUALC__) || \
316 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
317 #define wxVsnprintf_ _vsntprintf
318 #define wxSnprintf_ _sntprintf
319 #endif
320
321 // special case: these functions are missing under Win9x with Unicows so we
322 // have to implement them ourselves
323 #if wxUSE_UNICODE_MSLU
324 #define wxRemove wxMSLU__tremove
325 #define wxRename wxMSLU__trename
326 #else
327 #define wxRemove _tremove
328 #define wxRename _trename
329 #endif
330
331 // stdlib.h functions
332 #define wxAtoi _ttoi
333 #define wxAtol _ttol
334 // #define wxAtof _tttof -- notice that there is no such thing (why?)
335 #define wxGetenv _tgetenv
336 #define wxSystem _tsystem
337
338 // time.h functions
339 #define wxAsctime _tasctime
340 #define wxCtime _tctime
341 #else // !TCHAR-aware compilers
342 #if wxUSE_UNICODE
343 #include <wctype.h>
344
345 // this is probably glibc-specific
346 #if defined(__WCHAR_TYPE__)
347 // ctype.h functions (wctype.h)
348 #define wxIsalnum iswalnum
349 #define wxIsalpha iswalpha
350 #define wxIsctrl iswcntrl
351 #define wxIsdigit iswdigit
352 #define wxIsgraph iswgraph
353 #define wxIslower iswlower
354 #define wxIsprint iswprint
355 #define wxIspunct iswpunct
356 #define wxIsspace iswspace
357 #define wxIsupper iswupper
358 #define wxIsxdigit iswxdigit
359
360 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
361 // /usr/include/wctype.h incorrectly declares translations
362 // tables which provokes tons of compile-time warnings -- try
363 // to correct this
364 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
365 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
366 #else // !glibc 2.0
367 #define wxTolower towlower
368 #define wxToupper towupper
369 #endif // gcc/!gcc
370
371 // string.h functions (wchar.h)
372 #define wxStrcat wcscat
373 #define wxStrchr wcschr
374 #define wxStrcmp wcscmp
375 #define wxStrcoll wcscoll
376 #define wxStrcpy wcscpy
377 #define wxStrcspn wcscspn
378 #define wxStrlen_ wcslen // used in wxStrlen inline function
379 #define wxStrncat wcsncat
380 #define wxStrncmp wcsncmp
381 #define wxStrncpy wcsncpy
382 #define wxStrpbrk wcspbrk
383 #define wxStrrchr wcsrchr
384 #define wxStrspn wcsspn
385 #define wxStrstr wcsstr
386 #define wxStrtod wcstod
387 #define wxStrtok wcstok
388 #define wxStrtol wcstol
389 #define wxStrtoul wcstoul
390 #define wxStrxfrm wcsxfrm
391
392 #define wxFgetc fgetwc
393 #define wxFgetchar fgetwchar
394 #define wxFgets fgetws
395 #define wxFputc fputwc
396 #define wxFputchar fputwchar
397 #define wxGetc getwc
398 #define wxGetchar getwchar
399 #define wxGets getws
400 #define wxUngetc ungetwc
401
402 #ifdef HAVE_FPUTWC
403 #define wxPutc wputc
404 #define wxPutchar wputchar
405 #define wxPuts putws
406 #define wxFputs fputws
407 #else
408 #define wxNEED_FPUTWC
409
410 #include <stdio.h>
411
412 int wxFputs(const wxChar *ch, FILE *stream);
413 int wxPutc(wxChar ch, FILE *stream);
414
415 #define wxPuts(ws) wxFputs(ws, stdout)
416 #define wxPutchar(wch) wxPutc(wch, stdout)
417 #endif
418
419 // we need %s to %ls conversion for printf and scanf etc
420 #define wxNEED_PRINTF_CONVERSION
421
422 // glibc doesn't have wide char equivalents of the other stuff so
423 // use our own versions
424 #define wxNEED_WX_STDIO_H
425 #define wxNEED_WX_STDLIB_H
426 #define wxNEED_WX_TIME_H
427 #else // !glibc
428 #error "Please define wide character functions for your environment"
429 #endif
430 #else // ASCII
431 #include <ctype.h>
432 #include <string.h>
433
434 // ctype.h functions
435 #define wxIsalnum isalnum
436 #define wxIsalpha isalpha
437 #define wxIsctrl isctrl
438 #define wxIsdigit isdigit
439 #define wxIsgraph isgraph
440 #define wxIslower islower
441 #define wxIsprint isprint
442 #define wxIspunct ispunct
443 #define wxIsspace isspace
444 #define wxIsupper isupper
445 #define wxIsxdigit isxdigit
446 #define wxTolower tolower
447 #define wxToupper toupper
448
449 // locale.h functons
450 #define wxSetlocale setlocale
451
452 // string.h functions
453 #define wxStrcat strcat
454 #define wxStrchr strchr
455 #define wxStrcmp strcmp
456 #define wxStrcoll strcoll
457 #define wxStrcpy strcpy
458 #define wxStrcspn strcspn
459 #if !defined(__MWERKS__) || !defined(__WXMAC__)
460 #define wxStrdup strdup
461 #endif
462 // wxStricmp and wxStrnicmp are defined below
463 #define wxStrlen_ strlen // used in wxStrlen inline function
464 #define wxStrncat strncat
465 #define wxStrncmp strncmp
466 #define wxStrncpy strncpy
467 #define wxStrpbrk strpbrk
468 #define wxStrrchr strrchr
469 #define wxStrspn strspn
470 #define wxStrstr strstr
471 #define wxStrtod strtod
472 #ifdef HAVE_STRTOK_R
473 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
474 #else
475 #define wxStrtok(str, sep, last) strtok(str, sep)
476 #endif
477 #define wxStrtol strtol
478 #define wxStrtoul strtoul
479 #define wxStrxfrm strxfrm
480
481 // stdio.h functions
482 #define wxFopen fopen
483 #define wxFreopen freopen
484 #define wxPerror perror
485 #define wxRemove remove
486 #define wxRename rename
487 #define wxTmpnam tmpnam
488
489 #define wxFgetc fgetc
490 #define wxFgetchar fgetchar
491 #define wxFgets fgets
492 #define wxFputc fputc
493 #define wxFputchar fputchar
494 #define wxFprintf fprintf
495 #define wxFscanf fscanf
496 #define wxGetc getc
497 #define wxGetchar getchar
498 #define wxGets gets
499 #define wxPrintf printf
500 #define wxPutc putc
501 #define wxPutchar putchar
502 #define wxPuts puts
503 #define wxScanf scanf
504 #define wxSprintf sprintf
505 #define wxSscanf sscanf
506 #define wxUngetc ungetc
507 #define wxVfprintf vfprintf
508 #define wxVprintf vprintf
509 #define wxVsscanf vsscanf
510 #define wxVsprintf vsprintf
511
512 // stdlib.h functions
513 #define wxAtof atof
514 #define wxAtoi atoi
515 #define wxAtol atol
516 #define wxGetenv getenv
517 #define wxSystem system
518
519 // time.h functions
520 #define wxAsctime asctime
521 #define wxCtime ctime
522 #define wxStrftime strftime
523 #endif // Unicode/ASCII
524 #endif // TCHAR-aware compilers/the others
525
526 // ----------------------------------------------------------------------------
527 // various special cases
528 // ----------------------------------------------------------------------------
529
530 // define wxStricmp and wxStrnicmp for various compilers
531 //
532 // note that in Unicode mode we definitely are going to need our own version
533 #if !defined(wxStricmp) && !wxUSE_UNICODE
534 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
535 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
536 defined(__EMX__) || defined(__DJGPP__)
537 #define wxStricmp stricmp
538 #define wxStrnicmp strnicmp
539 #elif defined(__SC__) || defined(__VISUALC__) || \
540 (defined(__MWERKS__) && defined(__INTEL__))
541 #define wxStricmp _stricmp
542 #define wxStrnicmp _strnicmp
543 #elif defined(__UNIX__) || defined(__GNUWIN32__)
544 #define wxStricmp strcasecmp
545 #define wxStrnicmp strncasecmp
546 // #else -- use wxWindows implementation
547 #endif
548 #endif // !defined(wxStricmp)
549
550 // checks whether the passed in pointer is NULL and if the string is empty
551 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
552
553 // safe version of strlen() (returns 0 if passed NULL pointer)
554 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
555
556 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
557 // it's used in wx/buffer.h)
558 #if wxUSE_WCHAR_T
559 #ifdef HAVE_WCSLEN
560 #define wxWcslen wcslen
561 #else
562 inline size_t wxWcslen(const wchar_t *s)
563 {
564 size_t n = 0;
565 while ( *s++ )
566 n++;
567
568 return n;
569 }
570 #endif
571 #endif // wxUSE_WCHAR_T
572
573 WXDLLEXPORT bool wxOKlibc(); // for internal use
574
575 // ----------------------------------------------------------------------------
576 // printf() family saga
577 // ----------------------------------------------------------------------------
578
579 /*
580 First of all, we always want to define safe snprintf() function to be used
581 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
582 which we really need...), otherwise we implement it using our own printf()
583 code.
584
585 We define function with a trailing underscore here because the real one is a
586 wrapper around it as explained below
587 */
588 #ifndef wxVsnprintf_
589 #if wxUSE_UNICODE
590 #if defined(HAVE_VSWPRINTF)
591 #define wxVsnprintf_ vswprintf
592 #endif
593 #else // ASCII
594 // all versions of CodeWarrior supported by wxWindows apparently have
595 // vsnprintf()
596 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
597 // assume we have snprintf() too if we have vsnprintf()
598 #define wxVsnprintf_ vsnprintf
599 #define wxSnprintf_ snprintf
600 #endif
601 #endif
602 #endif // wxVsnprintf_ not defined yet
603
604 #ifndef wxVsnprintf_
605 // no [v]snprintf(), cook our own
606 WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
607 ...) ATTRIBUTE_PRINTF_3;
608 WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
609 va_list argptr);
610 #endif
611
612 /*
613 In Unicode mode we need to have all standard functions such as wprintf() and
614 so on but not all systems have them so use our own implementations in this
615 case.
616 */
617 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
618 #define wxNEED_WPRINTF
619 #endif
620
621 /*
622 More Unicode complications: although both ANSI C and C++ define a number of
623 wide character functions such as wprintf(), not all environments have them.
624 Worse, those which do have different behaviours: under Windows, %s format
625 specifier changes its meaning in Unicode build and expects a Unicode string
626 while under Unix/POSIX it still means an ASCII string even for wprintf() and
627 %ls has to be used for wide strings.
628
629 We choose to always emulate Windows behaviour as more useful for us so even
630 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
631
632 However, if we don't have any vswprintf() at all we don't need to redefine
633 anything as our own wxVsnprintf_() already behaves as needed.
634 */
635 #ifndef wxVsnprintf_
636 #undef wxNEED_PRINTF_CONVERSION
637 #endif
638
639 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
640 // we need to implement all wide character printf and scanf functions
641 // either because we don't have them at all or because they don't have the
642 // semantics we need
643
644 #include <stdio.h> // for FILE
645
646 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
647 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
648 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
649 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
650 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
651 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
652 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
653 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
654 int wxVprintf( const wxChar *format, va_list ap );
655 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
656 #endif // wxNEED_PRINTF_CONVERSION
657
658 // these 2 can be simply mapped to the versions with underscore at the end
659 // if we don't have to do the conversion
660 #ifdef wxNEED_PRINTF_CONVERSION
661 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_4;
662 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
663 #else
664 #define wxSnprintf wxSnprintf_
665 #define wxVsnprintf wxVsnprintf_
666 #endif
667
668 // ----------------------------------------------------------------------------
669 // various functions which might not be available in libc and for which we
670 // provide our own replacements in wxchar.cpp
671 // ----------------------------------------------------------------------------
672
673 // ctype.h functions
674 //
675 // VZ: note that this is never defined currently
676 #ifdef wxNEED_WX_CTYPE_H
677 WXDLLEXPORT int wxIsalnum(wxChar ch);
678 WXDLLEXPORT int wxIsalpha(wxChar ch);
679 WXDLLEXPORT int wxIsctrl(wxChar ch);
680 WXDLLEXPORT int wxIsdigit(wxChar ch);
681 WXDLLEXPORT int wxIsgraph(wxChar ch);
682 WXDLLEXPORT int wxIslower(wxChar ch);
683 WXDLLEXPORT int wxIsprint(wxChar ch);
684 WXDLLEXPORT int wxIspunct(wxChar ch);
685 WXDLLEXPORT int wxIsspace(wxChar ch);
686 WXDLLEXPORT int wxIsupper(wxChar ch);
687 WXDLLEXPORT int wxIsxdigit(wxChar ch);
688 WXDLLEXPORT int wxTolower(wxChar ch);
689 WXDLLEXPORT int wxToupper(wxChar ch);
690 #endif // wxNEED_WX_CTYPE_H
691
692 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
693 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
694 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
695 #undef wxIsspace
696 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
697 #endif // VC++
698
699
700 // string.h functions
701 //
702 // VZ: this is never defined neither currently
703 #ifdef wxNEED_WX_STRING_H
704 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
705 WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
706 WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
707 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
708 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
709 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
710 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
711 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
712 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
713 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
714 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
715 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
716 WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
717 WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
718 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
719 WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
720 WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
721 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
722 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
723 WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
724 WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
725 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
726 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
727 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
728 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
729 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
730 #endif // wxNEED_WX_STRING_H
731
732 #ifndef wxStrdup
733 WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
734 #endif
735
736 #ifndef wxStricmp
737 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
738 #endif
739
740 #ifndef wxStrnicmp
741 WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
742 #endif
743
744 #ifndef wxStrtok
745 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
746 #endif
747
748 #ifndef wxSetlocale
749 class WXDLLEXPORT wxWCharBuffer;
750 WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
751 #endif
752
753 // stdio.h functions
754 #ifdef wxNEED_WX_STDIO_H
755 #include <stdio.h>
756 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
757 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
758 WXDLLEXPORT int wxRemove(const wxChar *path);
759 WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath);
760
761 // *printf() family is handled separately
762 #endif // wxNEED_WX_STDIO_H
763
764
765 // stdlib.h functions
766 #ifndef wxAtof
767 WXDLLEXPORT double wxAtof(const wxChar *psz);
768 #endif
769
770 #ifdef wxNEED_WX_STDLIB_H
771 WXDLLEXPORT int wxAtoi(const wxChar *psz);
772 WXDLLEXPORT long wxAtol(const wxChar *psz);
773 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
774 WXDLLEXPORT int wxSystem(const wxChar *psz);
775 #endif
776
777
778 // time.h functions
779 #ifdef wxNEED_WX_TIME_H
780 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
781 const wxChar *fmt, const struct tm *tm);
782 #endif // wxNEED_WX_TIME_H
783
784 // ----------------------------------------------------------------------------
785 // multibyte to wide char conversion functions and macros
786 // ----------------------------------------------------------------------------
787
788 #if wxUSE_WCHAR_T
789 // multibyte<->widechar conversion
790 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
791 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
792
793 #if wxUSE_UNICODE
794 #define wxMB2WX wxMB2WC
795 #define wxWX2MB wxWC2MB
796 #define wxWC2WX wxStrncpy
797 #define wxWX2WC wxStrncpy
798 #else
799 #define wxMB2WX wxStrncpy
800 #define wxWX2MB wxStrncpy
801 #define wxWC2WX wxWC2MB
802 #define wxWX2WC wxMB2WC
803 #endif
804 #else // !wxUSE_UNICODE
805 // No wxUSE_WCHAR_T: we have to do something (JACS)
806 #define wxMB2WC wxStrncpy
807 #define wxWC2MB wxStrncpy
808 #define wxMB2WX wxStrncpy
809 #define wxWX2MB wxStrncpy
810 #define wxWC2WX wxWC2MB
811 #define wxWX2WC wxMB2WC
812 #endif
813
814 #endif //_WX_WXCHAR_H_
815