ft_free_null()
+ refactoring shell_loop()
This commit is contained in:
@@ -6,12 +6,14 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||
/* Updated: 2021/11/29 12:43:38 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/11/30 13:30:52 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static char *read_input(char *prompt, t_all *c);
|
||||
|
||||
void shell_loop(t_all *c)
|
||||
{
|
||||
char *line_input;
|
||||
@@ -21,18 +23,13 @@ void shell_loop(t_all *c)
|
||||
{
|
||||
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);
|
||||
line_input = read_input(c->prompt, c);
|
||||
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()
|
||||
ft_free_null(&line_input);
|
||||
if (!c->token_list)
|
||||
continue ;
|
||||
// Parsing
|
||||
@@ -43,10 +40,24 @@ void shell_loop(t_all *c)
|
||||
// Exec Pipeline
|
||||
exec_cmd_line(c);
|
||||
}
|
||||
else if (!line_input)
|
||||
{
|
||||
write(1, "exit\n", 5);
|
||||
exit_free(c, get_last_exit_status());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *read_input(char *prompt, t_all *c)
|
||||
{
|
||||
char *line_input;
|
||||
struct sigaction signal_behaviour;
|
||||
|
||||
ft_bzero(&signal_behaviour, sizeof signal_behaviour);
|
||||
signal_behaviour.sa_handler = sigint_handler_interactive;
|
||||
sigaction(SIGINT, &signal_behaviour, NULL);
|
||||
line_input = readline(prompt);
|
||||
signal_behaviour.sa_handler = SIG_IGN;
|
||||
sigaction(SIGINT, &signal_behaviour, NULL);
|
||||
if (!line_input)
|
||||
{
|
||||
write(1, "exit\n", 5);
|
||||
exit_free(c, get_last_exit_status());
|
||||
}
|
||||
return (line_input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user