-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_execute.c
More file actions
42 lines (41 loc) · 972 Bytes
/
Copy path_execute.c
File metadata and controls
42 lines (41 loc) · 972 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
#include "shell.h"
/**
* _executeCommand - Function is the main shell loop
* @info: The parameter & return info struct
* @argv: The argument vector
* Return: 0 on success, 1 on error, or error code
*/
int _executeCommand(info_t *info, char **argv)
{
ssize_t read_result = 0;
int builtin_ret = 0;
while (read_result != -1 && builtin_ret != -2)
{
_clearInfoStruct(info);
if (_isInteractive(info))
_puts("$ ");
_eputchar(BUF_FLUSH);
read_result = _getInput(info);
if (read_result != -1)
{
_setInfoStruct(info, argv);
builtin_ret = _findBuiltin(info);
if (builtin_ret == -1)
_findCommand(info);
}
else if (_isInteractive(info))
_putchar('\n');
_freeInfoStruct(info, 0);
}
_writeHistory(info);
_freeInfoStruct(info, 1);
if (!_isInteractive(info) && info->_status)
exit(info->_status);
if (builtin_ret == -2)
{
if (info->_errorNumber == -1)
exit(info->_status);
exit(info->_errorNumber);
}
return (builtin_ret);
}