summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-27 08:04:53 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-27 10:17:06 +0200
commit6467f92d78b694c6c5ddcead24629ba8be4b93ee (patch)
tree319cb102b878fb9c7b58f8676102e6c840a16e03
parentcaec298a482ed93140401185bf866edacad35742 (diff)
downloadcmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.tar.gz
cmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.tar.bz2
cmumble-6467f92d78b694c6c5ddcead24629ba8be4b93ee.zip
Handle whitespace around commands
-rw-r--r--src/io.c24
1 files 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;
}