CE add quit command
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m38s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m38s
This commit is contained in:
16
ce/ce.c
16
ce/ce.c
@@ -25,6 +25,8 @@ struct token {
|
|||||||
static int e_pid;
|
static int e_pid;
|
||||||
static int e_pgid;
|
static int e_pgid;
|
||||||
|
|
||||||
|
static bool run = true;
|
||||||
|
|
||||||
static void putch (char ch) { mail_send (e_pgid, &ch, 1); }
|
static void putch (char ch) { mail_send (e_pgid, &ch, 1); }
|
||||||
void putchar_ (char ch) { putch (ch); }
|
void putchar_ (char ch) { putch (ch); }
|
||||||
|
|
||||||
@@ -148,14 +150,18 @@ static void cmd_ls (struct list_node_link* tokens) {
|
|||||||
volume_close ();
|
volume_close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_help (struct list_node_link* tokens) {
|
static void cmd_quit (void) {
|
||||||
(void)tokens;
|
run = false;
|
||||||
|
printf ("Goodbye!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cmd_help (void) {
|
||||||
printf ("Available commands:\n");
|
printf ("Available commands:\n");
|
||||||
printf ("echo <word1> <word2> <word3> ...\n");
|
printf ("echo <word1> <word2> <word3> ...\n");
|
||||||
printf ("help\n");
|
printf ("help\n");
|
||||||
printf ("cat <file path>\n");
|
printf ("cat <file path>\n");
|
||||||
printf ("ls <directory path>\n");
|
printf ("ls <directory path>\n");
|
||||||
|
printf ("quit\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exec_tokens (struct list_node_link* tokens) {
|
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) {
|
if (strcmp (cmd_token->buffer, "echo") == 0) {
|
||||||
cmd_echo (tokens->next);
|
cmd_echo (tokens->next);
|
||||||
} else if (strcmp (cmd_token->buffer, "help") == 0) {
|
} else if (strcmp (cmd_token->buffer, "help") == 0) {
|
||||||
cmd_help (tokens->next);
|
cmd_help ();
|
||||||
} else if (strcmp (cmd_token->buffer, "cat") == 0) {
|
} else if (strcmp (cmd_token->buffer, "cat") == 0) {
|
||||||
cmd_cat (tokens->next);
|
cmd_cat (tokens->next);
|
||||||
} else if (strcmp (cmd_token->buffer, "ls") == 0) {
|
} else if (strcmp (cmd_token->buffer, "ls") == 0) {
|
||||||
cmd_ls (tokens->next);
|
cmd_ls (tokens->next);
|
||||||
|
} else if (strcmp (cmd_token->buffer, "quit") == 0) {
|
||||||
|
cmd_quit ();
|
||||||
} else {
|
} else {
|
||||||
printf ("ERROR: unknown command '%s'\n", cmd_token->buffer);
|
printf ("ERROR: unknown command '%s'\n", cmd_token->buffer);
|
||||||
}
|
}
|
||||||
@@ -193,7 +201,7 @@ void app_main (void) {
|
|||||||
char line_buffer[LINE_BUFFER_MAX + 1];
|
char line_buffer[LINE_BUFFER_MAX + 1];
|
||||||
memset (line_buffer, 0, sizeof (line_buffer));
|
memset (line_buffer, 0, sizeof (line_buffer));
|
||||||
|
|
||||||
for (;;) {
|
while (run) {
|
||||||
printf (PROMPT);
|
printf (PROMPT);
|
||||||
|
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user