source: trunk/minix/commands/yap/keys.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.8 KB
Line 
1/* Copyright (c) 1985 Ceriel J.H. Jacobs */
2
3# ifndef lint
4static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/keys.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
5# endif
6
7# define _KEYS_
8
9# include <ctype.h>
10# include "in_all.h"
11# include "machine.h"
12# include "keys.h"
13# include "commands.h"
14# include "prompt.h"
15# include "assert.h"
16
17char defaultmap[] = "\
18bf=P:bl=k:bl=^K:bl=^[[A:bot=l:bot=$:bot=^[[Y:bp=-:bp=^[[V:bs=^B:bse=?:bsl=S:\
19bsp=F:chm=X:exg=x:ff=N:fl=^J:fl=^M:fl=j:fl=^[[B:fp= :fp=^[[U:fs=^D:fse=/:\
20fsl=s:fsp=f:hlp=h:nse=n:nsr=r:red=^L:rep=.:bps=Z:bss=b:fps=z:fss=d:shl=!:\
21tom=':top=\\^:top=^[[H:vis=e:wrf=w:qui=q:qui=Q:mar=m:pip=|";
22
23char *strcpy();
24char *strcat();
25char *getenv();
26
27/*
28 * Construct an error message and return it
29 */
30
31STATIC char *
32kerror(key, emess) char *key, *emess; {
33 static char ebuf[80]; /* Room for the error message */
34
35 (VOID) strcpy(ebuf, key);
36 (VOID) strcat(ebuf, emess);
37 return ebuf;
38}
39
40/*
41 * Compile a keymap into commtable. Returns an error message if there
42 * is one
43 */
44
45STATIC char *
46compile(map, commtable)
47 register char *map; register struct keymap *commtable; {
48 register char *mark; /* Indicates start of mnemonic */
49 register char *c; /* Runs through buf */
50 register int temp;
51 char *escapes = commtable->k_esc;
52 char buf[10]; /* Will hold key sequence */
53
54 (VOID) strcpy(commtable->k_help,"Illegal command");
55 while (*map) {
56 c = buf;
57 mark = map; /* Start of mnemonic */
58 while (*map && *map != '=') {
59 map++;
60 }
61 if (!*map) {
62 /*
63 * Mnemonic should end with '='
64 */
65 return kerror(mark, ": Syntax error");
66 }
67 *map++ = 0;
68 while (*map) {
69 /*
70 * Get key sequence
71 */
72 if (*map == ':') {
73 /*
74 * end of key sequence
75 */
76 map++;
77 break;
78 }
79 *c = *map++ & 0177;
80 if (*c == '^' || *c == '\\') {
81 if (!(temp = *map++)) {
82 /*
83 * Escape not followed by a character
84 */
85 return kerror(mark, ": Syntax error");
86 }
87 if (*c == '^') {
88 if (temp == '?') *c = 0177;
89 else *c = temp & 037;
90 }
91 else *c = temp & 0177;
92 }
93 setused(*c);
94 c++;
95 if (c >= &buf[9]) {
96 return kerror(mark,": Key sequence too long");
97 }
98 }
99 *c = 0;
100 if (!(temp = lookup(mark))) {
101 return kerror(mark,": Nonexistent function");
102 }
103 if (c == &buf[1] && (commands[temp].c_flags & ESC) &&
104 escapes < &(commtable->k_esc[sizeof(commtable->k_esc)-1])) {
105 *escapes++ = buf[0] & 0177;
106 }
107 temp = addstring(buf, temp, &(commtable->k_mach));
108 if (temp == FSM_ISPREFIX) {
109 return kerror(mark,": Prefix of other key sequence");
110 }
111 if (temp == FSM_HASPREFIX) {
112 return kerror(mark,": Other key sequence is prefix");
113 }
114 assert(temp == FSM_OKE);
115 if (!strcmp(mark, "hlp")) {
116 /*
117 * Create an error message to be given when the user
118 * types an illegal command
119 */
120 (VOID) strcpy(commtable->k_help, "Type ");
121 (VOID) strcat(commtable->k_help, buf);
122 (VOID) strcat(commtable->k_help, " for help");
123 }
124 }
125 *escapes = 0;
126 return (char *) 0;
127}
128
129/*
130 * Initialize the keymaps
131 */
132
133VOID
134initkeys() {
135 register char *p;
136 static struct keymap xx[2];
137
138 currmap = &xx[0];
139 othermap = &xx[1];
140 p = compile(defaultmap, currmap); /* Compile default map */
141 assert(p == (char *) 0);
142 p = getenv("YAPKEYS");
143 if (p) {
144 if (!(p = compile(p, othermap))) {
145 /*
146 * No errors in user defined keymap. So, use it
147 */
148 do_chkm(0L);
149 return;
150 }
151 error(p);
152 }
153 othermap = 0; /* No other keymap */
154}
155
156int
157is_escape(c)
158{
159 register char *p = currmap->k_esc;
160
161 while (*p) {
162 if (c == *p++) return 1;
163 }
164 return 0;
165}
166
167static char keyset[16]; /* bitset indicating which keys are
168 * used
169 */
170/*
171 * Mark key "key" as used
172 */
173
174VOID
175setused(key) int key; {
176
177 keyset[(key & 0177) >> 3] |= (1 << (key & 07));
178}
179
180/*
181 * return non-zero if key "key" is used in a keymap
182 */
183
184int
185isused(key) int key; {
186
187 return keyset[(key & 0177) >> 3] & (1 << (key & 07));
188}
Note: See TracBrowser for help on using the repository browser.