This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
generated from HttpAnimation/MainTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
64 lines (56 loc) · 1.96 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "commands.h"
#define MAX_COMMAND_LENGTH 100
int main() {
char command[MAX_COMMAND_LENGTH];
while (1) {
printf("CDo> ");
fgets(command, sizeof(command), stdin);
// Remove trailing newline character
command[strcspn(command, "\n")] = '\0';
// Parse the command and argument (if any)
char *token = strtok(command, " ");
// Exit the shell if the user inputs "exit"
if (strcmp(token, "exit") == 0) {
exit_command();
break;
}
// Execute the appropriate command based on the token
if (strcmp(token, "echo") == 0) {
char *argument = strtok(NULL, "");
echo_command(argument);
} else if (strcmp(token, "read") == 0) {
char *argument = strtok(NULL, "");
read_command(argument);
} else if (strcmp(token, "ls") == 0) {
ls_command();
} else if (strcmp(token, "clear") == 0) {
clear_command();
} else if (strcmp(token, "host") == 0) {
char *argument = strtok(NULL, "");
host_command(argument);
} else if (strcmp(token, "help") == 0) {
help_command();
} else if (strcmp(token, "mkdir") == 0) {
char *argument = strtok(NULL, "");
mkdir_command(argument);
} else if (strcmp(token, "rm") == 0) {
char *flag = strtok(NULL, " ");
char *path = strtok(NULL, "");
rm_command(flag, path);
} else if (strcmp(token, "ping") == 0) {
char *url = strtok(NULL, "");
ping_command(url);
} else if (strcmp(token, "v") == 0) {
v_command();
} else if (strcmp(token, "start") == 0) {
char *script = strtok(NULL, "");
start_command(script);
} else {
printf("Unknown command: %s\n", token);
}
}
return 0;
}