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>
26 #include "gtxkeymap.h"
31 register struct keymap_map *tmap;
33 tmap = (struct keymap_map *)malloc(sizeof(struct keymap_map));
34 if (tmap != (struct keymap_map *)0)
35 memset(tmap, 0, sizeof(*tmap));
39 /* make a copy of a string; generic utility */
47 return NULL; /* propagate null strings around */
48 tp = (char *)malloc(strlen(aval) + 1);
55 BindIt(amap, aslot, atype, aproc, aname, arock)
56 struct keymap_map *amap;
64 register struct keymap_entry *tentry;
66 if (aslot < 0 || aslot >= KEYMAP_NENTRIES)
68 tentry = &amap->entries[aslot];
70 if (tp = tentry->name)
72 if (atype == KEYMAP_EMPTY) {
73 tentry->u.generic = NULL;
76 tentry->name = gtx_CopyString(aname);
77 tentry->u.generic = aproc;
83 keymap_BindToString(amap, astring, aproc, aname, arock)
84 register struct keymap_map *amap;
92 register afs_int32 code;
93 struct keymap_map *tmap;
96 /* walk down string, building submaps if possible, until we get to function
98 while (tc = *cptr++) {
99 /* see if we should do submap or final function */
100 if (*cptr == 0) { /* we're peeking: already skipped command char */
101 /* last character, do final function */
102 if (!aproc) /* delete the entry */
103 code = BindIt(amap, tc, KEYMAP_EMPTY, NULL, NULL, NULL);
106 BindIt(amap, tc, KEYMAP_PROC, (char *)aproc, aname,
111 /* more characters after this; do submap */
112 if (amap->entries[tc].type != KEYMAP_SUBMAP) {
113 tmap = keymap_Create();
115 BindIt(amap, tc, KEYMAP_SUBMAP, (char *)tmap, NULL, NULL);
117 tmap = amap->entries[tc].u.submap;
122 amap = tmap; /* continue processing this map */
125 /* here when all characters are gone */
129 /* delete a keymap and all of its recursively-included maps */
131 register struct keymap_map *amap;
134 register struct keymap_entry *tentry;
136 for (i = 0; i < KEYMAP_NENTRIES; i++) {
137 tentry = &amap->entries[i];
140 if (tentry->type == KEYMAP_SUBMAP)
141 keymap_Delete(tentry->u.submap);
147 keymap_InitState(astate, amap)
148 register struct keymap_state *astate;
149 struct keymap_map *amap;
151 memset(astate, 0, sizeof(*astate));
152 astate->initMap = amap;
153 astate->currentMap = amap;
157 keymap_ProcessKey(astate, akey, arock)
158 register struct keymap_state *astate;
162 register struct keymap_entry *tentry;
163 register afs_int32 code;
165 if (akey < 0 || akey >= KEYMAP_NENTRIES)
167 tentry = &astate->currentMap->entries[akey];
169 switch (tentry->type) {
171 keymap_ResetState(astate);
174 /* break commented out because of return above causing compiler warnings */
177 astate->currentMap = tentry->u.submap;
181 code = (*tentry->u.proc) (arock, tentry->rock);
182 keymap_ResetState(astate);
188 keymap_ResetState(astate)
189 register struct keymap_state *astate;
191 return keymap_InitState(astate, astate->initMap);