-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
59 lines (49 loc) · 1.09 KB
/
main.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
#include "header.h"
/**
* sig_handler - handles user input of ^C with the following
* @sig: integer value of signal to change, will be SIGINT = ^C
*
* Return: void
*/
void sig_handler(int sig)
{
(void) sig;
_puts("");
write(STDOUT_FILENO, "$ ", 2);
}
/**
* main - custom shell
* Return: 0
*/
int main(void)
{
arg_inventory_t *arginv;
int exit_status;
arginv = buildarginv();
signal(SIGINT, sig_handler);
while (!arginv->exit)
{
if (arginv->st_mode)
write(STDOUT_FILENO, "$ ", 2);
if (!_getline(&arginv->input_commands, &arginv->buflimit))
break;
add_node_history(&arginv->history, arginv->input_commands);
tokenize(&arginv->tokens, arginv->input_commands);
if (arginv->tokens.tokensN > 0)
{
expand_bash_vars(arginv);
if (parse(&arginv->parser, &arginv->tokens))
{
delete_parser(&arginv->parser);
delete_tokens(&arginv->tokens);
continue;
}
worker_execute(arginv);
delete_parser(&arginv->parser);
}
mem_reset(arginv->input_commands, BUFSIZE);
delete_tokens(&arginv->tokens);
}
exit_status = freeall(arginv);
return (exit_status);
}