1 | /* chardefs.h -- Character definitions for readline. */ |
2 | |
3 | /* Copyright (C) 1994-2015 Free Software Foundation, Inc. |
4 | |
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. |
7 | |
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. |
12 | |
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. |
17 | |
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/>. |
20 | */ |
21 | |
22 | #ifndef _CHARDEFS_H_ |
23 | #define _CHARDEFS_H_ |
24 | |
25 | #include <ctype.h> |
26 | |
27 | #include <string.h> |
28 | |
29 | #ifndef whitespace |
30 | #define whitespace(c) (((c) == ' ') || ((c) == '\t')) |
31 | #endif |
32 | |
33 | #ifdef CTRL |
34 | # undef CTRL |
35 | #endif |
36 | #ifdef UNCTRL |
37 | # undef UNCTRL |
38 | #endif |
39 | |
40 | /* Some character stuff. */ |
41 | #define control_character_threshold 0x020 /* Smaller than this is control. */ |
42 | #define control_character_mask 0x1f /* 0x20 - 1 */ |
43 | #define meta_character_threshold 0x07f /* Larger than this is Meta. */ |
44 | #define control_character_bit 0x40 /* 0x000000, must be off. */ |
45 | #define meta_character_bit 0x080 /* x0000000, must be on. */ |
46 | #define largest_char 255 /* Largest character value. */ |
47 | |
48 | #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0)) |
49 | #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char) |
50 | |
51 | #define CTRL(c) ((c) & control_character_mask) |
52 | #define META(c) ((c) | meta_character_bit) |
53 | |
54 | #define UNMETA(c) ((c) & (~meta_character_bit)) |
55 | #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit)) |
56 | |
57 | #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII)) |
58 | # define IN_CTYPE_DOMAIN(c) 1 |
59 | #else |
60 | # define IN_CTYPE_DOMAIN(c) isascii(c) |
61 | #endif |
62 | |
63 | #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus) |
64 | # define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) |
65 | #endif |
66 | |
67 | #if defined (CTYPE_NON_ASCII) |
68 | # define NON_NEGATIVE(c) 1 |
69 | #else |
70 | # define NON_NEGATIVE(c) ((unsigned char)(c) == (c)) |
71 | #endif |
72 | |
73 | /* Some systems define these; we want our definitions. */ |
74 | #undef ISPRINT |
75 | |
76 | /* Beware: these only work with single-byte ASCII characters. */ |
77 | |
78 | #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c)) |
79 | #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c)) |
80 | #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c)) |
81 | #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c)) |
82 | #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c)) |
83 | #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c)) |
84 | #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c)) |
85 | |
86 | #define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c)) |
87 | #define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c)) |
88 | #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9') |
89 | |
90 | #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c)) |
91 | #define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c)) |
92 | |
93 | #ifndef _rl_to_upper |
94 | # define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c)) |
95 | # define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c)) |
96 | #endif |
97 | |
98 | #ifndef _rl_digit_value |
99 | # define _rl_digit_value(x) ((x) - '0') |
100 | #endif |
101 | |
102 | #ifndef _rl_isident |
103 | # define _rl_isident(c) (ISALNUM(c) || (c) == '_') |
104 | #endif |
105 | |
106 | #ifndef ISOCTAL |
107 | # define ISOCTAL(c) ((c) >= '0' && (c) <= '7') |
108 | #endif |
109 | #define OCTVALUE(c) ((c) - '0') |
110 | |
111 | #define HEXVALUE(c) \ |
112 | (((c) >= 'a' && (c) <= 'f') \ |
113 | ? (c)-'a'+10 \ |
114 | : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0') |
115 | |
116 | #ifndef NEWLINE |
117 | #define NEWLINE '\n' |
118 | #endif |
119 | |
120 | #ifndef RETURN |
121 | #define RETURN CTRL('M') |
122 | #endif |
123 | |
124 | #ifndef RUBOUT |
125 | #define RUBOUT 0x7f |
126 | #endif |
127 | |
128 | #ifndef TAB |
129 | #define TAB '\t' |
130 | #endif |
131 | |
132 | #ifdef ABORT_CHAR |
133 | #undef ABORT_CHAR |
134 | #endif |
135 | #define ABORT_CHAR CTRL('G') |
136 | |
137 | #ifdef PAGE |
138 | #undef PAGE |
139 | #endif |
140 | #define PAGE CTRL('L') |
141 | |
142 | #ifdef SPACE |
143 | #undef SPACE |
144 | #endif |
145 | #define SPACE ' ' /* XXX - was 0x20 */ |
146 | |
147 | #ifdef ESC |
148 | #undef ESC |
149 | #endif |
150 | #define ESC CTRL('[') |
151 | |
152 | #endif /* _CHARDEFS_H_ */ |
153 | |