Remove trailing whitespace.
[dragonfly.git] / contrib / libreadline / 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 2, 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    59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22
23 #ifndef _CHARDEFS_H_
24 #define _CHARDEFS_H_
25
26 #include <ctype.h>
27
28 #if defined (HAVE_CONFIG_H)
29 #  if defined (HAVE_STRING_H)
30 #    include <string.h>
31 #  else
32 #    include <strings.h>
33 #  endif /* HAVE_STRING_H */
34 #else
35 #  include <string.h>
36 #endif /* !HAVE_CONFIG_H */
37
38 #ifndef whitespace
39 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
40 #endif
41
42 #ifdef CTRL
43 #undef CTRL
44 #endif
45
46 /* Some character stuff. */
47 #define control_character_threshold 0x020   /* Smaller than this is control. */
48 #define control_character_mask 0x1f         /* 0x20 - 1 */
49 #define meta_character_threshold 0x07f      /* Larger than this is Meta. */
50 #define control_character_bit 0x40          /* 0x000000, must be off. */
51 #define meta_character_bit 0x080            /* x0000000, must be on. */
52 #define largest_char 255                    /* Largest character value. */
53
54 #define CTRL_CHAR(c) ((c) < control_character_threshold && (c) >= 0)
55 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
56
57 #define CTRL(c) ((c) & control_character_mask)
58 #define META(c) ((c) | meta_character_bit)
59
60 #define UNMETA(c) ((c) & (~meta_character_bit))
61 #define UNCTRL(c) _rl_to_upper(((c)|control_character_bit))
62
63 /* Old versions
64 #define _rl_lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
65 #define _rl_uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
66 #define _rl_digit_p(c)  ((c) >= '0' && (c) <= '9')
67 */
68
69 #define _rl_lowercase_p(c) (islower(c))
70 #define _rl_uppercase_p(c) (isupper(c))
71 #define _rl_digit_p(x)  (isdigit (x))
72
73 #define _rl_pure_alphabetic(c) (_rl_lowercase_p(c) || _rl_uppercase_p(c))
74 #define ALPHABETIC(c)   (_rl_lowercase_p(c) || _rl_uppercase_p(c) || _rl_digit_p(c))
75
76 /* Old versions
77 #  define _rl_to_upper(c) (_rl_lowercase_p(c) ? ((c) - 32) : (c))
78 #  define _rl_to_lower(c) (_rl_uppercase_p(c) ? ((c) + 32) : (c))
79 */
80
81 #ifndef _rl_to_upper
82 #  define _rl_to_upper(c) (islower(c) ? toupper(c) : (c))
83 #  define _rl_to_lower(c) (isupper(c) ? tolower(c) : (c))
84 #endif
85
86 #ifndef _rl_digit_value
87 #define _rl_digit_value(x) ((x) - '0')
88 #endif
89
90 #ifndef NEWLINE
91 #define NEWLINE '\n'
92 #endif
93
94 #ifndef RETURN
95 #define RETURN CTRL('M')
96 #endif
97
98 #ifndef RUBOUT
99 #define RUBOUT 0x7f
100 #endif
101
102 #ifndef TAB
103 #define TAB '\t'
104 #endif
105
106 #ifdef ABORT_CHAR
107 #undef ABORT_CHAR
108 #endif
109 #define ABORT_CHAR CTRL('G')
110
111 #ifdef PAGE
112 #undef PAGE
113 #endif
114 #define PAGE CTRL('L')
115
116 #ifdef SPACE
117 #undef SPACE
118 #endif
119 #define SPACE ' '       /* XXX - was 0x20 */
120
121 #ifdef ESC
122 #undef ESC
123 #endif
124 #define ESC CTRL('[')
125
126 #ifndef ISOCTAL
127 #define ISOCTAL(c)      ((c) >= '0' && (c) <= '7')
128 #endif
129 #define OCTVALUE(c)     ((c) - '0')
130
131 #ifndef isxdigit
132 #  define isxdigit(c)   (isdigit((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
133 #endif
134
135 #define HEXVALUE(c) \
136   (((c) >= 'a' && (c) <= 'f') \
137         ? (c)-'a'+10 \
138         : (c) >= 'A' && (c) <= 'F' ? (c)-'A'+10 : (c)-'0')
139
140 #endif  /* _CHARDEFS_H_ */