xref: /dflybsd-src/contrib/gdb-7/readline/chardefs.h (revision 16003dcfd2baa152f5dd24794ec9f36e139eaeb8)
1*6b445a62SJohn Marino /* chardefs.h -- Character definitions for readline. */
2*6b445a62SJohn Marino 
3*6b445a62SJohn Marino /* Copyright (C) 1994-2009 Free Software Foundation, Inc.
4*6b445a62SJohn Marino 
5*6b445a62SJohn Marino    This file is part of the GNU Readline Library (Readline), a library
6*6b445a62SJohn Marino    for reading lines of text with interactive input and history editing.
7*6b445a62SJohn Marino 
8*6b445a62SJohn Marino    Readline is free software: you can redistribute it and/or modify
9*6b445a62SJohn Marino    it under the terms of the GNU General Public License as published by
10*6b445a62SJohn Marino    the Free Software Foundation, either version 3 of the License, or
11*6b445a62SJohn Marino    (at your option) any later version.
12*6b445a62SJohn Marino 
13*6b445a62SJohn Marino    Readline is distributed in the hope that it will be useful,
14*6b445a62SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*6b445a62SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*6b445a62SJohn Marino    GNU General Public License for more details.
17*6b445a62SJohn Marino 
18*6b445a62SJohn Marino    You should have received a copy of the GNU General Public License
19*6b445a62SJohn Marino    along with Readline.  If not, see <http://www.gnu.org/licenses/>.
20*6b445a62SJohn Marino */
21*6b445a62SJohn Marino 
22*6b445a62SJohn Marino #ifndef _CHARDEFS_H_
23*6b445a62SJohn Marino #define _CHARDEFS_H_
24*6b445a62SJohn Marino 
25*6b445a62SJohn Marino #include <ctype.h>
26*6b445a62SJohn Marino 
27*6b445a62SJohn Marino #if defined (HAVE_CONFIG_H)
28*6b445a62SJohn Marino #  if defined (HAVE_STRING_H)
29*6b445a62SJohn Marino #    if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
30*6b445a62SJohn Marino #      include <memory.h>
31*6b445a62SJohn Marino #    endif
32*6b445a62SJohn Marino #    include <string.h>
33*6b445a62SJohn Marino #  endif /* HAVE_STRING_H */
34*6b445a62SJohn Marino #  if defined (HAVE_STRINGS_H)
35*6b445a62SJohn Marino #    include <strings.h>
36*6b445a62SJohn Marino #  endif /* HAVE_STRINGS_H */
37*6b445a62SJohn Marino #else
38*6b445a62SJohn Marino #  include <string.h>
39*6b445a62SJohn Marino #endif /* !HAVE_CONFIG_H */
40*6b445a62SJohn Marino 
41*6b445a62SJohn Marino #ifndef whitespace
42*6b445a62SJohn Marino #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
43*6b445a62SJohn Marino #endif
44*6b445a62SJohn Marino 
45*6b445a62SJohn Marino #ifdef CTRL
46*6b445a62SJohn Marino #  undef CTRL
47*6b445a62SJohn Marino #endif
48*6b445a62SJohn Marino #ifdef UNCTRL
49*6b445a62SJohn Marino #  undef UNCTRL
50*6b445a62SJohn Marino #endif
51*6b445a62SJohn Marino 
52*6b445a62SJohn Marino /* Some character stuff. */
53*6b445a62SJohn Marino #define control_character_threshold 0x020   /* Smaller than this is control. */
54*6b445a62SJohn Marino #define control_character_mask 0x1f	    /* 0x20 - 1 */
55*6b445a62SJohn Marino #define meta_character_threshold 0x07f	    /* Larger than this is Meta. */
56*6b445a62SJohn Marino #define control_character_bit 0x40	    /* 0x000000, must be off. */
57*6b445a62SJohn Marino #define meta_character_bit 0x080	    /* x0000000, must be on. */
58*6b445a62SJohn Marino #define largest_char 255		    /* Largest character value. */
59*6b445a62SJohn Marino 
60*6b445a62SJohn Marino #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
61*6b445a62SJohn Marino #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
62*6b445a62SJohn Marino 
63*6b445a62SJohn Marino #define CTRL(c) ((c) & control_character_mask)
64*6b445a62SJohn Marino #define META(c) ((c) | meta_character_bit)
65*6b445a62SJohn Marino 
66*6b445a62SJohn Marino #define UNMETA(c) ((c) & (~meta_character_bit))
67*6b445a62SJohn Marino #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
68*6b445a62SJohn Marino 
69*6b445a62SJohn Marino #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
70*6b445a62SJohn Marino #  define IN_CTYPE_DOMAIN(c) 1
71*6b445a62SJohn Marino #else
72*6b445a62SJohn Marino #  define IN_CTYPE_DOMAIN(c) isascii(c)
73*6b445a62SJohn Marino #endif
74*6b445a62SJohn Marino 
75*6b445a62SJohn Marino #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
76*6b445a62SJohn Marino #  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
77*6b445a62SJohn Marino #endif
78*6b445a62SJohn Marino 
79*6b445a62SJohn Marino #if defined (CTYPE_NON_ASCII)
80*6b445a62SJohn Marino #  define NON_NEGATIVE(c) 1
81*6b445a62SJohn Marino #else
82*6b445a62SJohn Marino #  define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
83*6b445a62SJohn Marino #endif
84*6b445a62SJohn Marino 
85*6b445a62SJohn Marino /* Some systems define these; we want our definitions. */
86*6b445a62SJohn Marino #undef ISPRINT
87*6b445a62SJohn Marino 
88*6b445a62SJohn Marino /* Beware:  these only work with single-byte ASCII characters. */
89*6b445a62SJohn Marino 
90*6b445a62SJohn Marino #define ISALNUM(c)	(IN_CTYPE_DOMAIN (c) && isalnum (c))
91*6b445a62SJohn Marino #define ISALPHA(c)	(IN_CTYPE_DOMAIN (c) && isalpha (c))
92*6b445a62SJohn Marino #define ISDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isdigit (c))
93*6b445a62SJohn Marino #define ISLOWER(c)	(IN_CTYPE_DOMAIN (c) && islower (c))
94*6b445a62SJohn Marino #define ISPRINT(c)	(IN_CTYPE_DOMAIN (c) && isprint (c))
95*6b445a62SJohn Marino #define ISUPPER(c)	(IN_CTYPE_DOMAIN (c) && isupper (c))
96*6b445a62SJohn Marino #define ISXDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isxdigit (c))
97*6b445a62SJohn Marino 
98*6b445a62SJohn Marino #define _rl_lowercase_p(c)	(NON_NEGATIVE(c) && ISLOWER(c))
99*6b445a62SJohn Marino #define _rl_uppercase_p(c)	(NON_NEGATIVE(c) && ISUPPER(c))
100*6b445a62SJohn Marino #define _rl_digit_p(c)		((c) >= '0' && (c) <= '9')
101*6b445a62SJohn Marino 
102*6b445a62SJohn Marino #define _rl_pure_alphabetic(c)	(NON_NEGATIVE(c) && ISALPHA(c))
103*6b445a62SJohn Marino #define ALPHABETIC(c)		(NON_NEGATIVE(c) && ISALNUM(c))
104*6b445a62SJohn Marino 
105*6b445a62SJohn Marino #ifndef _rl_to_upper
106*6b445a62SJohn Marino #  define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
107*6b445a62SJohn Marino #  define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
108*6b445a62SJohn Marino #endif
109*6b445a62SJohn Marino 
110*6b445a62SJohn Marino #ifndef _rl_digit_value
111*6b445a62SJohn Marino #  define _rl_digit_value(x) ((x) - '0')
112*6b445a62SJohn Marino #endif
113*6b445a62SJohn Marino 
114*6b445a62SJohn Marino #ifndef _rl_isident
115*6b445a62SJohn Marino #  define _rl_isident(c) (ISALNUM(c) || (c) == '_')
116*6b445a62SJohn Marino #endif
117*6b445a62SJohn Marino 
118*6b445a62SJohn Marino #ifndef ISOCTAL
119*6b445a62SJohn Marino #  define ISOCTAL(c)	((c) >= '0' && (c) <= '7')
120*6b445a62SJohn Marino #endif
121*6b445a62SJohn Marino #define OCTVALUE(c)	((c) - '0')
122*6b445a62SJohn Marino 
123*6b445a62SJohn Marino #define HEXVALUE(c) \
124*6b445a62SJohn Marino   (((c) >= 'a' && (c) <= 'f') \
125*6b445a62SJohn Marino   	? (c)-'a'+10 \
126*6b445a62SJohn Marino   	: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
127*6b445a62SJohn Marino 
128*6b445a62SJohn Marino #ifndef NEWLINE
129*6b445a62SJohn Marino #define NEWLINE '\n'
130*6b445a62SJohn Marino #endif
131*6b445a62SJohn Marino 
132*6b445a62SJohn Marino #ifndef RETURN
133*6b445a62SJohn Marino #define RETURN CTRL('M')
134*6b445a62SJohn Marino #endif
135*6b445a62SJohn Marino 
136*6b445a62SJohn Marino #ifndef RUBOUT
137*6b445a62SJohn Marino #define RUBOUT 0x7f
138*6b445a62SJohn Marino #endif
139*6b445a62SJohn Marino 
140*6b445a62SJohn Marino #ifndef TAB
141*6b445a62SJohn Marino #define TAB '\t'
142*6b445a62SJohn Marino #endif
143*6b445a62SJohn Marino 
144*6b445a62SJohn Marino #ifdef ABORT_CHAR
145*6b445a62SJohn Marino #undef ABORT_CHAR
146*6b445a62SJohn Marino #endif
147*6b445a62SJohn Marino #define ABORT_CHAR CTRL('G')
148*6b445a62SJohn Marino 
149*6b445a62SJohn Marino #ifdef PAGE
150*6b445a62SJohn Marino #undef PAGE
151*6b445a62SJohn Marino #endif
152*6b445a62SJohn Marino #define PAGE CTRL('L')
153*6b445a62SJohn Marino 
154*6b445a62SJohn Marino #ifdef SPACE
155*6b445a62SJohn Marino #undef SPACE
156*6b445a62SJohn Marino #endif
157*6b445a62SJohn Marino #define SPACE ' '	/* XXX - was 0x20 */
158*6b445a62SJohn Marino 
159*6b445a62SJohn Marino #ifdef ESC
160*6b445a62SJohn Marino #undef ESC
161*6b445a62SJohn Marino #endif
162*6b445a62SJohn Marino #define ESC CTRL('[')
163*6b445a62SJohn Marino 
164*6b445a62SJohn Marino #endif  /* _CHARDEFS_H_ */
165