MSW compilation (and other) fixes
[wxWidgets.git] / include / wx / wxchar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxchar.h
3 // Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4 // Author: Joel Farley
5 // Modified by:
6 // Created: 1998/06/12
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows copyright
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 // only do SBCS or _UNICODE
20 #if defined (_MBCS )
21 # error "MBCS is not supported by wxChar"
22 #endif
23
24 // set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
25 #if defined(_UNICODE) || defined(UNICODE)
26 # undef wxUSE_UNICODE
27 # define wxUSE_UNICODE 1
28 #else
29 # ifndef wxUSE_UNICODE
30 # define wxUSE_UNICODE 0
31 # endif
32 #endif
33
34 // and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
35 #if wxUSE_UNICODE
36 # ifndef _UNICODE
37 # define _UNICODE
38 # endif
39 # ifndef UNICODE
40 # define UNICODE
41 # endif
42 #endif
43
44 // Windows (VC++) has broad TCHAR support
45 #if defined(__VISUALC__) && defined(__WIN32__)
46
47 # define HAVE_WCSLEN 1
48
49 # include <tchar.h>
50
51 # define T(x) _T(x)
52
53 # if wxUSE_UNICODE // temporary - preserve binary compatibility
54 typedef _TCHAR wxChar;
55 typedef _TSCHAR wxSChar;
56 typedef _TUCHAR wxUChar;
57 # else
58 # define wxChar char
59 # define wxSChar signed char
60 # define wxUChar unsigned char
61 # endif
62 // wchar_t is available
63 # undef wxUSE_WCHAR_T
64 # define wxUSE_WCHAR_T 1
65
66 // ctype.h functions
67 # define wxIsalnum _istalnum
68 # define wxIsalpha _istalpha
69 # define wxIsctrl _istctrl
70 # define wxIsdigit _istdigit
71 # define wxIsgraph _istgraph
72 # define wxIslower _istlower
73 # define wxIsprint _istprint
74 # define wxIspunct _istpunct
75 # define wxIsspace _istspace
76 # define wxIsupper _istupper
77 # define wxIsxdigit _istxdigit
78 # define wxTolower _totlower
79 # define wxToupper _totupper
80
81 // locale.h functons
82 # define wxSetlocale _tsetlocale
83
84 // string.h functions
85 # define wxStrcat _tcscat
86 # define wxStrchr _tcschr
87 # define wxStrcmp _tcscmp
88 # define wxStrcoll _tcscoll
89 # define wxStrcpy _tcscpy
90 # define wxStrcspn _tcscspn
91 # define wxStrftime _tcsftime
92 # define wxStricmp _tcsicmp
93 # define wxStrlen_ _tcslen // used in wxStrlen inline function
94 # define wxStrncat _tcsncat
95 # define wxStrncmp _tcsncmp
96 # define wxStrncpy _tcsncpy
97 # define wxStrpbrk _tcspbrk
98 # define wxStrrchr _tcsrchr
99 # define wxStrspn _tcsspn
100 # define wxStrstr _tcsstr
101 # define wxStrtod _tcstod
102 // is there a _tcstok[_r] ?
103 # define wxStrtol _tcstol
104 # define wxStrtoul _tcstoul
105 # define wxStrxfrm _tcsxfrm
106
107 // stdio.h functions
108 # define wxFgetc _fgettc
109 # define wxFgetchar _fgettchar
110 # define wxFgets _fgetts
111 # define wxFopen _tfopen
112 # define wxFputc _fputtc
113 # define wxFputchar _fputtchar
114 # define wxFprintf _ftprintf
115 # define wxFreopen _tfreopen
116 # define wxFscanf _ftscanf
117 # define wxGetc _gettc
118 # define wxGetchar _gettchar
119 # define wxGets _getts
120 # define wxPerror _tperror
121 # define wxPrintf _tprintf
122 # define wxPutc _puttc
123 # define wxPutchar _puttchar
124 # define wxPuts _putts
125 # define wxRemove _tremove
126 # define wxRename _trename
127 # define wxScanf _tscanf
128 # define wxSprintf _stprintf
129 # define wxSscanf _stscanf
130 # define wxTmpnam _ttmpnam
131 # define wxUngetc _tungetc
132 # define wxVfprint _vftprintf
133 # define wxVprintf _vtprintf
134 # define wxVsscanf _vstscanf
135 # define wxVsprintf _vstprintf
136
137 // stdlib.h functions
138 # if !wxUSE_UNICODE
139 # define wxAtof atof
140 # endif
141 # define wxAtoi _ttoi
142 # define wxAtol _ttol
143 # define wxGetenv _tgetenv
144 # define wxSystem _tsystem
145
146 // time.h functions
147 # define wxAsctime _tasctime
148 # define wxCtime _tctime
149
150 // #elif defined(XXX)
151 // #include XXX-specific files here
152 // typeddef YYY wxChar;
153
154 // translate wxZZZ names
155
156 #elif defined(__BORLANDC__) && defined(__WIN32__)
157
158 // Borland C++ 4.52 doesn't have much tchar support
159 // maybe Borland C++ 5.02 has, can't check right now
160 // but I'll use the Win32 API instead here
161
162 # include <tchar.h>
163 # if wxUSE_UNICODE // temporary - preserve binary compatibility
164 typedef _TCHAR wxChar;
165 typedef _TSCHAR wxSChar;
166 typedef _TUCHAR wxUChar;
167 # else
168 # define wxChar char
169 # define wxSChar signed char
170 # define wxUChar unsigned char
171 # endif
172 // wchar_t is available
173 # undef wxUSE_WCHAR_T
174 # define wxUSE_WCHAR_T 1
175
176 # define wxNEED_WX_CTYPE_H
177 // #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
178 # define wxNEED_WX_STRING_H
179 # define wxNEED_WX_STDIO_H
180 # define wxNEED_WX_STDLIB_H
181 # define wxNEED_WX_TIME_H
182 # define wxNEED_WCSLEN
183
184 #else//!TCHAR-aware compilers
185
186 // check whether we should include wchar.h or equivalent
187 # if wxUSE_UNICODE
188 # undef wxUSE_WCHAR_T
189 # define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
190 # elif !defined(wxUSE_WCHAR_T)
191 # if defined(__VISUALC__) && (__VISUALC__ < 900)
192 # define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
193 # elif defined(__UNIX__)
194 # if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
195 # define wxUSE_WCHAR_T 1
196 # else
197 # define wxUSE_WCHAR_T 0
198 # endif
199 # elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
200 # define wxUSE_WCHAR_T 0
201 # elif defined(__BORLANDC__) // WIN16 BC++
202 # define wxUSE_WCHAR_T 0
203 # elif defined(__WATCOMC__)
204 # define wxUSE_WCHAR_T 0
205 # else
206 // add additional compiler checks if this fails
207 # define wxUSE_WCHAR_T 1
208 # endif
209 # endif//wxUSE_UNICODE
210
211 # if wxUSE_WCHAR_T
212 # ifdef HAVE_WCSTR_H
213 # include <wcstr.h>
214 # else
215 # ifndef __FreeBSD__
216 # include <wchar.h>
217 # else
218 # include <stdlib.h>
219 # define wxNEED_WCSLEN
220 # endif
221 # endif
222 # endif
223
224 // check whether we are doing Unicode
225 # if wxUSE_UNICODE
226
227 # include <wctype.h>
228
229 // this is probably glibc-specific
230 # if defined(__WCHAR_TYPE__)
231
232 typedef __WCHAR_TYPE__ wxChar;
233 typedef signed __WCHAR_TYPE__ wxSChar;
234 typedef unsigned __WCHAR_TYPE__ wxUChar;
235
236 # define T(x) L##x
237
238 // ctype.h functions (wctype.h)
239 # define wxIsalnum iswalnum
240 # define wxIsalpha iswalpha
241 # define wxIsctrl iswcntrl
242 # define wxIsdigit iswdigit
243 # define wxIsgraph iswgraph
244 # define wxIslower iswlower
245 # define wxIsprint iswprint
246 # define wxIspunct iswpunct
247 # define wxIsspace iswspace
248 # define wxIsupper iswupper
249 # define wxIsxdigit iswxdigit
250
251 # if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
252 // /usr/include/wctype.h incorrectly declares translations tables which
253 // provokes tons of compile-time warnings - try to correct this
254 # define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
255 # define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
256 # else
257 # define wxTolower towlower
258 # define wxToupper towupper
259 # endif // gcc/!gcc
260
261 // string.h functions (wchar.h)
262 # define wxStrcat wcscat
263 # define wxStrchr wcschr
264 # define wxStrcmp wcscmp
265 # define wxStrcoll wcscoll
266 # define wxStrcpy wcscpy
267 # define wxStrcspn wcscspn
268 # define wxStrlen_ wcslen // used in wxStrlen inline function
269 # define wxStrncat wcsncat
270 # define wxStrncmp wcsncmp
271 # define wxStrncpy wcsncpy
272 # define wxStrpbrk wcspbrk
273 # define wxStrrchr wcsrchr
274 # define wxStrspn wcsspn
275 # define wxStrstr wcsstr
276 # define wxStrtod wcstod
277 # define wxStrtok wcstok
278 # define wxStrtol wcstol
279 # define wxStrtoul wcstoul
280 # define wxStrxfrm wcsxfrm
281
282 // glibc doesn't have wc equivalents of the other stuff
283 # define wxNEED_WX_STDIO_H
284 # define wxNEED_WX_STDLIB_H
285 # define wxNEED_WX_TIME_H
286
287 # else//!glibc
288 # error "Please define your compiler's Unicode conventions in wxChar.h"
289 # endif
290 # else//!Unicode
291
292 # include <ctype.h>
293 # include <string.h>
294
295 # if 0 // temporary - preserve binary compatibilty
296 typedef char wxChar;
297 typedef signed char wxSChar;
298 typedef unsigned char wxUChar;
299 # else
300 # define wxChar char
301 # define wxSChar signed char
302 # define wxUChar unsigned char
303 # endif
304
305 # ifdef __FreeBSD__
306 # undef T
307 # endif
308 # define T(x) x
309
310 // ctype.h functions
311 # define wxIsalnum isalnum
312 # define wxIsalpha isalpha
313 # define wxIsctrl isctrl
314 # define wxIsdigit isdigit
315 # define wxIsgraph isgraph
316 # define wxIslower islower
317 # define wxIsprint isprint
318 # define wxIspunct ispunct
319 # define wxIsspace isspace
320 # define wxIsupper isupper
321 # define wxIsxdigit isxdigit
322 # define wxTolower tolower
323 # define wxToupper toupper
324
325 // locale.h functons
326 # define wxSetlocale setlocale
327
328 // string.h functions
329 // #define wxStricmp strcasecmp
330 // wxStricmp is defined below!!
331
332 #ifdef HAVE_STRTOK_R
333 #define wxStrtok(str, sep, last) strtok_r(str, sep, last)
334 #else
335 #define wxStrtok(str, sep, last) strtok(str, sep)
336 #endif
337
338 // leave the rest to defaults below
339 # define wxNEED_WX_STRING_H
340 # define wxNEED_WX_STDIO_H
341 # define wxNEED_WX_STDLIB_H
342 # define wxNEED_WX_TIME_H
343
344 # endif//Unicode
345 #endif//TCHAR-aware compilers
346
347 // define wxStricmp for various compilers without Unicode possibilities
348 #if !defined(wxStricmp) && !wxUSE_UNICODE
349 # if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__) || defined(__VISAGECPP__) || defined(__EMX__)
350 # define wxStricmp stricmp
351 # elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS__) && defined(__INTEL__))
352 # define wxStricmp _stricmp
353 # elif defined(__UNIX__) || defined(__GNUWIN32__)
354 # define wxStricmp strcasecmp
355 # elif defined(__MWERKS__) && !defined(__INTEL__)
356 // use wxWindows' implementation
357 # else
358 // if you leave wxStricmp undefined, wxWindows' implementation will be used
359 # error "Please define string case-insensitive compare for your OS/compiler"
360 # endif
361 #endif
362
363 // if we need to define for standard headers, and we're not using Unicode,
364 // just define to standard C library routines
365 #if !wxUSE_UNICODE
366 # ifdef wxNEED_WX_STRING_H
367 # define wxStrcat strcat
368 # define wxStrchr strchr
369 # define wxStrcmp strcmp
370 # define wxStrcoll strcoll
371 # define wxStrcpy strcpy
372 # define wxStrcspn strcspn
373 # define wxStrdup strdup
374 # define wxStrlen_ strlen // used in wxStrlen inline function
375 # define wxStrncat strncat
376 # define wxStrncmp strncmp
377 # define wxStrncpy strncpy
378 # define wxStrpbrk strpbrk
379 # define wxStrrchr strrchr
380 # define wxStrspn strspn
381 # define wxStrstr strstr
382 # define wxStrtod strtod
383 # define wxStrtol strtol
384 # define wxStrtoul strtoul
385 # define wxStrxfrm strxfrm
386 # undef wxNEED_WX_STRING_H
387 # endif
388
389 # ifdef wxNEED_WX_STDIO_H
390 # define wxFgetc fgetc
391 # define wxFgetchar fgetchar
392 # define wxFgets fgets
393 # define wxFopen fopen
394 # define wxFputc fputc
395 # define wxFputchar fputchar
396 # define wxFprintf fprintf
397 # define wxFreopen freopen
398 # define wxFscanf fscanf
399 # define wxGetc getc
400 # define wxGetchar getchar
401 # define wxGets gets
402 # define wxPerror perror
403 # define wxPrintf printf
404 # define wxPutc putc
405 # define wxPutchar putchar
406 # define wxPuts puts
407 # define wxRemove remove
408 # define wxRename rename
409 # define wxScanf scanf
410 # define wxSprintf sprintf
411 # define wxSscanf sscanf
412 # define wxTmpnam tmpnam
413 # define wxUngetc ungetc
414 # define wxVfprint vfprintf
415 # define wxVprintf vprintf
416 # define wxVsscanf vsscanf
417 # define wxVsprintf vsprintf
418 # undef wxNEED_WX_STDIO_H
419 # endif
420
421 # ifdef wxNEED_WX_STDLIB_H
422 # define wxAtof atof
423 # define wxAtoi atoi
424 # define wxAtol atol
425 # define wxGetenv getenv
426 # define wxSystem system
427 # undef wxNEED_WX_STDLIB_H
428 # endif
429
430 # ifdef wxNEED_WX_TIME_H
431 # define wxAsctime asctime
432 # define wxCtime ctime
433 # define wxStrftime strftime
434 # undef wxNEED_WX_TIME_H
435 # endif
436 #endif //!Unicode
437
438 #if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
439 # define wcslen wxStrlen
440 # undef wxNEED_WCSLEN
441 #endif
442
443 /// checks whether the passed in pointer is NULL and if the string is empty
444 WXDLLEXPORT inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
445
446 #ifndef wxNEED_WX_STRING_H
447 /// safe version of strlen() (returns 0 if passed NULL pointer)
448 WXDLLEXPORT inline size_t wxStrlen(const wxChar *psz)
449 { return psz ? wxStrlen_(psz) : 0; }
450 #endif
451
452 #if wxUSE_WCHAR_T
453 // multibyte<->widechar conversion
454 WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
455 WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
456 # if wxUSE_UNICODE
457 # define wxMB2WX wxMB2WC
458 # define wxWX2MB wxWC2MB
459 # define wxWC2WX wxStrncpy
460 # define wxWX2WC wxStrncpy
461 # else
462 # define wxMB2WX wxStrncpy
463 # define wxWX2MB wxStrncpy
464 # define wxWC2WX wxWC2MB
465 # define wxWX2WC wxMB2WC
466 # endif
467 #else
468 // No wxUSE_WCHAR_T: we have to do something (JACS)
469 # define wxMB2WC wxStrncpy
470 # define wxWC2MB wxStrncpy
471 # define wxMB2WX wxStrncpy
472 # define wxWX2MB wxStrncpy
473 # define wxWC2WX wxWC2MB
474 # define wxWX2WC wxMB2WC
475 #endif
476
477 WXDLLEXPORT bool wxOKlibc(); // for internal use
478
479 // if libc versions are not available, use replacements defined in wxchar.cpp
480 #ifndef wxStrdup
481 WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
482 #endif
483
484 #ifndef wxStricmp
485 WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
486 #endif
487
488 #ifndef wxStrtok
489 WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
490 #endif
491
492 #ifndef wxSetlocale
493 WXDLLEXPORT wxChar * wxSetlocale(int category, const wxChar *locale);
494 #endif
495
496 #ifdef wxNEED_WCSLEN // for use in buffer.h
497 WXDLLEXPORT size_t wcslen(const wchar_t *s);
498 #endif
499
500 #ifdef wxNEED_WX_CTYPE_H
501 WXDLLEXPORT int wxIsalnum(wxChar ch);
502 WXDLLEXPORT int wxIsalpha(wxChar ch);
503 WXDLLEXPORT int wxIsctrl(wxChar ch);
504 WXDLLEXPORT int wxIsdigit(wxChar ch);
505 WXDLLEXPORT int wxIsgraph(wxChar ch);
506 WXDLLEXPORT int wxIslower(wxChar ch);
507 WXDLLEXPORT int wxIsprint(wxChar ch);
508 WXDLLEXPORT int wxIspunct(wxChar ch);
509 WXDLLEXPORT int wxIsspace(wxChar ch);
510 WXDLLEXPORT int wxIsupper(wxChar ch);
511 WXDLLEXPORT int wxIsxdigit(wxChar ch);
512 WXDLLEXPORT int wxTolower(wxChar ch);
513 WXDLLEXPORT int wxToupper(wxChar ch);
514 #endif
515
516 #ifdef wxNEED_WX_STRING_H
517 WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
518 WXDLLEXPORT wxChar * wxStrchr(const wxChar *s, wxChar c);
519 WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
520 WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
521 WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
522 WXDLLEXPORT size_t wxStrcspn(const wxChar *s, const wxChar *reject);
523 WXDLLEXPORT size_t wxStrlen(const wxChar *s);
524 WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
525 WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
526 WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
527 WXDLLEXPORT wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
528 WXDLLEXPORT wxChar * wxStrrchr(const wxChar *s, wxChar c);
529 WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
530 WXDLLEXPORT wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
531 WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
532 WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
533 WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
534 WXDLLEXPORT size_t wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
535 #endif
536
537 #ifdef wxNEED_WX_STDIO_H
538 # include <stdio.h>
539 # include <stdarg.h>
540 WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode);
541 WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
542 WXDLLEXPORT int wxPrintf(const wxChar *fmt, ...);
543 WXDLLEXPORT int wxVprintf(const wxChar *fmt, va_list argptr);
544 WXDLLEXPORT int wxFprintf(FILE *stream, const wxChar *fmt, ...);
545 WXDLLEXPORT int wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
546 WXDLLEXPORT int wxSprintf(wxChar *buf, const wxChar *fmt, ...);
547 WXDLLEXPORT int wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
548 WXDLLEXPORT int wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
549 WXDLLEXPORT int wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
550 #endif
551
552 #ifndef wxAtof
553 WXDLLEXPORT double wxAtof(const wxChar *psz);
554 #endif
555
556 #ifdef wxNEED_WX_STDLIB_H
557 WXDLLEXPORT int wxAtoi(const wxChar *psz);
558 WXDLLEXPORT long wxAtol(const wxChar *psz);
559 WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
560 WXDLLEXPORT int wxSystem(const wxChar *psz);
561 #endif
562
563 #ifdef wxNEED_WX_TIME_H
564 WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max, const wxChar *fmt, const struct tm *tm);
565 #endif
566
567 // a Unicode-friendly __FILE__ analog
568 #ifndef __TFILE__
569 #define __XFILE__(x) T(x)
570 #define __TFILE__ __XFILE__(__FILE__)
571 #endif
572
573 #endif
574 //_WX_WXCHAR_H_
575