summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-23 14:59:45 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-23 15:11:13 +0200
commit6efcc38a8521a17074626456cda67e7d35f2b7c5 (patch)
tree18ab529be994779425cd7949e9499466f627277d /src/io.c
parentcfde4eb9113d779b4b43c7a056691fd3e307f2c2 (diff)
downloadcmumble-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.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/io.c b/src/io.c
index ff7db5a..33d1232 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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);