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