-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshell.c
More file actions
48 lines (38 loc) · 895 Bytes
/
shell.c
File metadata and controls
48 lines (38 loc) · 895 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
46
47
48
#include "holberton.h"
/**
* main - Program that is simple UNIX command interpreter
* @argc: argument count
* @argv: argument vector
* @env: the environment
* Return: 0
*/
int main(int argc, char **argv, char **env)
{
char *prompt = "##--->";
char *line = NULL;
char **args = NULL;
int i = 0, status = 0, arg_num = 0;
static int exit_stat, tally;
size_t len = 0;
ssize_t read = 0;
(void)argc, (void)**argv;
while (TRUE)
{
if (isatty(STDIN_FILENO) == 1)
write(STDOUT_FILENO, prompt, 6);
read = getline(&line, &len, stdin);
++tally;
if (special_char(line, read, &exit_stat) == 127)
continue;
no_nl(line);
args = parser(line);
for (i = 0; args[i]; i++)
arg_num++;
builtins(line, args, env, &exit_stat);
status = _path(args[0], args, env, &exit_stat);
_execute(status, args, &exit_stat, &tally);
fflush(stdin);
}
free(line);
return (0);
}