Files
RockOS/programs/rocksh/main.c

46 lines
803 B
C
Raw Normal View History

#include <unistd.h>
#include <stdio.h>
2026-07-12 04:37:46 -05:00
#include <string.h>
const char* shell_prompt = "rocksh> ";
2026-07-12 04:37:46 -05:00
char buf[256];
size_t buf_offset = 0;
void parse_cmd() {
if (strcmp(buf, "exit") == 0) {
printf("bye!\n");
exit(0);
}
if (strcmp(buf, "motd") == 0) {
printf("rockos is the best!\n");
}
}
void reset() {
memset(buf, 0, 256);
buf_offset = 0;
}
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
printf(shell_prompt);
2026-07-12 04:37:46 -05:00
while (1) {
char c;
int rd = read(0, &c, 1);
if (rd > 0) {
if (c == '\n') {
parse_cmd();
reset();
printf(shell_prompt);
continue;
}
buf[buf_offset++] = c;
}
}
return 0;
}