Statistics
| Revision:

root / trunk / install / launcher / izpack-launcher-1.3_linux / src / wx / include / wx / wxchar.h @ 6834

History | View | Annotate | Download (29.7 KB)

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: wxchar.h 6834 2006-08-24 08:23:24Z jmvivo $
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
// ----------------------------------------------------------------------------
16
// first deal with Unicode setting: wxUSE_UNICODE should be defined as 0 or 1
17
// and is used by wxWindows, _UNICODE and/or UNICODE may be defined or used by
18
// the system headers so bring these settings in sync
19
// ----------------------------------------------------------------------------
20

    
21
// set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
22
#if defined(_UNICODE) || defined(UNICODE)
23
    #undef wxUSE_UNICODE
24
    #define wxUSE_UNICODE 1
25
#else
26
    #ifndef wxUSE_UNICODE
27
        #define wxUSE_UNICODE 0
28
    #endif
29
#endif // Unicode
30

    
31
// and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
32
#if wxUSE_UNICODE
33
    #ifndef _UNICODE
34
        #define _UNICODE
35
    #endif
36
    #ifndef UNICODE
37
        #define UNICODE
38
    #endif
39
#endif // Unicode
40

    
41
// check whether we have wchar_t
42
#if !defined(wxUSE_WCHAR_T)
43
    #if defined(__WIN16__)
44
        // no wchar_t under Win16 regadrless of compiler used
45
        #define wxUSE_WCHAR_T 0
46
    #elif defined(__UNIX__)
47
        #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
48
            #define wxUSE_WCHAR_T 1
49
        #else
50
            #define wxUSE_WCHAR_T 0
51
        #endif
52
    #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
53
        #define wxUSE_WCHAR_T 0
54
    #elif defined(__WATCOMC__)
55
        #define wxUSE_WCHAR_T 0
56
    #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
57
        #define wxUSE_WCHAR_T 0
58
    #else
59
        // add additional compiler checks if this fails
60
        #define wxUSE_WCHAR_T 1
61
    #endif
62
#endif // !defined(wxUSE_WCHAR_T)
63

    
64
// Unicode support requires wchar_t
65
#if wxUSE_UNICODE && !wxUSE_WCHAR_T
66
    #error "wchar_t must be available in Unicode build"
67
#endif // Unicode
68

    
69
// ----------------------------------------------------------------------------
70
// standard headers we need here
71
//
72
// NB: don't include any wxWindows headers here because almost of them include
73
//     this one!
74
// ----------------------------------------------------------------------------
75

    
76
// Required for wxPrintf() etc
77
#include <stdarg.h>
78

    
79
// non Unix compilers which do have wchar.h (but not tchar.h which is included
80
// below and which includes wchar.h anyhow).
81
// Actually MinGW has tchar.h, but it does not include wchar.h
82
#if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__)
83
    #ifndef HAVE_WCHAR_H
84
        #define HAVE_WCHAR_H
85
    #endif
86
#endif
87

    
88
#if wxUSE_WCHAR_T
89
    #ifdef HAVE_WCHAR_H
90
        // the current (as of Nov 2002) version of cygwin has a bug in its
91
        // wchar.h -- there is no extern "C" around the declarations in it and
92
        // this results in linking errors later; also, at least on some
93
        // Cygwin versions, wchar.h requires sys/types.h
94
        #ifdef __CYGWIN__
95
            #include <sys/types.h>
96
            extern "C" {
97
        #endif // Cygwin
98
                #include <wchar.h>
99
        #ifdef __CYGWIN__
100
            }
101
        #endif // Cygwin
102
    #elif defined(HAVE_WCSTR_H)
103
        // old compilers have relevant declarations here
104
        #include <wcstr.h>
105
    #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
106
        // include stdlib.h for wchar_t
107
        #include <stdlib.h>
108
    #endif // HAVE_WCHAR_H
109
#endif // wxUSE_WCHAR_T
110

    
111
// ----------------------------------------------------------------------------
112
// define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type
113
// mapped to either char or wchar_t depending on the ASCII/Unicode mode and have
114
// the function mapping _tfoo() -> foo() or wfoo()
115
// ----------------------------------------------------------------------------
116

    
117
// VC++ and BC++ starting with 5.2 have TCHAR support
118
#ifdef __VISUALC__
119
    #define wxHAVE_TCHAR_SUPPORT
