OSDN Git Service

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