-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute_cmd.c
More file actions
171 lines (164 loc) · 3.64 KB
/
Copy pathexecute_cmd.c
File metadata and controls
171 lines (164 loc) · 3.64 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include<dirent.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<signal.h>
#include<sys/resource.h>
#include<time.h>
#include<sys/types.h>
struct stat statRes;
struct rusage usage;
char *command,cpy_cmd[100];
char home[100],pwd[100],dir[100],user[256],host[256];
int pidlst[20000][3];
int pidnumber;
char pidname[1000][200];
char input_file[100], output_file[100];
int inputD, outputD;
int current_fg;
void pinfo2(char *pid);
void ls();
void hme();
void pd();
void cd();
void username();
void vi();
void vim();
void hostname();
void echo();
void showpwd();
void printEveryTime();
void pinfo();
void history();
void addTohist();
void envSet();
void unenvSet();
void kjob();
void jobs();
void overkill();
void fg();
void bg();
void INThandler();
void INThandlerz();
void cronJob();
void upArrow();
extern void execute_cmd(char *actual_cmd[], int len)
{
if( actual_cmd[0] == NULL)
return ;
printf("Command is : %d\n", (int)actual_cmd[0][0]);
if(strcmp(actual_cmd[0],"cd") == 0)
{
if(len == 1)
{
strcpy(dir,home);
cd();
}
else
{
if(strlen(actual_cmd[1])!=0 && actual_cmd[1][0]!='~')
strcpy(dir,actual_cmd[1]);
else if(actual_cmd[1][0]=='~'&&strlen(actual_cmd[1])!=1)
{
char newcommand[100];
newcommand[0] = '/';
for(int i=1;i<strlen(actual_cmd[1]);i++)
newcommand[i] = actual_cmd[1][i];
strcpy(dir, home);
strcat(dir, newcommand);
}
else
strcpy(dir,home);
cd();
}
}
else if(strcmp(actual_cmd[0],"echo") == 0)
{
echo(actual_cmd, len);
}
else if(strcmp(actual_cmd[0],"quit") == 0)
_exit(0);
else if(strcmp(actual_cmd[0],"pwd") == 0)
showpwd();
else if(strcmp(actual_cmd[0],"ls") == 0)
ls(actual_cmd[1]);
else if(strcmp(actual_cmd[0],"pinfo") == 0)
{
if(len<2)
pinfo();
else if(strlen(actual_cmd[1])==0)
{ pinfo();}
else
pinfo2(actual_cmd[1]);
}
else if(strcmp(actual_cmd[0], "history")==0)
{
if(len == 1)
history(10);
else if(len == 2)
{
if(strlen(actual_cmd[1])>0)
{
history(atoi(actual_cmd[1]));
}
else
history(10);
}
}
else if (strcmp(actual_cmd[0], "setenv") == 0)
{
envSet(actual_cmd, len);
}
else if(strcmp(actual_cmd[0], "unsetenv") == 0)
{
unenvSet(actual_cmd, len);
}
else if(strcmp(actual_cmd[0], "kjob") == 0)
{
kjob(actual_cmd, len);
}
else if(strcmp(actual_cmd[0], "jobs") == 0)
{
jobs();
}
else if(strcmp(actual_cmd[0], "overkill")==0)
{
overkill();
}
else if(strcmp(actual_cmd[0], "fg") == 0)
{
fg(actual_cmd, len);
}
else if(strcmp(actual_cmd[0], "bg") == 0)
{
bg(actual_cmd, len);
}
else if(strcmp(actual_cmd[0], "cronjob") == 0)
{
cronJob(actual_cmd, len);
}
else if((int)actual_cmd[0][0]==27 && (int)actual_cmd[0][1]==91 && (int)actual_cmd[0][2]==65)
{
int count =0;
for(int i=0; i<strlen(actual_cmd[0]); i++)
{
if((int)actual_cmd[0][0]==27 && (int)actual_cmd[0][1]==91 && (int)actual_cmd[0][2]==65)
count++;
}
upArrow(count);
}
else
{
if(len>1 && strcmp( actual_cmd[len-1],"&") == 0 )
{
actual_cmd[len-1] = NULL;
vi(actual_cmd,len);
}
else
vim(actual_cmd, len);
}
}