Merge in changes from bash-1.13. The most obvious one is
[external/binutils.git] / readline / chardefs.h
1 /* chardefs.h -- Character definitions for readline. */
2 #ifndef _CHARDEFS_
3 #define _CHARDEFS_
4
5 #include <ctype.h>
6
7 #if defined (HAVE_STRING_H)
8 #  include <string.h>
9 #else
10 #  include <strings.h>
11 #endif /* HAVE_STRING_H */
12
13 #ifndef savestring
14 extern char *xmalloc ();
15 #  ifndef strcpy
16 extern char *strcpy ();
17 #  endif
18 #define savestring(x) strcpy (xmalloc (1 + strlen (x)), (x))
19 #endif
20
21 #ifndef whitespace
22 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
23 #endif
24
25 #ifdef CTRL
26 #undef CTRL
27 #endif
28
29 /* Some character stuff. */
30 #define control_character_threshold 0x020   /* Smaller than this is control. */
31 #define meta_character_threshold 0x07f      /* Larger than this is Meta. */
32 #define control_character_bit 0x40          /* 0x000000, must be off. */
33 #define meta_character_bit 0x080            /* x0000000, must be on. */
34 #define largest_char 255                    /* Largest character value. */
35
36 #define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char)
37 #define CTRL(c) ((c) & (~control_character_bit))
38 #define META(c) ((c) | meta_character_bit)
39
40 #define UNMETA(c) ((c) & (~meta_character_bit))
41 #define UNCTRL(c) to_upper(((c)|control_character_bit))
42
43 #define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1)))
44 #define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1)))
45
46 #define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c))
47
48 #ifndef to_upper
49 #define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c))
50 #define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c))
51 #endif
52
53 #define CTRL_P(c) ((c) < control_character_threshold)
54 #define META_P(c) ((c) > meta_character_threshold)
55
56 #ifndef NEWLINE
57 #define NEWLINE '\n'
58 #endif
59
60 #ifndef RETURN
61 #define RETURN CTRL('M')
62 #endif
63
64 #ifndef RUBOUT
65 #define RUBOUT 0x07f
66 #endif
67
68 #ifndef TAB
69 #define TAB '\t'
70 #endif
71
72 #ifdef ABORT_CHAR
73 #undef ABORT_CHAR
74 #endif
75 #define ABORT_CHAR CTRL('G')
76
77 #ifdef PAGE
78 #undef PAGE
79 #endif
80 #define PAGE CTRL('L')
81
82 #ifdef SPACE
83 #undef SPACE
84 #endif
85 #define SPACE 0x020
86
87 #ifdef ESC
88 #undef ESC
89 #endif
90
91 #define ESC CTRL('[')
92
93 #endif  /* _CHARDEFS_ */