1 /* chardefs.h -- Character definitions for readline. */
3 /* Copyright (C) 1994-2015 Free Software Foundation, Inc.
5 This file is part of the GNU Readline Library (Readline), a library
6 for reading lines of text with interactive input and history editing.
8 Readline is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Readline is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Readline. If not, see <http://www.gnu.org/licenses/>.
27 #if defined (HAVE_CONFIG_H)
28 # if defined (HAVE_STRING_H)
29 # if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
33 # endif /* HAVE_STRING_H */
34 # if defined (HAVE_STRINGS_H)
36 # endif /* HAVE_STRINGS_H */
39 #endif /* !HAVE_CONFIG_H */
42 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
52 /* Some character stuff. */
53 #define control_character_threshold 0x020 /* Smaller than this is control. */
54 #define control_character_mask 0x1f /* 0x20 - 1 */
55 #define meta_character_threshold 0x07f /* Larger than this is Meta. */
56 #define control_character_bit 0x40 /* 0x000000, must be off. */
57 #define meta_character_bit 0x080 /* x0000000, must be on. */
58 #define largest_char 255 /* Largest character value. */
60 #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
61 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
63 #define CTRL(c) ((c) & control_character_mask)
64 #define META(c) ((c) | meta_character_bit)
66 #define UNMETA(c) ((c) & (~meta_character_bit))
67 #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
69 #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
70 # define IN_CTYPE_DOMAIN(c) 1
72 # define IN_CTYPE_DOMAIN(c) isascii(c)
75 #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus)
76 # define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
79 #if defined (CTYPE_NON_ASCII)
80 # define NON_NEGATIVE(c) 1
82 # define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
85 /* Some systems define these; we want our definitions. */
88 /* Beware: these only work with single-byte ASCII characters. */
90 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c))
91 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c))
92 #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c))
93 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c))
94 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c))
95 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c))
96 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c))
98 #define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
99 #define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
100 #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
102 #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
103 #define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c))
106 # define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
107 # define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
110 #ifndef _rl_digit_value
111 # define _rl_digit_value(x) ((x) - '0')
115 # define _rl_isident(c) (ISALNUM(c) || (c) == '_')
119 # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
121 #define OCTVALUE(c) ((c) - '0')
123 #define HEXVALUE(c) \
124 (((c) >= 'a' && (c) <= 'f') \
126 : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
133 #define RETURN CTRL('M')
147 #define ABORT_CHAR CTRL('G')
152 #define PAGE CTRL('L')
157 #define SPACE ' ' /* XXX - was 0x20 */
162 #define ESC CTRL('[')
164 #endif /* _CHARDEFS_H_ */