Automatic date update in version.in
[binutils-gdb.git] / readline / chardefs.h
blobe76c34b0c674fdaf76edc21e1b50a3f06692302f
1 /* chardefs.h -- Character definitions for readline. */
3 /* Copyright (C) 1994-2009 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/>.
22 #ifndef _CHARDEFS_H_
23 #define _CHARDEFS_H_
25 #include <ctype.h>
27 #if defined (HAVE_CONFIG_H)
28 # if defined (HAVE_STRING_H)
29 # if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
30 # include <memory.h>
31 # endif
32 # include <string.h>
33 # endif /* HAVE_STRING_H */
34 # if defined (HAVE_STRINGS_H)
35 # include <strings.h>
36 # endif /* HAVE_STRINGS_H */
37 #else
38 # include <string.h>
39 #endif /* !HAVE_CONFIG_H */
41 #ifndef whitespace
42 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
43 #endif
45 #ifdef CTRL
46 # undef CTRL
47 #endif
48 #ifdef UNCTRL
49 # undef UNCTRL
50 #endif
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
71 #else
72 # define IN_CTYPE_DOMAIN(c) isascii(c)
73 #endif
75 #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
76 # define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
77 #endif
79 #if defined (CTYPE_NON_ASCII)
80 # define NON_NEGATIVE(c) 1
81 #else
82 # define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
83 #endif
85 /* Some systems define these; we want our definitions. */
86 #undef ISPRINT
88 /* Beware: these only work with single-byte ASCII characters. */
90 #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
91 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
92 #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
93 #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
94 #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
95 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
96 #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (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))
105 #ifndef _rl_to_upper
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))
108 #endif
110 #ifndef _rl_digit_value
111 # define _rl_digit_value(x) ((x) - '0')
112 #endif
114 #ifndef _rl_isident
115 # define _rl_isident(c) (ISALNUM(c) || (c) == '_')
116 #endif
118 #ifndef ISOCTAL
119 # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
120 #endif
121 #define OCTVALUE(c) ((c) - '0')
123 #define HEXVALUE(c) \
124 (((c) >= 'a' && (c) <= 'f') \
125 ? (c)-'a'+10 \
126 : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
128 #ifndef NEWLINE
129 #define NEWLINE '\n'
130 #endif
132 #ifndef RETURN
133 #define RETURN CTRL('M')
134 #endif
136 #ifndef RUBOUT
137 #define RUBOUT 0x7f
138 #endif
140 #ifndef TAB
141 #define TAB '\t'
142 #endif
144 #ifdef ABORT_CHAR
145 #undef ABORT_CHAR
146 #endif
147 #define ABORT_CHAR CTRL('G')
149 #ifdef PAGE
150 #undef PAGE
151 #endif
152 #define PAGE CTRL('L')
154 #ifdef SPACE
155 #undef SPACE
156 #endif
157 #define SPACE ' ' /* XXX - was 0x20 */
159 #ifdef ESC
160 #undef ESC
161 #endif
162 #define ESC CTRL('[')
164 #endif /* _CHARDEFS_H_ */