OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [include/] [ctype.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* 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
extern const __ctype_touplow_t *__C_ctype_toupper;
105
extern const __ctype_touplow_t *__C_ctype_tolower;
106
 
107
#ifdef __UCLIBC_HAS_XLOCALE__
108
 
109
extern __const __ctype_mask_t **__ctype_b_loc (void)
110
     __attribute__ ((__const));
111
extern __const __ctype_touplow_t **__ctype_tolower_loc (void)
112
     __attribute__ ((__const));
113
extern __const __ctype_touplow_t **__ctype_toupper_loc (void)
114
     __attribute__ ((__const));
115
 
116
#define __UCLIBC_CTYPE_B        (*__ctype_b_loc())
117
#define __UCLIBC_CTYPE_TOLOWER  (*__ctype_tolower_loc())
118
#define __UCLIBC_CTYPE_TOUPPER  (*__ctype_toupper_loc())
119
 
120
#else  /* __UCLIBC_HAS_XLOCALE__ */
121
 
122
/* Pointers to the current global locale data in use. */
123
extern const __ctype_mask_t *__ctype_b;
124
extern const __ctype_touplow_t *__ctype_toupper;
125
extern const __ctype_touplow_t *__ctype_tolower;
126
 
127
#define __UCLIBC_CTYPE_B        (__ctype_b)
128
#define __UCLIBC_CTYPE_TOLOWER  (__ctype_tolower)
129
#define __UCLIBC_CTYPE_TOUPPER  (__ctype_toupper)
130
 
131
#endif /* __UCLIBC_HAS_XLOCALE__ */
132
 
133
#define __isctype(c, type) \
134
  ((__UCLIBC_CTYPE_B)[(int) (c)] & (__ctype_mask_t) type)
135
 
136
#define __isascii(c)    (((c) & ~0x7f) == 0)    /* If C is a 7 bit value.  */
137
#define __toascii(c)    ((c) & 0x7f)            /* Mask off high bits.  */
138
 
139
#ifdef __USE_MISC
140
 
141
/* The following are included for compatibility with older versions of
142
 * uClibc; but now they're only visible if MISC funcctionality is requested. */
143
extern int isxlower(int c) __THROW;
144
extern int isxupper(int c) __THROW;
145
 
146
/* isdigit() is really locale-invariant, so provide some small fast macros.
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
 
151
#endif
152
 
153
#define __exctype(name) extern int name (int) __THROW
154
 
155
__BEGIN_NAMESPACE_STD
156
 
157
/* The following names are all functions:
158
     int isCHARACTERISTIC(int c);
159
   which return nonzero iff C has CHARACTERISTIC.
160
   For the meaning of the characteristic names, see the `enum' above.  */
161
__exctype (isalnum);
162
__exctype (isalpha);
163
__exctype (iscntrl);
164
__exctype (isdigit);
165
__exctype (islower);
166
__exctype (isgraph);
167
__exctype (isprint);
168
__exctype (ispunct);
169
__exctype (isspace);
170
__exctype (isupper);
171
__exctype (isxdigit);
172
 
173
 
174
/* Return the lowercase version of C.  */
175
extern int tolower (int __c) __THROW;
176
 
177
/* Return the uppercase version of C.  */
178
extern int toupper (int __c) __THROW;
179
 
180
__END_NAMESPACE_STD
181
 
182
 
183
/* ISO C99 introduced one new function.  */
184
#ifdef  __USE_ISOC99
185
__BEGIN_NAMESPACE_C99
186
 
187
__exctype (isblank);
188
 
189
__END_NAMESPACE_C99
190
#endif
191
 
192
#ifdef __USE_GNU
193
/* Test C for a set of character classes according to MASK.  */
194
extern int isctype (int __c, int __mask) __THROW;
195
#endif
196
 
197
#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
198
 
199
/* Return nonzero iff C is in the ASCII set
200
   (i.e., is no more than 7 bits wide).  */
201
extern int isascii (int __c) __THROW;
202
 
203
/* Return the part of C that is in the ASCII set
204
   (i.e., the low-order 7 bits of C).  */
205
extern int toascii (int __c) __THROW;
206
 
207
/* These are the same as `toupper' and `tolower' except that they do not
208
   check the argument for being in the range of a `char'.  */
209
__exctype (_toupper);
210
__exctype (_tolower);
211
#endif /* Use SVID or use misc.  */
212
 
213
/* This code is needed for the optimized mapping functions.  */
214
#define __tobody(c, f, a, args) \
215
  (__extension__                                                              \
216
   ({ int __res;                                                              \
217
      if (sizeof (c) > 1)                                                     \
218
        {                                                                     \
219
          if (__builtin_constant_p (c))                                       \
220
            {                                                                 \
221
              int __c = (c);                                                  \
222
              __res = __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (a)[__c] : __c;      \
223
            }                                                                 \
224
          else                                                                \
225
            __res = f args;                                                   \
226
        }                                                                     \
227
      else                                                                    \
228
        __res = (a)[(int) (c)];                                               \
229
      __res; }))
230
 
231
#if !defined __NO_CTYPE && !defined __cplusplus
232
# define isalnum(c)     __isctype((c), _ISalnum)
233
# define isalpha(c)     __isctype((c), _ISalpha)
234
# define iscntrl(c)     __isctype((c), _IScntrl)
235
# define isdigit(c)     __isctype((c), _ISdigit)
236
# define islower(c)     __isctype((c), _ISlower)
237
# define isgraph(c)     __isctype((c), _ISgraph)
238
# define isprint(c)     __isctype((c), _ISprint)
239
# define ispunct(c)     __isctype((c), _ISpunct)
240
# define isspace(c)     __isctype((c), _ISspace)
241
# define isupper(c)     __isctype((c), _ISupper)
242
# define isxdigit(c)    __isctype((c), _ISxdigit)
243
 
244
# ifdef __USE_ISOC99
245
#  define isblank(c)    __isctype((c), _ISblank)
246
# endif
247
 
248
# ifdef __USE_EXTERN_INLINES
249
extern __inline int
250
tolower (int __c) __THROW
251
{
252
  return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOLOWER)[__c] : __c;
253
}
254
 
