33ee512f37ceb47be0f5ca96c24b4447591583fb
[platform/upstream/bash.git] / lib / readline / chardefs.h
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    59 Temple Place, Suite 330, Boston, MA 02111 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
50 /* Some character stuff. */
51 #define control_character_threshold 0x020   /* Smaller than this is control. */
52 #define control_character_mask 0x1f         /* 0x20 - 1 */
53 #define meta_character_threshold 0x07f      /* Larger than this is Meta. */
54 #define control_character_bit 0x40          /* 0x000000, must be off. */
55 #define meta_character_bit 0x080            /* x0000000, must be on. */
56 #define largest_char 255                    /* Largest character value. */
57
58 #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
59 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
60
61 #define CTRL(c) ((c) & control_character_mask)
62 #define META(c) ((c) | meta_character_bit)
63
64 #define UNMETA(c) ((c) & (~meta_character_bit))
65 #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
66
67 #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
68 #  define IN_CTYPE_DOMAIN(c) 1
69 #else
70 #  define IN_CTYPE_DOMAIN(c) isascii(c)
71 #endif
72
73 #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
74 #  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
75 #endif
76
77 #define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
78
79 #define ISALNUM(c)      (IN_CTYPE_DOMAIN (c) && isalnum (c))
80 #define ISALPHA(c)      (IN_CTYPE_DOMAIN (c) && isalpha (c))
81 #define ISDIGIT(c)      (IN_CTYPE_DOMAIN (c) && isdigit (c))
82 #define ISLOWER(c)      (IN_CTYPE_DOMAIN (c) && islower (c))
83 #define ISPRINT(c)      (IN_CTYPE_DOMAIN (c) && isprint (c))
84 #define ISUPPER(c)      (IN_CTYPE_DOMAIN (c) && isupper (c))
85 #define ISXDIGIT(c)     (IN_CTYPE_DOMAIN (c) && isxdigit (c))
86
87 #define _rl_lowercase_p(c)      (NON_NEGATIVE(c) && ISLOWER(c))
88 #define _rl_uppercase_p(c)      (NON_NEGATIVE(c) && ISUPPER(c))
89 #define _rl_digit_p(c)          ((c) >= '0' && (c) <= '9')
90
91 #define _rl_pure_alphabetic(c)  (NON_NEGATIVE(c) && ISALPHA(c))
92 #define ALPHABETIC(c)           (NON_NEGATIVE(c) && ISALNUM(c))
93
94 #ifndef _rl_to_upper
95 #  define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
96 #  define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
97 #endif
98
99 #ifndef _rl_digit_value
100 #  define _rl_digit_value(x) ((x) - '0')
101 #endif
102
103 #ifndef _rl_isident
104 #  define _rl_isident(c) (ISALNUM(c) || (c) == '_')
105 #endif
106
107 #ifndef ISOCTAL
108 #  define ISOCTAL(c)    ((c) >= '0' && (c) <= '7')
109 #endif
110 #define OCTVALUE(c)     ((c) - '0')
111
112 #define HEXVALUE(c) \
113   (((c) >= 'a' && (c) <= 'f') \
114         ? (c)-'a'+10 \
115         : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
116
117 #ifndef NEWLINE
118 #define NEWLINE '\n'
119 #endif
120
121 #ifndef RETURN
122 #define RETURN CTRL('M')
123 #endif
124
125 #ifndef RUBOUT
126 #define RUBOUT 0x7f
127 #endif
128
129 #ifndef TAB
130 #define TAB '\t'
131 #endif
132
133 #ifdef ABORT_CHAR
134 #undef ABORT_CHAR
135 #endif
136 #define ABORT_CHAR CTRL('G')
137
138 #ifdef PAGE
139 #undef PAGE
140 #endif
141 #define PAGE CTRL('L')
142
143 #ifdef SPACE
144 #undef SPACE
145 #endif
146 #define SPACE ' '       /* XXX - was 0x20 */
147
148 #ifdef ESC
149 #undef ESC
150 #endif
151 #define ESC CTRL('[')
152
153 #endif  /* _CHARDEFS_H_ */