]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/safe-ctype.h
spell ldscript correctly in outputs.exp et al
[thirdparty/gcc.git] / include / safe-ctype.h
CommitLineData
f6bbde28
ZW
1/* <ctype.h> replacement macros.
2
8d9254fc 3 Copyright (C) 2000-2020 Free Software Foundation, Inc.
f6bbde28
ZW
4 Contributed by Zack Weinberg <zackw@stanford.edu>.
5
6This file is part of the libiberty library.
7Libiberty is free software; you can redistribute it and/or
8modify it under the terms of the GNU Library General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12Libiberty is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Library General Public License for more details.
16
17You should have received a copy of the GNU Library General Public
18License along with libiberty; see the file COPYING.LIB. If
d6d47ea0
NC
19not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20Boston, MA 02110-1301, USA. */
f6bbde28
ZW
21
22/* This is a compatible replacement of the standard C library's <ctype.h>
23 with the following properties:
24
25 - Implements all isxxx() macros required by C99.
26 - Also implements some character classes useful when
27 parsing C-like languages.
28 - Does not change behavior depending on the current locale.
29 - Behaves properly for all values in the range of a signed or
30 unsigned char.
31
32 To avoid conflicts, this header defines the isxxx functions in upper
33 case, e.g. ISALPHA not isalpha. */
34
35#ifndef SAFE_CTYPE_H
36#define SAFE_CTYPE_H
37
7468e0b5 38/* Determine host character set. */
21299dbd
ZW
39#define HOST_CHARSET_UNKNOWN 0
40#define HOST_CHARSET_ASCII 1
41#define HOST_CHARSET_EBCDIC 2
7468e0b5
ZW
42
43#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
44 && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21
21299dbd 45# define HOST_CHARSET HOST_CHARSET_ASCII
f6bbde28 46#else
7468e0b5
ZW
47# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \
48 && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A
21299dbd 49# define HOST_CHARSET HOST_CHARSET_EBCDIC
7468e0b5 50# else
21299dbd 51# define HOST_CHARSET HOST_CHARSET_UNKNOWN
7468e0b5
ZW
52# endif
53#endif
f6bbde28
ZW
54
55/* Categories. */
56
57enum {
58 /* In C99 */
59 _sch_isblank = 0x0001, /* space \t */
60 _sch_iscntrl = 0x0002, /* nonprinting characters */
61 _sch_isdigit = 0x0004, /* 0-9 */
62 _sch_islower = 0x0008, /* a-z */
63 _sch_isprint = 0x0010, /* any printing character including ' ' */
64 _sch_ispunct = 0x0020, /* all punctuation */
65 _sch_isspace = 0x0040, /* space \t \n \r \f \v */
66 _sch_isupper = 0x0080, /* A-Z */
67 _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */
68
69 /* Extra categories useful to cpplib. */
70 _sch_isidst = 0x0200, /* A-Za-z_ */
71 _sch_isvsp = 0x0400, /* \n \r */
72 _sch_isnvsp = 0x0800, /* space \t \f \v \0 */
73
74 /* Combinations of the above. */
75 _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */
76 _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */
77 _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */
78 _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */
5a6943c7
NB
79 _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */
80 _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C
81 (plus ` and @) */
f6bbde28
ZW
82};
83
f6bbde28
ZW
84/* Character classification. */
85extern const unsigned short _sch_istable[256];
86
9bb9ef28 87#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit))
f6bbde28
ZW
88
89#define ISALPHA(c) _sch_test(c, _sch_isalpha)
90#define ISALNUM(c) _sch_test(c, _sch_isalnum)
91#define ISBLANK(c) _sch_test(c, _sch_isblank)
92#define ISCNTRL(c) _sch_test(c, _sch_iscntrl)
93#define ISDIGIT(c) _sch_test(c, _sch_isdigit)
94#define ISGRAPH(c) _sch_test(c, _sch_isgraph)
95#define ISLOWER(c) _sch_test(c, _sch_islower)
96#define ISPRINT(c) _sch_test(c, _sch_isprint)
97#define ISPUNCT(c) _sch_test(c, _sch_ispunct)
98#define ISSPACE(c) _sch_test(c, _sch_isspace)
99#define ISUPPER(c) _sch_test(c, _sch_isupper)
100#define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
101
102#define ISIDNUM(c) _sch_test(c, _sch_isidnum)
103#define ISIDST(c) _sch_test(c, _sch_isidst)
5a6943c7 104#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic)
f6bbde28
ZW
105#define IS_VSPACE(c) _sch_test(c, _sch_isvsp)
106#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp)
107#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp)
108
109/* Character transformation. */
110extern const unsigned char _sch_toupper[256];
111extern const unsigned char _sch_tolower[256];
d092a925
HB
112#define TOUPPER(c) _sch_toupper[(c) & 0xff]
113#define TOLOWER(c) _sch_tolower[(c) & 0xff]
f6bbde28 114
47cfcc3a
JB
115/* Prevent the users of safe-ctype.h from accidently using the routines
116 from ctype.h. Initially, the approach was to produce an error when
117 detecting that ctype.h has been included. But this was causing
118 trouble as ctype.h might get indirectly included as a result of
622c36c9
JB
119 including another system header (for instance gnulib's stdint.h).
120 So we include ctype.h here and then immediately redefine its macros. */
121
122#include <ctype.h>
47cfcc3a
JB
123#undef isalpha
124#define isalpha(c) do_not_use_isalpha_with_safe_ctype
125#undef isalnum
126#define isalnum(c) do_not_use_isalnum_with_safe_ctype
127#undef iscntrl
128#define iscntrl(c) do_not_use_iscntrl_with_safe_ctype
129#undef isdigit
130#define isdigit(c) do_not_use_isdigit_with_safe_ctype
131#undef isgraph
132#define isgraph(c) do_not_use_isgraph_with_safe_ctype
133#undef islower
134#define islower(c) do_not_use_islower_with_safe_ctype
135#undef isprint
136#define isprint(c) do_not_use_isprint_with_safe_ctype
137#undef ispunct
138#define ispunct(c) do_not_use_ispunct_with_safe_ctype
139#undef isspace
140#define isspace(c) do_not_use_isspace_with_safe_ctype
141#undef isupper
142#define isupper(c) do_not_use_isupper_with_safe_ctype
143#undef isxdigit
144#define isxdigit(c) do_not_use_isxdigit_with_safe_ctype
145#undef toupper
146#define toupper(c) do_not_use_toupper_with_safe_ctype
147#undef tolower
148#define tolower(c) do_not_use_tolower_with_safe_ctype
149
f6bbde28 150#endif /* SAFE_CTYPE_H */