255
extern __inline int
256
toupper (int __c) __THROW
257
{
258
  return __UCLIBC_CTYPE_IN_TO_DOMAIN(__c) ? (__UCLIBC_CTYPE_TOUPPER)[__c] : __c;
259
}
260
# endif
261
 
262
# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
263
#  define tolower(c)    __tobody (c, tolower, __UCLIBC_CTYPE_TOLOWER, (c))
264
#  define toupper(c)    __tobody (c, toupper, __UCLIBC_CTYPE_TOUPPER, (c))
265
# endif /* Optimizing gcc */
266
 
267
# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
268
#  define isascii(c)    __isascii (c)
269
#  define toascii(c)    __toascii (c)
270
 
271
#  define _tolower(c)   ((int) (__UCLIBC_CTYPE_TOLOWER)[(int) (c)])
272
#  define _toupper(c)   ((int) (__UCLIBC_CTYPE_TOUPPER)[(int) (c)])
273
# endif
274
 
275
#endif /* Not __NO_CTYPE.  */
276
 
277
 
278
#if defined(__USE_GNU) && defined(__UCLIBC_HAS_XLOCALE__)
279
/* The concept of one static locale per category is not very well
280
   thought out.  Many applications will need to process its data using
281
   information from several different locales.  Another application is
282
   the implementation of the internationalization handling in the
283
   upcoming ISO C++ standard library.  To support this another set of
284
   the functions using locale data exist which have an additional
285
   argument.
286
 
287
   Attention: all these functions are *not* standardized in any form.
288
   This is a proof-of-concept implementation.  */
289
 
290
/* Structure for reentrant locale using functions.  This is an
291
   (almost) opaque type for the user level programs.  */
292
# include <xlocale.h>
293
 
294
/* These definitions are similar to the ones above but all functions
295
   take as an argument a handle for the locale which shall be used.  */
296
#  define __isctype_l(c, type, locale) \
297
  ((locale)->__ctype_b[(int) (c)] & (__ctype_mask_t) type)
298
 
299
# define __exctype_l(name)                                                    \
300
  extern int name (int, __locale_t) __THROW
301
 
302
/* The following names are all functions:
303
     int isCHARACTERISTIC(int c, locale_t *locale);
304
   which return nonzero iff C has CHARACTERISTIC.
305
   For the meaning of the characteristic names, see the `enum' above.  */
