-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
43 lines (36 loc) · 734 Bytes
/
main.c
File metadata and controls
43 lines (36 loc) · 734 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
#include "main.h"
/**
* main - Entry point. Simple Shell Project
* @argc: args count
* @argv: args array
* @envp: env array
* Return: 0 (success)
*/
int main(int argc, char **argv, char **envp)
{
char *line = NULL;
size_t len = 0;
ssize_t res = 0;
int exit_status = 0, is_interactive = isatty(STDIN_FILENO);
(void) argc;
while (1)
{
if (is_interactive)
_puts("$ ");
res = getline(&line, &len, stdin);
if (res == -1)
{
break;
}
if (line[res - 1] == '\n')
line[res - 1] = '\0';
if ((_strcmp(line, "env")) == 0 || (_strcmp(line, "printenv")) == 0)
{
_printenv(envp);
continue;
}
exit_status = exec_command(line, argv[0], envp, exit_status);
}
free(line);
return (exit_status);
}