blob: 1fa1b089d0164c6794f3b3ff14bc0afb101c0d84 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001/* chardefs.h -- Character definitions for readline. */
2
Jari Aalto31859422009-01-12 13:36:28 +00003/* Copyright (C) 1994-2009 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00004
Jari Aalto31859422009-01-12 13:36:28 +00005 This file is part of the GNU Readline Library (Readline), a library
6 for reading lines of text with interactive input and history editing.
Jari Aalto726f6381996-08-26 18:22:31 +00007
Jari Aalto31859422009-01-12 13:36:28 +00008 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
Jari Aalto726f6381996-08-26 18:22:31 +000011 (at your option) any later version.
12
Jari Aalto31859422009-01-12 13:36:28 +000013 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
Jari Aalto726f6381996-08-26 18:22:31 +000016 GNU General Public License for more details.
17
Jari Aalto31859422009-01-12 13:36:28 +000018 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*/
Jari Aalto726f6381996-08-26 18:22:31 +000021
Jari Aaltoccc6cda1996-12-23 17:02:34 +000022#ifndef _CHARDEFS_H_
23#define _CHARDEFS_H_
Jari Aalto726f6381996-08-26 18:22:31 +000024
25#include <ctype.h>
26
Jari Aaltoccc6cda1996-12-23 17:02:34 +000027#if defined (HAVE_CONFIG_H)
28# if defined (HAVE_STRING_H)
Jari Aaltof73dda02001-11-13 17:56:06 +000029# if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
30# include <memory.h>
31# endif
Jari Aaltoccc6cda1996-12-23 17:02:34 +000032# include <string.h>
Jari Aaltoccc6cda1996-12-23 17:02:34 +000033# endif /* HAVE_STRING_H */
Jari Aaltof73dda02001-11-13 17:56:06 +000034# if defined (HAVE_STRINGS_H)
35# include <strings.h>
36# endif /* HAVE_STRINGS_H */
Jari Aalto726f6381996-08-26 18:22:31 +000037#else
Jari Aaltoccc6cda1996-12-23 17:02:34 +000038# include <string.h>
39#endif /* !HAVE_CONFIG_H */
Jari Aalto726f6381996-08-26 18:22:31 +000040
41#ifndef whitespace
42#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
43#endif
44
45#ifdef CTRL
Jari Aalto7117c2d2002-07-17 14:10:11 +000046# undef CTRL
47#endif
48#ifdef UNCTRL
49# undef UNCTRL
Jari Aalto726f6381996-08-26 18:22:31 +000050#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
Jari Aalto28ef6c32001-04-06 19:14:31 +000060#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
Jari Aalto726f6381996-08-26 18:22:31 +000061#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))
Jari Aaltoccc6cda1996-12-23 17:02:34 +000067#define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
Jari Aalto726f6381996-08-26 18:22:31 +000068
Jari Aaltof73dda02001-11-13 17:56:06 +000069#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
Jari Aalto726f6381996-08-26 18:22:31 +000074
Chet Rameyac50fba2014-02-26 09:36:43 -050075#if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus)
Jari Aaltof73dda02001-11-13 17:56:06 +000076# define isxdigit(c) (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
77#endif
Jari Aalto726f6381996-08-26 18:22:31 +000078
Jari Aaltob80f6442004-07-27 13:29:18 +000079#if defined (CTYPE_NON_ASCII)
80# define NON_NEGATIVE(c) 1
81#else
82# define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
83#endif
Jari Aalto726f6381996-08-26 18:22:31 +000084
Jari Aalto7117c2d2002-07-17 14:10:11 +000085/* Some systems define these; we want our definitions. */
86#undef ISPRINT
87
Jari Aalto95732b42005-12-07 14:08:12 +000088/* Beware: these only work with single-byte ASCII characters. */
89
Jari Aaltof73dda02001-11-13 17:56:06 +000090#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))
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))
Jari Aalto726f6381996-08-26 18:22:31 +0000104
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000105#ifndef _rl_to_upper
Jari Aaltof73dda02001-11-13 17:56:06 +0000106# 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))
Jari Aalto726f6381996-08-26 18:22:31 +0000108#endif
109
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000110#ifndef _rl_digit_value
Jari Aaltof73dda02001-11-13 17:56:06 +0000111# define _rl_digit_value(x) ((x) - '0')
Jari Aalto726f6381996-08-26 18:22:31 +0000112#endif
113
Jari Aaltof73dda02001-11-13 17:56:06 +0000114#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
Jari Aalto726f6381996-08-26 18:22:31 +0000128#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
Jari Aalto726f6381996-08-26 18:22:31 +0000162#define ESC CTRL('[')
163
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000164#endif /* _CHARDEFS_H_ */