1 /* chartypes.h -- extend ctype.h */
3 /* Copyright (C) 2001 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
21 #ifndef _SH_CHARTYPES_H
22 #define _SH_CHARTYPES_H
26 /* Jim Meyering writes:
28 "... Some ctype macros are valid only for character codes that
29 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
30 using /bin/cc or gcc but without giving an ansi option). So, all
31 ctype uses should be through macros like ISPRINT... If
32 STDC_HEADERS is defined, then autoconf has verified that the ctype
33 macros don't need to be guarded with references to isascii. ...
34 Defining IN_CTYPE_DOMAIN to 1 should let any compiler worth its salt
35 eliminate the && through constant folding."
36 Solaris defines some of these symbols so we must undefine them first. */
38 #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
39 # define IN_CTYPE_DOMAIN(c) 1
41 # define IN_CTYPE_DOMAIN(c) isascii(c)
44 #if !defined (isspace) && !defined (HAVE_ISSPACE)
45 # define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\f')
48 #if !defined (isprint) && !defined (HAVE_ISPRINT)
49 # define isprint(c) (isalpha(c) || isdigit(c) || ispunct(c))
52 #if defined (isblank) || defined (HAVE_ISBLANK)
53 # define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
55 # define ISBLANK(c) ((c) == ' ' || (c) == '\t')
58 #if defined (isgraph) || defined (HAVE_ISGRAPH)
59 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
61 # define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
64 #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
65 # define isxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
70 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
71 #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
72 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
73 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
74 #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
75 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
76 #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
77 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
78 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
79 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
81 #define ISLETTER(c) (ISALPHA(c))
83 #define DIGIT(c) ((c) >= '0' && (c) <= '9')
86 (((c) >= 'a' && (c) <= 'f') \
88 : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
91 # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
93 #define OCTVALUE(c) ((c) - '0')
95 #define TODIGIT(c) ((c) - '0')
96 #define TOCHAR(c) ((c) + '0')
98 #define TOLOWER(c) (ISUPPER(c) ? tolower(c) : (c))
99 #define TOUPPER(c) (ISLOWER(c) ? toupper(c) : (c))
102 # define TOASCII(c) (toascii(c))
104 # define TOASCII(c) ((c) & 0x7F)
107 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
108 since ours (we hope) works properly with all combinations of
109 machines, compilers, `char' and `unsigned char' argument types.
110 (Per Bothner suggested the basic approach.) */
111 #undef SIGN_EXTEND_CHAR
113 # define SIGN_EXTEND_CHAR(c) ((signed char) (c))
114 #else /* not __STDC__ */
115 /* As in Harbison and Steele. */
116 # define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
119 #endif /* _SH_CHARTYPES_H */