diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 19 | ||||
-rw-r--r-- | src/commands.h | 3 | ||||
-rw-r--r-- | src/io.c | 5 |
3 files changed, 26 insertions, 1 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) { diff --git a/src/commands.h b/src/commands.h index c95f238..1c56860 100644 --- a/src/commands.h +++ b/src/commands.h @@ -12,4 +12,7 @@ struct cmumble_command { void cmumble_commands_init(struct cmumble_context *ctx); +const char * +cmumble_command_complete(const char *text); + #endif /* _COMMANDS_H_ */ @@ -66,6 +66,7 @@ static void process_line(char *line) { struct cmumble_context *ctx = global_rl_user_data; + const char *cmd; int i; g_assert(global_rl_user_data); @@ -80,8 +81,10 @@ process_line(char *line) return; } + cmd = cmumble_command_complete(line); + for (i = 0; ctx->commands[i].name; ++i) { - if (strcmp(line, ctx->commands[i].name) == 0) { + if (strcmp(cmd, ctx->commands[i].name) == 0) { ctx->commands[i].callback(ctx); break; } |