jpayne@69: /* chardefs.h -- Character definitions for readline. */
jpayne@69:
jpayne@69: /* Copyright (C) 1994-2021 Free Software Foundation, Inc.
jpayne@69:
jpayne@69: This file is part of the GNU Readline Library (Readline), a library
jpayne@69: for reading lines of text with interactive input and history editing.
jpayne@69:
jpayne@69: Readline is free software: you can redistribute it and/or modify
jpayne@69: it under the terms of the GNU General Public License as published by
jpayne@69: the Free Software Foundation, either version 3 of the License, or
jpayne@69: (at your option) any later version.
jpayne@69:
jpayne@69: Readline is distributed in the hope that it will be useful,
jpayne@69: but WITHOUT ANY WARRANTY; without even the implied warranty of
jpayne@69: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
jpayne@69: GNU General Public License for more details.
jpayne@69:
jpayne@69: You should have received a copy of the GNU General Public License
jpayne@69: along with Readline. If not, see .
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef _CHARDEFS_H_
jpayne@69: #define _CHARDEFS_H_
jpayne@69:
jpayne@69: #include
jpayne@69:
jpayne@69: #if defined (HAVE_CONFIG_H)
jpayne@69: # if defined (HAVE_STRING_H)
jpayne@69: # include
jpayne@69: # endif /* HAVE_STRING_H */
jpayne@69: # if defined (HAVE_STRINGS_H)
jpayne@69: # include
jpayne@69: # endif /* HAVE_STRINGS_H */
jpayne@69: #else
jpayne@69: # include
jpayne@69: #endif /* !HAVE_CONFIG_H */
jpayne@69:
jpayne@69: #ifndef whitespace
jpayne@69: #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifdef CTRL
jpayne@69: # undef CTRL
jpayne@69: #endif
jpayne@69: #ifdef UNCTRL
jpayne@69: # undef UNCTRL
jpayne@69: #endif
jpayne@69:
jpayne@69: /* Some character stuff. */
jpayne@69: #define control_character_threshold 0x020 /* Smaller than this is control. */
jpayne@69: #define control_character_mask 0x1f /* 0x20 - 1 */
jpayne@69: #define meta_character_threshold 0x07f /* Larger than this is Meta. */
jpayne@69: #define control_character_bit 0x40 /* 0x000000, must be off. */
jpayne@69: #define meta_character_bit 0x080 /* x0000000, must be on. */
jpayne@69: #define largest_char 255 /* Largest character value. */
jpayne@69:
jpayne@69: #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
jpayne@69: #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
jpayne@69:
jpayne@69: #define CTRL(c) ((c) & control_character_mask)
jpayne@69: #define META(c) ((c) | meta_character_bit)
jpayne@69:
jpayne@69: #define UNMETA(c) ((c) & (~meta_character_bit))
jpayne@69: #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
jpayne@69:
jpayne@69: #ifndef UCHAR_MAX
jpayne@69: # define UCHAR_MAX 255
jpayne@69: #endif
jpayne@69: #ifndef CHAR_MAX
jpayne@69: # define CHAR_MAX 127
jpayne@69: #endif
jpayne@69:
jpayne@69: /* use this as a proxy for C89 */
jpayne@69: #if defined (HAVE_STDLIB_H) && defined (HAVE_STRING_H)
jpayne@69: # define IN_CTYPE_DOMAIN(c) 1
jpayne@69: # define NON_NEGATIVE(c) 1
jpayne@69: #else
jpayne@69: # define IN_CTYPE_DOMAIN(c) ((c) >= 0 && (c) <= CHAR_MAX)
jpayne@69: # define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
jpayne@69: #endif
jpayne@69:
jpayne@69: #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT) && !defined (__cplusplus)
jpayne@69: # define isxdigit(c) (isdigit((unsigned char)(c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
jpayne@69: #endif
jpayne@69:
jpayne@69: /* Some systems define these; we want our definitions. */
jpayne@69: #undef ISPRINT
jpayne@69:
jpayne@69: /* Beware: these only work with single-byte ASCII characters. */
jpayne@69:
jpayne@69: #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum ((unsigned char)c))
jpayne@69: #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha ((unsigned char)c))
jpayne@69: #define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit ((unsigned char)c))
jpayne@69: #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower ((unsigned char)c))
jpayne@69: #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint ((unsigned char)c))
jpayne@69: #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper ((unsigned char)c))
jpayne@69: #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit ((unsigned char)c))
jpayne@69:
jpayne@69: #define _rl_lowercase_p(c) (NON_NEGATIVE(c) && ISLOWER(c))
jpayne@69: #define _rl_uppercase_p(c) (NON_NEGATIVE(c) && ISUPPER(c))
jpayne@69: #define _rl_digit_p(c) ((c) >= '0' && (c) <= '9')
jpayne@69:
jpayne@69: #define _rl_alphabetic_p(c) (NON_NEGATIVE(c) && ISALNUM(c))
jpayne@69: #define _rl_pure_alphabetic(c) (NON_NEGATIVE(c) && ISALPHA(c))
jpayne@69:
jpayne@69: #ifndef _rl_to_upper
jpayne@69: # define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)(c)) : (c))
jpayne@69: # define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)(c)) : (c))
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef _rl_digit_value
jpayne@69: # define _rl_digit_value(x) ((x) - '0')
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef _rl_isident
jpayne@69: # define _rl_isident(c) (ISALNUM(c) || (c) == '_')
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef ISOCTAL
jpayne@69: # define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
jpayne@69: #endif
jpayne@69: #define OCTVALUE(c) ((c) - '0')
jpayne@69:
jpayne@69: #define HEXVALUE(c) \
jpayne@69: (((c) >= 'a' && (c) <= 'f') \
jpayne@69: ? (c)-'a'+10 \
jpayne@69: : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
jpayne@69:
jpayne@69: #ifndef NEWLINE
jpayne@69: #define NEWLINE '\n'
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef RETURN
jpayne@69: #define RETURN CTRL('M')
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef RUBOUT
jpayne@69: #define RUBOUT 0x7f
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef TAB
jpayne@69: #define TAB '\t'
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifdef ABORT_CHAR
jpayne@69: #undef ABORT_CHAR
jpayne@69: #endif
jpayne@69: #define ABORT_CHAR CTRL('G')
jpayne@69:
jpayne@69: #ifdef PAGE
jpayne@69: #undef PAGE
jpayne@69: #endif
jpayne@69: #define PAGE CTRL('L')
jpayne@69:
jpayne@69: #ifdef SPACE
jpayne@69: #undef SPACE
jpayne@69: #endif
jpayne@69: #define SPACE ' ' /* XXX - was 0x20 */
jpayne@69:
jpayne@69: #ifdef ESC
jpayne@69: #undef ESC
jpayne@69: #endif
jpayne@69: #define ESC CTRL('[')
jpayne@69:
jpayne@69: #endif /* _CHARDEFS_H_ */