diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-23 14:59:45 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-09-23 15:11:13 +0200 |
commit | 6efcc38a8521a17074626456cda67e7d35f2b7c5 (patch) | |
tree | 18ab529be994779425cd7949e9499466f627277d /src/io.c | |
parent | cfde4eb9113d779b4b43c7a056691fd3e307f2c2 (diff) | |
download | cmumble-6efcc38a8521a17074626456cda67e7d35f2b7c5.tar.gz cmumble-6efcc38a8521a17074626456cda67e7d35f2b7c5.tar.bz2 cmumble-6efcc38a8521a17074626456cda67e7d35f2b7c5.zip |
Add a command interface
Also add two simple commands: help and ls
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -66,6 +66,7 @@ static void process_line(char *line) { struct context *ctx = global_rl_user_data; + int i; g_assert(global_rl_user_data); @@ -79,14 +80,15 @@ process_line(char *line) return; } - if (strcmp(line, "quit") == 0) { - rl_already_prompted = 1; - g_main_loop_quit(ctx->loop); - } else if (strcmp(line, "clear") == 0) { - rl_clear_screen(0,0); - rl_reset_line_state(); - } else - g_print("readline: %s\n", line); + for (i = 0; ctx->commands[i].name; ++i) { + if (strcmp(line, ctx->commands[i].name) == 0) { + ctx->commands[i].callback(ctx); + break; + } + } + + if (ctx->commands[i].name == NULL) + g_print("Unknown command: %s\n", line); if (strlen(line)) add_history(line); |