-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
63 lines (51 loc) · 1.2 KB
/
main.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
#include "headers.h"
int main()
{
backnum = 0;
present = NULL;
fprocpid = -1;
shellpid = getpid();
getcwd(invokedir, MAX_LENGTH);
input = dup(STDIN_FILENO);
output = dup(STDOUT_FILENO);
fproc = malloc(sizeof(struct fore));
signal(SIGINT, ctrl_c_execution);
signal(SIGTSTP, ctrl_z_execution);
while (1)
{
fprocpid = -1;
print_prompt();
char *lineptr = NULL;
size_t readline;
size_t len;
int i = 0;
readline = getdelim(&lineptr, &len, 10, stdin);
if (readline == -1)
{
printf("\n");
exit(1);
}
lineptr[readline - 1] = '\0';
char *commtoken;
commtoken = strtok(lineptr, ";");
comm[i] = commtoken;
while (commtoken != NULL)
{
i++;
commtoken = strtok(NULL, ";");
comm[i] = commtoken;
}
for (int j = 0; j < i; j++)
{
if (strstr(comm[j], "|") != NULL)
{
pipe_execution(comm[j]);
}
else
{
tokenise(comm[j]);
}
}
check_for_bg_process();
}
}