-
Notifications
You must be signed in to change notification settings - Fork 1
/
keymap.c
79 lines (69 loc) · 1.3 KB
/
keymap.c
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
struct keymap **
lookup(struct keymap *global, struct keymap *local, enum km_op what)
{
int key;
struct keymap **k;
while (!end && (key=tty_readkey()) != EOF) {
if (abort_key(key))
return NULL;
if (local) {
k = getkey(local, key, what == km_op_ins_local);
if (k == NULL)
local = NULL;
else if (*k == NULL) {
if (what == km_op_ins_local)
return k;
else
local = NULL;
}
else {
switch ((*k)->type) {
case t_array:
case t_list:
local = *k;
break;
case t_key:
return k;
}
}
}
if (global) {
k = getkey(local, key, what == km_op_ins_global);
if (k == NULL)
global = NULL;
else if (*k == NULL) {
if (what == km_op_ins_global)
return k;
else
global = NULL;
}
else {
switch ((*k)->type) {
case t_array:
case t_list:
local = *k;
break;
case t_key:
return k;
}
}
}
}
}
struct keymap **
getkey(struct keymap *m, int key, enum km_op what)
{
struct keymap *l;
switch (m->type) {
case t_array:
if (key < 0 || key >= MAX_KEY)
return NULL;
return &(m->v.a->keymap+key);
case t_list:
for (l=m->v.l; l->next && l->next->key <= key; l=l->next) {
if (l->next->key == key)
return &(l->next->val);
}
/* XXX: insert */
return NULL;
}