1 /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
2 
3    Copyright 1992, 1994, 2008, 2010, 2011 Karl Berry.
4    Copyright 1998, 2000, 2005 Olaf Weber.
5 
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10 
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15 
16    You should have received a copy of the GNU Lesser General Public License
17    along with this library; if not, see <http://www.gnu.org/licenses/>.  */
18 
19 #ifndef KPATHSEA_C_CTYPE_H
20 #define KPATHSEA_C_CTYPE_H
21 
22 #include <ctype.h>
23 
24 /* Be sure we have `isascii', even if wrong.  */
25 #ifndef WIN32
26 #ifndef isascii
27 #define isascii(c) 1
28 #endif
29 #endif
30 
31 #define ISALNUM(c) (isascii (c) && isalnum(c))
32 #define ISALPHA(c) (isascii (c) && isalpha(c))
33 #define ISASCII isascii
34 #define ISCNTRL(c) (isascii (c) && iscntrl(c))
35 #define ISDIGIT(c) (isascii (c) && isdigit (c))
36 #define ISGRAPH(c) (isascii (c) && isgraph(c))
37 #define ISLOWER(c) (isascii (c) && islower(c))
38 #define ISPRINT(c) (isascii (c) && isprint(c))
39 #define ISPUNCT(c) (isascii (c) && ispunct(c))
40 #define ISSPACE(c) (isascii (c) && isspace(c))
41 #define ISUPPER(c) (isascii (c) && isupper(c))
42 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
43 #define TOASCII toascii
44 #define TOLOWER(c) (ISUPPER (c) ? tolower (c) : (c))
45 #define TOUPPER(c) (ISLOWER (c) ? toupper (c) : (c))
46 
47 /* This isn't part of the usual <ctype.h>, but it's useful sometimes.  */
48 #ifndef isblank
49 #define isblank(c) ((c) == ' ' || (c) == '\t')
50 #endif
51 
52 #define ISBLANK(c) (isascii (c) && isblank (c))
53 
54 
55 /* Here's why this mess is necessary:
56 
57 From: meyering@cs.utexas.edu (Jim Meyering)
58 Date: Wed, 25 Nov 1992 09:52:33 -0600
59 Subject: ss-921123: using isascii with <ctype.h> macros
60 
61   Yesterday some cursory regression testing found that GNU od
62   (in an upcoming release of textutils) generated incorrect output
63   when run on an SGI indigo because isprint ('\377') returned true.
64   Of course, '\377' is not a printing character;  the problem lay
65   in using isprint without first making sure its integer argument
66   corresponded to an ascii code.
67 
68   MORAL: always guard uses of ctype macros with isascii if it's available.
69   An obvious alternative is to avoid <ctype.h> and define and use your
70   own versions of the ctype macros.
71 
72   A pretty clean approach to using <ctype.h> and isascii was
73   suggested by David MacKenzie:
74 
75   #ifndef isascii
76   #define isascii(c) 1
77   #endif
78 
79   #define ISDIGIT(c) (isascii (c) && isdigit (c))
80   #define ISPRINT(c) (isascii (c) && isprint (c))
81   ...
82 
83   then, use ISDIGIT, etc. instead of isdigit, etc.  */
84 
85 #endif /* not KPATHSEA_C_CTYPE_H */
86