hirc

IRC client
Log | Files | Refs

commit d3be333ff2c7271aaa3679553c80df6afbcae35d
parent 56fab0f43cc2f23ae31deec586ba8faae4178bf7
Author: hhvn <dev@hhvn.uk>
Date:   Wed, 20 Apr 2022 15:27:44 +0100

Check if binding already exists with /bind + rectrl

Diffstat:
Msrc/commands.c | 3++-
Msrc/ui.c | 13++++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -1331,7 +1331,8 @@ command_bind) { ui_error("no such keybind: '%s'", binding); } else { - ui_bind(binding, cmd); + if (ui_bind(binding, cmd) == -1) + ui_error("keybind already exists: '%s'", binding); } } diff --git a/src/ui.c b/src/ui.c @@ -977,13 +977,18 @@ ui_unctrl(char *str) { int ui_bind(char *binding, char *cmd) { struct Keybind *p; - char *tmp; + char *tmp, *b; if (!binding || !cmd) return -1; + b = ui_rectrl(binding); + + for (p = keybinds; p; p = p->next) + if (strcmp(p->binding, b) == 0) + return -1; p = emalloc(sizeof(struct Keybind)); - p->binding = estrdup(ui_rectrl(binding)); + p->binding = estrdup(b); p->wbinding = stowc(p->binding); if (*cmd != '/') { tmp = emalloc(strlen(cmd) + 2); @@ -1004,12 +1009,14 @@ ui_bind(char *binding, char *cmd) { int ui_unbind(char *binding) { struct Keybind *p; + char *b; if (!binding) return -1; + b = ui_rectrl(binding); for (p=keybinds; p; p = p->next) { - if (strcmp(p->binding, binding) == 0) { + if (strcmp(p->binding, b) == 0) { if (p->prev) p->prev->next = p->next; else