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>
13
RCSID("$Header: /afs/sipb.mit.edu/project/openafs/debian/cvs/openafs/src/gtx/keymap.c,v 1.1.1.5 2001/09/11 14:32:46 hartmans Exp $");
15
#include "gtxkeymap.h"
17
struct keymap_map *keymap_Create() {
18
register struct keymap_map *tmap;
20
tmap = (struct keymap_map *) malloc(sizeof(struct keymap_map));
21
if (tmap != (struct keymap_map *)0)
22
memset(tmap, 0, sizeof(*tmap));
26
/* make a copy of a string; generic utility */
27
char *gtx_CopyString(aval)
28
register char *aval; {
31
if (!aval) return (char *) 0; /* propagate null strings around */
32
tp = (char *) malloc(strlen(aval)+1);
38
static int BindIt(amap, aslot, atype, aproc, aname, arock)
39
struct keymap_map *amap;
46
register struct keymap_entry *tentry;
48
if (aslot < 0 || aslot >= KEYMAP_NENTRIES) return -1;
49
tentry = &amap->entries[aslot];
53
if (atype == KEYMAP_EMPTY) {
54
tentry->u.generic = (char *) 0;
55
tentry->name = (char *) 0;
58
tentry->name = gtx_CopyString(aname);
59
tentry->u.generic = aproc;
65
keymap_BindToString(amap, astring, aproc, aname, arock)
66
register struct keymap_map *amap;
73
register afs_int32 code;
74
struct keymap_map *tmap;
77
/* walk down string, building submaps if possible, until we get to function
79
while (tc = *cptr++) {
80
/* see if we should do submap or final function */
81
if (*cptr == 0) { /* we're peeking: already skipped command char */
82
/* last character, do final function */
83
if (!aproc) /* delete the entry */
84
code = BindIt(amap, tc, KEYMAP_EMPTY, (char *) 0,
85
(char *) 0, (char *) 0);
87
code = BindIt(amap, tc, KEYMAP_PROC, (char *) aproc, aname, arock);
88
if (code) return code;
91
/* more characters after this; do submap */
92
if (amap->entries[tc].type != KEYMAP_SUBMAP) {
93
tmap = keymap_Create();
94
code = BindIt(amap, tc, KEYMAP_SUBMAP, (char *) tmap,
95
(char *) 0, (char *) 0);
98
tmap = amap->entries[tc].u.submap;
101
if (code) return code;
102
amap = tmap; /* continue processing this map */
105
/* here when all characters are gone */
109
/* delete a keymap and all of its recursively-included maps */
111
register struct keymap_map *amap; {
113
register struct keymap_entry *tentry;
115
for(i=0;i<KEYMAP_NENTRIES;i++) {
116
tentry = &amap->entries[i];
117
if (tentry->name) free(tentry->name);
118
if (tentry->type == KEYMAP_SUBMAP)
119
keymap_Delete(tentry->u.submap);
125
keymap_InitState(astate, amap)
126
register struct keymap_state *astate;
127
struct keymap_map *amap; {
128
memset(astate, 0, sizeof(*astate));
129
astate->initMap = amap;
130
astate->currentMap = amap;
134
keymap_ProcessKey(astate, akey, arock)
135
register struct keymap_state *astate;
138
register struct keymap_entry *tentry;
139
register afs_int32 code;
141
if (akey < 0 || akey >= KEYMAP_NENTRIES) return -1;
142
tentry = &astate->currentMap->entries[akey];
144
switch(tentry->type) {
146
keymap_ResetState(astate);
149
/* break commented out because of return above causing compiler warnings */
152
astate->currentMap = tentry->u.submap;
156
code = (*tentry->u.proc)(arock, tentry->rock);
157
keymap_ResetState(astate);
163
keymap_ResetState(astate)
164
register struct keymap_state *astate; {
165
return keymap_InitState(astate, astate->initMap);