Fixed glibc2.0 check (for that glibc2.0 workaround, which gives glibc2.1
[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 // Windows (VC++) has broad TCHAR support
25 #if defined(__VISUALC__) && defined(__WIN32__)
26
27 #include <tchar.h>
28 #if wxUSE_UNICODE // temporary - preserve binary compatibility
29 typedef _TCHAR wxChar;
30 typedef _TSCHAR wxSChar;
31 typedef _TUCHAR wxUChar;
32 #else
33 #define wxChar char
34 #define wxSChar signed char
35 #define wxUChar unsigned char
36 #endif
37
38 // ctype.h functions
39 #define wxIsalnum _istalnum
40 #define wxIsalpha _istalpha
41 #define wxIsctrl _istctrl
42 #define wxIsdigit _istdigit
43 #define wxIsgraph _istgraph
44 #define wxIslower _istlower
45 #define wxIsprint _istprint
46 #define wxIspunct _istpunct
47 #define wxIsspace _istspace
48 #define wxIsupper _istupper
49 #define wxIsxdigit _istxdigit
50 #define wxTolower _totlower
51 #define wxToupper _totupper
52
53 // locale.h functons
54 #define wxSetlocale _tsetlocale
55
56 // string.h functions
57 #define wxStrcat _tcscat
58 #define wxStrchr _tcschr
59 #define wxStrcmp _tcscmp
60 #define wxStrcoll _tcscoll
61 #define wxStrcpy _tcscpy
62 #define wxStrcspn _tcscspn
63 #define wxStrftime _tcsftime
64 #define wxStrncat _tcsncat
65 #define wxStrncmp _tcsncmp
66 #define wxStrncpy _tcsncpy
67 #define wxStrpbrk _tcspbrk
68 #define wxStrrchr _tcsrchr
69 #define wxStrspn _tcsspn
70 #define wxStrstr _tcsstr
71 #define wxStrtod _tcstod
72 // is there a _tcstok[_r] ?
73 #define wxStrtol _tcstol
74 #define wxStrtoul _tcstoul
75 #define wxStrxfrm _tcsxfrm
76
77 // stdio.h functions
78 #define wxFgetc _fgettc
79 #define wxFgetchar _fgettchar
80 #define wxFgets _fgetts
81 #define wxFopen _tfopen
82 #define wxFputc _fputtc
83 #define wxFputchar _fputtchar
84 #define wxFprintf _ftprintf
85 #define wxFreopen _tfreopen
86 #define wxFscanf _ftscanf
87 #define wxGetc _gettc
88 #define wxGetchar _gettchar
89 #define wxGets _getts
90 #define wxPerror _tperror
91 #define wxPrintf _tprintf
92 #define wxPutc _puttc
93 #define wxPutchar _puttchar
94 #define wxPuts _putts
95 #define wxRemove _tremove
96 #define wxRename _trename
97 #define wxScanf _tscanf
98 #define wxSprintf _stprintf
99 #define wxSscanf _stscanf
100 #define wxTmpnam _ttmpnam
101 #define wxUngetc _tungetc
102 #define wxVfprint _vftprintf
103 #define wxVprintf _vtprintf
104 #define wxVsprintf _vstprintf
105
106 // stdlib.h functions
107 #if !wxUSE_UNICODE
108 #define wxAtof atof
109 #endif
110 #define wxAtoi _ttoi
111 #define wxAtol _ttol
112 #define wxGetenv _tgetenv
113 #define wxSystem _tsystem
114
115 // time.h functions
116 #define wxAsctime _tasctime
117 #define wxCtime _tctime
118
119 // #elif defined(XXX)
120 // #include XXX-specific files here
121 // typeddef YYY wxChar;
122
123 // translate wxZZZ names
124
125 #else//!Windows (VC++)
126
127 // check whether we are doing Unicode
128 #if wxUSE_UNICODE
129
130 #include <wchar.h>
131 #include <wctype.h>
132
133 // this is probably glibc-specific
134 #if defined(__WCHAR_TYPE__)
135
136 typedef __WCHAR_TYPE__ wxChar;
137 typedef signed __WCHAR_TYPE__ wxSChar;
138 typedef unsigned __WCHAR_TYPE__ wxUChar;
139
140 #define _T(x) L##x
141
142 // ctype.h functions (wctype.h)
143 #define wxIsalnum iswalnum
144 #define wxIsalpha iswalpha
145 #define wxIsctrl iswcntrl
146 #define wxIsdigit iswdigit
147 #define wxIsgraph iswgraph
148 #define wxIslower iswlower
149 #define wxIsprint iswprint
150 #define wxIspunct iswpunct
151 #define wxIsspace iswspace
152 #define wxIsupper iswupper
153 #define wxIsxdigit iswxdigit
154
155 #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
156 // /usr/include/wctype.h incorrectly declares translations tables which
157 // provokes tons of compile-time warnings - try to correct this
158 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
159 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
160 #else
161 #define wxTolower towlower
162 #define wxToupper towupper
163 #endif // gcc/!gcc
164
165 // string.h functions (wchar.h)
166 #define wxStrcat wcscat
167 #define wxStrchr wcschr
168 #define wxStrcmp wcscmp
169 #define wxStrcoll wcscoll
170 #define wxStrcpy wcscpy
171 #define wxStrcspn wcscspn
172 #define wxStrncat wcsncat
173 #define wxStrncmp wcsncmp
174 #define wxStrncpy wcsncpy
175 #define wxStrpbrk wcspbrk
176 #define wxStrrchr wcsrchr
177 #define wxStrspn wcsspn
178 #define wxStrstr wcsstr
179 #define wxStrtod wcstod
180 #define wxStrtok wcstok
181 #define wxStrtol wcstol
182 #define wxStrtoul wcstoul
183 #define wxStrxfrm wcsxfrm
184
185 // glibc doesn't have wc equivalents of the other stuff
186 #define wxNEED_WX_STDIO_H
187 #define wxNEED_WX_STDLIB_H
188 #define wxNEED_WX_TIME_H
189
190 #else
191 #error "Please define your compiler's Unicode conventions in wxChar.h"
192 #endif
193 #else//!Unicode
194
195 #include <ctype.h>
196 #include <string.h>
197
198 #if 0 // temporary - preserve binary compatibilty
199 typedef char wxChar;
200 typedef signed char wxSChar;
201 typedef unsigned char wxUChar;
202 #else
203 #define wxChar char
204 #define wxSChar signed char
205 #define wxUChar unsigned char
206 #endif
207
208 #define _T(x) x
209
210 // ctype.h functions
211 #define wxIsalnum isalnum
212 #define wxIsalpha isalpha
213 #define wxIsctrl isctrl
214 #define wxIsdigit isdigit
215 #define wxIsgraph isgraph
216 #define wxIslower islower
217 #define wxIsprint isprint
218 #define wxIspunct ispunct
219 #define wxIsspace isspace
220 #define wxIsupper isupper
221 #define wxIsxdigit isxdigit
222 #define wxTolower tolower
223 #define wxToupper toupper
224
225 // locale.h functons
226 #define wxSetlocale setlocale
227
228 // string.h functions
229 #define wxStrcat strcat
230 #define wxStrchr strchr
231 #define wxStrcmp strcmp
232 #define wxStrcoll strcoll
233 #define wxStrcpy strcpy
234 #define wxStrcspn strcspn
235 #define wxStrdup strdup
236 #define wxStrncat strncat
237 #define wxStrncmp strncmp
238 #define wxStrncpy strncpy
239 #define wxStrpbrk strpbrk
240 #define wxStrrchr strrchr
241 #define wxStrspn strspn
242 #define wxStrstr strstr
243 #define wxStrtod strtod
244 // #define wxStrtok strtok_r // this needs a configure check
245 #define wxStrtol strtol
246 #define wxStrtoul strtoul
247 #define wxStrxfrm strxfrm
248
249 // stdio.h functions
250 #define wxFgetc fgetc
251 #define wxFgetchar fgetchar
252 #define wxFgets fgets
253 #define wxFopen fopen
254 #define wxFputc fputc
255 #define wxFputchar fputchar
256 #define wxFprintf fprintf
257 #define wxFreopen freopen
258 #define wxFscanf fscanf
259 #define wxGetc getc
260 #define wxGetchar getchar
261 #define wxGets gets
262 #define wxPerror perror
263 #define wxPrintf printf
264 #define wxPutc putc
265 #define wxPutchar putchar
266 #define wxPuts puts
267 #define wxRemove remove
268 #define wxRename rename
269 #define wxScanf scanf
270 #define wxSprintf sprintf
271 #define wxSscanf sscanf
272 #define wxTmpnam tmpnam
273 #define wxUngetc ungetc
274 #define wxVfprint vfprintf
275 #define wxVprintf vprintf
276 #define wxVsprintf vsprintf
277
278 // stdlib.h functions
279 #define wxAtof atof
280 #define wxAtoi atoi
281 #define wxAtol atol
282 #define wxGetenv getenv
283 #define wxSystem system
284
285 // time.h functions
286 #define wxAsctime asctime
287 #define wxCtime ctime
288 #define wxStrftime strftime
289
290 #endif//Unicode
291 #endif
292
293
294 /// checks whether the passed in pointer is NULL and if the string is empty
295 inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
296
297 /// safe version of strlen() (returns 0 if passed NULL pointer)
298 inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
299 #if defined(__VISUALC__)
300 { return psz ? _tcslen(psz) : 0; }
301 #elif wxUSE_UNICODE
302 { return psz ? wcslen(psz) : 0; }
303 #else
304 { return psz ? strlen(psz) : 0; }
305 #endif
306
307 /// portable strcasecmp/_stricmp
308 inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
309 #if defined(__VISUALC__)
310 { return _tcsicmp(psz1, psz2); }
311 #elif defined(__BORLANDC__) && !wxUSE_UNICODE
312 { return stricmp(psz1, psz2); }
313 #elif defined(__UNIX__) || defined(__GNUWIN32__)
314 #if !wxUSE_UNICODE
315 { return strcasecmp(psz1, psz2); }
316 #else // glibc doesn't seem to have wide char equivalent
317 {
318 register wxChar c1, c2;
319 do {
320 c1 = wxTolower(*psz1++);
321 c2 = wxTolower(*psz2++);
322 } while ( c1 && (c1 == c2) );
323
324 return c1 - c2;
325 }
326 #endif
327 #else
328 // almost all compilers/libraries provide this function (unfortunately under
329 // different names), that's why we don't implement our own which will surely
330 // be more efficient than this code (uncomment to use):
331 /*
332 register wxChar c1, c2;
333 do {
334 c1 = wxTolower(*psz1++);
335 c2 = wxTolower(*psz2++);
336 } while ( c1 && (c1 == c2) );
337
338 return c1 - c2;
339 */
340
341 #error "Please define string case-insensitive compare for your OS/compiler"
342 #endif // OS/compiler
343
344 // multibyte<->widechar conversion
345 size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
346 size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
347 #if wxUSE_UNICODE
348 #define wxMB2WX wxMB2WC
349 #define wxWX2MB wxWC2MB
350 #define wxWC2WX wxStrncpy
351 #define wxWX2WC wxStrncpy
352 #else
353 #define wxMB2WX wxStrncpy
354 #define wxWX2MB wxStrncpy
355 #define wxWC2WX wxWC2MB
356 #define wxWX2WC wxMB2WC
357 #endif
358
359 // if libc versions are not available, use replacements defined in wxchar.cpp
360 #ifndef wxStrdup
361 wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
362 #endif
363
364 #ifndef wxStrtok
365 wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
366 #endif
367
368 #ifndef wxSetlocale
369 wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
370 #endif
371
372 #ifdef wxNEED_WX_STDIO_H
373 #include <stdio.h>
374 #include <stdarg.h>
375 int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
376 int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
377 int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
378 int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
379 int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
380 int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
381 #endif
382
383 #ifndef wxAtof
384 double WXDLLEXPORT wxAtof(const wxChar *psz);
385 #endif
386
387 #ifdef wxNEED_WX_STDLIB_H
388 int WXDLLEXPORT wxAtoi(const wxChar *psz);
389 long WXDLLEXPORT wxAtol(const wxChar *psz);
390 wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
391 int WXDLLEXPORT wxSystem(const wxChar *psz);
392 #endif
393
394 #endif
395 //_WX_WXCHAR_H_