-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.c
More file actions
105 lines (104 loc) · 2.32 KB
/
command.c
File metadata and controls
105 lines (104 loc) · 2.32 KB
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
99
100
101
102
103
104
105
#include<stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include<unistd.h>
#include<string.h>
#include <dirent.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<time.h>
#include<grp.h>
#include <sys/wait.h>
#include<fcntl.h>
#include "cd.h"
#include "command.h"
#include "display.h"
#include "echo.h"
#include "execute.h"
#include "ls.h"
#include "nightswatch.h"
#include "pinfo.h"
#include "redirection.h"
#include "pwd.h"
#include "global.h"
#include "global.c"
#include "pipe.h"
#include "jobs.h"
#include "env.h"
// Function to execute any command based on the input given
void ExecuteCommand(char command[],char *token,const char delemiter[])
{
if(strchr(command,'|') != NULL)
{
ExecutePipe(command,token,delemiter);
}
else if(strchr(command,'<') != NULL || strchr(command,'>') != NULL)
{
ExecuteRedirection(token,delemiter);
}
else if(strchr(command,'&') != NULL)
{
ExecuteOtherCommands(token,delemiter);
}
else if(strcmp(token,"cd") == 0)
{
ExecuteCD(token,delemiter);
}
else if(strcmp(token,"pwd") == 0)
{
ExecutePWD();
}
else if(strcmp(token,"echo") == 0)
{
ExecuteECHO(command,token,delemiter);
}
else if(strcmp(token,"ls") == 0)
{
ExecuteLS(token,delemiter);
}
else if(strcmp(token,"pinfo") == 0)
{
ExecutePINFO(token,delemiter);
}
else if(strcmp(token,"nightswatch") == 0)
{
ExecuteNightsWatch(token,delemiter);
}
else if(strcmp(token, "setenv") == 0)
{
ExecuteEnv(token, delemiter ,1);
}
else if(strcmp(token, "unsetenv") == 0)
{
ExecuteEnv(token, delemiter ,0);
}
else if(strcmp(token, "quit") == 0)
{
exit(0);
}
else if(strcmp(token, "jobs") == 0)
{
PrintJobs(delemiter);
}
else if(strcmp(token, "kjob") == 0)
{
KillJobs(token, delemiter);
}
else if(strcmp(token, "overkill") == 0)
{
OverKill();
}
else if(strcmp(token, "fg") == 0)
{
Fg(token, delemiter);
}
else if(strcmp(token, "bg") == 0)
{
Bg(token, delemiter);
}
else
{
ExecuteOtherCommands(token,delemiter);
}
return;
}