forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.c
More file actions
executable file
·188 lines (166 loc) · 3.75 KB
/
Copy pathkeys.c
File metadata and controls
executable file
·188 lines (166 loc) · 3.75 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* Copyright (c) 1985 Ceriel J.H. Jacobs */
# ifndef lint
static char rcsid[] = "$Header$";
# endif
# define _KEYS_
# include <ctype.h>
# include "in_all.h"
# include "machine.h"
# include "keys.h"
# include "commands.h"
# include "prompt.h"
# include "assert.h"
char defaultmap[] = "\
bf=P:bl=k:bl=^K:bl=^[[A:bot=l:bot=$:bot=^[[Y:bp=-:bp=^[[V:bs=^B:bse=?:bsl=S:\
bsp=F:chm=X:exg=x:ff=N:fl=^J:fl=^M:fl=j:fl=^[[B:fp= :fp=^[[U:fs=^D:fse=/:\
fsl=s:fsp=f:hlp=h:nse=n:nsr=r:red=^L:rep=.:bps=Z:bss=b:fps=z:fss=d:shl=!:\
tom=':top=\\^:top=^[[H:vis=e:wrf=w:qui=q:qui=Q:mar=m:pip=|";
char *strcpy();
char *strcat();
char *getenv();
/*
* Construct an error message and return it
*/
STATIC char *
kerror(key, emess) char *key, *emess; {
static char ebuf[80]; /* Room for the error message */
(VOID) strcpy(ebuf, key);
(VOID) strcat(ebuf, emess);
return ebuf;
}
/*
* Compile a keymap into commtable. Returns an error message if there
* is one
*/
STATIC char *
compile(map, commtable)
register char *map; register struct keymap *commtable; {
register char *mark; /* Indicates start of mnemonic */
register char *c; /* Runs through buf */
register int temp;
char *escapes = commtable->k_esc;
char buf[10]; /* Will hold key sequence */
(VOID) strcpy(commtable->k_help,"Illegal command");
while (*map) {
c = buf;
mark = map; /* Start of mnemonic */
while (*map && *map != '=') {
map++;
}
if (!*map) {
/*
* Mnemonic should end with '='
*/
return kerror(mark, ": Syntax error");
}
*map++ = 0;
while (*map) {
/*
* Get key sequence
*/
if (*map == ':') {
/*
* end of key sequence
*/
map++;
break;
}
*c = *map++ & 0177;
if (*c == '^' || *c == '\\') {
if (!(temp = *map++)) {
/*
* Escape not followed by a character
*/
return kerror(mark, ": Syntax error");
}
if (*c == '^') {
if (temp == '?') *c = 0177;
else *c = temp & 037;
}
else *c = temp & 0177;
}
setused(*c);
c++;
if (c >= &buf[9]) {
return kerror(mark,": Key sequence too long");
}
}
*c = 0;
if (!(temp = lookup(mark))) {
return kerror(mark,": Nonexistent function");
}
if (c == &buf[1] && (commands[temp].c_flags & ESC) &&
escapes < &(commtable->k_esc[sizeof(commtable->k_esc)-1])) {
*escapes++ = buf[0] & 0177;
}
temp = addstring(buf, temp, &(commtable->k_mach));
if (temp == FSM_ISPREFIX) {
return kerror(mark,": Prefix of other key sequence");
}
if (temp == FSM_HASPREFIX) {
return kerror(mark,": Other key sequence is prefix");
}
assert(temp == FSM_OKE);
if (!strcmp(mark, "hlp")) {
/*
* Create an error message to be given when the user
* types an illegal command
*/
(VOID) strcpy(commtable->k_help, "Type ");
(VOID) strcat(commtable->k_help, buf);
(VOID) strcat(commtable->k_help, " for help");
}
}
*escapes = 0;
return (char *) 0;
}
/*
* Initialize the keymaps
*/
VOID
initkeys() {
register char *p;
static struct keymap xx[2];
currmap = &xx[0];
othermap = &xx[1];
p = compile(defaultmap, currmap); /* Compile default map */
assert(p == (char *) 0);
p = getenv("YAPKEYS");
if (p) {
if (!(p = compile(p, othermap))) {
/*
* No errors in user defined keymap. So, use it
*/
do_chkm(0L);
return;
}
error(p);
}
othermap = 0; /* No other keymap */
}
int
is_escape(c)
{
register char *p = currmap->k_esc;
while (*p) {
if (c == *p++) return 1;
}
return 0;
}
static char keyset[16]; /* bitset indicating which keys are
* used
*/
/*
* Mark key "key" as used
*/
VOID
setused(key) int key; {
keyset[(key & 0177) >> 3] |= (1 << (key & 07));
}
/*
* return non-zero if key "key" is used in a keymap
*/
int
isused(key) int key; {
return keyset[(key & 0177) >> 3] & (1 << (key & 07));
}