-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.c
98 lines (93 loc) · 2.01 KB
/
execute.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "headers.h"
#include "functions.h"
char *executeCommand(char *command, char *path)
{
if (debug)
printf("EXECUTEcommand = %s\n", command);
char entry[MY_LEN] = "";
strcpy(entry, command);
char copy[MY_LEN] = "";
strcpy(copy,command);
if(debug) printf("copy = %s\n",copy);
char* NewCommand = HandleRedirection(copy);
if(debug) printf("NewCommand after handling = %s\n",NewCommand);
if(NewCommand == NULL) return NULL;
strcpy(command, " ");
strcpy(command, NewCommand);
if (debug)
printf("NEW EXECUTEcommand = %s\n", NewCommand);
char temp[MY_LEN] = "";
strcpy(temp,NewCommand);
char *cmd = strtok(NewCommand," \t");
if(debug) printf("temp = %s\n",temp);
if (debug)
printf("cmd = %s\n", cmd);
if (cmd == NULL)
{
return NULL;
}
else if (!strcmp(cmd, "cd"))
{
cd(temp, path);
}
else if (!strcmp(cmd, "pwd"))
{
pwd();
}
else if (!strcmp(cmd, "echo"))
{
Echo(temp);
}
else if (!strcmp(cmd, "ls"))
{
ls(path, temp);
}
else if (!strcmp(cmd, "quit") || !strcmp(cmd,"exit"))
{
QUIT = 1;
}
else if (!strcmp(cmd, "pinfo"))
{
pinfo(temp);
}
else if (!strcmp(cmd, "discover"))
{
discover(path, temp);
}
else if (!strcmp(cmd, "history"))
{
// AddHistory(entry);
// createHistory();
history();
return NULL;
}
else if(!strcmp(cmd, "jobs"))
{
jobs(temp);
}
else if(!strcmp(cmd, "sig"))
{
sig(temp);
}
else if(!strcmp(cmd, "fg"))
{
fg(temp);
}
else if(!strcmp(cmd, "bg"))
{
bg(temp);
}
else if (!strcmp(cmd, ""))
{
return NULL;
}
else
{
// printf("Error: %s: Command not found\n", cmd);
systemCommand(path, temp);
}
if (debug)
printf("execmd sends %s to his\n", temp);
ResetStreams();
// AddHistory(entry);
}