annotate kpathsea/c-ctype.h @ 1315:611d403c7f3d

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