1/* 2** Copyright 2004, Axel D��rfler, axeld@pinc-software.de. All rights reserved. 3** Distributed under the terms of the MIT License. 4*/ 5 6 7#include <ctype.h> 8 9 10// disable macros defined in ctype.h 11#undef isalnum 12#undef isalpha 13#undef isascii 14#undef isblank 15#undef iscntrl 16#undef isdigit 17#undef islower 18#undef isgraph 19#undef isprint 20#undef ispunct 21#undef isspace 22#undef isupper 23#undef isxdigit 24#undef toascii 25#undef tolower 26#undef toupper 27 28 29extern "C" 30{ 31 32 33unsigned short int __ctype_mb_cur_max = 1; 34 35 36unsigned short 37__ctype_get_mb_cur_max() 38{ 39 return __ctype_mb_cur_max; 40} 41 42 43int 44isalnum(int c) 45{ 46 if (c >= -128 && c < 256) 47 return (*__ctype_b_loc())[c] & (_ISupper | _ISlower | _ISdigit); 48 49 return 0; 50} 51 52 53int 54isalpha(int c) 55{ 56 if (c >= -128 && c < 256) 57 return (*__ctype_b_loc())[c] & (_ISupper | _ISlower); 58 59 return 0; 60} 61 62 63int 64isascii(int c) 65{ 66 /* ASCII characters have bit 8 cleared */ 67 return (c & ~0x7f) == 0; 68} 69 70 71int 72isblank(int c) 73{ 74 if (c >= -128 && c < 256) 75 return (*__ctype_b_loc())[c] & _ISblank; 76 77 return 0; 78} 79 80 81int 82iscntrl(int c) 83{ 84 if (c >= -128 && c < 256) 85 return (*__ctype_b_loc())[c] & _IScntrl; 86 87 return 0; 88} 89 90 91int 92isdigit(int c) 93{ 94 if (c >= -128 && c < 256) 95 return (*__ctype_b_loc())[c] & _ISdigit; 96 97 return 0; 98} 99 100 101int 102isgraph(int c) 103{ 104 if (c >= -128 && c < 256) 105 return (*__ctype_b_loc())[c] & _ISgraph; 106 107 return 0; 108} 109 110 111int 112islower(int c) 113{ 114 if (c >= -128 && c < 256) 115 return (*__ctype_b_loc())[c] & _ISlower; 116 117 return 0; 118} 119 120 121int 122isprint(int c) 123{ 124 if (c >= -128 && c < 256) 125 return (*__ctype_b_loc())[c] & _ISprint; 126 127 return 0; 128} 129 130 131int 132ispunct(int c) 133{ 134 if (c >= -128 && c < 256) 135 return (*__ctype_b_loc())[c] & _ISpunct; 136 137 return 0; 138} 139 140 141int 142isspace(int c) 143{ 144 if (c >= -128 && c < 256) 145 return (*__ctype_b_loc())[c] & _ISspace; 146 147 return 0; 148} 149 150 151int 152isupper(int c) 153{ 154 if (c >= -128 && c < 256) 155 return (*__ctype_b_loc())[c] & _ISupper; 156 157 return 0; 158} 159 160 161int 162isxdigit(int c) 163{ 164 if (c >= -128 && c < 256) 165 return (*__ctype_b_loc())[c] & _ISxdigit; 166 167 return 0; 168} 169 170 171int 172toascii(int c) 173{ 174 /* Clear higher bits */ 175 return c & 0x7f; 176} 177 178 179int 180tolower(int c) 181{ 182 if (c >= -128 && c < 256) 183 return (*__ctype_tolower_loc())[c]; 184 185 return c; 186} 187 188 189int 190toupper(int c) 191{ 192 if (c >= -128 && c < 256) 193 return (*__ctype_toupper_loc())[c]; 194 195 return c; 196} 197 198 199} 200