Subversion Repositories Kolibri OS

Rev

Rev 5192 | Rev 6330 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
#ifndef _CTYPE_H_
2
#define _CTYPE_H_
3
 
4
#include "_ansi.h"
5
 
6
_BEGIN_STD_C
7
 
8
int _EXFUN(isalnum, (int __c));
9
int _EXFUN(isalpha, (int __c));
10
int _EXFUN(iscntrl, (int __c));
11
int _EXFUN(isdigit, (int __c));
12
int _EXFUN(isgraph, (int __c));
13
int _EXFUN(islower, (int __c));
14
int _EXFUN(isprint, (int __c));
15
int _EXFUN(ispunct, (int __c));
16
int _EXFUN(isspace, (int __c));
17
int _EXFUN(isupper, (int __c));
18
int _EXFUN(isxdigit,(int __c));
19
int _EXFUN(tolower, (int __c));
20
int _EXFUN(toupper, (int __c));
21
 
22
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
23
int _EXFUN(isblank, (int __c));
24
#endif
25
 
26
#ifndef __STRICT_ANSI__
27
int _EXFUN(isascii, (int __c));
28
int _EXFUN(toascii, (int __c));
29
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
30
#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
31
#endif
32
 
33
#define	_U	01
34
#define	_L	02
35
#define	_N	04
36
#define	_S	010
37
#define _P	020
38
#define _C	040
39
#define _X	0100
40
#define	_B	0200
41
 
42
#ifndef _MB_CAPABLE
43
_CONST
44
#endif
6099 serge 45
extern	__IMPORT char	*__ctype_ptr__;
4349 Serge 46
 
47
#ifndef __cplusplus
48
/* These macros are intentionally written in a manner that will trigger
49
   a gcc -Wall warning if the user mistakenly passes a 'char' instead
50
   of an int containing an 'unsigned char'.  Note that the sizeof will
51
   always be 1, which is what we want for mapping EOF to __ctype_ptr__[0];
52
   the use of a raw index inside the sizeof triggers the gcc warning if
53
   __c was of type char, and sizeof masks side effects of the extra __c.
54
   Meanwhile, the real index to __ctype_ptr__+1 must be cast to int,
55
   since isalpha(0x100000001LL) must equal isalpha(1), rather than being
56
   an out-of-bounds reference on a 64-bit machine.  */
57
#define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)(__c)])
58
 
59
#define	isalpha(__c)	(__ctype_lookup(__c)&(_U|_L))
60
#define	isupper(__c)	((__ctype_lookup(__c)&(_U|_L))==_U)
61
#define	islower(__c)	((__ctype_lookup(__c)&(_U|_L))==_L)
62
#define	isdigit(__c)	(__ctype_lookup(__c)&_N)
63
#define	isxdigit(__c)	(__ctype_lookup(__c)&(_X|_N))
64
#define	isspace(__c)	(__ctype_lookup(__c)&_S)
65
#define ispunct(__c)	(__ctype_lookup(__c)&_P)
66
#define isalnum(__c)	(__ctype_lookup(__c)&(_U|_L|_N))
67
#define isprint(__c)	(__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
68
#define	isgraph(__c)	(__ctype_lookup(__c)&(_P|_U|_L|_N))
69
#define iscntrl(__c)	(__ctype_lookup(__c)&_C)
70
 
71
#if defined(__GNUC__) && \
72
    (!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
73
#define isblank(__c) \
74
  __extension__ ({ __typeof__ (__c) __x = (__c);		\
75
        (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
76
#endif
77
 
78
 
79
/* Non-gcc versions will get the library versions, and will be
80
   slightly slower.  These macros are not NLS-aware so they are
81
   disabled if the system supports the extended character sets. */
82
# if defined(__GNUC__)
83
#  if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
84
#   define toupper(__c) \
85
  __extension__ ({ __typeof__ (__c) __x = (__c);	\
86
      islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
87
#   define tolower(__c) \
88
  __extension__ ({ __typeof__ (__c) __x = (__c);	\
89
      isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
90
#  else /* _MB_EXTENDED_CHARSETS* */
91
/* Allow a gcc warning if the user passed 'char', but defer to the
92
   function.  */
93
#   define toupper(__c) \
94
  __extension__ ({ __typeof__ (__c) __x = (__c);	\
95
      (void) __ctype_ptr__[__x]; (toupper) (__x);})
96
#   define tolower(__c) \
97
  __extension__ ({ __typeof__ (__c) __x = (__c);	\
98
      (void) __ctype_ptr__[__x]; (tolower) (__x);})
99
#  endif /* _MB_EXTENDED_CHARSETS* */
100
# endif /* __GNUC__ */
101
#endif /* !__cplusplus */
102
 
103
#ifndef __STRICT_ANSI__
104
#define isascii(__c)	((unsigned)(__c)<=0177)
105
#define toascii(__c)	((__c)&0177)
106
#endif
107
 
108
/* For C++ backward-compatibility only.  */
109
extern	__IMPORT _CONST char	_ctype_[];
110
 
111
_END_STD_C
112
 
113
#endif /* _CTYPE_H_ */