120
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
121
    #define wxHAVE_TCHAR_SUPPORT
122
    #include <ctype.h>
123
#elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
124
    #define wxHAVE_TCHAR_SUPPORT
125
    #include <stddef.h>
126
    #include <string.h>
127
    #include <ctype.h>
128
#elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
129
    // VZ: the old VisualAge definitions were completely wrong and had no
130
    //     chance at all to work in Unicode build anyhow so let's pretend that
131
    //     VisualAge does _not_ support TCHAR for the moment (as indicated by
132
    //     "0 &&" above) until someone really has time to delve into Unicode
133
    //     issues under OS/2
134

    
135
    // VisualAge 4.0+ supports TCHAR
136
    #define wxHAVE_TCHAR_SUPPORT
137
#endif // compilers with (good) TCHAR support
138

    
139
#ifdef wxHAVE_TCHAR_SUPPORT
140
    // get TCHAR definition if we've got it
141
    #include <tchar.h>
142

    
143
    // we surely do have wchar_t if we have TCHAR
144
    #ifndef wxUSE_WCHAR_T
145
        #define wxUSE_WCHAR_T 1
146
    #endif // !defined(wxUSE_WCHAR_T)
147

    
148
    // and we also do have wcslen()
149
    #ifndef HAVE_WCSLEN
150
        #define HAVE_WCSLEN
151
    #endif
152
#endif // wxHAVE_TCHAR_SUPPORT
153

    
154
// ----------------------------------------------------------------------------
155
// define wxChar type
156
// ----------------------------------------------------------------------------
157

    
158
// TODO: define wxCharInt to be equal to either int or wint_t?
159

    
160
#if !wxUSE_UNICODE
161
    typedef char wxChar;
162
    typedef signed char wxSChar;
163
    typedef unsigned char wxUChar;
164
#else // Unicode
165
    // VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as
166
    //     signed/unsigned version of it which (a) makes sense to me (unlike
167
    //     char wchar_t is always unsigned) and (b) was how the previous
168
    //     definitions worked so keep it like this
169

    
170
    // GNU libc has __WCHAR_TYPE__ which requires special treatment, see
171
    // comment below
172
    #if !defined(__WCHAR_TYPE__) || \
