OSDN Git Service

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