update README
[rofl0r-gnuboy.git] / rckeys.c
blobd2f8fb7c55e609e414e253edfc13c466d3633a0d
1 #undef _GNU_SOURCE
2 #define _GNU_SOURCE
3 #include <string.h>
7 #include <stdlib.h>
9 #include "defs.h"
10 #include "rc.h"
11 #include "input.h"
16 char *keybind[MAX_KEYS];
21 int rc_bindkey(char *keyname, char *cmd)
23 int key;
24 char *a;
26 key = k_keycode(keyname);
27 if (!key) return -1;
29 a = strdup(cmd);
30 if (!a) die("out of memory binding key\n");
32 if (keybind[key]) free(keybind[key]);
33 keybind[key] = a;
35 return 0;
40 int rc_unbindkey(char *keyname)
42 int key;
44 key = k_keycode(keyname);
45 if (!key) return -1;
47 if (keybind[key]) free(keybind[key]);
48 keybind[key] = NULL;
49 return 0;
53 void rc_unbindall()
55 int i;
57 for (i = 0; i < MAX_KEYS; i++)
59 if (keybind[i])
61 free(keybind[i]);
62 keybind[i] = NULL;
69 void rc_dokey(int key, int st)
71 if (!keybind[key]) return;
72 if (keybind[key][0] != '+' && !st) return;
74 if (st)
75 rc_command(keybind[key]);
76 else
78 keybind[key][0] = '-';
79 rc_command(keybind[key]);
80 keybind[key][0] = '+';