Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /* Copyright (C) 2002 Manuel Novoa III * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * The GNU C Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with the GNU C Library; see the file COPYING.LIB. If * not, see <http://www.gnu.org/licenses/>. */ /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! * * Besides uClibc, I'm using this code in my libc for elks, which is * a 16-bit environment with a fairly limited compiler. It would make * things much easier for me if this file isn't modified unnecessarily. * In particular, please put any new or replacement functions somewhere * else, and modify the makefile to use your version instead. * Thanks. Manuel * * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */ #if !defined(_CTYPE_H) && !defined(_WCTYPE_H) #error Always include <{w}ctype.h> rather than <bits/uClibc_ctype.h> #endif #ifndef _BITS_UCLIBC_CTYPE_H #define _BITS_UCLIBC_CTYPE_H #ifdef __UCLIBC_GEN_LOCALE /* We are in extra/locale/gen_XXX tools build */ #include "uClibc_charclass.h" #else /* Define some ctype macros valid for the C/POSIX locale. */ /* ASCII ords of \t, \f, \n, \r, and \v are 9, 12, 10, 13, 11 respectively. */ #define __C_isspace(c) \ ((sizeof(c) == sizeof(char)) \ ? ((((c) == ' ') || (((unsigned char)((c) - 9)) <= (13 - 9)))) \ : ((((c) == ' ') || (((unsigned int)((c) - 9)) <= (13 - 9))))) #define __C_isblank(c) (((c) == ' ') || ((c) == '\t')) #define __C_isdigit(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - '0')) < 10) \ : (((unsigned int)((c) - '0')) < 10)) #define __C_isxdigit(c) \ (__C_isdigit(c) \ || ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((((c)) | 0x20) - 'a')) < 6) \ : (((unsigned int)((((c)) | 0x20) - 'a')) < 6))) #define __C_iscntrl(c) \ ((sizeof(c) == sizeof(char)) \ ? ((((unsigned char)(c)) < 0x20) || ((c) == 0x7f)) \ : ((((unsigned int)(c)) < 0x20) || ((c) == 0x7f))) #define __C_isalpha(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)(((c) | 0x20) - 'a')) < 26) \ : (((unsigned int)(((c) | 0x20) - 'a')) < 26)) #define __C_isalnum(c) (__C_isalpha(c) || __C_isdigit(c)) #define __C_isprint(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - 0x20)) <= (0x7e - 0x20)) \ : (((unsigned int)((c) - 0x20)) <= (0x7e - 0x20))) #define __C_islower(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - 'a')) < 26) \ : (((unsigned int)((c) - 'a')) < 26)) #define __C_isupper(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - 'A')) < 26) \ : (((unsigned int)((c) - 'A')) < 26)) #define __C_ispunct(c) \ ((!__C_isalnum(c)) \ && ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - 0x21)) <= (0x7e - 0x21)) \ : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21)))) #define __C_isgraph(c) \ ((sizeof(c) == sizeof(char)) \ ? (((unsigned char)((c) - 0x21)) <= (0x7e - 0x21)) \ : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21))) #define __C_tolower(c) (__C_isupper(c) ? ((c) | 0x20) : (c)) #define __C_toupper(c) (__C_islower(c) ? ((c) ^ 0x20) : (c)) /**********************************************************************/ __BEGIN_DECLS #ifdef _LIBC /* These are uClibc-specific. */ # define __isdigit_char(c) ((unsigned char)((c) - '0') <= 9) # define __isdigit_int(c) ((unsigned int)((c) - '0') <= 9) #endif /* Now some non-ansi/iso c99 macros. */ #ifdef __UCLIBC_SUSV4_LEGACY__ #define __isascii(c) (((c) & ~0x7f) == 0) #define __toascii(c) ((c) & 0x7f) /* Works correctly *only* on lowercase letters! */ #define _toupper(c) ((c) ^ 0x20) /* Works correctly *only* on letters (of any case) and numbers */ #define _tolower(c) ((c) | 0x20) #endif __END_DECLS /**********************************************************************/ #ifdef __GNUC__ # define __body_C_macro(f,args) __C_ ## f args # define __body(f,c) \ (__extension__ ({ \ int __res; \ if (sizeof(c) > sizeof(char)) { \ int __c = (c); \ __res = __body_C_macro(f,(__c)); \ } else { \ unsigned char __c = (c); \ __res = __body_C_macro(f,(__c)); \ } \ __res; \ })) # define __isspace(c) __body(isspace,c) # define __isblank(c) __body(isblank,c) # define __isdigit(c) __body(isdigit,c) # define __isxdigit(c) __body(isxdigit,c) # define __iscntrl(c) __body(iscntrl,c) # define __isalpha(c) __body(isalpha,c) # define __isalnum(c) __body(isalnum,c) # define __isprint(c) __body(isprint,c) # define __islower(c) __body(islower,c) # define __isupper(c) __body(isupper,c) # define __ispunct(c) __body(ispunct,c) # define __isgraph(c) __body(isgraph,c) /*locale-aware ctype.h has no __tolower, why stub locale *tries to have it? remove after 0.9.31 *# define __tolower(c) __body(tolower,c) *# define __toupper(c) __body(toupper,c) */ /* Do not combine in one #if - unifdef tool is not that clever */ # ifndef __NO_CTYPE # ifndef __cplusplus # define isspace(c) __isspace(c) # define isblank(c) __isblank(c) # define isdigit(c) __isdigit(c) # define isxdigit(c) __isxdigit(c) # define iscntrl(c) __iscntrl(c) # define isalpha(c) __isalpha(c) # define isalnum(c) __isalnum(c) # define isprint(c) __isprint(c) # define islower(c) __islower(c) # define isupper(c) __isupper(c) # define ispunct(c) __ispunct(c) # define isgraph(c) __isgraph(c) # define tolower(c) __body(tolower,c) # define toupper(c) __body(toupper,c) # endif # endif #else /* !_GNUC__ */ # ifndef __NO_CTYPE # ifndef __cplusplus /* These macros should be safe from side effects! * (not all __C_xxx macros are) */ # define isdigit(c) __C_isdigit(c) # define isalpha(c) __C_isalpha(c) # define isprint(c) __C_isprint(c) # define islower(c) __C_islower(c) # define isupper(c) __C_isupper(c) # define isgraph(c) __C_isgraph(c) # endif # endif #endif /* __GNUC__ */ /**********************************************************************/ #endif /* __UCLIBC_GEN_LOCALE */ #endif /* _BITS_UCLIBC_CTYPE_H */ |