removed pdclib, strange things were happening..., user shell kinda works now
This commit is contained in:
46
programs/rocksh/main.c
Normal file
46
programs/rocksh/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user