-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboom.c
80 lines (70 loc) · 1.55 KB
/
boom.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
# include "header.h"
void callingcmd(char *str,int zip,char* str9);
void getboom(int a){
ll j=0;
const char delimiters[] = " \t\n\0";
char *totken = strtok(extasks[a], delimiters);
while (totken != NULL)
{
exruntask[j]=totken;
j++;
totken = strtok(NULL, delimiters);
}
exruntask[j]=NULL;
}
void callingboom(char *str){
ll i=0;
const char boomdelimiters[] = "@$";
for (ll i = 0,j=0; i < strlen(str); i++)
{
if(str[i]=='@')
{
sym[j]=0;
j++;
}
if(str[i]=='$')
{
sym[j]=1;
j++;
}
}
char *totken = strtok(str, boomdelimiters);
while (totken != NULL)
{
extasks[i]=totken;
i++;
totken = strtok(NULL, boomdelimiters);
}
ll boom_cmd=i;
for (ll i = 0; i < boom_cmd; i++)
{
sym_exit[i]=0;
if(i==0 || (sym_exit[i-1]==1 && sym[i-1]==1) ||(sym_exit[i-1]==0 && sym[i-1]==0))
{
getboom(i);
pid_t pid=fork();
if(pid<0)
{
perror("fork");
sym_exit[i]=1;
}
else if(pid==0)
{
// callingcmd(extasks[i],0,execut);
if(execvp(exruntask[0],exruntask)<0)
{
perror("cmd not found");
sym_exit[i]=1;
}
}
else
{
wait(NULL);
sym_exit[i]=0;
}
// z=i;
}
}
exit_fail=2;
return;
}