1 /* 2 * ctype.h 3 * 4 * This assumes ISO 8859-1, being a reasonable superset of ASCII. 5 */ 6 7 #ifndef _CTYPE_H 8 #define _CTYPE_H 9 10 #include <klibc/extern.h> 11 12 #ifndef __CTYPE_NO_INLINE 13 # define __ctype_inline static __inline__ 14 #else 15 # define __ctype_inline 16 #endif 17 18 /* 19 * This relies on the following definitions: 20 * 21 * cntrl = !print 22 * alpha = upper|lower 23 * graph = punct|alpha|digit 24 * blank = '\t' || ' ' (per POSIX requirement) 25 */ 26 enum { 27 __ctype_upper = (1 << 0), 28 __ctype_lower = (1 << 1), 29 __ctype_digit = (1 << 2), 30 __ctype_xdigit = (1 << 3), 31 __ctype_space = (1 << 4), 32 __ctype_print = (1 << 5), 33 __ctype_punct = (1 << 6), 34 __ctype_cntrl = (1 << 7), 35 }; 36 37 extern const unsigned char __ctypes[]; 38 39 __ctype_inline int isalnum(int __c) 40 { 41 return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower | __ctype_digit); 42 } 43 44 __ctype_inline int isalpha(int __c) 45 { 46 return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower); 47 } 48 49 __ctype_inline int isascii(int __c) 50 { 51 return !(__c & ~0x7f); 52 } 53 54 __ctype_inline int isblank(int __c) 55 { 56 return (__c == '\t') || (__c == ' '); 57 } 58 59 __ctype_inline int iscntrl(int __c) 60 { 61 return __ctypes[__c + 1] & __ctype_cntrl; 62 } 63 64 __ctype_inline int isdigit(int __c) 65 { 66 return ((unsigned)__c - '0') <= 9; 67 } 68 69 __ctype_inline int isgraph(int __c) 70 { 71 return __ctypes[__c + 1] & 72 (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct); 73 } 74 75 __ctype_inline int islower(int __c) 76 { 77 return __ctypes[__c + 1] & __ctype_lower; 78 } 79 80 __ctype_inline int isprint(int __c) 81 { 82 return __ctypes[__c + 1] & __ctype_print; 83 } 84 85 __ctype_inline int ispunct(int __c) 86 { 87 return __ctypes[__c + 1] & __ctype_punct; 88 } 89 90 __ctype_inline int isspace(int __c) 91 { 92 return __ctypes[__c + 1] & __ctype_space; 93 } 94 95 __ctype_inline int isupper(int __c) 96 { 97 return __ctypes[__c + 1] & __ctype_upper; 98 } 99 100 __ctype_inline int isxdigit(int __c) 101 { 102 return __ctypes[__c + 1] & __ctype_xdigit; 103 } 104 105 /* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */ 106 #define _toupper(__c) ((__c) & ~32) 107 #define _tolower(__c) ((__c) | 32) 108 109 __ctype_inline int toupper(int __c) 110 { 111 return islower(__c) ? _toupper(__c) : __c; 112 } 113 114 __ctype_inline int tolower(int __c) 115 { 116 return isupper(__c) ? _tolower(__c) : __c; 117 } 118 119 __extern char *skipspace(const char *p); 120 __extern void chrreplace(char *source, char old, char new); 121 122 #endif /* _CTYPE_H */ 123