1130803Smarcel/* <ctype.h> replacement macros. 2130803Smarcel 3130803Smarcel Copyright (C) 2000, 2001 Free Software Foundation, Inc. 4130803Smarcel Contributed by Zack Weinberg <zackw@stanford.edu>. 5130803Smarcel 6130803SmarcelThis file is part of the libiberty library. 7130803SmarcelLibiberty is free software; you can redistribute it and/or 8130803Smarcelmodify it under the terms of the GNU Library General Public 9130803SmarcelLicense as published by the Free Software Foundation; either 10130803Smarcelversion 2 of the License, or (at your option) any later version. 11130803Smarcel 12130803SmarcelLibiberty is distributed in the hope that it will be useful, 13130803Smarcelbut WITHOUT ANY WARRANTY; without even the implied warranty of 14130803SmarcelMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15130803SmarcelLibrary General Public License for more details. 16130803Smarcel 17130803SmarcelYou should have received a copy of the GNU Library General Public 18130803SmarcelLicense along with libiberty; see the file COPYING.LIB. If 19130803Smarcelnot, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20130803SmarcelBoston, MA 02111-1307, USA. */ 21130803Smarcel 22130803Smarcel/* This is a compatible replacement of the standard C library's <ctype.h> 23130803Smarcel with the following properties: 24130803Smarcel 25130803Smarcel - Implements all isxxx() macros required by C99. 26130803Smarcel - Also implements some character classes useful when 27130803Smarcel parsing C-like languages. 28130803Smarcel - Does not change behavior depending on the current locale. 29130803Smarcel - Behaves properly for all values in the range of a signed or 30130803Smarcel unsigned char. 31130803Smarcel 32130803Smarcel To avoid conflicts, this header defines the isxxx functions in upper 33130803Smarcel case, e.g. ISALPHA not isalpha. */ 34130803Smarcel 35130803Smarcel#ifndef SAFE_CTYPE_H 36130803Smarcel#define SAFE_CTYPE_H 37130803Smarcel 38130803Smarcel#ifdef isalpha 39130803Smarcel #error "safe-ctype.h and ctype.h may not be used simultaneously" 40130803Smarcel#endif 41130803Smarcel 42130803Smarcel/* Determine host character set. */ 43130803Smarcel#define HOST_CHARSET_UNKNOWN 0 44130803Smarcel#define HOST_CHARSET_ASCII 1 45130803Smarcel#define HOST_CHARSET_EBCDIC 2 46130803Smarcel 47130803Smarcel#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ 48130803Smarcel && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 49130803Smarcel# define HOST_CHARSET HOST_CHARSET_ASCII 50130803Smarcel#else 51130803Smarcel# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \ 52130803Smarcel && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A 53130803Smarcel# define HOST_CHARSET HOST_CHARSET_EBCDIC 54130803Smarcel# else 55130803Smarcel# define HOST_CHARSET HOST_CHARSET_UNKNOWN 56130803Smarcel# endif 57130803Smarcel#endif 58130803Smarcel 59130803Smarcel/* Categories. */ 60130803Smarcel 61130803Smarcelenum { 62130803Smarcel /* In C99 */ 63130803Smarcel _sch_isblank = 0x0001, /* space \t */ 64130803Smarcel _sch_iscntrl = 0x0002, /* nonprinting characters */ 65130803Smarcel _sch_isdigit = 0x0004, /* 0-9 */ 66130803Smarcel _sch_islower = 0x0008, /* a-z */ 67130803Smarcel _sch_isprint = 0x0010, /* any printing character including ' ' */ 68130803Smarcel _sch_ispunct = 0x0020, /* all punctuation */ 69130803Smarcel _sch_isspace = 0x0040, /* space \t \n \r \f \v */ 70130803Smarcel _sch_isupper = 0x0080, /* A-Z */ 71130803Smarcel _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ 72130803Smarcel 73130803Smarcel /* Extra categories useful to cpplib. */ 74130803Smarcel _sch_isidst = 0x0200, /* A-Za-z_ */ 75130803Smarcel _sch_isvsp = 0x0400, /* \n \r */ 76130803Smarcel _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ 77130803Smarcel 78130803Smarcel /* Combinations of the above. */ 79130803Smarcel _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ 80130803Smarcel _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ 81130803Smarcel _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ 82130803Smarcel _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ 83130803Smarcel _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ 84130803Smarcel _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C 85130803Smarcel (plus ` and @) */ 86130803Smarcel}; 87130803Smarcel 88130803Smarcel/* Character classification. */ 89130803Smarcelextern const unsigned short _sch_istable[256]; 90130803Smarcel 91130803Smarcel#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit)) 92130803Smarcel 93130803Smarcel#define ISALPHA(c) _sch_test(c, _sch_isalpha) 94130803Smarcel#define ISALNUM(c) _sch_test(c, _sch_isalnum) 95130803Smarcel#define ISBLANK(c) _sch_test(c, _sch_isblank) 96130803Smarcel#define ISCNTRL(c) _sch_test(c, _sch_iscntrl) 97130803Smarcel#define ISDIGIT(c) _sch_test(c, _sch_isdigit) 98130803Smarcel#define ISGRAPH(c) _sch_test(c, _sch_isgraph) 99130803Smarcel#define ISLOWER(c) _sch_test(c, _sch_islower) 100130803Smarcel#define ISPRINT(c) _sch_test(c, _sch_isprint) 101130803Smarcel#define ISPUNCT(c) _sch_test(c, _sch_ispunct) 102130803Smarcel#define ISSPACE(c) _sch_test(c, _sch_isspace) 103130803Smarcel#define ISUPPER(c) _sch_test(c, _sch_isupper) 104130803Smarcel#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit) 105130803Smarcel 106130803Smarcel#define ISIDNUM(c) _sch_test(c, _sch_isidnum) 107130803Smarcel#define ISIDST(c) _sch_test(c, _sch_isidst) 108130803Smarcel#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) 109130803Smarcel#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) 110130803Smarcel#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) 111130803Smarcel#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) 112130803Smarcel 113130803Smarcel/* Character transformation. */ 114130803Smarcelextern const unsigned char _sch_toupper[256]; 115130803Smarcelextern const unsigned char _sch_tolower[256]; 116130803Smarcel#define TOUPPER(c) _sch_toupper[(c) & 0xff] 117130803Smarcel#define TOLOWER(c) _sch_tolower[(c) & 0xff] 118130803Smarcel 119130803Smarcel#endif /* SAFE_CTYPE_H */ 120