173
        (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
174
        // standard case
175
        typedef wchar_t wxChar;
176
        typedef wchar_t wxSChar;
177
        typedef wchar_t wxUChar;
178
    #else // __WCHAR_TYPE__ and gcc < 2.96
179
        // VS: wxWindows used to define wxChar as __WCHAR_TYPE__ here. However,
180
        //     this doesn't work with new GCC 3.x compilers because wchar_t is
181
        //     C++'s builtin type in the new standard. OTOH, old compilers (GCC
182
        //     2.x) won't accept new definition of wx{S,U}Char, therefore we
183
        //     have to define wxChar conditionally depending on detected
184
        //     compiler & compiler version.
185
        //     with old definition of wxChar.
186
        typedef __WCHAR_TYPE__ wxChar;
187
        typedef __WCHAR_TYPE__ wxSChar;
188
        typedef __WCHAR_TYPE__ wxUChar;
189
    #endif // __WCHAR_TYPE__
190
#endif // ASCII/Unicode
191

    
192
// ----------------------------------------------------------------------------
193
// define _T() and related macros
194
// ----------------------------------------------------------------------------
195

    
196
// BSD systems define _T() to be something different in ctype.h, override it
197
#if defined(__FreeBSD__) || defined(__DARWIN__)
198
    #include <ctype.h>
199
    #undef _T
200
#endif
201

    
202
// could already be defined by tchar.h (it's quasi standard)
203
#ifndef _T
204
    #if !wxUSE_UNICODE
205
        #define _T(x) x
206
    #else // Unicode
207
        #define _T(x) L ## x
208
    #endif // ASCII/Unicode
209
#endif // !defined(_T)
210

    
211
// although global macros with such names are normally bad, we want to have
212
// another name for _T() which should be used to avoid confusion between _T()
213
// and _() in wxWindows sources
214
#define wxT(x)       _T(x)
215

    
216
// Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs
217
#ifndef __TFILE__
218
    #define __XFILE__(x) wxT(x)
219
    #define __TFILE__ __XFILE__(__FILE__)
220
#endif
221

    
222
#ifndef __TDATE__
223
    #define __XDATE__(x) wxT(x)
224
    #define __TDATE__ __XDATE__(__DATE__)
225
#endif
226

    
227
#ifndef __TTIME__
228
    #define __XTIME__(x) wxT(x)
229
    #define __TTIME__ __XTIME__(__TIME__)
230
#endif
231

    
232
// ----------------------------------------------------------------------------
233
// define wxFoo() function for each standard foo() function whose signature
234
// (exceptionally including the return type) includes any mention of char:
235
// wxFoo() is going to be a Unicode-friendly version of foo(), i.e. will have
236
// the same signature but with char replaced by wxChar which allows us to use
237
// it in Unicode build as well
238
// ----------------------------------------------------------------------------
239

    
240
#ifdef wxHAVE_TCHAR_SUPPORT
241
    #include <ctype.h>
242

    
243
    // ctype.h functions
244
    #define  wxIsalnum   _istalnum
245
    #define  wxIsalpha   _istalpha
246
    #define  wxIsctrl    _istctrl
247
    #define  wxIsdigit   _istdigit
248
    #define  wxIsgraph   _istgraph
249
    #define  wxIslower   _istlower
250
    #define  wxIsprint   _istprint
251
    #define  wxIspunct   _istpunct
252
    #define  wxIsspace   _istspace
253
    #define  wxIsupper   _istupper
254
    #define  wxIsxdigit  _istxdigit
255
    #define  wxTolower   _totlower
256
    #define  wxToupper   _totupper
257

    
258
    // locale.h functons
259
    #define  wxSetlocale _tsetlocale
260

    
261
    // string.h functions
262
    #define  wxStrcat    _tcscat
263
    #define  wxStrchr    _tcschr
264
    #define  wxStrcmp    _tcscmp
265
    #define  wxStrcoll   _tcscoll
266
    #define  wxStrcpy    _tcscpy
267
    #define  wxStrcspn   _tcscspn
268
    #define  wxStrdup    _tcsdup
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_   wxWcslen // wxStrlen_() is used in wxStrlen()
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  wxStrtol    wcstol
388
            #define  wxStrtoul   wcstoul
389
            #define  wxStrxfrm   wcsxfrm
390

    
391
            #define  wxFgetc     fgetwc
392
            #define  wxFgetchar  fgetwchar
393
            #define  wxFgets     fgetws
394
            #define  wxFputc     fputwc
395
            #define  wxFputchar  fputwchar
396
            #define  wxGetc      getwc
397
            #define  wxGetchar   getwchar
398
            #define  wxGets      getws
399
            #define  wxUngetc    ungetwc
400

    
401
            #ifdef HAVE_FPUTWC
402
                #define  wxPutc      wputc
403
                #define  wxPutchar   wputchar
404
                #define  wxPuts      putws
405
                #define  wxFputs     fputws
406
            #else
407
                #define wxNEED_FPUTWC
408

    
409
                #include <stdio.h>
410

    
411
                int wxFputs(const wxChar *ch, FILE *stream);
412
                int wxPutc(wxChar ch, FILE *stream);
413

    
414
                #define wxPuts(ws) wxFputs(ws, stdout)
415
                #define wxPutchar(wch) wxPutc(wch, stdout)
416
            #endif
417

    
418
            // we need %s to %ls conversion for printf and scanf etc
419
            #define wxNEED_PRINTF_CONVERSION
420

    
421
            // glibc doesn't have wide char equivalents of the other stuff so
422
            // use our own versions
423
            #define wxNEED_WX_STDIO_H
424
            #define wxNEED_WX_STDLIB_H
425
            #define wxNEED_WX_TIME_H
426
        #else // !glibc
427
            #error  "Please define wide character functions for your environment"
428
        #endif
429
    #else // ASCII
430
        #include <ctype.h>
431
        #include <string.h>
432

    
433
        // ctype.h functions
434
        #define  wxIsalnum   isalnum
435
        #define  wxIsalpha   isalpha
436
        #define  wxIsctrl    isctrl
437
        #define  wxIsdigit   isdigit
438
        #define  wxIsgraph   isgraph
439
        #define  wxIslower   islower
440
        #define  wxIsprint   isprint
441
        #define  wxIspunct   ispunct
442
        #define  wxIsspace   isspace
443
        #define  wxIsupper   isupper
444
        #define  wxIsxdigit  isxdigit
445
        #define  wxTolower   tolower
446
        #define  wxToupper   toupper
447

    
448
         // locale.h functons
449
        #define  wxSetlocale setlocale
450

    
451
         // string.h functions
452
        #define  wxStrcat    strcat
453
        #define  wxStrchr    strchr
454
        #define  wxStrcmp    strcmp
455
        #define  wxStrcoll   strcoll
456
        #define  wxStrcpy    strcpy
457
        #define  wxStrcspn   strcspn
458
        #if !defined(__MWERKS__) || !defined(__WXMAC__)
459
            #define  wxStrdup    strdup
460
        #endif
461
        // wxStricmp and wxStrnicmp are defined below
462
        #define  wxStrlen_   strlen // used in wxStrlen inline function
463
        #define  wxStrncat   strncat
464
        #define  wxStrncmp   strncmp
465
        #define  wxStrncpy   strncpy
466
        #define  wxStrpbrk   strpbrk
467
        #define  wxStrrchr   strrchr
468
        #define  wxStrspn    strspn
469
        #define  wxStrstr    strstr
470
        #define  wxStrtod    strtod
471
        #ifdef HAVE_STRTOK_R
472
            #define  wxStrtok(str, sep, last)    strtok_r(str, sep, last)
473
        #endif
474
        #define  wxStrtol    strtol
475
        #define  wxStrtoul   strtoul
476
        #define  wxStrxfrm   strxfrm
477

    
478
        // stdio.h functions
479
        #define  wxFopen     fopen
480
        #define  wxFreopen   freopen
481
        #define  wxPerror    perror
482
        #define  wxRemove    remove
483
        #define  wxRename    rename
484
        #define  wxTmpnam    tmpnam
485

    
486
        #define  wxFgetc     fgetc
487
        #define  wxFgetchar  fgetchar
488
        #define  wxFgets     fgets
489
        #define  wxFputc     fputc
490
        #define  wxFputchar  fputchar
491
        #define  wxFprintf   fprintf
492
        #define  wxFscanf    fscanf
493
        #define  wxGetc      getc
494
        #define  wxGetchar   getchar
495
        #define  wxGets      gets
496
        #define  wxPrintf    printf
497
        #define  wxPutc      putc
498
        #define  wxPutchar   putchar
499
        #define  wxPuts      puts
500
        #define  wxScanf     scanf
501
        #define  wxSprintf   sprintf
502
        #define  wxSscanf    sscanf
503
        #define  wxUngetc    ungetc
504
        #define  wxVfprintf  vfprintf
505
        #define  wxVprintf   vprintf
506
        #define  wxVsscanf   vsscanf
507
        #define  wxVsprintf  vsprintf
508

    
509
        // stdlib.h functions
510
        #define  wxAtof      atof
511
        #define  wxAtoi      atoi
512
        #define  wxAtol      atol
513
        #define  wxGetenv    getenv
514
        #define  wxSystem    system
515

    
516
        // time.h functions
517
        #define  wxAsctime   asctime
518
        #define  wxCtime     ctime
519
        #define  wxStrftime  strftime
520
    #endif // Unicode/ASCII
521
#endif // TCHAR-aware compilers/the others
522

    
523
// ----------------------------------------------------------------------------
524
// various special cases
525
// ----------------------------------------------------------------------------
526

    
527
// define wxStricmp and wxStrnicmp for various compilers
528
//
529
// note that in Unicode mode we definitely are going to need our own version
530
#if !defined(wxStricmp) && !wxUSE_UNICODE
531
    #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
532
            defined(__SALFORDC__) || defined(__VISAGECPP__) || \
533
            defined(__EMX__) || defined(__DJGPP__)
534
        #define wxStricmp stricmp
535
        #define wxStrnicmp strnicmp
536
    #elif defined(__SC__) || defined(__VISUALC__) || \
537
            (defined(__MWERKS__) && defined(__INTEL__))
538
        #define wxStricmp _stricmp
539
        #define wxStrnicmp _strnicmp
540
    #elif defined(__UNIX__) || defined(__GNUWIN32__)
541
        #define wxStricmp strcasecmp
542
        #define wxStrnicmp strncasecmp
543
    // #else -- use wxWindows implementation
544
    #endif
545
#endif // !defined(wxStricmp)
546

    
547
// define wxWcslen() which should be always available if wxUSE_WCHAR_T == 1 (as
548
// it's used in wx/buffer.h -- and also might be used just below by wxStrlen()
549
// when wxStrlen_() is #define'd as wxWcslen so do it before defining wxStrlen)
550
#if wxUSE_WCHAR_T
551
    #ifdef HAVE_WCSLEN
552
        #define wxWcslen wcslen
553
    #else
554
        inline size_t wxWcslen(const wchar_t *s)
555
        {
556
            size_t n = 0;
557
            while ( *s++ )
558
                n++;
559

    
560
            return n;
561
        }
562
    #endif
563
#endif // wxUSE_WCHAR_T
564

    
565
// checks whether the passed in pointer is NULL and if the string is empty
566
inline bool wxIsEmpty(const wxChar *p) { return !p || !*p; }
567

    
568
// safe version of strlen() (returns 0 if passed NULL pointer)
569
inline size_t wxStrlen(const wxChar *psz) { return psz ? wxStrlen_(psz) : 0; }
570

    
571
WXDLLEXPORT bool wxOKlibc(); // for internal use
572

    
573
// ----------------------------------------------------------------------------
574
// printf() family saga
575
// ----------------------------------------------------------------------------
576

    
577
/*
578
   First of all, we always want to define safe snprintf() function to be used
579
   instead of sprintf(). Some compilers already have it (or rather vsnprintf()
580
   which we really need...), otherwise we implement it using our own printf()
581
   code.
582

583
   We define function with a trailing underscore here because the real one is a
584
   wrapper around it as explained below
585
 */
586
#ifndef wxVsnprintf_
587
    #if wxUSE_UNICODE
588
        #if defined(HAVE__VSNWPRINTF)
589
            #define wxVsnprintf_    _vsnwprintf
590
        /* MinGW?MSVCRT has the wrong vswprintf */
591
        #elif defined(HAVE_VSWPRINTF) && !defined(__MINGW32__)
592
            #define wxVsnprintf_    vswprintf
593
        #endif
594
    #else // ASCII
595
        // all versions of CodeWarrior supported by wxWindows apparently have
596
        // vsnprintf()
597
        #if defined(HAVE_VSNPRINTF) || defined(__MWERKS__)
598
            // assume we have snprintf() too if we have vsnprintf()
599
            #define wxVsnprintf_    vsnprintf
600
            #define wxSnprintf_     snprintf
601
        #endif
602
    #endif
603
#endif // wxVsnprintf_ not defined yet
604

    
605
#ifndef wxSnprintf_
606
    // no [v]snprintf(), cook our own
607
    WXDLLEXPORT int wxSnprintf_(wxChar *buf, size_t len, const wxChar *format,
608
                                ...) ATTRIBUTE_PRINTF_3;
609
#endif
610
#ifndef wxVsnprintf_
611
    WXDLLEXPORT int wxVsnprintf_(wxChar *buf, size_t len, const wxChar *format,
612
                                 va_list argptr);
613
#endif
614

    
615
/*
616
   In Unicode mode we need to have all standard functions such as wprintf() and
617
   so on but not all systems have them so use our own implementations in this
618
   case.
619
 */
620
#if wxUSE_UNICODE && !defined(wxHAVE_TCHAR_SUPPORT) && !defined(HAVE_WPRINTF)
621
    #define wxNEED_WPRINTF
622
#endif
623

    
624
/*
625
   More Unicode complications: although both ANSI C and C++ define a number of
626
   wide character functions such as wprintf(), not all environments have them.
627
   Worse, those which do have different behaviours: under Windows, %s format
628
   specifier changes its meaning in Unicode build and expects a Unicode string
629
   while under Unix/POSIX it still means an ASCII string even for wprintf() and
630
   %ls has to be used for wide strings.
631

632
   We choose to always emulate Windows behaviour as more useful for us so even
633
   if we have wprintf() we still must wrap it in a non trivial wxPrintf().
634

635
   However, if we don't have any vswprintf() at all we don't need to redefine
636
   anything as our own wxVsnprintf_() already behaves as needed.
637
*/
638
#ifndef wxVsnprintf_
639
    #undef wxNEED_PRINTF_CONVERSION
640
#endif
641

    
642
#if defined(wxNEED_PRINTF_CONVERSION) || defined(wxNEED_WPRINTF)
643
    // we need to implement all wide character printf and scanf functions
644
    // either because we don't have them at all or because they don't have the
645
    // semantics we need
646

    
647
    #include <stdio.h>  // for FILE
648

    
649
    int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
650
    int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
651
    int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
652
    int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap );
