summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2016-11-27 18:07:42 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2016-11-27 18:07:42 +0100
commit1203abd362a212b6cb6a02ff54f466d3a23dbf83 (patch)
tree6d3db4240e76a90def031b1bc2c312b09643697d /src
parente1e5337644671c7df1703a0916242868bcccd1fc (diff)
cmd: check for duplicated entries
- registering duplicate short commands is no longer possible - disable a couple of short commands, use long command instead (short commands should only be used for very frequently used things) - menu: properly register/unregister digit handlers for active calls thanks to Juha Heinanen for reporting an issue with the 'a' key
Diffstat (limited to 'src')
-rw-r--r--src/cmd.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cmd.c b/src/cmd.c
index 4c9d4ca..f0ad6e9 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -73,8 +73,8 @@ static int ctx_alloc(struct cmd_ctx **ctxp, const struct cmd *cmd)
}
-static struct cmds *cmds_find(const struct commands *commands,
- const struct cmd *cmdv)
+struct cmds *cmds_find(const struct commands *commands,
+ const struct cmd *cmdv)
{
struct le *le;
@@ -396,6 +396,17 @@ int cmd_register(struct commands *commands,
for (i=0; i<cmdc; i++) {
const struct cmd *cmd = &cmdv[i];
+ if (cmd->key) {
+ const struct cmd *x = cmd_find_by_key(commands,
+ cmd->key);
+ if (x) {
+ warning("short command '%c' already"
+ " registered as \"%s\"\n",
+ x->key, x->desc);
+ return EALREADY;
+ }
+ }
+
if (cmd->key == LONG_PREFIX) {
warning("cmd: cannot register command with"
" short key '%c'\n", cmd->key);