diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-27 08:04:53 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-27 10:17:06 +0200 |
commit | 6467f92d78b694c6c5ddcead24629ba8be4b93ee (patch) | |
tree | 319cb102b878fb9c7b58f8676102e6c840a16e03 | |
parent | caec298a482ed93140401185bf866edacad35742 (diff) | |
download | cmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.tar.gz cmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.tar.bz2 cmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.zip |
Handle whitespace around commands
-rw-r--r-- | src/io.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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; } |