-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_handler.c
65 lines (53 loc) · 1.13 KB
/
command_handler.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "main.h"
/**
* handle_commands - handles multiple commands
*
* @commands: array of commands
*/
void handle_commands(char **commands)
{
if (commands == NULL)
return;
while (*commands != NULL)
{
char **argv = NULL;
if (is_operator(*commands))
{
handle_operator(&commands, get_state()->status);
continue;
}
argv = parse_command(*commands);
get_state()->status = handle_command(argv);
commands++;
string_array_free(&argv);
}
}
/**
* handle_command - handles command
*
* @argv: argument vector
*
* Return: status of command
*/
int handle_command(char **argv)
{
int status = 0;
get_state()->count++;
if (argv == NULL)
return (0);
if (strcmp(argv[0], "exit") == 0)
builtin_exit(argv);
else if (strcmp(argv[0], "env") == 0)
status = builtin_env();
else if (strcmp(argv[0], "setenv") == 0)
status = builtin_setenv(argv);
else if (strcmp(argv[0], "unsetenv") == 0)
status = builtin_unsetenv(argv);
else if (strcmp(argv[0], "cd") == 0)
status = builtin_cd(argv);
else if (strcmp(argv[0], "alias") == 0)
status = builtin_alias(argv);
else
status = execute(argv);
return (status);
}