-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathshell.c
51 lines (46 loc) · 995 Bytes
/
shell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdlib/filesystem.h"
#include "stdlib/stdio.h"
#include "stdlib/string.h"
#include "stdlib/syscalls.h"
void print_prompt() {
printf("> ");
}
void handle_ls(char* input) {
bool flag_long = false;
char* flag = input + 2;
while (*flag == ' ') {
flag++;
}
if (*flag != 0) {
if (strncmp(flag, "-l", 2) == 0) {
flag_long = true;
} else {
printf("Unrecognized flag `%s`\n", flag);
return;
}
}
struct file_t files[10];
uint32_t num_files = count_files();
list_files(files);
for (uint32_t i = 0; i < num_files; i++) {
if (flag_long) {
printf("%s (%d bytes)\n", files[i].name, files[i].size);
} else {
printf("%s\n", files[i].name);
}
}
}
void handle_input(char* input) {
if (strncmp(input, "ls", 2) == 0) {
handle_ls(input);
} else {
printf("Unknown command `%s`\n", input);
}
printf("> ");
}
int main() {
print_prompt();
register_input_handler(handle_input);
while(1){}
return 0;
}