From 6467f92d78b694c6c5ddcead24629ba8be4b93ee Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 27 Sep 2011 08:04:53 +0200 Subject: Handle whitespace around commands --- src/io.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/io.c b/src/io.c index 1d4d4ec..25b3af6 100644 --- a/src/io.c +++ b/src/io.c @@ -62,6 +62,19 @@ print_preserve_prompt(const gchar *string) } } +static const char * +skip_whitespace(const char *text) +{ + int i; + + for (i = 0; text[i] != '\0'; ++i) { + if (text[i] != ' ') + return &text[i]; + } + + return &text[i]; +} + static void process_line(char *line) { @@ -81,10 +94,17 @@ process_line(char *line) return; } - cmd = cmumble_command_complete(line); + cmd = skip_whitespace(line); + cmd = cmumble_command_complete(cmd); for (i = 0; ctx->commands[i].name; ++i) { - if (strcmp(cmd, ctx->commands[i].name) == 0) { + if (strncmp(cmd, ctx->commands[i].name, + strlen(ctx->commands[i].name)) == 0) { + + if (strlen(cmd) > strlen(ctx->commands[i].name) && + cmd[strlen(ctx->commands[i].name)] != ' ') + continue; + ctx->commands[i].callback(ctx); break; } -- cgit