2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
19 #include "gtxkeymap.h"
24 register struct keymap_map *tmap;
26 tmap = (struct keymap_map *)malloc(sizeof(struct keymap_map));
27 if (tmap != (struct keymap_map *)0)
28 memset(tmap, 0, sizeof(*tmap));
32 /* make a copy of a string; generic utility */
40 return NULL; /* propagate null strings around */
41 tp = (char *)malloc(strlen(aval) + 1);
48 BindIt(amap, aslot, atype, aproc, aname, arock)
49 struct keymap_map *amap;
57 register struct keymap_entry *tentry;
59 if (aslot < 0 || aslot >= KEYMAP_NENTRIES)
61 tentry = &amap->entries[aslot];
63 if (tp = tentry->name)
65 if (atype == KEYMAP_EMPTY) {
66 tentry->u.generic = NULL;
69 tentry->name = gtx_CopyString(aname);
70 tentry->u.generic = aproc;
76 keymap_BindToString(amap, astring, aproc, aname, arock)
77 register struct keymap_map *amap;
85 register afs_int32 code;
86 struct keymap_map *tmap;
89 /* walk down string, building submaps if possible, until we get to function
91 while (tc = *cptr++) {
92 /* see if we should do submap or final function */
93 if (*cptr == 0) { /* we're peeking: already skipped command char */
94 /* last character, do final function */
95 if (!aproc) /* delete the entry */
96 code = BindIt(amap, tc, KEYMAP_EMPTY, NULL, NULL, NULL);
99 BindIt(amap, tc, KEYMAP_PROC, (char *)aproc, aname,
104 /* more characters after this; do submap */
105 if (amap->entries[tc].type != KEYMAP_SUBMAP) {
106 tmap = keymap_Create();
108 BindIt(amap, tc, KEYMAP_SUBMAP, (char *)tmap, NULL, NULL);
110 tmap = amap->entries[tc].u.submap;
115 amap = tmap; /* continue processing this map */
118 /* here when all characters are gone */
122 /* delete a keymap and all of its recursively-included maps */
124 register struct keymap_map *amap;
127 register struct keymap_entry *tentry;
129 for (i = 0; i < KEYMAP_NENTRIES; i++) {
130 tentry = &amap->entries[i];
133 if (tentry->type == KEYMAP_SUBMAP)
134 keymap_Delete(tentry->u.submap);
140 keymap_InitState(astate, amap)
141 register struct keymap_state *astate;
142 struct keymap_map *amap;
144 memset(astate, 0, sizeof(*astate));
145 astate->initMap = amap;
146 astate->currentMap = amap;
150 keymap_ProcessKey(astate, akey, arock)
151 register struct keymap_state *astate;
155 register struct keymap_entry *tentry;
156 register afs_int32 code;
158 if (akey < 0 || akey >= KEYMAP_NENTRIES)
160 tentry = &astate->currentMap->entries[akey];
162 switch (tentry->type) {
164 keymap_ResetState(astate);
167 /* break commented out because of return above causing compiler warnings */
170 astate->currentMap = tentry->u.submap;
174 code = (*tentry->u.proc) (arock, tentry->rock);
175 keymap_ResetState(astate);
181 keymap_ResetState(astate)
182 register struct keymap_state *astate;
184 return keymap_InitState(astate, astate->initMap);