OSDN Git Service

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