]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wxchar.h
split wxBase into wxBase and wxNet libraries
[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 // Almost all compiler have strdup(), but not quite all: CodeWarrior under Mac
84 // and VC++ for Windows CE don't provide it
85 #if !(defined(__MWERKS__) && defined(__WXMAC__)) && !defined(__WXWINCE__)
86 // use #define, not inline wrapper, as it is tested with #ifndef below
87 #define wxStrdupA strdup
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 // Actually MinGW has tchar.h, but it does not include wchar.h
93 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
94 #ifndef HAVE_WCHAR_H
95 #define HAVE_WCHAR_H
96 #endif
97 #endif
98
99 #if wxUSE_WCHAR_T
100 #ifdef HAVE_WCHAR_H
101 // the current (as of Nov 2002) version of cygwin has a bug in its
102 // wchar.h -- there is no extern "C" around the declarations in it and
103 // this results in linking errors later; also, at least on some
104 // Cygwin versions, wchar.h requires sys/types.h
105 #ifdef __CYGWIN__
106 #include <sys/types.h>
107 extern "C" {
108 #endif // Cygwin
109 #include <wchar.h>
110 #ifdef __CYGWIN__
111 }
112 #endif // Cygwin
113 #elif defined(HAVE_WCSTR_H)
114 // old compilers have relevant declarations here
115 #include <wcstr.h>
116 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
117 // include stdlib.h for wchar_t
118 #include <stdlib.h>
119 #endif // HAVE_WCHAR_H
120 #endif // wxUSE_WCHAR_T
121
122 // ----------------------------------------------------------------------------
123 // define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
124 // mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
125 // the function mapping _tfoo() -> foo() or wfoo()
126 // ----------------------------------------------------------------------------
127
128 // VC++ and BC++ starting with 5.2 have TCHAR support
129 #ifdef __VISUALC__
130 #define wxHAVE_TCHAR_SUPPORT
131 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
132 #define wxHAVE_TCHAR_SUPPORT
133 #include <ctype.h>
134 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
135 #define wxHAVE_TCHAR_SUPPORT
136 #include <stddef.h>
137 #include <string.h>
138 #include <ctype.h>
139 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
140 // VZ: the old VisualAge definitions were completely wrong and had no
141 // chance at all to work in Unicode build anyhow so let's pretend that
142 // VisualAge does _not_ support TCHAR for the moment (as indicated by
143 // "0 &&" above) until someone really has time to delve into Unicode
144 // issues under OS/2
145
146 // VisualAge 4.0+ supports TCHAR
147 #define wxHAVE_TCHAR_SUPPORT
148 #endif // compilers with (good) TCHAR support
149
150 #ifdef __MWERKS__
151 #define HAVE_WPRINTF
152 #endif
153
154 #ifdef wxHAVE_TCHAR_SUPPORT
155 // get TCHAR definition if we've got it
156 #include <tchar.h>
157
158 // we surely do have wchar_t if we have TCHAR
159 #ifndef wxUSE_WCHAR_T
160 #define wxUSE_WCHAR_T 1
161 #endif // !defined(wxUSE_WCHAR_T)
162
163 // and we also do have wcslen()
164 #ifndef HAVE_WCSLEN
165 #define HAVE_WCSLEN
166 #endif
167 #endif // wxHAVE_TCHAR_SUPPORT
168
169 // ----------------------------------------------------------------------------
170 // define wxChar type
171 // ----------------------------------------------------------------------------
172
173 // TODO: define wxCharInt to be equal to either int or wint_t?
174
175 #if !wxUSE_UNICODE
176 typedef char wxChar;
177 typedef signed char wxSChar;
178 typedef unsigned char wxUChar;
179 #else // Unicode
180 // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
181 // signed/unsigned version of it which (a) makes sense to me (unlike
182 // char wchar_t is always unsigned) and (b) was how the previous
183 // definitions worked so keep it like this
184
185 // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
186 // comment below
187 #if !defined(__WCHAR_TYPE__) || \
188 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
189 // standard case
190 typedef wchar_t wxChar;
191 typedef wchar_t wxSChar;
192 typedef wchar_t wxUChar;
193 #else // __WCHAR_TYPE__ and gcc < 2.96
194 // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
195 // this doesn't work with new GCC 3.x compilers because wchar_t is
196 // C++'s builtin type in the new standard. OTOH, old compilers (GCC
197 // 2.x) won't accept new definition of wx{S,U}Char, therefore we
198 // have to define wxChar conditionally depending on detected
199 // compiler & compiler version.
200 // with old definition of wxChar.
201 typedef __WCHAR_TYPE__ wxChar;
202 typedef __WCHAR_TYPE__ wxSChar;
203 typedef __WCHAR_TYPE__ wxUChar;
204 #endif // __WCHAR_TYPE__
205 #endif // ASCII/Unicode
206
207 // ----------------------------------------------------------------------------
208 // define _T() and related macros
209 // ----------------------------------------------------------------------------
210
211 // BSD systems define _T() to be something different in ctype.h, override it
212 #if defined(__FreeBSD__) || defined(__DARWIN__)
213 #include <ctype.h>
214 #undef _T
215 #endif
216
217 // could already be defined by tchar.h (it's quasi standard)
218 #ifndef _T
219 #if !wxUSE_UNICODE
220 #define _T(x) x
221 #else // Unicode
222 #define _T(x) L ## x
223 #endif // ASCII/Unicode
224 #endif // !defined(_T)
225
226 // although global macros with such names are normally bad, we want to have
227 // another name for _T() which should be used to avoid confusion between _T()
228 // and _() in wxWindows sources
229 #define wxT(x) _T(x)
230
231 // Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
232 #ifndef __TFILE__
233 #define __XFILE__(x) wxT(x)
234 #define __TFILE__ __XFILE__(__FILE__)
235 #endif
236
237 #ifndef __TDATE__
238 #define __XDATE__(x) wxT(x)
239 #define __TDATE__ __XDATE__(__DATE__)
240 #endif
241
242 #ifndef __TTIME__
243 #define __XTIME__(x) wxT(x)
244 #define __TTIME__ __XTIME__(__TIME__)
245 #endif
246
247 // ----------------------------------------------------------------------------
248 // define wxFoo() function for each standard foo() function whose signature
249 // (exceptionally including the return type) includes any mention of char:
250 // wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
251 // the same signature but with char replaced by wxChar which allows us to use
252 // it in Unicode build as well
253 // ----------------------------------------------------------------------------
254
255 #ifdef wxHAVE_TCHAR_SUPPORT
256 #include <ctype.h>
257
258 // ctype.h functions
259 #define wxIsalnum _istalnum
260 #define wxIsalpha _istalpha
261 #define wxIsctrl _istctrl
262 #define wxIsdigit _istdigit
263 #define wxIsgraph _istgraph
264 #define wxIslower _istlower
265 #define wxIsprint _istprint
266 #define wxIspunct _istpunct
267 #define wxIsspace _istspace
268 #define wxIsupper _istupper
269 #define wxIsxdigit _istxdigit
270 #define wxTolower _totlower
271 #define wxToupper _totupper
272
273 // locale.h functons
274 #define wxSetlocale _tsetlocale
275
276 // string.h functions
277 #define wxStrcat _tcscat
278 #define wxStrchr _tcschr
279 #define wxStrcmp _tcscmp
280 #define wxStrcoll _tcscoll
281 #define wxStrcpy _tcscpy
282 #define wxStrcspn _tcscspn
283 #define wxStrdupW _wcsdup // notice the 'W'!
284 #define wxStrftime _tcsftime
285 #define wxStricmp _tcsicmp
286 #define wxStrnicmp _tcsnicmp
287 #define wxStrlen_ _tcslen // used in wxStrlen inline function
288 #define wxStrncat _tcsncat
289 #define wxStrncmp _tcsncmp
290 #define wxStrncpy _tcsncpy
291 #define wxStrpbrk _tcspbrk
292 #define wxStrrchr _tcsrchr
293 #define wxStrspn _tcsspn
294 #define wxStrstr _tcsstr
295 #define wxStrtod _tcstod
296 #define wxStrtol _tcstol
297 #define wxStrtoul _tcstoul
298 #define wxStrxfrm _tcsxfrm
299
300 // stdio.h functions
301 #define wxFgetc _fgettc
302 #define wxFgetchar _fgettchar
303 #define wxFgets _fgetts
304 #define wxFopen _tfopen
305 #define wxFputc _fputtc
306 #define wxFputchar _fputtchar
307 #define wxFprintf _ftprintf
308 #define wxFputs _fputts
309 #define wxFreopen _tfreopen
310 #define wxFscanf _ftscanf
311 #define wxGetc _gettc
312 #define wxGetchar _gettchar
313 #define wxGets _getts
314 #define wxPerror _tperror
315 #define wxPrintf _tprintf
316 #define wxPutc _puttc
317 #define wxPutchar _puttchar
318 #define wxPuts _putts
319 #define wxScanf _tscanf
320 #define wxSprintf _stprintf
321 #define wxSscanf _stscanf
322 #define wxTmpnam _ttmpnam
323 #define wxUngetc _tungetc
324 #define wxVfprintf _vftprintf
325 #define wxVprintf _vtprintf
326 #define wxVsscanf _vstscanf
327 #define wxVsprintf _vstprintf
328
329 // special case: not all TCHAR-aware compilers have those
330 #if defined(__VISUALC__) || \
331 (defined(__BORLANDC__) && __BORLANDC__ >= 0x540)
332 #define wxVsnprintf_ _vsntprintf
333 #define wxSnprintf_ _sntprintf
334 #endif
335
336 // special case: these functions are missing under Win9x with Unicows so we
337 // have to implement them ourselves
338 #if wxUSE_UNICODE_MSLU
339 #define wxRemove wxMSLU__tremove
340 #define wxRename wxMSLU__trename
341 #else
342 #ifdef __WXWINCE__
343 #define wxRemove DeleteFile
344 #else
345 #define wxRemove _tremove
346 #define wxRename _trename
347 #endif
348 #endif
349
350 // stdlib.h functions
351 #define wxAtoi _ttoi
352 #define wxAtol _ttol
353 // #define wxAtof _tttof -- notice that there is no such thing (why?)
354 #define wxGetenv _tgetenv
355 #define wxSystem _tsystem
356
357 // time.h functions
358 #define wxAsctime _tasctime
359 #define wxCtime _tctime
360 #else // !TCHAR-aware compilers
361 #if wxUSE_UNICODE
362 #include <wctype.h>
363
364 // this is probably glibc-specific
365 #if defined(__WCHAR_TYPE__)
366 // ctype.h functions (wctype.h)
367 #define wxIsalnum iswalnum
368 #define wxIsalpha iswalpha
369 #define wxIsctrl iswcntrl
370 #define wxIsdigit iswdigit
371 #define wxIsgraph iswgraph
372 #define wxIslower iswlower
373 #define wxIsprint iswprint
374 #define wxIspunct iswpunct
375 #define wxIsspace iswspace
376 #define wxIsupper iswupper
377 #define wxIsxdigit iswxdigit
378
379 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
380 // /usr/include/wctype.h incorrectly declares translations
381 // tables which provokes tons of compile-time warnings -- try
382 // to correct this
383 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
384 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
385 #else // !glibc 2.0
386 #define wxTolower towlower
387 #define wxToupper towupper
388 #endif // gcc/!gcc
389
390 // string.h functions (wchar.h)
391 #define wxStrcat wcscat
392 #define wxStrchr wcschr
393 #define wxStrcmp wcscmp
394 #define wxStrcoll wcscoll
395 #define wxStrcpy wcscpy
396 #define wxStrcspn wcscspn
397 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
398 #define wxStrncat wcsncat
399 #define wxStrncmp wcsncmp
400 #define wxStrncpy wcsncpy
401 #define wxStrpbrk wcspbrk
402 #define wxStrrchr wcsrchr
403 #define wxStrspn wcsspn
404 #define wxStrstr wcsstr
405 #define wxStrtod wcstod
406 #define wxStrtol wcstol
407 #define wxStrtoul wcstoul
408 #define wxStrxfrm wcsxfrm
409
410 #define wxFgetc fgetwc
411 #define wxFgetchar fgetwchar
412 #define wxFgets fgetws
413 #define wxFputc fputwc
414 #define wxFputchar fputwchar
415 #define wxGetc getwc
416 #define wxGetchar getwchar
417 #define wxGets getws
418 #define wxUngetc ungetwc
419
420 #ifdef HAVE_FPUTWC
421 #define wxPutc wputc
422 #define wxPutchar wputchar
423 #define wxPuts putws
424 #define wxFputs fputws
425 #else
426 #define wxNEED_FPUTWC
427
428 #include <stdio.h>
429
430 int wxFputs(const wxChar *ch, FILE *stream);
431 int wxPutc(wxChar ch, FILE *stream);
432
433 #define wxPuts(ws) wxFputs(ws, stdout)
434 #define wxPutchar(wch) wxPutc(wch, stdout)
435 #endif
436
437 // we need %s to %ls conversion for printf and scanf etc
438 #define wxNEED_PRINTF_CONVERSION
439
440 // glibc doesn't have wide char equivalents of the other stuff so
441 // use our own versions
442 #define wxNEED_WX_STDIO_H
443 #define wxNEED_WX_STDLIB_H
444 #define wxNEED_WX_TIME_H
445 #elif defined(__MWERKS__) && ( defined(macintosh) || defined(__MACH__) )
446 // ctype.h functions (wctype.h)
447 #define wxIsalnum iswalnum
448 #define wxIsalpha iswalpha
449 #define wxIsctrl iswcntrl
450 #define wxIsdigit iswdigit
451 #define wxIsgraph iswgraph
452 #define wxIslower iswlower
453 #define wxIsprint iswprint
454 #define wxIspunct iswpunct
455 #define wxIsspace iswspace
456 #define wxIsupper iswupper
457 #define wxIsxdigit iswxdigit
458 #define wxTolower towlower
459 #define wxToupper towupper
460
461 // string.h functions (wchar.h)
462 #define wxStrcat wcscat
463 #define wxStrchr wcschr
464 #define wxStrcmp wcscmp
465 #define wxStrcoll wcscoll
466 #define wxStrcpy wcscpy
467 #define wxStrcspn wcscspn
468 #define wxStrlen_ wxWcslen // wxStrlen_() is used in wxStrlen()
469 #define wxStrncat wcsncat
470 #define wxStrncmp wcsncmp
471 #define wxStrncpy wcsncpy
472 #define wxStrpbrk wcspbrk
473 #define wxStrrchr wcsrchr
474 #define wxStrspn wcsspn
475 #define wxStrstr wcsstr
476 #define wxStrtod wcstod
477 #define wxStrtol wcstol
478 #define wxStrtoul wcstoul
479 #define wxStrxfrm wcsxfrm
480
481 #define wxFgetc fgetwc
482 #define wxFgetchar fgetwchar
483 #define wxFgets fgetws
484 #define wxFputc fputwc
485 #define wxFputchar fputwchar
486 #define wxGetc getwc
487 #define wxGetchar getwchar
488 #define wxGets getws
489 #define wxUngetc ungetwc
490
491 #define wxNEED_PRINTF_CONVERSION
492
493 #define wxPutc putwc
494 #define wxPutchar putwchar
495 #define wxFputs fputws
496
497 // stdio.h functions
498
499 #define wxNEED_WX_STDIO_H
500
501 // stdlib.h functions
502 #define wxAtof watof
503 #define wxAtoi watoi
504 #define wxAtol watol
505 #define wxGetenv(a) ((wxChar*)NULL)
506 #define wxSystem(a) ((int)NULL)
507
508 // time.h functions
509 #define wxAsctime wasciitime
510 #define wxCtime wctime
511 #define wxStrftime wcsftime
512
513 /*
514 #define wxNEED_FPUTWC
515
516 #include <stdio.h>
517
518 int wxFputs(const wxChar *ch, FILE *stream);
519 int wxPutc(wxChar ch, FILE *stream);
520
521 #define wxPuts(ws) wxFputs(ws, stdout)
522 #define wxPutchar(wch) wxPutc(wch, stdout)
523
524 // we need %s to %ls conversion for printf and scanf etc
525 #define wxNEED_PRINTF_CONVERSION
526 // glibc doesn't have wide char equivalents of the other stuff so
527 // use our own versions
528 #define wxNEED_WX_STDIO_H
529 #define wxNEED_WX_STDLIB_H
530 #define wxNEED_WX_TIME_H
531 */
532 #else // !metrowerks for apple
533 #error "Please define wide character functions for your environment"
534 #endif
535 #else // ASCII
536 #include <ctype.h>
537 #include <string.h>
538
539 // ctype.h functions
540 #define wxIsalnum isalnum
541 #define wxIsalpha isalpha
542 #define wxIsctrl isctrl
543 #define wxIsdigit isdigit
544 #define wxIsgraph isgraph
545 #define wxIslower islower
546 #define wxIsprint isprint
547 #define wxIspunct ispunct
548 #define wxIsspace isspace
549 #define wxIsupper isupper
550 #define wxIsxdigit isxdigit
551 #define wxTolower tolower
552 #define wxToupper toupper
553
554 // locale.h functons
555 #define wxSetlocale setlocale
556
557 // string.h functions
558 #define wxStrcat strcat
559 #define wxStrchr strchr
560 #define wxStrcmp strcmp
561 #define wxStrcoll strcoll
562 #define wxStrcpy strcpy
563 #define wxStrcspn strcspn
564
565 // wxStricmp and wxStrnicmp are defined below
566 #define wxStrlen_ strlen // used in wxStrlen inline function
567 #define wxStrncat strncat
568 #define wxStrncmp strncmp
569 #define wxStrncpy strncpy
570 #define wxStrpbrk strpbrk
571 #define wxStrrchr strrchr
572 #define wxStrspn strspn
573 #define wxStrstr strstr
574 #define wxStrtod strtod
575 #ifdef HAVE_STRTOK_R
576 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
577 #endif
578 #define wxStrtol strtol
579 #define wxStrtoul strtoul
580 #define wxStrxfrm strxfrm
581
582 // stdio.h functions
583 #if defined(__WXMAC__) && !defined(__DARWIN__)
584 #include <stdio.h>
585 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
586 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
587 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
588 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
589 #else
590 #define wxFopen fopen
591 #define wxFreopen freopen
592 #define wxRemove remove
593 #define wxRename rename
594 #endif
595 #define wxPerror perror
596 #define wxTmpnam tmpnam
597
598 #define wxFgetc fgetc
599 #define wxFgetchar fgetchar
600 #define wxFgets fgets
601 #define wxFputc fputc
602 #define wxFputchar fputchar
603 #define wxFprintf fprintf
604 #define wxFscanf fscanf
605 #define wxGetc getc
606 #define wxGetchar getchar
607 #define wxGets gets
608 #define wxPrintf printf
609 #define wxPutc putc
610 #define wxPutchar putchar
611 #define wxPuts puts
612 #define wxScanf scanf
613 #define wxSprintf sprintf
614 #define wxSscanf sscanf
615 #define wxUngetc ungetc
616 #define wxVfprintf vfprintf
617 #define wxVprintf vprintf
618 #define wxVsscanf vsscanf
619 #define wxVsprintf vsprintf
620
621 // stdlib.h functions
622 #define wxAtof atof
623 #define wxAtoi atoi
624 #define wxAtol atol
625 #define wxGetenv getenv
626 #define wxSystem system
627
628 // time.h functions
629 #define wxAsctime asctime
630 #define wxCtime ctime
631 #define wxStrftime strftime
632 #endif // Unicode/ASCII
633 #endif // TCHAR-aware compilers/the others
634
635 // ----------------------------------------------------------------------------
636 // various special cases
637 // ----------------------------------------------------------------------------
638
639 // define wxStricmp and wxStrnicmp for various compilers
640 //
641 // note that in Unicode mode we definitely are going to need our own version
642 #if !defined(wxStricmp) && !wxUSE_UNICODE
643 #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
644 defined(__SALFORDC__) || defined(__VISAGECPP__) || \
645 defined(__EMX__) || defined(__DJGPP__)
646 #define wxStricmp stricmp
647 #define wxStrnicmp strnicmp
648 #elif defined(__SYMANTEC__) || defined(__VISUALC__) || \
649 (defined(__MWERKS__) && defined(__INTEL__))
650 #define wxStricmp _stricmp
651 #define wxStrnicmp _strnicmp
652 #elif defined(__UNIX__) || defined(__GNUWIN32__)
653 #define wxStricmp strcasecmp
654 #define wxStrnicmp strncasecmp
655 // #else -- use wxWindows implementation
656 #endif
657 #endif // !defined(wxStricmp)
658
659 // define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
660 // it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
661 // when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
662 #if wxUSE_WCHAR_T
663 #ifdef HAVE_WCSLEN
664 #define wxWcslen wcslen
665 #else
666 inline size_t wxWcslen(const wchar_t *s)
667 {
668 size_t n = 0;
669 while ( *s++ )
670 n++;
671
672 return n;
673 }
674 #endif
675 #endif // wxUSE_WCHAR_T
676
677 // checks whether the passed in pointer is NULL and if the string is empty
678 inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
679
680 // safe version of strlen() (returns 0 if passed NULL pointer)
681 inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
682
683 // each of strdup() and wcsdup() may or may not be available but we need both
684 // of them anyhow for wx/buffer.h so we define the missing one(s) in
685 // wxchar.cpp and so we should always have both wxStrdupA and wxStrdupW
686 // defined -- if this is somehow not the case in some situations, please
687 // correct that and not the lines here
688 #if wxUSE_UNICODE
689 #define wxStrdup wxStrdupW
690 #else
691 #define wxStrdup wxStrdupA
692 #endif
693
694 WXDLLIMPEXP_BASE bool wxOKlibc(); // for internal use
695
696 // ----------------------------------------------------------------------------
697 // printf() family saga
698 // ----------------------------------------------------------------------------
699
700 /*
701 For some systems vsnprintf() exists in the system libraries but not in the
702 headers, so we need to declare it ourselves to be able to use it.
703 */
704 #if defined(HAVE_VSNPRINTF) && !defined(HAVE_VSNPRINTF_DECL)
705 extern "C"
706 int vsnprintf(char *str, size_t size, const char *format, va_list ap);
707 #endif // !HAVE_VSNPRINTF_DECL
708
709 /*
710 First of all, we always want to define safe snprintf() function to be used
711 instead of sprintf(). Some compilers already have it (or rather vsnprintf()
712 which we really need...), otherwise we implement it using our own printf()
713 code.
714
715 We define function with a trailing underscore here because the real one is a
716 wrapper around it as explained below
717 */
718 #ifndef wxVsnprintf_
719 #if wxUSE_UNICODE
720 #if defined(__MWERKS__)
721 #define HAVE_WCSRTOMBS 1
722 #define HAVE_VSWPRINTF 1
723 #endif
724 #if defined(HAVE__VSNWPRINTF)
725 #define wxVsnprintf_ _vsnwprintf
726 /* MinGW?MSVCRT has the wrong vswprintf */
727 #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
728 #define wxVsnprintf_ vswprintf
729 #endif
730 #else // ASCII
731 // all versions of CodeWarrior supported by wxWindows apparently have
732 // vsnprintf()
733 #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
734 // assume we have snprintf() too if we have vsnprintf()
735 #define wxVsnprintf_ vsnprintf
736 #define wxSnprintf_ snprintf
737 #endif
738 #endif
739 #endif // wxVsnprintf_ not defined yet
740
741 #ifndef wxSnprintf_
742 // no [v]snprintf(), cook our own
743 WXDLLIMPEXP_BASE int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
744 ...) ATTRIBUTE_PRINTF_3;
745 #endif
746 #ifndef wxVsnprintf_
747 WXDLLIMPEXP_BASE int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
748 va_list argptr);
749 #endif
750
751 /*
752 In Unicode mode we need to have all standard functions such as wprintf() and
753 so on but not all systems have them so use our own implementations in this
754 case.
755 */
756 #if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
757 #define wxNEED_WPRINTF
758 #endif
759
760 /*
761 More Unicode complications: although both ANSI C and C++ define a number of
762 wide character functions such as wprintf(), not all environments have them.
763 Worse, those which do have different behaviours: under Windows, %s format
764 specifier changes its meaning in Unicode build and expects a Unicode string
765 while under Unix/POSIX it still means an ASCII string even for wprintf() and
766 %ls has to be used for wide strings.
767
768 We choose to always emulate Windows behaviour as more useful for us so even
769 if we have wprintf() we still must wrap it in a non trivial wxPrintf().
770
771 However, if we don't have any vswprintf() at all we don't need to redefine
772 anything as our own wxVsnprintf_() already behaves as needed.
773 */
774 #ifndef wxVsnprintf_
775 #undef wxNEED_PRINTF_CONVERSION
776 #endif
777
778 #if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
779 // we need to implement all wide character printf and scanf functions
780 // either because we don't have them at all or because they don't have the
781 // semantics we need
782
783 #include <stdio.h> // for FILE
784
785 int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
786 int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
787 int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
788 int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
789 int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
790 int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
791 int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
792 int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
793 int wxVprintf( const wxChar *format, va_list ap );
794 int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
795 #endif // wxNEED_PRINTF_CONVERSION
796
797 // these 2 can be simply mapped to the versions with underscore at the end
798 // if we don't have to do the conversion
799 #ifdef wxNEED_PRINTF_CONVERSION
800 int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
801 int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
802 #else
803 #define wxSnprintf wxSnprintf_
804 #define wxVsnprintf wxVsnprintf_
805 #endif
806
807 // ----------------------------------------------------------------------------
808 // various functions which might not be available in libc and for which we
809 // provide our own replacements in wxchar.cpp
810 // ----------------------------------------------------------------------------
811
812 // ctype.h functions
813 //
814 // VZ: note that this is never defined currently
815 #ifdef wxNEED_WX_CTYPE_H
816 WXDLLIMPEXP_BASE int wxIsalnum(wxChar ch);
817 WXDLLIMPEXP_BASE int wxIsalpha(wxChar ch);
818 WXDLLIMPEXP_BASE int wxIsctrl(wxChar ch);
819 WXDLLIMPEXP_BASE int wxIsdigit(wxChar ch);
820 WXDLLIMPEXP_BASE int wxIsgraph(wxChar ch);
821 WXDLLIMPEXP_BASE int wxIslower(wxChar ch);
822 WXDLLIMPEXP_BASE int wxIsprint(wxChar ch);
823 WXDLLIMPEXP_BASE int wxIspunct(wxChar ch);
824 WXDLLIMPEXP_BASE int wxIsspace(wxChar ch);
825 WXDLLIMPEXP_BASE int wxIsupper(wxChar ch);
826 WXDLLIMPEXP_BASE int wxIsxdigit(wxChar ch);
827 WXDLLIMPEXP_BASE int wxTolower(wxChar ch);
828 WXDLLIMPEXP_BASE int wxToupper(wxChar ch);
829 #endif // wxNEED_WX_CTYPE_H
830
831 // under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
832 // the file parsing -- this may be true for 5.0 as well, update #ifdef then
833 #if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
834 #undef wxIsspace
835 #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
836 #endif // VC++
837
838
839 // string.h functions
840 //
841 // VZ: this is never defined neither currently
842 #ifdef wxNEED_WX_STRING_H
843 WXDLLIMPEXP_BASE wxChar * wxStrcat(wxChar *dest, const wxChar *src);
844 WXDLLIMPEXP_BASE const wxChar * wxStrchr(const wxChar *s, wxChar c);
845 WXDLLIMPEXP_BASE wxChar * wxStrchr(wxChar *s, wxChar c)
846 { return (wxChar *)wxStrchr((const wxChar *)s, c); }
847 WXDLLIMPEXP_BASE int wxStrcmp(const wxChar *s1, const wxChar *s2);
848 WXDLLIMPEXP_BASE int wxStrcoll(const wxChar *s1, const wxChar *s2);
849 WXDLLIMPEXP_BASE wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
850 WXDLLIMPEXP_BASE size_t wxStrcspn(const wxChar *s, const wxChar *reject);
851 WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar *s);
852 WXDLLIMPEXP_BASE wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
853 WXDLLIMPEXP_BASE int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
854 WXDLLIMPEXP_BASE wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
855 WXDLLIMPEXP_BASE const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
856 WXDLLIMPEXP_BASE wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
857 { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
858 WXDLLIMPEXP_BASE const wxChar * wxStrrchr(const wxChar *s, wxChar c);
859 WXDLLIMPEXP_BASE wxChar * wxStrrchr(wxChar *s, wxChar c)
860 { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
861 WXDLLIMPEXP_BASE size_t wxStrspn(const wxChar *s, const wxChar *accept);
862 WXDLLIMPEXP_BASE const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
863 WXDLLIMPEXP_BASE wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
864 { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
865 WXDLLIMPEXP_BASE double wxStrtod(const wxChar *nptr, wxChar **endptr);
866 WXDLLIMPEXP_BASE long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
867 WXDLLIMPEXP_BASE unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
868 WXDLLIMPEXP_BASE size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
869 #endif // wxNEED_WX_STRING_H
870
871 #ifndef wxStrdupA
872 WXDLLIMPEXP_BASE char *wxStrdupA(const char *psz);
873 #endif
874
875 #ifndef wxStrdupW
876 WXDLLIMPEXP_BASE wchar_t *wxStrdupW(const wchar_t *pwz);
877 #endif
878
879 #ifndef wxStricmp
880 WXDLLIMPEXP_BASE int wxStricmp(const wxChar *psz1, const wxChar *psz2);
881 #endif
882
883 #ifndef wxStrnicmp
884 WXDLLIMPEXP_BASE int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
885 #endif
886
887 #ifndef wxStrtok
888 WXDLLIMPEXP_BASE wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
889 #endif
890
891 #ifndef wxSetlocale
892 class WXDLLIMPEXP_BASE wxWCharBuffer;
893 WXDLLIMPEXP_BASE wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
894 #endif
895
896 // stdio.h functions
897 #ifdef wxNEED_WX_STDIO_H
898 #include <stdio.h>
899 WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
900 WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
901 WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
902 WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
903
904 // *printf() family is handled separately
905 #endif // wxNEED_WX_STDIO_H
906
907
908 // stdlib.h functions
909 #ifndef wxAtof
910 WXDLLIMPEXP_BASE double wxAtof(const wxChar *psz);
911 #endif
912
913 #ifdef wxNEED_WX_STDLIB_H
914 WXDLLIMPEXP_BASE int wxAtoi(const wxChar *psz);
915 WXDLLIMPEXP_BASE long wxAtol(const wxChar *psz);
916 WXDLLIMPEXP_BASE wxChar * wxGetenv(const wxChar *name);
917 WXDLLIMPEXP_BASE int wxSystem(const wxChar *psz);
918 #endif
919
920
921 // time.h functions
922 #ifdef wxNEED_WX_TIME_H
923 #if defined(__MWERKS__) && defined(macintosh)
924 #include <time.h>
925 #endif
926 WXDLLIMPEXP_BASE size_t wxStrftime(wxChar *s, size_t max,
927 const wxChar *fmt, const struct tm *tm);
928 #endif // wxNEED_WX_TIME_H
929
930 // missing functions in WinCE
931 #ifdef __WXWINCE__
932 WXDLLIMPEXP_BASE char* strdup(const char* s);
933 WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
934
935 #if _WIN32_WCE <= 211
936 WXDLLIMPEXP_BASE int isspace(int c);
937 WXDLLIMPEXP_BASE int isascii( int c );
938 #endif
939 #endif
940
941 // ----------------------------------------------------------------------------
942 // multibyte to wide char conversion functions and macros
943 // ----------------------------------------------------------------------------
944
945 #if wxUSE_WCHAR_T
946 // multibyte<->widechar conversion
947 WXDLLIMPEXP_BASE size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
948 WXDLLIMPEXP_BASE size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
949
950 #if wxUSE_UNICODE
951 #define wxMB2WX wxMB2WC
952 #define wxWX2MB wxWC2MB
953 #define wxWC2WX wxStrncpy
954 #define wxWX2WC wxStrncpy
955 #else
956 #define wxMB2WX wxStrncpy
957 #define wxWX2MB wxStrncpy
958 #define wxWC2WX wxWC2MB
959 #define wxWX2WC wxMB2WC
960 #endif
961 #else // !wxUSE_UNICODE
962 // No wxUSE_WCHAR_T: we have to do something (JACS)
963 #define wxMB2WC wxStrncpy
964 #define wxWC2MB wxStrncpy
965 #define wxMB2WX wxStrncpy
966 #define wxWX2MB wxStrncpy
967 #define wxWC2WX wxWC2MB
968 #define wxWX2WC wxMB2WC
969 #endif
970
971 #endif //_WX_WXCHAR_H_
972