From caec298a482ed93140401185bf866edacad35742 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 27 Sep 2011 06:45:43 +0200 Subject: Add support for command shortcuts So that distinct substrings of commands, can be used as shortcuts. --- src/commands.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/commands.c') diff --git a/src/commands.c b/src/commands.c index 4683068..3e4e7aa 100644 --- a/src/commands.c +++ b/src/commands.c @@ -3,6 +3,7 @@ #include "cmumble.h" #include +#include #include #include @@ -67,6 +68,24 @@ static const struct cmumble_command commands[] = { { NULL, NULL , NULL} }; +const char * +cmumble_command_complete(const char *text) +{ + int i = 0; + int found_index = -1; + + do { + if (strncmp(commands[i].name, text, strlen(text)) == 0) { + /* Found at least two matches, so do not complete. */ + if (found_index >= 0) + return text; + found_index = i; + } + } while (commands[++i].name); + + return found_index >= 0 ? commands[found_index].name : text; +} + void cmumble_commands_init(struct cmumble_context *ctx) { -- cgit