]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/bits/uClibc_ctype.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / bits / uClibc_ctype.h
1 /*  Copyright (C) 2002     Manuel Novoa III
2  *
3  *  This library is free software; you can redistribute it and/or
4  *  modify it under the terms of the GNU Lesser General Public
5  *  License as published by the Free Software Foundation; either
6  *  version 2.1 of the License, or (at your option) any later version.
7  *
8  *  The GNU C Library is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *  Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with the GNU C Library; see the file COPYING.LIB.  If
15  *  not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!
19  *
20  *  Besides uClibc, I'm using this code in my libc for elks, which is
21  *  a 16-bit environment with a fairly limited compiler.  It would make
22  *  things much easier for me if this file isn't modified unnecessarily.
23  *  In particular, please put any new or replacement functions somewhere
24  *  else, and modify the makefile to use your version instead.
25  *  Thanks.  Manuel
26  *
27  *  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION! */
28
29 #if !defined(_CTYPE_H) && !defined(_WCTYPE_H)
30 #error Always include <{w}ctype.h> rather than <bits/uClibc_ctype.h>
31 #endif
32
33 #ifndef _BITS_UCLIBC_CTYPE_H
34 #define _BITS_UCLIBC_CTYPE_H
35
36 #ifdef __UCLIBC_GEN_LOCALE
37 /* We are in extra/locale/gen_XXX tools build */
38
39 #include "uClibc_charclass.h"
40
41 #else
42
43 /* Define some ctype macros valid for the C/POSIX locale. */
44
45 /* ASCII ords of \t, \f, \n, \r, and \v are 9, 12, 10, 13, 11 respectively. */
46 #define __C_isspace(c) \
47         ((sizeof(c) == sizeof(char)) \
48          ? ((((c) == ' ') || (((unsigned char)((c) - 9)) <= (13 - 9)))) \
49          : ((((c) == ' ') || (((unsigned int)((c) - 9)) <= (13 - 9)))))
50 #define __C_isblank(c) (((c) == ' ') || ((c) == '\t'))
51 #define __C_isdigit(c) \
52         ((sizeof(c) == sizeof(char)) \
53          ? (((unsigned char)((c) - '0')) < 10) \
54          : (((unsigned int)((c) - '0')) < 10))
55 #define __C_isxdigit(c) \
56         (__C_isdigit(c) \
57          || ((sizeof(c) == sizeof(char)) \
58                  ? (((unsigned char)((((c)) | 0x20) - 'a')) < 6) \
59                  : (((unsigned int)((((c)) | 0x20) - 'a')) < 6)))
60 #define __C_iscntrl(c) \
61         ((sizeof(c) == sizeof(char)) \
62          ? ((((unsigned char)(c)) < 0x20) || ((c) == 0x7f)) \
63          : ((((unsigned int)(c)) < 0x20) || ((c) == 0x7f)))
64 #define __C_isalpha(c) \
65         ((sizeof(c) == sizeof(char)) \
66          ? (((unsigned char)(((c) | 0x20) - 'a')) < 26) \
67          : (((unsigned int)(((c) | 0x20) - 'a')) < 26))
68 #define __C_isalnum(c) (__C_isalpha(c) || __C_isdigit(c))
69 #define __C_isprint(c) \
70         ((sizeof(c) == sizeof(char)) \
71          ? (((unsigned char)((c) - 0x20)) <= (0x7e - 0x20)) \
72          : (((unsigned int)((c) - 0x20)) <= (0x7e - 0x20)))
73 #define __C_islower(c) \
74         ((sizeof(c) == sizeof(char)) \
75          ? (((unsigned char)((c) - 'a')) < 26) \
76          : (((unsigned int)((c) - 'a')) < 26))
77 #define __C_isupper(c) \
78         ((sizeof(c) == sizeof(char)) \
79          ? (((unsigned char)((c) - 'A')) < 26) \
80          : (((unsigned int)((c) - 'A')) < 26))
81 #define __C_ispunct(c) \
82         ((!__C_isalnum(c)) \
83          && ((sizeof(c) == sizeof(char)) \
84                  ? (((unsigned char)((c) - 0x21)) <= (0x7e - 0x21)) \
85                  : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21))))
86 #define __C_isgraph(c) \
87         ((sizeof(c) == sizeof(char)) \
88          ? (((unsigned char)((c) - 0x21)) <= (0x7e - 0x21)) \
89          : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21)))
90
91 #define __C_tolower(c) (__C_isupper(c) ? ((c) | 0x20) : (c))
92 #define __C_toupper(c) (__C_islower(c) ? ((c) ^ 0x20) : (c))
93
94 /**********************************************************************/
95 __BEGIN_DECLS
96
97 #ifdef _LIBC
98 /* These are uClibc-specific. */
99 # define __isdigit_char(c) ((unsigned char)((c) - '0') <= 9)
100 # define __isdigit_int(c)  ((unsigned int)((c) - '0') <= 9)
101 #endif
102
103 /* Now some non-ansi/iso c99 macros. */
104
105 #ifdef __UCLIBC_SUSV4_LEGACY__
106 #define __isascii(c) (((c) & ~0x7f) == 0)
107 #define __toascii(c) ((c) & 0x7f)
108 /* Works correctly *only* on lowercase letters! */
109 #define _toupper(c) ((c) ^ 0x20)
110 /* Works correctly *only* on letters (of any case) and numbers */
111 #define _tolower(c) ((c) | 0x20)
112 #endif
113
114 __END_DECLS
115
116 /**********************************************************************/
117 #ifdef __GNUC__
118
119 # define __body_C_macro(f,args)  __C_ ## f args
120
121 # define __body(f,c) \
122 (__extension__ ({ \
123         int __res; \
124         if (sizeof(c) > sizeof(char)) { \
125                 int __c = (c); \
126                 __res = __body_C_macro(f,(__c)); \
127         } else { \
128                 unsigned char __c = (c); \
129                 __res = __body_C_macro(f,(__c)); \
130         } \
131         __res; \
132 }))
133
134 # define __isspace(c)   __body(isspace,c)
135 # define __isblank(c)   __body(isblank,c)
136 # define __isdigit(c)   __body(isdigit,c)
137 # define __isxdigit(c)  __body(isxdigit,c)
138 # define __iscntrl(c)   __body(iscntrl,c)
139 # define __isalpha(c)   __body(isalpha,c)
140 # define __isalnum(c)   __body(isalnum,c)
141 # define __isprint(c)   __body(isprint,c)
142 # define __islower(c)   __body(islower,c)
143 # define __isupper(c)   __body(isupper,c)
144 # define __ispunct(c)   __body(ispunct,c)
145 # define __isgraph(c)   __body(isgraph,c)
146
147 /*locale-aware ctype.h has no __tolower, why stub locale
148  *tries to have it? remove after 0.9.31
149  *# define __tolower(c) __body(tolower,c)
150  *# define __toupper(c) __body(toupper,c)
151  */
152
153 /* Do not combine in one #if - unifdef tool is not that clever */
154 # ifndef __NO_CTYPE
155 # ifndef __cplusplus
156
157 #  define isspace(c)    __isspace(c)
158 #  define isblank(c)    __isblank(c)
159 #  define isdigit(c)    __isdigit(c)
160 #  define isxdigit(c)   __isxdigit(c)
161 #  define iscntrl(c)    __iscntrl(c)
162 #  define isalpha(c)    __isalpha(c)
163 #  define isalnum(c)    __isalnum(c)
164 #  define isprint(c)    __isprint(c)
165 #  define islower(c)    __islower(c)
166 #  define isupper(c)    __isupper(c)
167 #  define ispunct(c)    __ispunct(c)
168 #  define isgraph(c)    __isgraph(c)
169
170 #  define tolower(c)    __body(tolower,c)
171 #  define toupper(c)    __body(toupper,c)
172
173 # endif
174 # endif
175
176 #else  /* !_GNUC__ */
177
178 # ifndef __NO_CTYPE
179 # ifndef __cplusplus
180
181 /* These macros should be safe from side effects!
182  * (not all __C_xxx macros are) */
183 #  define isdigit(c)    __C_isdigit(c)
184 #  define isalpha(c)    __C_isalpha(c)
185 #  define isprint(c)    __C_isprint(c)
186 #  define islower(c)    __C_islower(c)
187 #  define isupper(c)    __C_isupper(c)
188 #  define isgraph(c)    __C_isgraph(c)
189
190 # endif
191 # endif
192
193 #endif /* __GNUC__ */
194 /**********************************************************************/
195
196 #endif  /* __UCLIBC_GEN_LOCALE */
197
198 #endif /* _BITS_UCLIBC_CTYPE_H */