1169695Skan/* <ctype.h> replacement macros. 2169695Skan 3169695Skan Copyright (C) 2000, 2001 Free Software Foundation, Inc. 4169695Skan Contributed by Zack Weinberg <zackw@stanford.edu>. 5169695Skan 6169695SkanThis file is part of the libiberty library. 7169695SkanLibiberty is free software; you can redistribute it and/or 8169695Skanmodify it under the terms of the GNU Library General Public 9169695SkanLicense as published by the Free Software Foundation; either 10169695Skanversion 2 of the License, or (at your option) any later version. 11169695Skan 12169695SkanLibiberty is distributed in the hope that it will be useful, 13169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of 14169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15169695SkanLibrary General Public License for more details. 16169695Skan 17169695SkanYou should have received a copy of the GNU Library General Public 18169695SkanLicense along with libiberty; see the file COPYING.LIB. If 19169695Skannot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 20169695SkanBoston, MA 02110-1301, USA. */ 21169695Skan 22169695Skan/* This is a compatible replacement of the standard C library's <ctype.h> 23169695Skan with the following properties: 24169695Skan 25169695Skan - Implements all isxxx() macros required by C99. 26169695Skan - Also implements some character classes useful when 27169695Skan parsing C-like languages. 28169695Skan - Does not change behavior depending on the current locale. 29169695Skan - Behaves properly for all values in the range of a signed or 30169695Skan unsigned char. 31169695Skan 32169695Skan To avoid conflicts, this header defines the isxxx functions in upper 33169695Skan case, e.g. ISALPHA not isalpha. */ 34169695Skan 35169695Skan#ifndef SAFE_CTYPE_H 36169695Skan#define SAFE_CTYPE_H 37169695Skan 38169695Skan#ifdef isalpha 39169695Skan #error "safe-ctype.h and ctype.h may not be used simultaneously" 40169695Skan#endif 41169695Skan 42169695Skan/* Determine host character set. */ 43169695Skan#define HOST_CHARSET_UNKNOWN 0 44169695Skan#define HOST_CHARSET_ASCII 1 45169695Skan#define HOST_CHARSET_EBCDIC 2 46169695Skan 47169695Skan#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ 48169695Skan && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 49169695Skan# define HOST_CHARSET HOST_CHARSET_ASCII 50169695Skan#else 51169695Skan# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \ 52169695Skan && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A 53169695Skan# define HOST_CHARSET HOST_CHARSET_EBCDIC 54169695Skan# else 55169695Skan# define HOST_CHARSET HOST_CHARSET_UNKNOWN 56169695Skan# endif 57169695Skan#endif 58169695Skan 59169695Skan/* Categories. */ 60169695Skan 61169695Skanenum { 62169695Skan /* In C99 */ 63169695Skan _sch_isblank = 0x0001, /* space \t */ 64169695Skan _sch_iscntrl = 0x0002, /* nonprinting characters */ 65169695Skan _sch_isdigit = 0x0004, /* 0-9 */ 66169695Skan _sch_islower = 0x0008, /* a-z */ 67169695Skan _sch_isprint = 0x0010, /* any printing character including ' ' */ 68169695Skan _sch_ispunct = 0x0020, /* all punctuation */ 69169695Skan _sch_isspace = 0x0040, /* space \t \n \r \f \v */ 70169695Skan _sch_isupper = 0x0080, /* A-Z */ 71169695Skan _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ 72169695Skan 73169695Skan /* Extra categories useful to cpplib. */ 74169695Skan _sch_isidst = 0x0200, /* A-Za-z_ */ 75169695Skan _sch_isvsp = 0x0400, /* \n \r */ 76169695Skan _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ 77169695Skan 78169695Skan /* Combinations of the above. */ 79169695Skan _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ 80169695Skan _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ 81169695Skan _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ 82169695Skan _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ 83169695Skan _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ 84169695Skan _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C 85169695Skan (plus ` and @) */ 86169695Skan}; 87169695Skan 88169695Skan/* Character classification. */ 89169695Skanextern const unsigned short _sch_istable[256]; 90169695Skan 91169695Skan#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit)) 92169695Skan 93169695Skan#define ISALPHA(c) _sch_test(c, _sch_isalpha) 94169695Skan#define ISALNUM(c) _sch_test(c, _sch_isalnum) 95169695Skan#define ISBLANK(c) _sch_test(c, _sch_isblank) 96169695Skan#define ISCNTRL(c) _sch_test(c, _sch_iscntrl) 97169695Skan#define ISDIGIT(c) _sch_test(c, _sch_isdigit) 98169695Skan#define ISGRAPH(c) _sch_test(c, _sch_isgraph) 99169695Skan#define ISLOWER(c) _sch_test(c, _sch_islower) 100169695Skan#define ISPRINT(c) _sch_test(c, _sch_isprint) 101169695Skan#define ISPUNCT(c) _sch_test(c, _sch_ispunct) 102169695Skan#define ISSPACE(c) _sch_test(c, _sch_isspace) 103169695Skan#define ISUPPER(c) _sch_test(c, _sch_isupper) 104169695Skan#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit) 105169695Skan 106169695Skan#define ISIDNUM(c) _sch_test(c, _sch_isidnum) 107169695Skan#define ISIDST(c) _sch_test(c, _sch_isidst) 108169695Skan#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) 109169695Skan#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) 110169695Skan#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) 111169695Skan#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) 112169695Skan 113169695Skan/* Character transformation. */ 114169695Skanextern const unsigned char _sch_toupper[256]; 115169695Skanextern const unsigned char _sch_tolower[256]; 116169695Skan#define TOUPPER(c) _sch_toupper[(c) & 0xff] 117169695Skan#define TOLOWER(c) _sch_tolower[(c) & 0xff] 118169695Skan 119169695Skan#endif /* SAFE_CTYPE_H */ 120