-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecute.c
More file actions
44 lines (39 loc) · 857 Bytes
/
execute.c
File metadata and controls
44 lines (39 loc) · 857 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
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
#include "helper.h"
#include "builtin.h"
char *builtin_str[] = {"cd", "pwd", "echo", "quit", "jobs", "killallbg", "sendsig", "fg"};
int (*builtin_func[]) (char **) = {&main_cd, &main_pwd, &main_echo, &main_exit, &main_listjobs, &main_killallbg, &main_sendsig, &main_fg};
int main_execute(char **args)
{
int i, len;
if (args[0] == NULL) {
return 1;
}
for (i = 0; i < 8; i++)
{
if (strcmp(args[0], builtin_str[i]) == 0)
{
len = 0;
while(args[len] != NULL)
{
if (strcmp("&", args[len]) == 0)
{
args[len] = NULL;
break;
}
len++;
}
return (*builtin_func[i])(args);
}
}
return main_launch(args);
}