forked from erikaosgue/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
45 lines (42 loc) · 891 Bytes
/
shell.c
File metadata and controls
45 lines (42 loc) · 891 Bytes
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
#include "shell.h"
/**
* main - This is a simple UNIX command interpreter
* @ac: The number of strings pointed to by av
* @av: argument vector or array of arguments
* @env: enviroment list
* Return: Always 0.
*/
int main(int ac, char *av[], char **env)
{
int flag = 1, check, count = 0, exit_ = 0;
char *buffer = NULL, **args;
str_p buf_count;
do
{
buf_count = shell_prompt(count, exit_);
buffer = buf_count.buffer;
count = buf_count.count;
if (*buffer != '\0')
{
args = split_line(buffer, " \t");
if (args[0] != NULL)
{
if (_strcmp(args[0], "exit") == 0)
{
free(args), free(buffer);
exit(exit_);
}
else
{
check = apply_builtins(args, buffer);
if (check != 0)
exit_ = access_to_family(args, buffer, av, count);
}
}
free(args);
}
free(buffer);
} while (flag);
(void)ac, (void)env;
return (0);
}