8c92811dd765a720d5a79329f81b9d9daf049daf
[platform/upstream/bash.git] / lib / readline / chardefs.h
1 /* chardefs.h -- Character definitions for readline. */
2
3 /* Copyright (C) 1994 Free Software Foundation, Inc.
4
5    This file is part of the GNU Readline Library, a library for
6    reading lines of text with interactive input and history editing.
7
8    The GNU Readline Library is free software; you can redistribute it
9    and/or modify it under the terms of the GNU General Public License
10    as published by the Free Software Foundation; either version 1, or
11    (at your option) any later version.
12
13    The GNU Readline Library is distributed in the hope that it will be
14    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    The GNU General Public License is often shipped with GNU software, and
19    is generally kept in a file called COPYING or LICENSE.  If you do not
20    have a copy of the license, write to the Free Software Foundation,
21    675 Mass Ave, Cambridge, MA 02139, USA. */
22
23 #ifndef _CHARDEFS_H
24 #define _CHARDEFS_H
25
26 #include <ctype.h>
27
28 #if defined (HAVE_STRING_H)
29 #  include <string.h>
30 #else
31 #  include <strings.h>
32 #endif /* HAVE_STRING_H */
33
34 #ifndef whitespace
35 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
36 #endif
37
38 #ifdef CTRL
39 #undef CTRL
40 #endif
41
42 /* Some character stuff. */
43 #define control_character_threshold 0x020   /* Smaller than this is control. */
44 #define control_character_mask 0x1f         /* 0x20 - 1 */
45 #define meta_character_threshold 0x07f      /* Larger than this is Meta. */
46 #define control_character_bit 0x40          /* 0x000000, must be off. */
47 #define meta_character_bit 0x080            /* x0000000, must be on. */
48 #define largest_char 255                    /* Largest character value. */
49
50 #define CTRL_CHAR(c) ((c) < control_character_threshold)
51 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
52
53 #define CTRL(c) ((c) & control_character_mask)
54 #define META(c) ((c) | meta_character_bit)
55
56 #define UNMETA(c) ((c) & (~meta_character_bit))
57 #define UNCTRL(c) to_upper(((c)|control_character_bit))
58
59 /* Old versions
60 #define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
61 #define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
62 #define digit_p(c)  ((c) >= '0' && (c) <= '9')
63 */
64
65 #define lowercase_p(c) (islower(c))
66 #define uppercase_p(c) (isupper(c))
67 #define digit_p(x)  (isdigit (x))
68
69 #define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c))
70
71 /* Old versions
72 #  define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c))
73 #  define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c))
74 */
75
76 #ifndef to_upper
77 #  define to_upper(c) (islower(c) ? toupper(c) : (c))
78 #  define to_lower(c) (isupper(c) ? tolower(c) : (c))
79 #endif
80
81 #ifndef digit_value
82 #define digit_value(x) ((x) - '0')
83 #endif
84
85 #ifndef NEWLINE
86 #define NEWLINE '\n'
87 #endif
88
89 #ifndef RETURN
90 #define RETURN CTRL('M')
91 #endif
92
93 #ifndef RUBOUT
94 #define RUBOUT 0x7f
95 #endif
96
97 #ifndef TAB
98 #define TAB '\t'
99 #endif
100
101 #ifdef ABORT_CHAR
102 #undef ABORT_CHAR
103 #endif
104 #define ABORT_CHAR CTRL('G')
105
106 #ifdef PAGE
107 #undef PAGE
108 #endif
109 #define PAGE CTRL('L')
110
111 #ifdef SPACE
112 #undef SPACE
113 #endif
114 #define SPACE ' '       /* XXX - was 0x20 */
115
116 #ifdef ESC
117 #undef ESC
118 #endif
119
120 #define ESC CTRL('[')
121
122 #endif  /* _CHARDEFS_H */