-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
50 lines (42 loc) · 737 Bytes
/
main.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
48
49
50
#include "main.h"
/**
* main - open shell, project base
* Return: int
*/
int main(void)
{
char *buff = NULL, **args;
size_t read_size = 0;
ssize_t buff_size = 0;
int exit_status = 0;
while (1)
{
if (isatty(0))
printf("hsh$ ");
buff_size = getline(&buff, &read_size, stdin);
if (buff_size == -1 || _strcmp("exit\n", buff) == 0)
{
free(buff);
break;
}
buff[buff_size - 1] = '\0';
if (_strcmp("env", buff) == 0)
{
_env();
continue;
}
if (empty_line(buff) == 1)
{
exit_status = 0;
continue;
}
args = _split(buff, " ");
args[0] = search_path(args[0]);
if (args[0] != NULL)
exit_status = execute(args);
else
perror("Error");
free(args);
}
return (exit_status);
}