306
__exctype_l (isalnum_l);
307
__exctype_l (isalpha_l);
308
__exctype_l (iscntrl_l);
309
__exctype_l (isdigit_l);
310
__exctype_l (islower_l);
311
__exctype_l (isgraph_l);
312
__exctype_l (isprint_l);
313
__exctype_l (ispunct_l);
314
__exctype_l (isspace_l);
315
__exctype_l (isupper_l);
316
__exctype_l (isxdigit_l);
317
 
318
__exctype_l (isblank_l);
319
 
320
 
321
/* Return the lowercase version of C in locale L.  */
322
extern int __tolower_l (int __c, __locale_t __l) __THROW;
323
extern int tolower_l (int __c, __locale_t __l) __THROW;
324
 
325
/* Return the uppercase version of C.  */
326
extern int __toupper_l (int __c, __locale_t __l) __THROW;
327
extern int toupper_l (int __c, __locale_t __l) __THROW;
328
 
329
# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
330
#  define __tolower_l(c, locale) \
331
  __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale))
332
#  define __toupper_l(c, locale) \
333
  __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale))
334
#  define tolower_l(c, locale)  __tolower_l ((c), (locale))
335
#  define toupper_l(c, locale)  __toupper_l ((c), (locale))
336
# endif /* Optimizing gcc */
337
 
338
 
339
# ifndef __NO_CTYPE
340
#  define __isalnum_l(c,l)      __isctype_l((c), _ISalnum, (l))
341
#  define __isalpha_l(c,l)      __isctype_l((c), _ISalpha, (l))
342
#  define __iscntrl_l(c,l)      __isctype_l((c), _IScntrl, (l))
343
#  define __isdigit_l(c,l)      __isctype_l((c), _ISdigit, (l))
344
#  define __islower_l(c,l)      __isctype_l((c), _ISlower, (l))
345
#  define __isgraph_l(c,l)      __isctype_l((c), _ISgraph, (l))
346
#  define __isprint_l(c,l)      __isctype_l((c), _ISprint, (l))
347
#  define __ispunct_l(c,l)      __isctype_l((c), _ISpunct, (l))
348
#  define __isspace_l(c,l)      __isctype_l((c), _ISspace, (l))
349
#  define __isupper_l(c,l)      __isctype_l((c), _ISupper, (l))
350
#  define __isxdigit_l(c,l)     __isctype_l((c), _ISxdigit, (l))
351
 
352
#  define __isblank_l(c,l)      __isctype_l((c), _ISblank, (l))
353
 
354
#  if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
355
#   define __isascii_l(c,l)     ((l), __isascii (c))
356
#   define __toascii_l(c,l)     ((l), __toascii (c))
357
#  endif
358
 
359
#  define isalnum_l(c,l)        __isalnum_l ((c), (l))
360
#  define isalpha_l(c,l)        __isalpha_l ((c), (l))
361
#  define iscntrl_l(c,l)        __iscntrl_l ((c), (l))
362
#  define isdigit_l(c,l)        __isdigit_l ((c), (l))
363
#  define islower_l(c,l)        __islower_l ((c), (l))
364
#  define isgraph_l(c,l)        __isgraph_l ((c), (l))
365
#  define isprint_l(c,l)        __isprint_l ((c), (l))
366
#  define ispunct_l(c,l)        __ispunct_l ((c), (l))
367
#  define isspace_l(c,l)        __isspace_l ((c), (l))
368
#  define isupper_l(c,l)        __isupper_l ((c), (l))
369
#  define isxdigit_l(c,l)       __isxdigit_l ((c), (l))
370
 
371
#  define isblank_l(c,l)        __isblank_l ((c), (l))
372
 
373
#  if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
374
#   define isascii_l(c,l)       __isascii_l ((c), (l))
375
#   define toascii_l(c,l)       __toascii_l ((c), (l))
376
#  endif
377
 
378
# endif /* Not __NO_CTYPE.  */
379
 
380
#endif /* Use GNU.  */
381
 
382
__END_DECLS
383
 
384
#else  /* __UCLIBC_HAS_CTYPE_TABLES__ */
385
 
386
#include <bits/uClibc_ctype.h>
387
 
388
#endif
389
 
390
#endif /* ctype.h  */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.