653
    int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_1;
654
    int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
655
    int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_2;
656
    int wxVfprintf( FILE *stream, const wxChar *format, va_list ap );
657
    int wxVprintf( const wxChar *format, va_list ap );
658
    int wxVsprintf( wxChar *str, const wxChar *format, va_list ap );
659
#endif // wxNEED_PRINTF_CONVERSION
660

    
661
// these 2 can be simply mapped to the versions with underscore at the end
662
// if we don't have to do the conversion
663
#ifdef wxNEED_PRINTF_CONVERSION
664
    int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3;
665
    int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap );
666
#else
667
    #define wxSnprintf wxSnprintf_
668
    #define wxVsnprintf wxVsnprintf_
669
#endif
670

    
671
// ----------------------------------------------------------------------------
672
// various functions which might not be available in libc and for which we
673
// provide our own replacements in wxchar.cpp
674
// ----------------------------------------------------------------------------
675

    
676
// ctype.h functions
677
//
678
// VZ: note that this is never defined currently
679
#ifdef wxNEED_WX_CTYPE_H
680
    WXDLLEXPORT int wxIsalnum(wxChar ch);
681
    WXDLLEXPORT int wxIsalpha(wxChar ch);
682
    WXDLLEXPORT int wxIsctrl(wxChar ch);
