1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

LibC: Provide macros for the <ctype.h> functions

These are required for the 'tr' port.
This commit is contained in:
Gunnar Beutner 2021-04-10 15:52:01 +02:00 committed by Andreas Kling
parent fe8b1a732e
commit 03ffdeb43a
2 changed files with 167 additions and 34 deletions

View file

@ -47,17 +47,93 @@ const char _ctype_[256] = {
_L, _L, _L, _P, _P, _P, _P, _C
};
int tolower(int c)
#undef isalnum
int isalnum(int c)
{
if (c >= 'A' && c <= 'Z')
return c | 0x20;
return c;
return __inline_isalnum(c);
}
#undef isalpha
int isalpha(int c)
{
return __inline_isalpha(c);
}
#undef iscntrl
int iscntrl(int c)
{
return __inline_iscntrl(c);
}
#undef isdigit
int isdigit(int c)
{
return __inline_isdigit(c);
}
#undef isxdigit
int isxdigit(int c)
{
return __inline_isxdigit(c);
}
#undef isspace
int isspace(int c)
{
return __inline_isspace(c);
}
#undef ispunct
int ispunct(int c)
{
return __inline_ispunct(c);
}
#undef isprint
int isprint(int c)
{
return __inline_isprint(c);
}
#undef isgraph
int isgraph(int c)
{
return __inline_isgraph(c);
}
#undef isupper
int isupper(int c)
{
return __inline_isupper(c);
}
#undef islower
int islower(int c)
{
return __inline_islower(c);
}
#undef isascii
int isascii(int c)
{
return ((unsigned)c <= 127);
}
#undef toascii
int toascii(int c)
{
return __inline_toascii(c);
}
#undef tolower
int tolower(int c)
{
return __inline_tolower(c);
}
#undef toupper
int toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c & ~0x20;
return c;
return __inline_toupper(c);
}
}

View file

@ -42,65 +42,122 @@ __BEGIN_DECLS
extern const char _ctype_[256];
int tolower(int);
int toupper(int);
static inline int isalnum(int c)
static inline int __inline_isalnum(int c)
{
return (_ctype_[(unsigned char)(c)] & (_U | _L | _N));
return _ctype_[(unsigned char)(c)] & (_U | _L | _N);
}
static inline int isalpha(int c)
static inline int __inline_isalpha(int c)
{
return (_ctype_[(unsigned char)(c)] & (_U | _L));
return _ctype_[(unsigned char)(c)] & (_U | _L);
}
static inline int iscntrl(int c)
static inline int __inline_isascii(int c)
{
return (_ctype_[(unsigned char)(c)] & (_C));
return (unsigned)c <= 127;
}
static inline int isdigit(int c)
static inline int __inline_iscntrl(int c)
{
return (_ctype_[(unsigned char)(c)] & (_N));
return _ctype_[(unsigned char)(c)] & (_C);
}
static inline int isxdigit(int c)
static inline int __inline_isdigit(int c)
{
return (_ctype_[(unsigned char)(c)] & (_N | _X));
return _ctype_[(unsigned char)(c)] & (_N);
}
static inline int isspace(int c)
static inline int __inline_isxdigit(int c)
{
return (_ctype_[(unsigned char)(c)] & (_S));
return _ctype_[(unsigned char)(c)] & (_N | _X);
}
static inline int ispunct(int c)
static inline int __inline_isspace(int c)
{
return (_ctype_[(unsigned char)(c)] & (_P));
return _ctype_[(unsigned char)(c)] & (_S);
}
static inline int isprint(int c)
static inline int __inline_ispunct(int c)
{
return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B));
return _ctype_[(unsigned char)(c)] & (_P);
}
static inline int isgraph(int c)
static inline int __inline_isprint(int c)
{
return (_ctype_[(unsigned char)(c)] & (_P | _U | _L | _N));
return _ctype_[(unsigned char)(c)] & (_P | _U | _L | _N | _B);
}
static inline int islower(int c)
static inline int __inline_isgraph(int c)
{
return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _L);
return _ctype_[(unsigned char)(c)] & (_P | _U | _L | _N);
}
static inline int isupper(int c)
static inline int __inline_islower(int c)
{
return ((_ctype_[(unsigned char)(c)] & (_U | _L)) == _U);
return _ctype_[(unsigned char)(c)] & (_L);
}
#define isascii(c) ((unsigned)c <= 127)
#define toascii(c) ((c)&127)
static inline int __inline_isupper(int c)
{
return _ctype_[(unsigned char)(c)] & (_U);
}
static inline int __inline_toascii(int c)
{
return c & 127;
}
static inline int __inline_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return c | 0x20;
return c;
}
static inline int __inline_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c & ~0x20;
return c;
}
#ifdef __cplusplus
extern "C" {
#endif
int isalnum(int c);
int isalpha(int c);
int isascii(int c);
int iscntrl(int c);
int isdigit(int c);
int isxdigit(int c);
int isspace(int c);
int ispunct(int c);
int isprint(int c);
int isgraph(int c);
int islower(int c);
int isupper(int c);
int toascii(int c);
int tolower(int c);
int toupper(int c);
#ifdef __cplusplus
}
#endif
#define isalnum __inline_isalnum
#define isalpha __inline_isalpha
#define isascii __inline_isascii
#define iscntrl __inline_iscntrl
#define isdigit __inline_isdigit
#define isxdigit __inline_isxdigit
#define isspace __inline_isspace
#define ispunct __inline_ispunct
#define isprint __inline_isprint
#define isgraph __inline_isgraph
#define islower __inline_islower
#define isupper __inline_isupper
#define toascii __inline_toascii
#define tolower __inline_tolower
#define toupper __inline_toupper
__END_DECLS