1 /* $MirOS: src/include/ctype.h,v 1.19 2008/11/30 13:08:49 tg Exp $ */ 2 3 /*- 4 * Copyright (c) 2006, 2007, 2008 5 * Thorsten Glaser <tg@mirbsd.de> 6 * 7 * Provided that these terms and disclaimer and all copyright notices 8 * are retained or reproduced in an accompanying document, permission 9 * is granted to deal in this work without restriction, including un- 10 * limited rights to use, publicly perform, distribute, sell, modify, 11 * merge, give away, or sublicence. 12 * 13 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 14 * the utmost extent permitted by applicable law, neither express nor 15 * implied; without malicious intent or gross negligence. In no event 16 * may a licensor, author or contributor be held liable for indirect, 17 * direct, other damage, loss, or other issues arising in any way out 18 * of dealing in the work, even if advised of the possibility of such 19 * damage or existence of a defect, except proven that it results out 20 * of said person's immediate fault when using the work as intended. 21 */ 22 23 #ifndef _CTYPE_H_ 24 #define _CTYPE_H_ 25 26 #include <sys/cdefs.h> 27 28 /* from src/lib/libc/include/mir18n.h,v 1.18 */ 29 #define _ctp_alnum 0x000C 30 #define _ctp_alpha 0x0004 31 #define _ctp_blank 0x0040 32 #define _ctp_cntrl 0x0080 33 #define _ctp_digit 0x0408 34 #define _ctp_graph 0x1020 35 #define _ctp_lower 0x0102 36 #define _ctp_print 0x0020 37 #define _ctp_punct 0x1C20 38 #define _ctp_space 0x0010 39 #define _ctp_title 0x0003 40 #define _ctp_upper 0x0201 41 #define _ctp_xdigit 0x0008 42 43 __BEGIN_DECLS 44 int isalnum(int); 45 int isalpha(int); 46 int iscntrl(int); 47 int isdigit(int); 48 int isgraph(int); 49 int islower(int); 50 int isprint(int); 51 int ispunct(int); 52 int isspace(int); 53 int istitle(int); 54 int isupper(int); 55 int isxdigit(int); 56 int tolower(int); 57 int totitle(int); 58 int toupper(int); 59 60 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 61 int isascii(int); 62 #if __OPENBSD_VISIBLE 63 int isbinry(int); 64 #endif 65 int isblank(int); 66 int toascii(int); 67 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 68 69 #if !defined(lint) 70 71 extern const unsigned char __C_attribute_table_pg[256]; 72 73 #ifdef __GNUC__ 74 #define __CTYPE_IMPL(c,t) __extension__({ \ 75 unsigned __CTYPE_Ic = (c); \ 76 \ 77 (__CTYPE_Ic > 127) ? 0 : \ 78 ((__C_attribute_table_pg[__CTYPE_Ic] & (_ctp_ ## t & 0xFF)) && \ 79 !(__C_attribute_table_pg[__CTYPE_Ic] & (_ctp_ ## t >> 8))); \ 80 }) 81 #else 82 #define __CTYPE_IMPL(c,t) \ 83 ((((unsigned)(c)) > 127) ? 0 : \ 84 ((__C_attribute_table_pg[((unsigned)(c))] & \ 85 (_ctp_ ## t & 0xFF)) && \ 86 !(__C_attribute_table_pg[((unsigned)(c))] & \ 87 (_ctp_ ## t >> 8)))) 88 #endif 89 90 #define isalnum(c) __CTYPE_IMPL((c),alnum) 91 #define isalpha(c) __CTYPE_IMPL((c),alpha) 92 #define iscntrl(c) __CTYPE_IMPL((c),cntrl) 93 #define isdigit(c) __CTYPE_IMPL((c),digit) 94 #define isgraph(c) __CTYPE_IMPL((c),graph) 95 #define islower(c) __CTYPE_IMPL((c),lower) 96 #define isprint(c) __CTYPE_IMPL((c),print) 97 #define ispunct(c) __CTYPE_IMPL((c),punct) 98 #define isspace(c) __CTYPE_IMPL((c),space) 99 #define istitle(c) 0 100 #define isupper(c) __CTYPE_IMPL((c),upper) 101 #define isxdigit(c) __CTYPE_IMPL((c),xdigit) 102 103 #ifdef __GNUC__ 104 #define tolower(c) __extension__({ \ 105 int __CTYPE_Tl = (c); \ 106 \ 107 (__CTYPE_Tl >= 'A') && (__CTYPE_Tl <= 'Z') ? \ 108 __CTYPE_Tl - 'A' + 'a' : __CTYPE_Tl; \ 109 }) 110 #define toupper(c) __extension__({ \ 111 int __CTYPE_Tu = (c); \ 112 \ 113 (__CTYPE_Tu >= 'a') && (__CTYPE_Tu <= 'z') ? \ 114 __CTYPE_Tu - 'a' + 'A' : __CTYPE_Tu; \ 115 }) 116 #else 117 #define tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c)) 118 #define toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c)) 119 #endif 120 #define totitle(c) toupper(c) 121 122 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) 123 #define isascii(c) ((unsigned)(c) < 0x80) 124 #define isblank(c) __CTYPE_IMPL((c),blank) 125 #define toascii(c) ((c) & 0x7F) 126 127 #define _tolower(c) ((c) | 0x20) 128 #define _toupper(c) ((c) & 0xDF) 129 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */ 130 131 #if __OPENBSD_VISIBLE 132 #define isbinry(c) __extension__({ \ 133 uint8_t __CTYPE_Ic = (c); \ 134 \ 135 ((__CTYPE_Ic == 0x00) || (__CTYPE_Ic == 0xC0) || \ 136 (__CTYPE_Ic == 0xC1) || (__CTYPE_Ic > 0xEF)); \ 137 }) 138 #endif 139 140 #endif /* !lint */ 141 142 __END_DECLS 143 144 #endif /* !_CTYPE_H_ */ 145