diff --git a/ce/ce.c b/ce/ce.c index 919c845..9aab7b7 100644 --- a/ce/ce.c +++ b/ce/ce.c @@ -25,6 +25,8 @@ struct token { static int e_pid; static int e_pgid; +static bool run = true; + static void putch (char ch) { mail_send (e_pgid, &ch, 1); } void putchar_ (char ch) { putch (ch); } @@ -148,14 +150,18 @@ static void cmd_ls (struct list_node_link* tokens) { volume_close (); } -static void cmd_help (struct list_node_link* tokens) { - (void)tokens; +static void cmd_quit (void) { + run = false; + printf ("Goodbye!\n"); +} +static void cmd_help (void) { printf ("Available commands:\n"); printf ("echo ...\n"); printf ("help\n"); printf ("cat \n"); printf ("ls \n"); + printf ("quit\n"); } static void exec_tokens (struct list_node_link* tokens) { @@ -164,11 +170,13 @@ static void exec_tokens (struct list_node_link* tokens) { if (strcmp (cmd_token->buffer, "echo") == 0) { cmd_echo (tokens->next); } else if (strcmp (cmd_token->buffer, "help") == 0) { - cmd_help (tokens->next); + cmd_help (); } else if (strcmp (cmd_token->buffer, "cat") == 0) { cmd_cat (tokens->next); } else if (strcmp (cmd_token->buffer, "ls") == 0) { cmd_ls (tokens->next); + } else if (strcmp (cmd_token->buffer, "quit") == 0) { + cmd_quit (); } else { printf ("ERROR: unknown command '%s'\n", cmd_token->buffer); } @@ -193,7 +201,7 @@ void app_main (void) { char line_buffer[LINE_BUFFER_MAX + 1]; memset (line_buffer, 0, sizeof (line_buffer)); - for (;;) { + while (run) { printf (PROMPT); char ch = 0;