xref: /openbsd/gnu/lib/libreadline/chardefs.h (revision 9704b281)
11acd27e7Smillert /* chardefs.h -- Character definitions for readline. */
21acd27e7Smillert 
31acd27e7Smillert /* Copyright (C) 1994 Free Software Foundation, Inc.
41acd27e7Smillert 
51acd27e7Smillert    This file is part of the GNU Readline Library, a library for
61acd27e7Smillert    reading lines of text with interactive input and history editing.
71acd27e7Smillert 
81acd27e7Smillert    The GNU Readline Library is free software; you can redistribute it
91acd27e7Smillert    and/or modify it under the terms of the GNU General Public License
101acd27e7Smillert    as published by the Free Software Foundation; either version 2, or
111acd27e7Smillert    (at your option) any later version.
121acd27e7Smillert 
131acd27e7Smillert    The GNU Readline Library is distributed in the hope that it will be
141acd27e7Smillert    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
151acd27e7Smillert    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
161acd27e7Smillert    GNU General Public License for more details.
171acd27e7Smillert 
181acd27e7Smillert    The GNU General Public License is often shipped with GNU software, and
191acd27e7Smillert    is generally kept in a file called COPYING or LICENSE.  If you do not
201acd27e7Smillert    have a copy of the license, write to the Free Software Foundation,
211acd27e7Smillert    59 Temple Place, Suite 330, Boston, MA 02111 USA. */
221acd27e7Smillert 
231acd27e7Smillert #ifndef _CHARDEFS_H_
241acd27e7Smillert #define _CHARDEFS_H_
251acd27e7Smillert 
261acd27e7Smillert #include <ctype.h>
271acd27e7Smillert 
281acd27e7Smillert #if defined (HAVE_CONFIG_H)
291acd27e7Smillert #  if defined (HAVE_STRING_H)
30*af70c2dfSkettenis #    if ! defined (STDC_HEADERS) && defined (HAVE_MEMORY_H)
31*af70c2dfSkettenis #      include <memory.h>
32*af70c2dfSkettenis #    endif
331acd27e7Smillert #    include <string.h>
341acd27e7Smillert #  endif /* HAVE_STRING_H */
35*af70c2dfSkettenis #  if defined (HAVE_STRINGS_H)
36*af70c2dfSkettenis #    include <strings.h>
37*af70c2dfSkettenis #  endif /* HAVE_STRINGS_H */
381acd27e7Smillert #else
391acd27e7Smillert #  include <string.h>
401acd27e7Smillert #endif /* !HAVE_CONFIG_H */
411acd27e7Smillert 
421acd27e7Smillert #ifndef whitespace
431acd27e7Smillert #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
441acd27e7Smillert #endif
451acd27e7Smillert 
461acd27e7Smillert #ifdef CTRL
471acd27e7Smillert #  undef CTRL
481acd27e7Smillert #endif
49*af70c2dfSkettenis #ifdef UNCTRL
50*af70c2dfSkettenis #  undef UNCTRL
51*af70c2dfSkettenis #endif
521acd27e7Smillert 
531acd27e7Smillert /* Some character stuff. */
541acd27e7Smillert #define control_character_threshold 0x020   /* Smaller than this is control. */
551acd27e7Smillert #define control_character_mask 0x1f	    /* 0x20 - 1 */
561acd27e7Smillert #define meta_character_threshold 0x07f	    /* Larger than this is Meta. */
571acd27e7Smillert #define control_character_bit 0x40	    /* 0x000000, must be off. */
581acd27e7Smillert #define meta_character_bit 0x080	    /* x0000000, must be on. */
591acd27e7Smillert #define largest_char 255		    /* Largest character value. */
601acd27e7Smillert 
61*af70c2dfSkettenis #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0))
621acd27e7Smillert #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
631acd27e7Smillert 
641acd27e7Smillert #define CTRL(c) ((c) & control_character_mask)
651acd27e7Smillert #define META(c) ((c) | meta_character_bit)
661acd27e7Smillert 
671acd27e7Smillert #define UNMETA(c) ((c) & (~meta_character_bit))
681acd27e7Smillert #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
691acd27e7Smillert 
70*af70c2dfSkettenis #if defined STDC_HEADERS || (!defined (isascii) && !defined (HAVE_ISASCII))
71*af70c2dfSkettenis #  define IN_CTYPE_DOMAIN(c) 1
72*af70c2dfSkettenis #else
73*af70c2dfSkettenis #  define IN_CTYPE_DOMAIN(c) isascii(c)
74*af70c2dfSkettenis #endif
75*af70c2dfSkettenis 
76*af70c2dfSkettenis #if !defined (isxdigit) && !defined (HAVE_ISXDIGIT)
77*af70c2dfSkettenis #  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
78*af70c2dfSkettenis #endif
79*af70c2dfSkettenis 
80*af70c2dfSkettenis #define NON_NEGATIVE(c)	((unsigned char)(c) == (c))
81*af70c2dfSkettenis 
82*af70c2dfSkettenis /* Some systems define these; we want our definitions. */
83*af70c2dfSkettenis #undef ISPRINT
84*af70c2dfSkettenis 
85*af70c2dfSkettenis #define ISALNUM(c)	(IN_CTYPE_DOMAIN (c) && isalnum (c))
86*af70c2dfSkettenis #define ISALPHA(c)	(IN_CTYPE_DOMAIN (c) && isalpha (c))
87*af70c2dfSkettenis #define ISDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isdigit (c))
88*af70c2dfSkettenis #define ISLOWER(c)	(IN_CTYPE_DOMAIN (c) && islower (c))
89*af70c2dfSkettenis #define ISPRINT(c)	(IN_CTYPE_DOMAIN (c) && isprint (c))
90*af70c2dfSkettenis #define ISUPPER(c)	(IN_CTYPE_DOMAIN (c) && isupper (c))
91*af70c2dfSkettenis #define ISXDIGIT(c)	(IN_CTYPE_DOMAIN (c) && isxdigit (c))
92*af70c2dfSkettenis 
93*af70c2dfSkettenis #define _rl_lowercase_p(c)	(NON_NEGATIVE(c) && ISLOWER(c))
94*af70c2dfSkettenis #define _rl_uppercase_p(c)	(NON_NEGATIVE(c) && ISUPPER(c))
951acd27e7Smillert #define _rl_digit_p(c)		((c) >= '0' && (c) <= '9')
961acd27e7Smillert 
97*af70c2dfSkettenis #define _rl_pure_alphabetic(c)	(NON_NEGATIVE(c) && ISALPHA(c))
98*af70c2dfSkettenis #define ALPHABETIC(c)		(NON_NEGATIVE(c) && ISALNUM(c))
991acd27e7Smillert 
1001acd27e7Smillert #ifndef _rl_to_upper
101*af70c2dfSkettenis #  define _rl_to_upper(c) (_rl_lowercase_p(c) ? toupper((unsigned char)c) : (c))
102*af70c2dfSkettenis #  define _rl_to_lower(c) (_rl_uppercase_p(c) ? tolower((unsigned char)c) : (c))
1031acd27e7Smillert #endif
1041acd27e7Smillert 
1051acd27e7Smillert #ifndef _rl_digit_value
1061acd27e7Smillert #  define _rl_digit_value(x) ((x) - '0')
1071acd27e7Smillert #endif
1081acd27e7Smillert 
109*af70c2dfSkettenis #ifndef _rl_isident
110*af70c2dfSkettenis #  define _rl_isident(c) (ISALNUM(c) || (c) == '_')
111*af70c2dfSkettenis #endif
112*af70c2dfSkettenis 
113*af70c2dfSkettenis #ifndef ISOCTAL
114*af70c2dfSkettenis #  define ISOCTAL(c)	((c) >= '0' && (c) <= '7')
115*af70c2dfSkettenis #endif
116*af70c2dfSkettenis #define OCTVALUE(c)	((c) - '0')
117*af70c2dfSkettenis 
118*af70c2dfSkettenis #define HEXVALUE(c) \
119*af70c2dfSkettenis   (((c) >= 'a' && (c) <= 'f') \
120*af70c2dfSkettenis 	? (c)-'a'+10 \
121*af70c2dfSkettenis 	: (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
122*af70c2dfSkettenis 
1231acd27e7Smillert #ifndef NEWLINE
1241acd27e7Smillert #define NEWLINE '\n'
1251acd27e7Smillert #endif
1261acd27e7Smillert 
1271acd27e7Smillert #ifndef RETURN
1281acd27e7Smillert #define RETURN CTRL('M')
1291acd27e7Smillert #endif
1301acd27e7Smillert 
1311acd27e7Smillert #ifndef RUBOUT
1321acd27e7Smillert #define RUBOUT 0x7f
1331acd27e7Smillert #endif
1341acd27e7Smillert 
1351acd27e7Smillert #ifndef TAB
1361acd27e7Smillert #define TAB '\t'
1371acd27e7Smillert #endif
1381acd27e7Smillert 
1391acd27e7Smillert #ifdef ABORT_CHAR
1401acd27e7Smillert #undef ABORT_CHAR
1411acd27e7Smillert #endif
1421acd27e7Smillert #define ABORT_CHAR CTRL('G')
1431acd27e7Smillert 
1441acd27e7Smillert #ifdef PAGE
1451acd27e7Smillert #undef PAGE
1461acd27e7Smillert #endif
1471acd27e7Smillert #define PAGE CTRL('L')
1481acd27e7Smillert 
1491acd27e7Smillert #ifdef SPACE
1501acd27e7Smillert #undef SPACE
1511acd27e7Smillert #endif
1521acd27e7Smillert #define SPACE ' '	/* XXX - was 0x20 */
1531acd27e7Smillert 
1541acd27e7Smillert #ifdef ESC
1551acd27e7Smillert #undef ESC
1561acd27e7Smillert #endif
1571acd27e7Smillert #define ESC CTRL('[')
1581acd27e7Smillert 
1591acd27e7Smillert #endif  /* _CHARDEFS_H_ */
160