source: trunk/libs/newlib/src/newlib/libc/include/ctype.h @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 5.7 KB
Line 
1#ifndef _CTYPE_H_
2#define _CTYPE_H_
3
4#include "_ansi.h"
5#include <sys/cdefs.h>
6
7#if __POSIX_VISIBLE >= 200809 || __MISC_VISIBLE || defined (_COMPILING_NEWLIB)
8#include <xlocale.h>
9#endif
10
11_BEGIN_STD_C
12
13int isalnum (int __c);
14int isalpha (int __c);
15int iscntrl (int __c);
16int isdigit (int __c);
17int isgraph (int __c);
18int islower (int __c);
19int isprint (int __c);
20int ispunct (int __c);
21int isspace (int __c);
22int isupper (int __c);
23int isxdigit (int __c);
24int tolower (int __c);
25int toupper (int __c);
26
27#if __ISO_C_VISIBLE >= 1999
28int isblank (int __c);
29#endif
30
31#if __MISC_VISIBLE || __XSI_VISIBLE
32int isascii (int __c);
33int toascii (int __c);
34#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
35#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
36#endif
37
38#if __POSIX_VISIBLE >= 200809
39extern int isalnum_l (int __c, locale_t __l);
40extern int isalpha_l (int __c, locale_t __l);
41extern int isblank_l (int __c, locale_t __l);
42extern int iscntrl_l (int __c, locale_t __l);
43extern int isdigit_l (int __c, locale_t __l);
44extern int isgraph_l (int __c, locale_t __l);
45extern int islower_l (int __c, locale_t __l);
46extern int isprint_l (int __c, locale_t __l);
47extern int ispunct_l (int __c, locale_t __l);
48extern int isspace_l (int __c, locale_t __l);
49extern int isupper_l (int __c, locale_t __l);
50extern int isxdigit_l(int __c, locale_t __l);
51extern int tolower_l (int __c, locale_t __l);
52extern int toupper_l (int __c, locale_t __l);
53#endif
54
55#if __MISC_VISIBLE
56extern int isascii_l (int __c, locale_t __l);
57extern int toascii_l (int __c, locale_t __l);
58#endif
59
60#define _U      01
61#define _L      02
62#define _N      04
63#define _S      010
64#define _P      020
65#define _C      040
66#define _X      0100
67#define _B      0200
68
69const char *__locale_ctype_ptr (void);
70# define __CTYPE_PTR    (__locale_ctype_ptr ())
71
72#ifndef __cplusplus
73/* These macros are intentionally written in a manner that will trigger
74   a gcc -Wall warning if the user mistakenly passes a 'char' instead
75   of an int containing an 'unsigned char'.  Note that the sizeof will
76   always be 1, which is what we want for mapping EOF to __CTYPE_PTR[0];
77   the use of a raw index inside the sizeof triggers the gcc warning if
78   __c was of type char, and sizeof masks side effects of the extra __c.
79   Meanwhile, the real index to __CTYPE_PTR+1 must be cast to int,
80   since isalpha(0x100000001LL) must equal isalpha(1), rather than being
81   an out-of-bounds reference on a 64-bit machine.  */
82#define __ctype_lookup(__c) ((__CTYPE_PTR+sizeof(""[__c]))[(int)(__c)])
83
84#define isalpha(__c)    (__ctype_lookup(__c)&(_U|_L))
85#define isupper(__c)    ((__ctype_lookup(__c)&(_U|_L))==_U)
86#define islower(__c)    ((__ctype_lookup(__c)&(_U|_L))==_L)
87#define isdigit(__c)    (__ctype_lookup(__c)&_N)
88#define isxdigit(__c)   (__ctype_lookup(__c)&(_X|_N))
89#define isspace(__c)    (__ctype_lookup(__c)&_S)
90#define ispunct(__c)    (__ctype_lookup(__c)&_P)
91#define isalnum(__c)    (__ctype_lookup(__c)&(_U|_L|_N))
92#define isprint(__c)    (__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
93#define isgraph(__c)    (__ctype_lookup(__c)&(_P|_U|_L|_N))
94#define iscntrl(__c)    (__ctype_lookup(__c)&_C)
95
96#if defined(__GNUC__) && __ISO_C_VISIBLE >= 1999
97#define isblank(__c) \
98  __extension__ ({ __typeof__ (__c) __x = (__c);                \
99        (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
100#endif
101
102#if __POSIX_VISIBLE >= 200809
103const char *__locale_ctype_ptr_l (locale_t);
104#define __ctype_lookup_l(__c,__l) ((__locale_ctype_ptr_l(__l)+sizeof(""[__c]))[(int)(__c)])
105
106#define isalpha_l(__c,__l)      (__ctype_lookup_l(__c,__l)&(_U|_L))
107#define isupper_l(__c,__l)      ((__ctype_lookup_l(__c,__l)&(_U|_L))==_U)
108#define islower_l(__c,__l)      ((__ctype_lookup_l(__c,__l)&(_U|_L))==_L)
109#define isdigit_l(__c,__l)      (__ctype_lookup_l(__c,__l)&_N)
110#define isxdigit_l(__c,__l)     (__ctype_lookup_l(__c,__l)&(_X|_N))
111#define isspace_l(__c,__l)      (__ctype_lookup_l(__c,__l)&_S)
112#define ispunct_l(__c,__l)      (__ctype_lookup_l(__c,__l)&_P)
113#define isalnum_l(__c,__l)      (__ctype_lookup_l(__c,__l)&(_U|_L|_N))
114#define isprint_l(__c,__l)      (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N|_B))
115#define isgraph_l(__c,__l)      (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N))
116#define iscntrl_l(__c,__l)      (__ctype_lookup_l(__c,__l)&_C)
117
118#if defined(__GNUC__)
119#define isblank_l(__c, __l) \
120  __extension__ ({ __typeof__ (__c) __x = (__c);                \
121        (__ctype_lookup_l(__x,__l)&_B) || (int) (__x) == '\t';})
122#endif
123
124#endif /* __POSIX_VISIBLE >= 200809 */
125
126#if __MISC_VISIBLE || __XSI_VISIBLE
127#define isascii(__c)    ((unsigned)(__c)<=0177)
128#define toascii(__c)    ((__c)&0177)
129#endif
130
131#if __MISC_VISIBLE
132#define isascii_l(__c,__l)      ((__l),(unsigned)(__c)<=0177)
133#define toascii_l(__c,__l)      ((__l),(__c)&0177)
134#endif
135
136/* Non-gcc versions will get the library versions, and will be
137   slightly slower.  These macros are not NLS-aware so they are
138   disabled if the system supports the extended character sets. */
139# if defined(__GNUC__)
140#  if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
141#   define toupper(__c) \
142  __extension__ ({ __typeof__ (__c) __x = (__c);        \
143      islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
144#   define tolower(__c) \
145  __extension__ ({ __typeof__ (__c) __x = (__c);        \
146      isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
147#  else /* _MB_EXTENDED_CHARSETS* */
148/* Allow a gcc warning if the user passed 'char', but defer to the
149   function.  */
150#   define toupper(__c) \
151  __extension__ ({ __typeof__ (__c) __x = (__c);        \
152      (void) __CTYPE_PTR[__x]; (toupper) (__x);})
153#   define tolower(__c) \
154  __extension__ ({ __typeof__ (__c) __x = (__c);        \
155      (void) __CTYPE_PTR[__x]; (tolower) (__x);})
156#  endif /* _MB_EXTENDED_CHARSETS* */
157# endif /* __GNUC__ */
158
159#if __POSIX_VISIBLE >= 200809
160#endif /* __POSIX_VISIBLE >= 200809 */
161
162#endif /* !__cplusplus */
163
164/* For C++ backward-compatibility only.  */
165extern  __IMPORT const char     _ctype_[];
166
167_END_STD_C
168
169#endif /* _CTYPE_H_ */
Note: See TracBrowser for help on using the repository browser.