177298Sobrien/* <ctype.h> replacement macros. 277298Sobrien 378828Sobrien Copyright (C) 2000, 2001 Free Software Foundation, Inc. 477298Sobrien Contributed by Zack Weinberg <zackw@stanford.edu>. 577298Sobrien 677298SobrienThis file is part of the libiberty library. 777298SobrienLibiberty is free software; you can redistribute it and/or 877298Sobrienmodify it under the terms of the GNU Library General Public 977298SobrienLicense as published by the Free Software Foundation; either 1077298Sobrienversion 2 of the License, or (at your option) any later version. 1177298Sobrien 1277298SobrienLibiberty is distributed in the hope that it will be useful, 1377298Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of 1477298SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1577298SobrienLibrary General Public License for more details. 1677298Sobrien 1777298SobrienYou should have received a copy of the GNU Library General Public 1877298SobrienLicense along with libiberty; see the file COPYING.LIB. If 19218822Sdimnot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 20218822SdimBoston, MA 02110-1301, USA. */ 2177298Sobrien 2277298Sobrien/* This is a compatible replacement of the standard C library's <ctype.h> 2377298Sobrien with the following properties: 2477298Sobrien 2577298Sobrien - Implements all isxxx() macros required by C99. 2677298Sobrien - Also implements some character classes useful when 2777298Sobrien parsing C-like languages. 2877298Sobrien - Does not change behavior depending on the current locale. 2977298Sobrien - Behaves properly for all values in the range of a signed or 3077298Sobrien unsigned char. 3177298Sobrien 3277298Sobrien To avoid conflicts, this header defines the isxxx functions in upper 3377298Sobrien case, e.g. ISALPHA not isalpha. */ 3477298Sobrien 3577298Sobrien#ifndef SAFE_CTYPE_H 3677298Sobrien#define SAFE_CTYPE_H 3777298Sobrien 3877298Sobrien#ifdef isalpha 3977298Sobrien #error "safe-ctype.h and ctype.h may not be used simultaneously" 40130561Sobrien#endif 41130561Sobrien 42130561Sobrien/* Determine host character set. */ 43130561Sobrien#define HOST_CHARSET_UNKNOWN 0 44130561Sobrien#define HOST_CHARSET_ASCII 1 45130561Sobrien#define HOST_CHARSET_EBCDIC 2 46130561Sobrien 47130561Sobrien#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ 48130561Sobrien && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 49130561Sobrien# define HOST_CHARSET HOST_CHARSET_ASCII 5077298Sobrien#else 51130561Sobrien# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \ 52130561Sobrien && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A 53130561Sobrien# define HOST_CHARSET HOST_CHARSET_EBCDIC 54130561Sobrien# else 55130561Sobrien# define HOST_CHARSET HOST_CHARSET_UNKNOWN 56130561Sobrien# endif 57130561Sobrien#endif 5877298Sobrien 5977298Sobrien/* Categories. */ 6077298Sobrien 6177298Sobrienenum { 6277298Sobrien /* In C99 */ 6377298Sobrien _sch_isblank = 0x0001, /* space \t */ 6477298Sobrien _sch_iscntrl = 0x0002, /* nonprinting characters */ 6577298Sobrien _sch_isdigit = 0x0004, /* 0-9 */ 6677298Sobrien _sch_islower = 0x0008, /* a-z */ 6777298Sobrien _sch_isprint = 0x0010, /* any printing character including ' ' */ 6877298Sobrien _sch_ispunct = 0x0020, /* all punctuation */ 6977298Sobrien _sch_isspace = 0x0040, /* space \t \n \r \f \v */ 7077298Sobrien _sch_isupper = 0x0080, /* A-Z */ 7177298Sobrien _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ 7277298Sobrien 7377298Sobrien /* Extra categories useful to cpplib. */ 7477298Sobrien _sch_isidst = 0x0200, /* A-Za-z_ */ 7577298Sobrien _sch_isvsp = 0x0400, /* \n \r */ 7677298Sobrien _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ 7777298Sobrien 7877298Sobrien /* Combinations of the above. */ 7977298Sobrien _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ 8077298Sobrien _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ 8177298Sobrien _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ 8277298Sobrien _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ 8389857Sobrien _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ 8489857Sobrien _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C 8589857Sobrien (plus ` and @) */ 8677298Sobrien}; 8777298Sobrien 8877298Sobrien/* Character classification. */ 8977298Sobrienextern const unsigned short _sch_istable[256]; 9077298Sobrien 9189857Sobrien#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit)) 9277298Sobrien 9377298Sobrien#define ISALPHA(c) _sch_test(c, _sch_isalpha) 9477298Sobrien#define ISALNUM(c) _sch_test(c, _sch_isalnum) 9577298Sobrien#define ISBLANK(c) _sch_test(c, _sch_isblank) 9677298Sobrien#define ISCNTRL(c) _sch_test(c, _sch_iscntrl) 9777298Sobrien#define ISDIGIT(c) _sch_test(c, _sch_isdigit) 9877298Sobrien#define ISGRAPH(c) _sch_test(c, _sch_isgraph) 9977298Sobrien#define ISLOWER(c) _sch_test(c, _sch_islower) 10077298Sobrien#define ISPRINT(c) _sch_test(c, _sch_isprint) 10177298Sobrien#define ISPUNCT(c) _sch_test(c, _sch_ispunct) 10277298Sobrien#define ISSPACE(c) _sch_test(c, _sch_isspace) 10377298Sobrien#define ISUPPER(c) _sch_test(c, _sch_isupper) 10477298Sobrien#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit) 10577298Sobrien 10677298Sobrien#define ISIDNUM(c) _sch_test(c, _sch_isidnum) 10777298Sobrien#define ISIDST(c) _sch_test(c, _sch_isidst) 10889857Sobrien#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) 10977298Sobrien#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) 11077298Sobrien#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) 11177298Sobrien#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) 11277298Sobrien 11377298Sobrien/* Character transformation. */ 11477298Sobrienextern const unsigned char _sch_toupper[256]; 11577298Sobrienextern const unsigned char _sch_tolower[256]; 11677298Sobrien#define TOUPPER(c) _sch_toupper[(c) & 0xff] 11777298Sobrien#define TOLOWER(c) _sch_tolower[(c) & 0xff] 11877298Sobrien 11977298Sobrien#endif /* SAFE_CTYPE_H */ 120