diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-27 06:45:43 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-27 06:45:43 +0200 |
commit | caec298a482ed93140401185bf866edacad35742 (patch) | |
tree | 890720c3613671a70562de623c9d4de21310f163 /src/commands.c | |
parent | 8ee1bc1d4f559ed2a048bf9c1fa5e3a88eb542c5 (diff) | |
download | cmumble-caec298a482ed93140401185bf866edacad35742.tar.gz cmumble-caec298a482ed93140401185bf866edacad35742.tar.bz2 cmumble-caec298a482ed93140401185bf866edacad35742.zip |
Add support for command shortcuts
So that distinct substrings of commands,
can be used as shortcuts.
Diffstat (limited to 'src/commands.c')
-rw-r--r-- | src/commands.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <glib.h> +#include <string.h> #include <readline/readline.h> #include <readline/history.h> @@ -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) { |