-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteractive.c
More file actions
49 lines (48 loc) · 1.09 KB
/
interactive.c
File metadata and controls
49 lines (48 loc) · 1.09 KB
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
#include "main.h"
/**
* interactive - Function that run SHELL program in interactive mode
* @argv: Argument vector
* Return: .
*/
void interactive(char **argv)
{
char *line = NULL, *command, *line_copy,
**cmd_argv = {NULL}, *environment[] = {NULL};
size_t len = 0;
ssize_t read;
int status = 0, count = 0, i;
while (1)
{
count++;
write(1, ":) ", sizeof(":) ") - 1);
read = _getline(&line, &len, stdin);
if (read == -1)
{
write(1, "\n", 1);
break;
}
line_copy = handle_new_line(line);
command = is_excutable(line_copy);
if (_strcmp(line_copy, "\n") == 0 || line_copy[0] == '#')
continue;
else if (is_builtin(argv[0], line_copy, &status, count, line) != -1)
{
free(command);
continue;
}
else if (command != NULL)
{
cmd_argv = generate_argv(line_copy);
i = excute(command, cmd_argv, environment, &status);
if (i == 0)
print_error(argv[0], count, status, line_copy);
}
else if (command == NULL)
{
excute_notFound(line_copy, cmd_argv, environment, &status);
print_error(argv[0], count, status, line_copy);
}
free(command);
}
free(line);
}