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