dvitomp fix from Akira
[mplib] / src / texk / kpathsea / c-ctype.h
1 /* c-ctype.h: ASCII-safe versions of the <ctype.h> macros.
2
3    Copyright 1992, 1994, 2008 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'.  */
25 #ifdef WIN32
26 #include <oldnames.h>
27 #else
28 #ifndef isascii
29 #define isascii(c) 1
30 #endif
31 #endif
32
33 #define ISALNUM(c) (isascii (c) && isalnum(c))
34 #define ISALPHA(c) (isascii (c) && isalpha(c))
35 #define ISASCII isascii
36 #define ISCNTRL(c) (isascii (c) && iscntrl(c))
37 #define ISDIGIT(c) (isascii (c) && isdigit (c))
38 #define ISGRAPH(c) (isascii (c) && isgraph(c))
39 #define ISLOWER(c) (isascii (c) && islower(c))
40 #define ISPRINT(c) (isascii (c) && isprint(c))
41 #define ISPUNCT(c) (isascii (c) && ispunct(c))
42 #define ISSPACE(c) (isascii (c) && isspace(c))
43 #define ISUPPER(c) (isascii (c) && isupper(c))
44 #define ISXDIGIT(c) (isascii (c) && isxdigit(c))
45 #define TOASCII toascii
46 #define TOLOWER(c) (ISUPPER (c) ? tolower (c) : (c))
47 #define TOUPPER(c) (ISLOWER (c) ? toupper (c) : (c))
48
49 /* This isn't part of the usual <ctype.h>, but it's useful sometimes.  */
50 #ifndef isblank
51 #define isblank(c) ((c) == ' ' || (c) == '\t')
52 #endif
53
54 #define ISBLANK(c) (isascii (c) && isblank (c))
55
56
57 /* Here's why this mess is necessary:
58
59 From: meyering@cs.utexas.edu (Jim Meyering)
60 Date: Wed, 25 Nov 1992 09:52:33 -0600
61 Subject: ss-921123: using isascii with <ctype.h> macros
62
63   Yesterday some cursory regression testing found that GNU od
64   (in an upcoming release of textutils) generated incorrect output
65   when run on an SGI indigo because isprint ('\377') returned true.
66   Of course, '\377' is not a printing character;  the problem lay
67   in using isprint without first making sure its integer argument
68   corresponded to an ascii code.
69
70   MORAL: always guard uses of ctype macros with isascii if it's available.
71   An obvious alternative is to avoid <ctype.h> and define and use your
72   own versions of the ctype macros.
73
74   A pretty clean approach to using <ctype.h> and isascii was
75   suggested by David MacKenzie:
76
77   #ifndef isascii
78   #define isascii(c) 1
79   #endif
80
81   #define ISDIGIT(c) (isascii (c) && isdigit (c))
82   #define ISPRINT(c) (isascii (c) && isprint (c))
83   ...
84
85   then, use ISDIGIT, etc. instead of isdigit, etc.  */
86   
87 #endif /* not KPATHSEA_C_CTYPE_H */