2000-02-17 20:39:52 +01:00
|
|
|
#ifndef _CTYPE_H_
|
|
|
|
#define _CTYPE_H_
|
|
|
|
|
|
|
|
#include "_ansi.h"
|
|
|
|
|
2002-06-28 01:58:38 +02:00
|
|
|
_BEGIN_STD_C
|
|
|
|
|
2000-02-17 20:39:52 +01:00
|
|
|
int _EXFUN(isalnum, (int __c));
|
|
|
|
int _EXFUN(isalpha, (int __c));
|
|
|
|
int _EXFUN(iscntrl, (int __c));
|
|
|
|
int _EXFUN(isdigit, (int __c));
|
|
|
|
int _EXFUN(isgraph, (int __c));
|
|
|
|
int _EXFUN(islower, (int __c));
|
|
|
|
int _EXFUN(isprint, (int __c));
|
|
|
|
int _EXFUN(ispunct, (int __c));
|
|
|
|
int _EXFUN(isspace, (int __c));
|
|
|
|
int _EXFUN(isupper, (int __c));
|
|
|
|
int _EXFUN(isxdigit,(int __c));
|
|
|
|
int _EXFUN(tolower, (int __c));
|
|
|
|
int _EXFUN(toupper, (int __c));
|
|
|
|
|
2008-10-15 22:49:56 +02:00
|
|
|
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
|
2002-06-18 20:49:17 +02:00
|
|
|
int _EXFUN(isblank, (int __c));
|
2008-10-15 22:36:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __STRICT_ANSI__
|
2000-02-17 20:39:52 +01:00
|
|
|
int _EXFUN(isascii, (int __c));
|
|
|
|
int _EXFUN(toascii, (int __c));
|
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
2009-04-24 14:27:36 +02:00
|
|
|
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
|
|
|
|
#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
|
2000-02-17 20:39:52 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _U 01
|
|
|
|
#define _L 02
|
|
|
|
#define _N 04
|
|
|
|
#define _S 010
|
|
|
|
#define _P 020
|
|
|
|
#define _C 040
|
|
|
|
#define _X 0100
|
|
|
|
#define _B 0200
|
|
|
|
|
2009-04-02 09:53:12 +02:00
|
|
|
#ifndef _MB_CAPABLE
|
|
|
|
_CONST
|
|
|
|
#endif
|
2009-03-31 11:31:38 +02:00
|
|
|
extern __IMPORT char *__ctype_ptr__;
|
2000-02-17 20:39:52 +01:00
|
|
|
|
2001-06-11 23:51:41 +02:00
|
|
|
#ifndef __cplusplus
|
Trigger gcc warning if isFoo macros are called with plain char.
* libc/include/ctype.h (isalpha, isupper, islower, isdigit)
(isxdigit, isspace, ispunct, isalnum, isprint, isgraph)
(iscntrl, isblank, toupper, tolower): Rewrite to let 'gcc -Wall'
warn when user calls macro with a char argument.
2009-04-24 14:20:07 +02:00
|
|
|
/* These macros are intentionally written in a manner that will trigger
|
|
|
|
a gcc -Wall warning if the user mistakenly passes a 'char' instead
|
Fix isalpha(0x100000001LL) and friends on 64-bit machines.
* libc/include/ctype.h (__ctype_lookup): New macro.
(isalpha, isupper, islower, isdigit, isxdigit, isspace, ispunct)
(isalnum, isprint, isgraph, iscntrl, isblank): Use it to fix bug
on 64-bit machines.
2009-10-24 15:24:29 +02:00
|
|
|
of an int containing an 'unsigned char'. Note that the sizeof will
|
|
|
|
always be 1, which is what we want for mapping EOF to __ctype_ptr__[0];
|
|
|
|
the use of a raw index inside the sizeof triggers the gcc warning if
|
|
|
|
__c was of type char, and sizeof masks side effects of the extra __c.
|
|
|
|
Meanwhile, the real index to __ctype_ptr__+1 must be cast to int,
|
|
|
|
since isalpha(0x100000001LL) must equal isalpha(1), rather than being
|
|
|
|
an out-of-bounds reference on a 64-bit machine. */
|
|
|
|
#define __ctype_lookup(__c) ((__ctype_ptr__+sizeof(""[__c]))[(int)__c])
|
|
|
|
|
|
|
|
#define isalpha(__c) (__ctype_lookup(__c)&(_U|_L))
|
|
|
|
#define isupper(__c) ((__ctype_lookup(__c)&(_U|_L))==_U)
|
|
|
|
#define islower(__c) ((__ctype_lookup(__c)&(_U|_L))==_L)
|
|
|
|
#define isdigit(__c) (__ctype_lookup(__c)&_N)
|
|
|
|
#define isxdigit(__c) (__ctype_lookup(__c)&(_X|_N))
|
|
|
|
#define isspace(__c) (__ctype_lookup(__c)&_S)
|
|
|
|
#define ispunct(__c) (__ctype_lookup(__c)&_P)
|
|
|
|
#define isalnum(__c) (__ctype_lookup(__c)&(_U|_L|_N))
|
|
|
|
#define isprint(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
|
|
|
|
#define isgraph(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N))
|
|
|
|
#define iscntrl(__c) (__ctype_lookup(__c)&_C)
|
2005-03-17 21:11:23 +01:00
|
|
|
|
2009-04-09 12:37:58 +02:00
|
|
|
#if defined(__GNUC__) && \
|
|
|
|
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
|
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
2009-04-24 14:27:36 +02:00
|
|
|
#define isblank(__c) \
|
|
|
|
__extension__ ({ __typeof__ (__c) __x = (__c); \
|
Fix isalpha(0x100000001LL) and friends on 64-bit machines.
* libc/include/ctype.h (__ctype_lookup): New macro.
(isalpha, isupper, islower, isdigit, isxdigit, isspace, ispunct)
(isalnum, isprint, isgraph, iscntrl, isblank): Use it to fix bug
on 64-bit machines.
2009-10-24 15:24:29 +02:00
|
|
|
(__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
|
2009-03-26 10:45:11 +01:00
|
|
|
#endif
|
|
|
|
|
2005-03-17 21:11:23 +01:00
|
|
|
|
2000-02-17 20:39:52 +01:00
|
|
|
/* Non-gcc versions will get the library versions, and will be
|
2009-03-31 11:31:38 +02:00
|
|
|
slightly slower. These macros are not NLS-aware so they are
|
|
|
|
disabled if the system supports the extended character sets. */
|
2009-05-01 00:53:00 +02:00
|
|
|
# if defined(__GNUC__)
|
|
|
|
# if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
|
|
|
|
# define toupper(__c) \
|
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
2009-04-24 14:27:36 +02:00
|
|
|
__extension__ ({ __typeof__ (__c) __x = (__c); \
|
2009-05-01 00:53:00 +02:00
|
|
|
islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
|
|
|
|
# define tolower(__c) \
|
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
2009-04-24 14:27:36 +02:00
|
|
|
__extension__ ({ __typeof__ (__c) __x = (__c); \
|
2009-05-01 00:53:00 +02:00
|
|
|
isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
|
|
|
|
# else /* _MB_EXTENDED_CHARSETS* */
|
|
|
|
/* Allow a gcc warning if the user passed 'char', but defer to the
|
|
|
|
function. */
|
|
|
|
# define toupper(__c) \
|
|
|
|
__extension__ ({ __typeof__ (__c) __x = (__c); \
|
|
|
|
(void) __ctype_ptr__[__x]; (toupper) (__x);})
|
|
|
|
# define tolower(__c) \
|
|
|
|
__extension__ ({ __typeof__ (__c) __x = (__c); \
|
|
|
|
(void) __ctype_ptr__[__x]; (tolower) (__x);})
|
|
|
|
# endif /* _MB_EXTENDED_CHARSETS* */
|
|
|
|
# endif /* __GNUC__ */
|
2001-06-11 23:51:41 +02:00
|
|
|
#endif /* !__cplusplus */
|
2000-02-17 20:39:52 +01:00
|
|
|
|
|
|
|
#ifndef __STRICT_ANSI__
|
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
2009-04-24 14:27:36 +02:00
|
|
|
#define isascii(__c) ((unsigned)(__c)<=0177)
|
|
|
|
#define toascii(__c) ((__c)&0177)
|
2000-02-17 20:39:52 +01:00
|
|
|
#endif
|
|
|
|
|
2008-07-24 19:55:26 +02:00
|
|
|
/* For C++ backward-compatibility only. */
|
|
|
|
extern __IMPORT _CONST char _ctype_[];
|
|
|
|
|
2002-06-28 01:58:38 +02:00
|
|
|
_END_STD_C
|
|
|
|
|
2000-02-17 20:39:52 +01:00
|
|
|
#endif /* _CTYPE_H_ */
|