diff options
author | hpa <hpa> | 2004-11-10 22:31:50 +0000 |
---|---|---|
committer | hpa <hpa> | 2004-11-10 22:31:50 +0000 |
commit | 17f967640cef484f83d755c9dd016a946711236f (patch) | |
tree | 00bf0c0f2926cd6a9761eb372b55d090305aca44 /com32/include/ctype.h | |
parent | c67a2ac96611fa6aeb9ff3602c5e0c8265f1cc9d (diff) | |
download | syslinux-17f967640cef484f83d755c9dd016a946711236f.tar.gz |
Very first cut at a klibc-derived C library for com32
Diffstat (limited to 'com32/include/ctype.h')
-rw-r--r-- | com32/include/ctype.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/com32/include/ctype.h b/com32/include/ctype.h new file mode 100644 index 00000000..daa6a8ef --- /dev/null +++ b/com32/include/ctype.h @@ -0,0 +1,119 @@ +/* + * ctype.h + * + * This assumes ISO 8859-1, being a reasonable superset of ASCII. + */ + +#ifndef _CTYPE_H +#define _CTYPE_H + +#ifndef __CTYPE_NO_INLINE +# define __ctype_inline extern __inline__ +#else +# define __ctype_inline +#endif + +/* + * 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 const unsigned char __ctypes[]; + +__ctype_inline int isalnum(int __c) +{ + return __ctypes[__c+1] & + (__ctype_upper|__ctype_lower|__ctype_digit); +} + +__ctype_inline int isalpha(int __c) +{ + return __ctypes[__c+1] & + (__ctype_upper|__ctype_lower); +} + +__ctype_inline int isascii(int __c) +{ + return !(__c & ~0x7f); +} + +__ctype_inline int isblank(int __c) +{ + return (__c == '\t') || (__c == ' '); +} + +__ctype_inline int iscntrl(int __c) +{ + return __ctypes[__c+1] & __ctype_cntrl; +} + +__ctype_inline int isdigit(int __c) +{ + return ((unsigned)__c - '0') <= 9; +} + +__ctype_inline int isgraph(int __c) +{ + return __ctypes[__c+1] & + (__ctype_upper|__ctype_lower|__ctype_digit|__ctype_punct); +} + +__ctype_inline int islower(int __c) +{ + return __ctypes[__c+1] & __ctype_lower; +} + +__ctype_inline int isprint(int __c) +{ + return __ctypes[__c+1] & __ctype_print; +} + +__ctype_inline int ispunct(int __c) +{ + return __ctypes[__c+1] & __ctype_punct; +} + +__ctype_inline int isspace(int __c) +{ + return __ctypes[__c+1] & __ctype_space; +} + +__ctype_inline int isupper(int __c) +{ + return __ctypes[__c+1] & __ctype_upper; +} + +__ctype_inline int 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) + +__ctype_inline int toupper(int __c) +{ + return islower(__c) ? _toupper(__c) : __c; +} + +__ctype_inline int tolower(int __c) +{ + return isupper(__c) ? _tolower(__c) : __c; +} + +#endif /* _CTYPE_H */ |