1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
* ctype.h
*
* This assumes ISO 8859-1, being a reasonable superset of ASCII.
*/
#ifndef _CTYPE_H
#define _CTYPE_H
#include <klibc/extern.h>
#include <klibc/compiler.h>
/*
* This relies on the following definitions:
*
* cntrl = !print
* alpha = upper|lower
* graph = punct|alpha|digit
* blank = '\t' || ' ' (per POSIX requirement)
*/
enum {
__ctype_upper = (1 << 0),
__ctype_lower = (1 << 1),
__ctype_digit = (1 << 2),
__ctype_xdigit = (1 << 3),
__ctype_space = (1 << 4),
__ctype_print = (1 << 5),
__ctype_punct = (1 << 6),
__ctype_cntrl = (1 << 7),
};
__extern int isalnum(int);
__extern int isalpha(int);
__extern int isascii(int);
__extern int isblank(int);
__extern int iscntrl(int);
__extern int isdigit(int);
__extern int isgraph(int);
__extern int islower(int);
__extern int isprint(int);
__extern int ispunct(int);
__extern int isspace(int);
__extern int isupper(int);
__extern int isxdigit(int);
__extern int toupper(int);
__extern int tolower(int);
extern const unsigned char __ctypes[];
__must_inline int __ctype_isalnum(int);
__must_inline int __ctype_isalpha(int);
__must_inline int __ctype_isascii(int);
__must_inline int __ctype_isblank(int);
__must_inline int __ctype_iscntrl(int);
__must_inline int __ctype_isdigit(int);
__must_inline int __ctype_isgraph(int);
__must_inline int __ctype_islower(int);
__must_inline int __ctype_isprint(int);
__must_inline int __ctype_ispunct(int);
__must_inline int __ctype_isspace(int);
__must_inline int __ctype_isupper(int);
__must_inline int __ctype_isxdigit(int);
__must_inline int __ctype_isalnum(int __c)
{
return __ctypes[__c + 1] &
(__ctype_upper | __ctype_lower | __ctype_digit);
}
__must_inline int __ctype_isalpha(int __c)
{
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
}
__must_inline int __ctype_isascii(int __c)
{
return !(__c & ~0x7f);
}
__must_inline int __ctype_isblank(int __c)
{
return (__c == '\t') || (__c == ' ');
}
__must_inline int __ctype_iscntrl(int __c)
{
return __ctypes[__c + 1] & __ctype_cntrl;
}
__must_inline int __ctype_isdigit(int __c)
{
return ((unsigned)__c - '0') <= 9;
}
__must_inline int __ctype_isgraph(int __c)
{
return __ctypes[__c + 1] &
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
}
__must_inline int __ctype_islower(int __c)
{
return __ctypes[__c + 1] & __ctype_lower;
}
__must_inline int __ctype_isprint(int __c)
{
return __ctypes[__c + 1] & __ctype_print;
}
__must_inline int __ctype_ispunct(int __c)
{
return __ctypes[__c + 1] & __ctype_punct;
}
__must_inline int __ctype_isspace(int __c)
{
return __ctypes[__c + 1] & __ctype_space;
}
__must_inline int __ctype_isupper(int __c)
{
return __ctypes[__c + 1] & __ctype_upper;
}
__must_inline int __ctype_isxdigit(int __c)
{
return __ctypes[__c + 1] & __ctype_xdigit;
}
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
#define _toupper(__c) ((__c) & ~32)
#define _tolower(__c) ((__c) | 32)
__must_inline int __ctype_toupper(int);
__must_inline int __ctype_tolower(int);
__must_inline int __ctype_toupper(int __c)
{
return __ctype_islower(__c) ? _toupper(__c) : __c;
}
__must_inline int __ctype_tolower(int __c)
{
return __ctype_isupper(__c) ? _tolower(__c) : __c;
}
#ifdef __CTYPE_NO_INLINE
# define __CTYPEFUNC(X) \
__extern int X(int);
#else
#define __CTYPEFUNC(X) \
__extern_inline int X(int __c) \
{ \
return __ctype_##X(__c); \
}
#endif
__CTYPEFUNC(isalnum)
__CTYPEFUNC(isalpha)
__CTYPEFUNC(isascii)
__CTYPEFUNC(isblank)
__CTYPEFUNC(iscntrl)
__CTYPEFUNC(isdigit)
__CTYPEFUNC(isgraph)
__CTYPEFUNC(islower)
__CTYPEFUNC(isprint)
__CTYPEFUNC(ispunct)
__CTYPEFUNC(isspace)
__CTYPEFUNC(isupper)
__CTYPEFUNC(isxdigit)
__CTYPEFUNC(toupper)
__CTYPEFUNC(tolower)
#endif /* _CTYPE_H */
|