-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
41 lines (32 loc) · 943 Bytes
/
shell.c
File metadata and controls
41 lines (32 loc) · 943 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
#include "user.h"
void main(void) {
/* page fault beacuse that address is not user mode accesible */
// *((volatile int *)0x80200000) = 0x1234;
// printf("hello world from the shell\n");
while (1) {
prompt:
printf("> ");
char cmdline[128];
for (int i = 0;; i++) {
char ch = getchar();
putchar(ch);
if (i == sizeof(cmdline) - 1) {
printf("command line too long\n");
goto prompt;
} else if (ch == '\r') {
printf("\n");
cmdline[i] = '\0';
break;
} else {
cmdline[i] = ch;
}
}
if (strcmp(cmdline, "hello") == 0) {
printf("hello to you\n");
} else if (strcmp(cmdline, "exit") == 0) {
exit();
} else {
printf("unknown command %s\n", cmdline);
}
}
}