- Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathshell.c
More file actions
Latest commit
51 lines (46 loc) · 995 Bytes
/
Copy pathshell.c
File metadata and controls
51 lines (46 loc) · 995 Bytes
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"
voidprint_prompt() {
printf("> ");
}
voidhandle_ls(char*input) {
boolflag_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;
}
}
structfile_tfiles[10];
uint32_tnum_files=count_files();
list_files(files);
for (uint32_ti=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);
}
}
}
voidhandle_input(char*input) {
if (strncmp(input, "ls", 2) ==0) {
handle_ls(input);
} else {
printf("Unknown command `%s`\n", input);
}
printf("> ");
}
intmain() {
print_prompt();
register_input_handler(handle_input);
while(1){}
return0;
}