-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlooper.c
More file actions
51 lines (48 loc) · 1.04 KB
/
looper.c
File metadata and controls
51 lines (48 loc) · 1.04 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
#include "shell.h"
/**
* looper - starts the shell loop
* @shellf: pointer to a struct that
* contains shell info
*/
void looper(shell_info shellf)
{
int loop = 1, sig_eof = 1, path_stat;
while (loop)
{
if (shellf.mode == 1)
write(STDOUT_FILENO, "$ ", 2);
shellf.command = get_command(&sig_eof);
if (sig_eof == -1)
{
free(shellf.command);
if (shellf.mode == 1)
write(STDOUT_FILENO, "\n", 1);
exit(shellf.stat);
} else
{
shellf.args = tokenize(shellf.command);
variable(shellf);
shellf.stat = check_builtins(shellf);
if (shellf.stat != 0)
{
if (shellf.stat == -1 || shellf.stat == 1)
shellf.stat = 0;
freedom(shellf);
shellf.loop_count += 1;
continue;
}
path_stat = check_path(shellf);
if (path_stat == 0)
{
print_err(shellf), freedom(shellf);
shellf.stat = 127, shellf.loop_count += 1;
continue;
} else if (path_stat == -1)
{
free(shellf.args), shellf.loop_count += 1;
continue;
}
shellf.stat = execute(shellf), shellf.loop_count += 1;
}
}
}