-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.c
44 lines (43 loc) · 824 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
#include "shell.h"
/**
* main - Entry point for simple_shell program.
* @ac: argument count
* @argv: command-line arguments
* @env: environment variables
* Return: 0 on success, 1 on failure.
*/
int main(int ac, char **argv, char **env)
{
char *input = NULL;
int is_terminal = isatty(STDIN_FILENO);
signal(SIGINT, signal_c);
while (1)
{
if (is_terminal)
prompt();
input = get_line();
if (input == NULL)
{
if (feof(stdin))
{
free(input);
input = NULL;
write(STDOUT_FILENO, "\n", 1);
exit(EXIT_SUCCESS);
}
free(input);
input = NULL;
exit(EXIT_FAILURE);
}
input[strcspn(input, "\n")] = '\0';
if (input[0] != '\0')
{
argv = parse_command(input);
executeCommand(ac, argv, env);
free(input);
free(argv);
argv = NULL;
}
}
return (EXIT_SUCCESS);
}