Fix make rule for generation of "ucontext_i.h" when building in separate directory...
[uclibc-ng.git] / include / ctype.h
blobecd5e730886a4ecb87dda8131d65dafce96b87b4
1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2001,02
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 * ISO C99 Standard 7.4: Character handling <ctype.h>
23 #ifndef _CTYPE_H
24 #define _CTYPE_H 1
26 #include <features.h>
27 #include <bits/types.h>
29 __BEGIN_DECLS
30 __BEGIN_NAMESPACE_STD
32 /* The following names are all functions:
33 int isCHARACTERISTIC(int c);
34 which return nonzero iff C has CHARACTERISTIC.
35 For the meaning of the characteristic names, see the `enum' above. */
36 extern int isalnum(int __c) __THROW;
37 libc_hidden_proto(isalnum)
38 extern int isalpha(int __c) __THROW;
39 libc_hidden_proto(isalpha)
40 extern int iscntrl(int __c) __THROW;
41 libc_hidden_proto(iscntrl)
42 extern int isdigit(int __c) __THROW;
43 libc_hidden_proto(isdigit)
44 extern int islower(int __c) __THROW;
45 libc_hidden_proto(islower)
46 extern int isgraph(int __c) __THROW;
47 libc_hidden_proto(isgraph)
48 extern int isprint(int __c) __THROW;
49 libc_hidden_proto(isprint)
50 extern int ispunct(int __c) __THROW;
51 libc_hidden_proto(ispunct)
52 extern int isspace(int __c) __THROW;
53 libc_hidden_proto(isspace)
54 extern int isupper(int __c) __THROW;
55 libc_hidden_proto(isupper)
56 extern int isxdigit(int __c) __THROW;
57 libc_hidden_proto(isxdigit)
60 /* Return the lowercase version of C. */
61 extern int tolower(int __c) __THROW;
62 libc_hidden_proto(tolower)
64 /* Return the uppercase version of C. */
65 extern int toupper(int __c) __THROW;
66 libc_hidden_proto(toupper)
68 #if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) && \
69 defined __UCLIBC_SUSV4_LEGACY__
70 /* Return nonzero iff C is in the ASCII set
71 (i.e., is no more than 7 bits wide). */
72 extern int isascii(int __c) __THROW;
73 libc_hidden_proto(isascii)
74 /* Return the part of C that is in the ASCII set
75 (i.e., the low-order 7 bits of C). */
76 extern int toascii(int __c) __THROW;
77 #endif
79 __END_NAMESPACE_STD
82 /* ISO C99 introduced one new function. */
83 #ifdef __USE_ISOC99
84 __BEGIN_NAMESPACE_C99
86 extern int isblank(int __c) __THROW;
87 libc_hidden_proto(isblank)
89 __END_NAMESPACE_C99
90 #endif
91 __END_DECLS
93 #ifndef __UCLIBC_HAS_CTYPE_TABLES__
95 /* "Stub locale": we are permanently in C/POSIX locale.
96 * Using simple(r) ctype.h machinery in this header instead: */
97 #include <bits/uClibc_ctype.h>
99 #else
101 __BEGIN_DECLS
103 #ifndef _ISbit
104 /* These are all the characteristics of characters.
105 If there get to be more than 16 distinct characteristics,
106 __ctype_mask_t will need to be adjusted. */
108 /* libstdc++ from gcc toolchain needs this macro. */
109 # define _ISbit(bit) (1 << (bit))
111 enum
113 _ISupper = _ISbit (0), /* UPPERCASE. */
114 _ISlower = _ISbit (1), /* lowercase. */
115 _ISalpha = _ISbit (2), /* Alphabetic. */
116 _ISdigit = _ISbit (3), /* Numeric. */
117 _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
118 _ISspace = _ISbit (5), /* Whitespace. */
119 _ISprint = _ISbit (6), /* Printing. */
120 _ISgraph = _ISbit (7), /* Graphical. */
121 _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
122 _IScntrl = _ISbit (9), /* Control character. */
123 _ISpunct = _ISbit (10), /* Punctuation. */
124 _ISalnum = _ISbit (11) /* Alphanumeric. */
126 #else
127 #error _ISbit already defined!
128 #endif /* ! _ISbit */
130 /* __ctype_XXX_t types and __UCLIBC_CTYPE_x_TBL_OFFSET constants */
131 #include <bits/uClibc_touplow.h>
133 #ifdef __UCLIBC_HAS_CTYPE_SIGNED__
134 # define __UCLIBC_CTYPE_IN_TO_DOMAIN(c) (((unsigned int)((c) + 128)) < 384)
135 #else
136 # define __UCLIBC_CTYPE_IN_TO_DOMAIN(c) (((unsigned int)(c)) < 256)
137 #endif
139 /* In the thread-specific locale model (see `uselocale' in <locale.h>)
140 we cannot use global variables for these as was done in the past.
141 Instead, the following accessor functions return the address of
142 each variable, which is local to the current thread if multithreaded.
144 These point into arrays of 384, so they can be indexed by any `unsigned
145 char' value [0,255]; by EOF (-1); or by any `signed char' value
146 [-128,-1). ISO C requires that the ctype functions work for `unsigned
147 char' values and for EOF; we also support negative `signed char' values
148 for broken old programs. The case conversion arrays are of `int's
149 rather than `unsigned char's because tolower (EOF) must be EOF, which
150 doesn't fit into an `unsigned char'. But today more important is that
151 the arrays are also used for multi-byte character sets. */
153 /* uClibc differences:
155 * When __UCLIBC_HAS_CTYPE_SIGNED is defined,
157 * The upper and lower mapping arrays are type int16_t, so that
158 * they may store all char values plus EOF. The glibc reasoning
159 * given above for these being type int is questionable, as the
160 * ctype mapping functions map from the set of (unsigned) char
161 * and EOF back into the set. They have no awareness of multi-byte
162 * or wide characters.
164 * Otherwise,
166 * The ctype array is defined for -1..255.
167 * The upper and lower mapping arrays are defined for 0..255.
168 * The upper and lower mapping arrays are type unsigned char.
171 /* Pointers to the default C-locale data. */
172 extern const __ctype_mask_t *__C_ctype_b;
173 libc_hidden_proto(__C_ctype_b)
174 extern const __ctype_touplow_t *__C_ctype_toupper;
175 libc_hidden_proto(__C_ctype_toupper)
176 extern const __ctype_touplow_t *__C_ctype_tolower;
177 libc_hidden_proto(__C_ctype_tolower)
179 #ifdef __UCLIBC_HAS_XLOCALE__
181 const __ctype_mask_t **__ctype_b_loc(void) __attribute__ ((const));
182 libc_hidden_proto(__ctype_b_loc)
183 const __ctype_touplow_t **__ctype_tolower_loc(void) __attribute__ ((const));
184 libc_hidden_proto(__ctype_tolower_loc)
185 const __ctype_touplow_t **__ctype_toupper_loc(void) __attribute__ ((const));
186 libc_hidden_proto(__ctype_toupper_loc)
187 #define __UCLIBC_CTYPE_B (*__ctype_b_loc())
188 #define __UCLIBC_CTYPE_TOLOWER (*__ctype_tolower_loc())
189 #define __UCLIBC_CTYPE_TOUPPER (*__ctype_toupper_loc())
191 #else /* __UCLIBC_HAS_XLOCALE__ */
193 /* Pointers to the current global locale data in use. */
194 extern const __ctype_mask_t *__ctype_b;
195 libc_hidden_proto(__ctype_b)
196 extern const __ctype_touplow_t *__ctype_toupper;
197 libc_hidden_proto(__ctype_toupper)
198 extern const __ctype_touplow_t *__ctype_tolower;
199 libc_hidden_proto(__ctype_tolower)
200 #define __UCLIBC_CTYPE_B (__ctype_b)
201 #define __UCLIBC_CTYPE_TOLOWER (__ctype_tolower)
202 #define __UCLIBC_CTYPE_TOUPPER (__ctype_toupper)
204 #endif /* __UCLIBC_HAS_XLOCALE__ */
206 #ifdef __UCLIBC_SUSV4_LEGACY__
207 #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
208 #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
209 #endif
211 #ifdef _LIBC
212 /* These are uClibc-specific. */
213 #define __isdigit_char(C) (((unsigned char)((C) - '0')) <= 9)
214 #define __isdigit_int(C) (((unsigned int)((C) - '0')) <= 9)
215 #endif
217 #ifdef __USE_GNU
218 /* Test C for a set of character classes according to MASK. */
219 extern int isctype(int __c, int __mask) __THROW;
220 #endif
222 #if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
223 && defined __UCLIBC_SUSV4_LEGACY__
224 /* These are the same as `toupper' and `tolower' except that they do not
225 check the argument for being in the range of a `char'. */
226 extern int _toupper(int __c) __THROW;
227 extern int _tolower(int __c) __THROW;
228 #endif /* Use SVID or use misc. */
230 /* This code is needed for the optimized mapping functions. */
231 #define __tobody(c, f, table, args) \
232 (__extension__ ({ \
233 int __res; \
234 if (sizeof(c) > 1) { \
235 if (__builtin_constant_p(c)) { \
236 int __c = (c); \
237 __res = __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (table)[__c] : __c; \
238 } else \
239 __res = f args; \
240 } else \
241 __res = (table)[(int) (c)]; \
242 __res; \
245 #define __isctype(c, type) ((__UCLIBC_CTYPE_B)[(int)(c)] & (__ctype_mask_t)type)
246 /* Do not combine in one #if - unifdef tool is not that clever */
247 #ifndef __NO_CTYPE
248 #ifndef __cplusplus
249 # define isalnum(c) __isctype((c), _ISalnum)
250 # define isalpha(c) __isctype((c), _ISalpha)
251 # define iscntrl(c) __isctype((c), _IScntrl)
252 # define isdigit(c) __isctype((c), _ISdigit)
253 # define islower(c) __isctype((c), _ISlower)
254 # define isgraph(c) __isctype((c), _ISgraph)
255 # define isprint(c) __isctype((c), _ISprint)
256 # define ispunct(c) __isctype((c), _ISpunct)
257 # define isspace(c) __isctype((c), _ISspace)
258 # define isupper(c) __isctype((c), _ISupper)
259 # define isxdigit(c) __isctype((c), _ISxdigit)
260 # ifdef __USE_ISOC99
261 # define isblank(c) __isctype((c), _ISblank)
262 # endif
264 # ifdef __USE_EXTERN_INLINES
265 __extern_inline int
266 __NTH (tolower (int __c))
268 return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOLOWER)[__c] : __c;
270 __extern_inline int
271 __NTH (toupper (int __c))
273 return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOUPPER)[__c] : __c;
275 # endif
277 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
278 # define tolower(c) __tobody(c, tolower, __UCLIBC_CTYPE_TOLOWER, (c))
279 # define toupper(c) __tobody(c, toupper, __UCLIBC_CTYPE_TOUPPER, (c))
280 # endif /* Optimizing gcc */
282 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
283 && defined __UCLIBC_SUSV4_LEGACY__
284 # define isascii(c) __isascii (c)
285 # define toascii(c) __toascii (c)
286 # define _tolower(c) ((int) (__UCLIBC_CTYPE_TOLOWER)[(int) (c)])
287 # define _toupper(c) ((int) (__UCLIBC_CTYPE_TOUPPER)[(int) (c)])
288 # endif
290 #endif /* not __cplusplus */
291 #endif /* not __NO_CTYPE */
294 #if defined __USE_GNU && defined __UCLIBC_HAS_XLOCALE__
295 /* The concept of one static locale per category is not very well
296 thought out. Many applications will need to process its data using
297 information from several different locales. Another application is
298 the implementation of the internationalization handling in the
299 upcoming ISO C++ standard library. To support this another set of
300 the functions using locale data exist which have an additional
301 argument.
303 Attention: all these functions are *not* standardized in any form.
304 This is a proof-of-concept implementation. */
306 /* Structure for reentrant locale using functions. This is an
307 (almost) opaque type for the user level programs. */
308 # include <xlocale.h>
310 /* These definitions are similar to the ones above but all functions
311 take as an argument a handle for the locale which shall be used. */
312 extern int isalnum_l(int, __locale_t) __THROW;
313 libc_hidden_proto(isalnum_l)
314 extern int isalpha_l(int, __locale_t) __THROW;
315 libc_hidden_proto(isalpha_l)
316 extern int iscntrl_l(int, __locale_t) __THROW;
317 libc_hidden_proto(iscntrl_l)
318 extern int isdigit_l(int, __locale_t) __THROW;
319 libc_hidden_proto(isdigit_l)
320 extern int islower_l(int, __locale_t) __THROW;
321 libc_hidden_proto(islower_l)
322 extern int isgraph_l(int, __locale_t) __THROW;
323 libc_hidden_proto(isgraph_l)
324 extern int isprint_l(int, __locale_t) __THROW;
325 libc_hidden_proto(isprint_l)
326 extern int ispunct_l(int, __locale_t) __THROW;
327 libc_hidden_proto(ispunct_l)
328 extern int isspace_l(int, __locale_t) __THROW;
329 libc_hidden_proto(isspace_l)
330 extern int isupper_l(int, __locale_t) __THROW;
331 libc_hidden_proto(isupper_l)
332 extern int isxdigit_l(int, __locale_t) __THROW;
333 libc_hidden_proto(isxdigit_l)
334 extern int isblank_l(int, __locale_t) __THROW;
335 libc_hidden_proto(isblank_l)
337 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
338 && defined __UCLIBC_SUSV4_LEGACY__
339 /* Return nonzero iff C is in the ASCII set
340 (i.e., is no more than 7 bits wide). */
341 extern int isascii_l (int __c) __THROW;
342 libc_hidden_proto(isascii_l)
344 # endif
346 /* Return the lowercase version of C in locale L. */
347 extern int tolower_l (int __c, __locale_t __l) __THROW;
348 libc_hidden_proto(tolower_l)
350 /* Return the uppercase version of C. */
351 extern int toupper_l (int __c, __locale_t __l) __THROW;
353 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
354 # define tolower_l(c, locale) __tobody(c, tolower_l, (locale)->__ctype_tolower, (c, locale))
355 # define toupper_l(c, locale) __tobody(c, toupper_l, (locale)->__ctype_toupper, (c, locale))
356 # endif /* Optimizing gcc */
359 # define __isctype_l(c, type, locale) ((locale)->__ctype_b[(int) (c)] & (__ctype_mask_t) type)
360 # ifndef __NO_CTYPE
361 # define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
362 # define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
363 # define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
364 # define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
365 # define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
366 # define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
367 # define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
368 # define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
369 # define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
370 # define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
371 # define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
372 # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
374 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
375 && defined __UCLIBC_SUSV4_LEGACY__
376 # define __isascii_l(c,l) ((l), __isascii (c))
377 # define __toascii_l(c,l) ((l), __toascii (c))
378 # endif
380 # define isalnum_l(c,l) __isalnum_l ((c), (l))
381 # define isalpha_l(c,l) __isalpha_l ((c), (l))
382 # define iscntrl_l(c,l) __iscntrl_l ((c), (l))
383 # define isdigit_l(c,l) __isdigit_l ((c), (l))
384 # define islower_l(c,l) __islower_l ((c), (l))
385 # define isgraph_l(c,l) __isgraph_l ((c), (l))
386 # define isprint_l(c,l) __isprint_l ((c), (l))
387 # define ispunct_l(c,l) __ispunct_l ((c), (l))
388 # define isspace_l(c,l) __isspace_l ((c), (l))
389 # define isupper_l(c,l) __isupper_l ((c), (l))
390 # define isxdigit_l(c,l) __isxdigit_l ((c), (l))
391 # define isblank_l(c,l) __isblank_l ((c), (l))
393 # if (defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN) \
394 && defined __UCLIBC_SUSV4_LEGACY__
395 # define isascii_l(c,l) __isascii_l ((c), (l))
396 # define toascii_l(c,l) __toascii_l ((c), (l))
397 # endif
399 # endif /* Not __NO_CTYPE. */
401 #endif /* Use GNU. */
403 __END_DECLS
405 #endif /* __UCLIBC_HAS_CTYPE_TABLES__ */
407 #if defined _LIBC && !defined __UCLIBC_SUSV4_LEGACY__
408 /* We define {__,}isascii for internal use only */
409 # define __isascii(c) (((c) & ~0x7f) == 0)
410 # define isascii(c) __isascii (c)
411 #endif
413 #endif /* ctype.h */