X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fclient%2Fkeybindings.c;h=ab34d2443faf313aad9717ed33bc7590c8d0210e;hb=a8097b8fef09444ebac0f1e2d3ffc4e621557b28;hp=73fc2c8541a7ea346c2ed8d8b697206e68d470ae;hpb=cda9c65e89a5dfb0c8306cd7ac74427df29c3c21;p=plomrogue
diff --git a/src/client/keybindings.c b/src/client/keybindings.c
index 73fc2c8..ab34d24 100644
--- a/src/client/keybindings.c
+++ b/src/client/keybindings.c
@@ -5,7 +5,7 @@
#include /* FILE, sprintf(), snprintf() */
#include /* uint8_t, uint16_t, uint32_t */
#include /* free(), atoi() */
-#include /* strlen(), strchr(), strcmp(), memcpy() */
+#include /* strlen(), strchr() */
#include "../common/readwrite.h" /* try_fopen(), textfile_sizes(), try_fgets(),
* try_fclose(), try_fclose_unlink_rename(),
* try_fwrite()
@@ -77,13 +77,14 @@ static uint8_t try_keycode(uint16_t keycode_given, char * keyname,
-extern char * get_actionname_to_keycode(struct KeyBinding * kb_p, uint16_t key)
+extern struct Command * get_command_to_keycode(struct KeyBinding * kb_p,
+ uint16_t key)
{
while (0 != kb_p)
{
if (key == kb_p->key)
{
- return kb_p->name;
+ return kb_p->command;
}
kb_p = kb_p->next;
}
@@ -92,22 +93,7 @@ extern char * get_actionname_to_keycode(struct KeyBinding * kb_p, uint16_t key)
-extern uint16_t get_keycode_to_action(struct KeyBinding * kb_p, char * name)
-{
- while (0 != kb_p)
- {
- if (0 == strcmp(kb_p->name, name))
- {
- return kb_p->key;
- }
- kb_p = kb_p->next;
- }
- return 0;
-}
-
-
-
-extern char * get_name_to_keycode(uint16_t keycode)
+extern char * get_keyname_to_keycode(uint16_t keycode)
{
char * f_name = "get_name_to_keycode()";
char * keyname = try_malloc(15, f_name); /* FIXME: Why 15? */
@@ -168,9 +154,8 @@ extern void init_keybindings(char * path, struct KeyBindingDB * kbd)
kb_p->next = 0;
kb_p->key = atoi(command);
cmdptr = strchr(command, ' ') + 1;
- kb_p->name = try_malloc(strlen(cmdptr), f_name);
- memcpy(kb_p->name, cmdptr, strlen(cmdptr) - 1);
- kb_p->name[strlen(cmdptr) - 1] = '\0';
+ cmdptr[strlen(cmdptr) - 1] = '\0';
+ kb_p->command = get_command(cmdptr);
loc_last_ptr = & kb_p->next;
}
try_fclose(file, f_name);
@@ -190,9 +175,9 @@ extern void save_keybindings(char * path, struct KeyBindingDB * kbd)
struct KeyBinding * kb_p = kbd->kbs;
while (0 != kb_p)
{
- if (strlen(kb_p->name) > linemax)
+ if (strlen(kb_p->command->dsc_short) > linemax)
{
- linemax = strlen(kb_p->name);
+ linemax = strlen(kb_p->command->dsc_short);
}
kb_p = kb_p->next;
}
@@ -201,7 +186,7 @@ extern void save_keybindings(char * path, struct KeyBindingDB * kbd)
kb_p = kbd->kbs;
while (0 != kb_p)
{
- snprintf(line, linemax, "%d %s\n", kb_p->key, kb_p->name);
+ snprintf(line, linemax, "%d %s\n", kb_p->key, kb_p->command->dsc_short);
try_fwrite(line, sizeof(char), strlen(line), file, f_name);
kb_p = kb_p->next;
}
@@ -221,7 +206,6 @@ extern void free_keybindings(struct KeyBinding * kb_start)
{
free_keybindings(kb_p);
}
- free(kb_start->name);
free(kb_start);
}