-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
47 lines (46 loc) · 833 Bytes
/
shell.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
#include "shell.h"
/**
* shell - Infinite loop that runs shell
* @ac: Arg count
* @av: args passed to shell at beginning of prog
* @env: Environment
* Return: Void
*/
void shell(int ac, char **av, char **env)
{
char *line;
char **args;
int status = 1;
char *tmp = NULL;
char *er;
char *filename;
int flow;
er = "Error";
do {
prompt();
line = _getline();
args = split_line(line);
flow = bridge(args[0], args);
if (flow == 2)
{
filename = args[0];
args[0] = find_path(args[0], tmp, er);
if (args[0] == er)
{
args[0] = search_cwd(filename, er);
if (args[0] == filename)
write(1, er, 5);
}
}
if (args[0] != er)
status = execute_prog(args, line, env, flow);
free(line);
free(args);
} while (status);
if (!ac)
(void)ac;
if (!av)
(void)av;
if (!env)
(void)env;
}