00001 /* clib/include/ctype.h 00002 * 00003 * Provides ctype 00004 * This version of ctype doesnt handle EOF 00005 * This implementation of cytpe is very simple and some flags may be wrong 00006 * An attempt was made to make the defines line up with the BSD/GNU ones so 00007 * they should be compatible 00008 * 00009 * Copyright 2003 Simtec Electronics 00010 * 00011 * Permission is hereby granted, free of charge, to any person 00012 * obtaining a copy of this software and associated documentation 00013 * files (the "Software"), to deal in the Software without 00014 * restriction, including without limitation the rights to use, copy, 00015 * modify, merge, publish, distribute, sublicense, and/or sell copies 00016 * of the Software, and to permit persons to whom the Software is 00017 * furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00025 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00026 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00027 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00028 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00029 * SOFTWARE. 00030 * 00031 */ 00032 00033 #ifndef _ABLE_CLIB_CTYPE_H 00034 #define _ABLE_CLIB_CTYPE_H 1 00035 00036 /* each macro set a bit indicating a type, 8 flags is 1 bytes worth 00037 * each character has a byte with its apropriate flags set 00038 * The macros below select for specific flags masked out of the flag array 00039 */ 00040 #define _U 0x01 /* upper case */ 00041 #define _L 0x02 /* lower case */ 00042 #define _D 0x04 /* digit */ 00043 #define _C 0x08 /* control charcter */ 00044 #define _P 0x10 /* punctuation */ 00045 #define _S 0x20 /* white space (space/lf/tab) */ 00046 #define _X 0x40 /* hex digits (A-F) */ 00047 #define _SP 0x80 /* hard space (0x20) */ 00048 00049 extern const unsigned char _ctype[]; 00050 00051 #define __ismask(x) (_ctype[(int)(unsigned char)(x)]) 00052 00053 #define isprint(c) ((__ismask(c) & ( _U | _L | _D | _P | _SP )) != 0) 00054 #define isgraph(c) ((__ismask(c) & ( _U | _L | _D | _P )) != 0) 00055 #define isalnum(c) ((__ismask(c) & ( _U | _L | _D )) != 0) 00056 #define isalpha(c) ((__ismask(c) & ( _U | _L )) != 0) 00057 #define isupper(c) ((__ismask(c) & ( _U )) != 0) 00058 #define islower(c) ((__ismask(c) & ( _L )) != 0) 00059 #define isdigit(c) ((__ismask(c) & ( _D )) != 0) 00060 #define ispunct(c) ((__ismask(c) & ( _P )) != 0) 00061 #define isspace(c) ((__ismask(c) & ( _S )) != 0) 00062 #define isxdigit(c) ((__ismask(c) & ( _D | _X )) != 0) 00063 #define iscntrl(c) ((__ismask(c) & ( _C )) != 0) 00064 00065 /* define everything top bit set as not ascii */ 00066 #define isascii(c) (((unsigned char)(c))<=0x7f) 00067 00068 /* to change to ascii simply clear top bit */ 00069 #define toascii(c) (((unsigned char)(c))&0x7f) 00070 00071 /* is blank checks for space and tab character */ 00072 #define isblank(c) (((c) == ' ') || ((c) == '\t')) 00073 00074 static inline unsigned char __tolower(unsigned char c) 00075 { 00076 if (isupper(c)) 00077 c -= 'A'-'a'; 00078 return c; 00079 } 00080 00081 static inline unsigned char __toupper(unsigned char c) 00082 { 00083 if (islower(c)) 00084 c -= 'a'-'A'; 00085 return c; 00086 } 00087 00088 #define tolower(c) __tolower(c) 00089 #define toupper(c) __toupper(c) 00090 00091 #endif /* _ABLE_CLIB_CTYPE_H */