683
    WXDLLEXPORT int wxIsdigit(wxChar ch);
684
    WXDLLEXPORT int wxIsgraph(wxChar ch);
685
    WXDLLEXPORT int wxIslower(wxChar ch);
686
    WXDLLEXPORT int wxIsprint(wxChar ch);
687
    WXDLLEXPORT int wxIspunct(wxChar ch);
688
    WXDLLEXPORT int wxIsspace(wxChar ch);
689
    WXDLLEXPORT int wxIsupper(wxChar ch);
690
    WXDLLEXPORT int wxIsxdigit(wxChar ch);
691
    WXDLLEXPORT int wxTolower(wxChar ch);
692
    WXDLLEXPORT int wxToupper(wxChar ch);
693
#endif // wxNEED_WX_CTYPE_H
694

    
695
// under VC++ 6.0 isspace() returns 1 for 8 bit chars which completely breaks
696
// the file parsing -- this may be true for 5.0 as well, update #ifdef then
697
#if defined(__VISUALC__) && (__VISUALC__ >= 1200) && !wxUSE_UNICODE
698
    #undef wxIsspace
699
    #define wxIsspace(c) ((((unsigned)c) < 128) && isspace(c))
700
#endif // VC++
701

    
702

    
703
// string.h functions
704
//
705
// VZ: this is never defined neither currently
706
#ifdef wxNEED_WX_STRING_H
707
    WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
