Files
RockOS/programs/rocksh/main.c

46 lines
809 B
C
Raw Normal View History

#include <string.h>
#include <stdio.h>
#include <unistd.h>
const char* shell_prompt = "rocksh> ";
static void process_cmd(const char* cmd) {
size_t cmd_len = strlen(cmd);
if (cmd_len < 1) {
return;
}
if (strcmp(cmd, "exit") == 0) {
printf("bye!\n");
exit(0);
}
printf("command not recognized: %s\n", cmd);
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
char cmd[128];
size_t p = 0;
printf("%s", shell_prompt);
while (1) {
char c = getchar();
printf("%c", c);
if (c != '\n') {
cmd[p++] = c;
continue;
}
cmd[p] = 0;
process_cmd(cmd);
memset(cmd, 0, 128);
p = 0;
printf("%s", shell_prompt);
}
return 0;
}