-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.c
More file actions
65 lines (60 loc) · 1.68 KB
/
core.c
File metadata and controls
65 lines (60 loc) · 1.68 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* core.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: okamili <okamili@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/29 03:06:38 by okamili #+# #+# */
/* Updated: 2023/06/20 17:49:26 by okamili ### ########.fr */
/* */
/* ************************************************************************** */
#include "core.h"
void sig_handler(int sign)
{
if (sign == SIGINT)
{
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}
void struct_execution(t_cmd *head, int *err)
{
while (head)
{
if (head->sep && head->sep[0] == '|')
head = run_pipe_commands(head, err);
else
run_commands(head);
head = get_next_cmd(head, err);
}
}
int main(int argc, char **argv, char **env)
{
int err;
char *input;
t_cmd *cmds;
env_init(argc, argv, env);
signal(SIGINT, sig_handler);
signal(SIGQUIT, SIG_IGN);
err = 0;
while (1)
{
input = prompt();
if (!input)
{
printf("\nexit\n");
close_prgm(NULL);
}
add_history(input);
cmds = input_split(input, &err);
if (cmds)
cmds->prev_error = err;
parsing(cmds);
free(input);
struct_execution(cmds, &err);
}
return (0);
}