708
    WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
709
    WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
710
        { return (wxChar *)wxStrchr((const wxChar *)s, c); }
711
    WXDLLEXPORT int      wxStrcmp(const wxChar *s1, const wxChar *s2);
712
    WXDLLEXPORT int      wxStrcoll(const wxChar *s1, const wxChar *s2);
713
    WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
714
    WXDLLEXPORT size_t   wxStrcspn(const wxChar *s, const wxChar *reject);
715
    WXDLLEXPORT size_t   wxStrlen(const wxChar *s);
716
    WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
717
    WXDLLEXPORT int      wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
718
    WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
719
    WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
720
    WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
721
        { return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
722
    WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
723
    WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
724
        { return (wxChar *)wxStrrchr((const wxChar *)s, c); }
725
    WXDLLEXPORT size_t   wxStrspn(const wxChar *s, const wxChar *accept);
726
    WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
727
    WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
728
        { return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
729
    WXDLLEXPORT double   wxStrtod(const wxChar *nptr, wxChar **endptr);
730
    WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
731
    WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
732
    WXDLLEXPORT size_t   wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
733
#endif // wxNEED_WX_STRING_H
734

    
735
#ifndef wxStrdup
736
WXDLLEXPORT wxChar * wxStrdup(const wxChar *psz);
737
#endif
738

    
739
#ifndef wxStricmp
740
WXDLLEXPORT int wxStricmp(const wxChar *psz1, const wxChar *psz2);
741
#endif
742

    
743
#ifndef wxStrnicmp
744
WXDLLEXPORT int wxStrnicmp(const wxChar *psz1, const wxChar *psz2, size_t len);
745
#endif
746

    
747
#ifndef wxStrtok
748
WXDLLEXPORT wxChar * wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
749
#endif
750

    
751
#ifndef wxSetlocale
752
class WXDLLEXPORT wxWCharBuffer;
753
WXDLLEXPORT wxWCharBuffer wxSetlocale(int category, const wxChar *locale);
754
#endif
755

    
756
// stdio.h functions
757
#ifdef wxNEED_WX_STDIO_H
758
    #include <stdio.h>
759
    WXDLLEXPORT FILE *   wxFopen(const wxChar *path, const wxChar *mode);
760
    WXDLLEXPORT FILE *   wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
761
    WXDLLEXPORT int      wxRemove(const wxChar *path);
762
    WXDLLEXPORT int      wxRename(const wxChar *oldpath, const wxChar *newpath);
763

    
764
    // *printf() family is handled separately
765
#endif // wxNEED_WX_STDIO_H
766

    
767

    
768
// stdlib.h functions
769
#ifndef wxAtof
770
WXDLLEXPORT double   wxAtof(const wxChar *psz);
771
#endif
772

    
773
#ifdef wxNEED_WX_STDLIB_H
774
WXDLLEXPORT int      wxAtoi(const wxChar *psz);
775
WXDLLEXPORT long     wxAtol(const wxChar *psz);
776
WXDLLEXPORT wxChar * wxGetenv(const wxChar *name);
777
WXDLLEXPORT int      wxSystem(const wxChar *psz);
778
#endif
779

    
780

    
781
// time.h functions
782
#ifdef wxNEED_WX_TIME_H
783
    WXDLLEXPORT size_t wxStrftime(wxChar *s, size_t max,
784
                                  const wxChar *fmt, const struct tm *tm);
785
#endif // wxNEED_WX_TIME_H
786

    
787
// ----------------------------------------------------------------------------
788
// multibyte to wide char conversion functions and macros
789
// ----------------------------------------------------------------------------
790

    
791
#if wxUSE_WCHAR_T
792
    // multibyte<->widechar conversion
793
    WXDLLEXPORT size_t wxMB2WC(wchar_t *buf, const char *psz, size_t n);
794
    WXDLLEXPORT size_t wxWC2MB(char *buf, const wchar_t *psz, size_t n);
795

    
796
    #if wxUSE_UNICODE
797
        #define wxMB2WX wxMB2WC
798
        #define wxWX2MB wxWC2MB
799
        #define wxWC2WX wxStrncpy
800
        #define wxWX2WC wxStrncpy
801
    #else
802
        #define wxMB2WX wxStrncpy
803
        #define wxWX2MB wxStrncpy
804
        #define wxWC2WX wxWC2MB
805
        #define wxWX2WC wxMB2WC
806
    #endif
807
#else // !wxUSE_UNICODE
808
    // No wxUSE_WCHAR_T: we have to do something (JACS)
809
    #define wxMB2WC wxStrncpy
810
    #define wxWC2MB wxStrncpy
811
    #define wxMB2WX wxStrncpy
812
    #define wxWX2MB wxStrncpy
813
    #define wxWC2WX wxWC2MB
814
    #define wxWX2WC wxMB2WC
815
#endif
816

    
817
#endif //_WX_WXCHAR_H_
818