121308Sache/* chardefs.h -- Character definitions for readline. */
221308Sache
321308Sache/* Copyright (C) 1994 Free Software Foundation, Inc.
421308Sache
521308Sache   This file is part of the GNU Readline Library, a library for
621308Sache   reading lines of text with interactive input and history editing.
721308Sache
821308Sache   The GNU Readline Library is free software; you can redistribute it
921308Sache   and/or modify it under the terms of the GNU General Public License
1058310Sache   as published by the Free Software Foundation; either version 2, or
1121308Sache   (at your option) any later version.
1221308Sache
1321308Sache   The GNU Readline Library is distributed in the hope that it will be
1421308Sache   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
1521308Sache   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1621308Sache   GNU General Public License for more details.
1721308Sache
1821308Sache   The GNU General Public License is often shipped with GNU software, and
1921308Sache   is generally kept in a file called COPYING or LICENSE.  If you do not
2021308Sache   have a copy of the license, write to the Free Software Foundation,
2158310Sache   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
2221308Sache
2321308Sache#ifndef _CHARDEFS_H_
2421308Sache#define _CHARDEFS_H_
2521308Sache
2621308Sache#include <ctype.h>
2721308Sache
2821308Sache#if defined (HAVE_CONFIG_H)
2921308Sache#  if defined (HAVE_STRING_H)
30119610Sache#    if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
31119610Sache#      include <memory.h>
32119610Sache#    endif
3321308Sache#    include <string.h>
34119610Sache#  endif /* HAVE_STRING_H */
35119610Sache#  if defined (HAVE_STRINGS_H)
3621308Sache#    include <strings.h>
37119610Sache#  endif /* HAVE_STRINGS_H */
3821308Sache#else
3921308Sache#  include <string.h>
4021308Sache#endif /* !HAVE_CONFIG_H */
4121308Sache
4221308Sache#ifndef whitespace
4321308Sache#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
4421308Sache#endif
4521308Sache
4621308Sache#ifdef CTRL
47119610Sache#  undef CTRL
4821308Sache#endif
49119610Sache#ifdef UNCTRL
50119610Sache#  undef UNCTRL
51119610Sache#endif
5221308Sache
5321308Sache/* Some character stuff. */
5421308Sache#define control_character_threshold 0x020   /* Smaller than this is control. */
5521308Sache#define control_character_mask 0x1f	    /* 0x20 - 1 */
5621308Sache#define meta_character_threshold 0x07f	    /* Larger than this is Meta. */
5721308Sache#define control_character_bit 0x40	    /* 0x000000, must be off. */
5821308Sache#define meta_character_bit 0x080	    /* x0000000, must be on. */
5921308Sache#define largest_char 255		    /* Largest character value. */
6021308Sache
6175406Sache#define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
6221308Sache#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
6321308Sache
6421308Sache#define CTRL(c) ((c) & control_character_mask)
6521308Sache#define META(c) ((c) | meta_character_bit)
6621308Sache
6721308Sache#define UNMETA(c) ((c) & (~meta_character_bit))
6821308Sache#define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
6921308Sache
70119610Sache#if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
71119610Sache#  define IN_CTYPE_DOMAIN(c) 1
72119610Sache#else
73119610Sache#  define IN_CTYPE_DOMAIN(c) isascii(c)
74119610Sache#endif
7521308Sache
76119610Sache#if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
77119610Sache#  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
78119610Sache#endif
7921308Sache
80136644Sache#if defined (CTYPE_NON_ASCII)
81136644Sache#  define NON_NEGATIVE(c) 1
82136644Sache#else
83136644Sache#  define NON_NEGATIVE(c) ((unsigned char)(c) == (c))
84136644Sache#endif
8521308Sache
86119610Sache/* Some systems define these; we want our definitions. */
87119610Sache#undef ISPRINT
8821308Sache
89157184Sache/* Beware:  these only work with single-byte ASCII characters. */
90157184Sache
91119610Sache#define ISALNUM(c)	(IN_CTYPE_DOMAIN (c) && isalnum (c))
92119610Sache#define ISALPHA(c)	(IN_CTYPE_DOMAIN (c) && isalpha (c))
93119610Sache#define ISDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isdigit (c))
94119610Sache#define ISLOWER(c)	(IN_CTYPE_DOMAIN (c) && islower (c))
95119610Sache#define ISPRINT(c)	(IN_CTYPE_DOMAIN (c) && isprint (c))
96119610Sache#define ISUPPER(c)	(IN_CTYPE_DOMAIN (c) && isupper (c))
97119610Sache#define ISXDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isxdigit (c))
98119610Sache
99119610Sache#define _rl_lowercase_p(c)	(NON_NEGATIVE(c) && ISLOWER(c))
100119610Sache#define _rl_uppercase_p(c)	(NON_NEGATIVE(c) && ISUPPER(c))
101119610Sache#define _rl_digit_p(c)		((c) >= '0' && (c) <= '9')
102119610Sache
103119610Sache#define _rl_pure_alphabetic(c)	(NON_NEGATIVE(c) && ISALPHA(c))
104119610Sache#define ALPHABETIC(c)		(NON_NEGATIVE(c) && ISALNUM(c))
105119610Sache
10621308Sache#ifndef _rl_to_upper
107119610Sache#  define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
108119610Sache#  define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
10921308Sache#endif
11021308Sache
11121308Sache#ifndef _rl_digit_value
112119610Sache#  define _rl_digit_value(x) ((x) - '0')
11321308Sache#endif
11421308Sache
115119610Sache#ifndef _rl_isident
116119610Sache#  define _rl_isident(c) (ISALNUM(c) || (c) == '_')
117119610Sache#endif
118119610Sache
119119610Sache#ifndef ISOCTAL
120119610Sache#  define ISOCTAL(c)	((c) >= '0' && (c) <= '7')
121119610Sache#endif
122119610Sache#define OCTVALUE(c)	((c) - '0')
123119610Sache
124119610Sache#define HEXVALUE(c) \
125119610Sache  (((c) >= 'a' && (c) <= 'f') \
126119610Sache  	? (c)-'a'+10 \
127119610Sache  	: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
128119610Sache
12921308Sache#ifndef NEWLINE
13021308Sache#define NEWLINE '\n'
13121308Sache#endif
13221308Sache
13321308Sache#ifndef RETURN
13421308Sache#define RETURN CTRL('M')
13521308Sache#endif
13621308Sache
13721308Sache#ifndef RUBOUT
13821308Sache#define RUBOUT 0x7f
13921308Sache#endif
14021308Sache
14121308Sache#ifndef TAB
14221308Sache#define TAB '\t'
14321308Sache#endif
14421308Sache
14521308Sache#ifdef ABORT_CHAR
14621308Sache#undef ABORT_CHAR
14721308Sache#endif
14821308Sache#define ABORT_CHAR CTRL('G')
14921308Sache
15021308Sache#ifdef PAGE
15121308Sache#undef PAGE
15221308Sache#endif
15321308Sache#define PAGE CTRL('L')
15421308Sache
15521308Sache#ifdef SPACE
15621308Sache#undef SPACE
15721308Sache#endif
15821308Sache#define SPACE ' '	/* XXX - was 0x20 */
15921308Sache
16021308Sache#ifdef ESC
16121308Sache#undef ESC
16221308Sache#endif
16321308Sache#define ESC CTRL('[')
16421308Sache
16521308Sache#endif  /* _CHARDEFS_H_ */
166