| 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 | #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 */ |
| 40 | |
| 41 | #ifndef whitespace |
| 42 | #define whitespace(c) (((c) == ' ') || ((c) == '\t')) |
| 43 | #endif |
| 44 | |
| 45 | #ifdef CTRL |
| 46 | # undef CTRL |
| 47 | #endif |
| 48 | #ifdef UNCTRL |
| 49 | # undef UNCTRL |
| 50 | #endif |
| 51 | |
| 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. */ |
| 59 | |
| 60 | #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0)) |
| 61 | #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char) |
| 62 | |
| 63 | #define CTRL(c) ((c) & control_character_mask) |
| 64 | #define META(c) ((c) | meta_character_bit) |
| 65 | |
| 66 | #define UNMETA(c) ((c) & (~meta_character_bit)) |
| 67 | #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit)) |
| 68 | |
| 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 |
| 74 | |
| 75 | #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus) |
| 76 | # define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) |
| 77 | #endif |
| 78 | |
| 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 |
| 84 | |
| 85 | /* Some systems define these; we want our definitions. */ |
| 86 | #undef ISPRINT |
| 87 | |
| 88 | /* Beware: these only work with single-byte ASCII characters. */ |
| 89 | |
| 90 | #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c)) |
| 91 | #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c)) |
| 92 | #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c)) |
| 93 | #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c)) |
| 94 | #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c)) |
| 95 | #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c)) |
| 96 | #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c)) |
| 97 | |
| 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') |
| 101 | |
| 102 | #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c)) |
| 103 | #define ALPHABETIC(c) (NON_NEGATIVE(c) && ISALNUM(c)) |
| 104 | |
| 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 |
| 109 | |
| 110 | #ifndef _rl_digit_value |
| 111 | # define _rl_digit_value(x) ((x) - '0') |
| 112 | #endif |
| 113 | |
| 114 | #ifndef _rl_isident |
| 115 | # define _rl_isident(c) (ISALNUM(c) || (c) == '_') |
| 116 | #endif |
| 117 | |
| 118 | #ifndef ISOCTAL |
| 119 | # define ISOCTAL(c) ((c) >= '0' && (c) <= '7') |
| 120 | #endif |
| 121 | #define OCTVALUE(c) ((c) - '0') |
| 122 | |
| 123 | #define HEXVALUE(c) \ |
| 124 | (((c) >= 'a' && (c) <= 'f') \ |
| 125 | ? (c)-'a'+10 \ |
| 126 | : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0') |
| 127 | |
| 128 | #ifndef NEWLINE |
| 129 | #define NEWLINE '\n' |
| 130 | #endif |
| 131 | |
| 132 | #ifndef RETURN |
| 133 | #define RETURN CTRL('M') |
| 134 | #endif |
| 135 | |
| 136 | #ifndef RUBOUT |
| 137 | #define RUBOUT 0x7f |
| 138 | #endif |
| 139 | |
| 140 | #ifndef TAB |
| 141 | #define TAB '\t' |
| 142 | #endif |
| 143 | |
| 144 | #ifdef ABORT_CHAR |
| 145 | #undef ABORT_CHAR |
| 146 | #endif |
| 147 | #define ABORT_CHAR CTRL('G') |
| 148 | |
| 149 | #ifdef PAGE |
| 150 | #undef PAGE |
| 151 | #endif |
| 152 | #define PAGE CTRL('L') |
| 153 | |
| 154 | #ifdef SPACE |
| 155 | #undef SPACE |
| 156 | #endif |
| 157 | #define SPACE ' ' /* XXX - was 0x20 */ |
| 158 | |
| 159 | #ifdef ESC |
| 160 | #undef ESC |
| 161 | #endif |
| 162 | #define ESC CTRL('[') |
| 163 | |
| 164 | #endif /* _CHARDEFS_H_ */ |