-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
71 lines (64 loc) · 1.25 KB
/
Copy pathshell.c
File metadata and controls
71 lines (64 loc) · 1.25 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
#include "shell.h"
/**
* executes_command - this func exec the command from user.
* @env: env variable.
* @av: argument from user.
* @path: command path.
* Return: exits.
**/
int executes_command(char **env, char **av, int path)
{
char *_command = NULL;
char **user_command = NULL;
int exits = 0;
int k = 0;
_command = _getuser_command();
if (_command)
{
path++;
user_command = _getstoken(_command);
if (!user_command)
{
free(_command);
return (exits);
}
if ((!_strcmp(user_command[0], "exit")) && user_command[1] == NULL)
exit_cmd(user_command, _command, exits);
if (!_strcmp(user_command[0], "env"))
_getenv(env);
else
{
k = sep_path(&user_command[0], env);
exits = _forks(user_command, av, env, _command, path, k);
if (k == 0)
free(user_command[0]);
}
free(user_command);
}
else
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
exit(exits);
}
free(_command);
return (exits);
}
/**
* main - main function of the shell project.
* @ac: argument counter.
* @av: arguments to be parsed.
* @env: env variable
* Return: exits..
*/
int main(int ac, char **av, char **env)
{
int path = 0;
int exits = 0;
(void)ac;
while (1)
{
exits = executes_command(env, av, path);
}
return (exits);
}