-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell_2.c
42 lines (40 loc) · 803 Bytes
/
shell_2.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
#include "shell.h"
/**
* main - Entry point
* @ac: Arguments counter
* @av: Arguments array
*
* Return: Always 0 (Success)
*/
int main(int ac, char **av)
{
int interactive = (ac == 1 && isatty(STDIN_FILENO));
size_t buflen = 0;
char *buffer = NULL, **argv = NULL;
if (ac == 2)
{
execute_from_file(av[1]);
return (0);
}
while (1)
{
if (interactive && isatty(STDIN_FILENO))
_puts("$ ");
buffer = _getline();
buflen = _strlen(buffer);
if (buffer[buflen - 1] == '\n')
buffer[buflen - 1] = '\0';
remove_spaces(buffer);
delete_comments(buffer);
if (_strlen(buffer) == 0)
continue;
argv = split_string(buffer, " \t\n");
if (check_builtin(argv))
continue;
handle_path(argv, buffer);
execute_command(argv);
free(buffer);
buffer = NULL;
}
return (0);
}