53 lines
1.8 KiB
C
53 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* shell_loop.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
|
/* Updated: 2021/11/17 15:29:35 by hulamy ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "minishell.h"
|
|
|
|
void shell_loop(t_all *c)
|
|
{
|
|
char *line_input;
|
|
|
|
line_input = NULL;
|
|
while (1)
|
|
{
|
|
if (line_input)
|
|
free(line_input);
|
|
c->signal_behaviour.sa_handler = sigint_handler_interactive;
|
|
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
line_input = readline(c->prompt);
|
|
if (line_input && *line_input)
|
|
{
|
|
c->signal_behaviour.sa_handler = SIG_IGN;
|
|
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
add_history(line_input);
|
|
// Lexing
|
|
c->token_list = input_to_tokens(line_input);
|
|
free(line_input);
|
|
line_input = NULL; // TODO : free_null()
|
|
if (!c->token_list)
|
|
continue ;
|
|
// Parsing
|
|
c->cmd_arr = parsing(c->token_list);
|
|
ft_lstclear((t_list **)&c->token_list, free);
|
|
if (!c->cmd_arr)
|
|
continue ;
|
|
// Exec Pipeline
|
|
exec_cmd_line(c);
|
|
}
|
|
else if (!line_input)
|
|
{
|
|
write(1, "exit\n", 5);
|
|
free_exit(c, c->last_exit_status);
|
|
}
|
|
}
|
|
}
|