-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathASCII.H
118 lines (104 loc) · 2.92 KB
/
ASCII.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (c) 1990,1991,1992 Chris and John Downey */
/***
* @(#)ascii.h 2.1 (Chris & John Downey) 7/29/92
* program name:
xvi
* function:
PD version of UNIX "vi" editor, with extensions.
* module name:
ascii.h
* module function:
Keycode definitions for special keys - e.g. help, cursor arrow
keys, page up, page down etc., & test & conversion macros for
single characters.
On systems that have any special keys, the routine 'inchar' in
the terminal interface code should return one of the codes
here.
This file is specific to the ASCII character set; versions for
other character sets could be implemented if required.
* history:
STEVIE - ST Editor for VI Enthusiasts, Version 3.10
Originally by Tim Thompson (twitch!tjt)
Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
Heavily modified by Chris & John Downey
***/
#include <ctype.h>
/*
* Tests on single characters.
*/
#define is_alpha(c) (isascii(c) && isalpha(c))
#define is_upper(c) (isascii(c) && isupper(c))
#define is_lower(c) (isascii(c) && islower(c))
#define is_digit(c) (isascii(c) && isdigit(c))
#define is_xdigit(c) (isascii(c) && isxdigit(c))
#define is_octdigit(c) ((c) >= '0' && (c) <= '7')
#define is_space(c) (isascii(c) && isspace(c))
#define is_punct(c) (isascii(c) && ispunct(c))
#define is_alnum(c) (isascii(c) && isalnum(c))
#define is_print(c) (isascii(c) && isprint(c))
#define is_graph(c) (isascii(c) && isgraph(c))
#define is_cntrl(c) (isascii(c) && iscntrl(c))
/*
* Conversions.
*
* Note that no argument validity checking is performed.
*/
/*
* Upper case to lower case.
*/
#define to_lower(c) ((c) | 040)
/*
* Lower case to upper case.
*/
#define to_upper(c) ((c) & 0137)
/*
* Hexadecimal digit to binary integer.
*/
#define hex_to_bin(h) (is_digit(h) ? (h) & 017 : ((h) & 7) + 9)
/*
* Key codes.
*/
#define K_HELP 0x80
#define K_UNDO 0x81
#define K_INSERT 0x82
#define K_HOME 0x83
#define K_UARROW 0x84
#define K_DARROW 0x85
#define K_LARROW 0x86
#define K_RARROW 0x87
#define K_CGRAVE 0x88 /* control grave accent */
#define K_PGDOWN 0x89
#define K_PGUP 0x8a
#define K_END 0x8b
/*
* Function keys.
*/
#define K_FUNC(n) (0xa0 + (n))
/*
* Some common control characters.
*/
#define ESC '\033'
#define DEL '\177'
#undef CTRL
#define CTRL(x) ((x) & 0x1f)
/*
* Convert a command character to an ASCII character.
*
* This is needed for normal(), which uses the mapped value as an
* index into a table.
*
* QNX is the only ASCII-based system which gives us a minor problem
* here because its newline character is the same as control-^; so we
* convert this value to an ASCII linefeed.
*/
#ifdef QNX
# define ascii_map(n) ((n) == '\n' ? 012 : (n))
#else
# define ascii_map(n) (n)
#endif
/*
* The top bit for extended character sets.
* Note that this is NOT related to the size of a char in bits,
* but to the ASCII character set - i.e. it is always 128.
*/
#define TOP_BIT 128