ft_free_null()
+ refactoring shell_loop()
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/29 12:43:15 by lperrey ### ########.fr */
|
/* Updated: 2021/11/30 13:12:04 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ typedef void *(*t_dup_f)(void *);
|
|||||||
void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *));
|
void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *));
|
||||||
void ft_perror_io(char *err_str, char *io_file);
|
void ft_perror_io(char *err_str, char *io_file);
|
||||||
int ft_reti_perror_io(int ret, char *err_str, char *io_file);
|
int ft_reti_perror_io(int ret, char *err_str, char *io_file);
|
||||||
|
void ft_free_null(void *ptr);
|
||||||
|
|
||||||
char **ft_split_quotes(char const *s, char c);
|
char **ft_split_quotes(char const *s, char c);
|
||||||
char *ft_strdup_quotes(const char *s);
|
char *ft_strdup_quotes(const char *s);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/29 12:35:02 by lperrey ### ########.fr */
|
/* Updated: 2021/11/30 13:37:09 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -70,10 +70,7 @@ static int search_cmd_path(char *cmd_name, char **cmd_path, char *path[])
|
|||||||
if (access(*cmd_path, X_OK) == 0)
|
if (access(*cmd_path, X_OK) == 0)
|
||||||
break ;
|
break ;
|
||||||
else
|
else
|
||||||
{
|
ft_free_null(cmd_path);
|
||||||
free(*cmd_path);
|
|
||||||
*cmd_path = NULL; // TODO : free_null()
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
free(cmd_name);
|
free(cmd_name);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */
|
/* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/27 12:58:20 by lperrey ### ########.fr */
|
/* Updated: 2021/11/30 13:11:48 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -211,3 +211,9 @@ int ft_reti_perror_io(int ret, char *err_str, char *io_file)
|
|||||||
perror(io_file);
|
perror(io_file);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_free_null(void *ptr)
|
||||||
|
{
|
||||||
|
free(*(char**)ptr);
|
||||||
|
*(char**)ptr = NULL;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
/* Created: 2021/11/07 02:01:33 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/07 04:33:04 by lperrey ### ########.fr */
|
/* Updated: 2021/11/30 13:46:46 by lperrey ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -55,8 +55,7 @@ static t_token *insert_tokens(t_token *t, t_token *insert_lst)
|
|||||||
t_token *insert_lst_last;
|
t_token *insert_lst_last;
|
||||||
|
|
||||||
t->id = 0;
|
t->id = 0;
|
||||||
free(t->content);
|
ft_free_null(&t->content);
|
||||||
t->content = NULL; // TODO : free_null()
|
|
||||||
if (!insert_lst)
|
if (!insert_lst)
|
||||||
return (t);
|
return (t);
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,14 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
/* 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"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static char *read_input(char *prompt, t_all *c);
|
||||||
|
|
||||||
void shell_loop(t_all *c)
|
void shell_loop(t_all *c)
|
||||||
{
|
{
|
||||||
char *line_input;
|
char *line_input;
|
||||||
@@ -21,18 +23,13 @@ void shell_loop(t_all *c)
|
|||||||
{
|
{
|
||||||
if (line_input)
|
if (line_input)
|
||||||
free(line_input);
|
free(line_input);
|
||||||
c->signal_behaviour.sa_handler = sigint_handler_interactive;
|
line_input = read_input(c->prompt, c);
|
||||||
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
||||||
line_input = readline(c->prompt);
|
|
||||||
if (line_input && *line_input)
|
if (line_input && *line_input)
|
||||||
{
|
{
|
||||||
c->signal_behaviour.sa_handler = SIG_IGN;
|
|
||||||
sigaction(SIGINT, &c->signal_behaviour, NULL);
|
|
||||||
add_history(line_input);
|
add_history(line_input);
|
||||||
// Lexing
|
// Lexing
|
||||||
c->token_list = input_to_tokens(line_input);
|
c->token_list = input_to_tokens(line_input);
|
||||||
free(line_input);
|
ft_free_null(&line_input);
|
||||||
line_input = NULL; // TODO : free_null()
|
|
||||||
if (!c->token_list)
|
if (!c->token_list)
|
||||||
continue ;
|
continue ;
|
||||||
// Parsing
|
// Parsing
|
||||||
@@ -43,10 +40,24 @@ void shell_loop(t_all *c)
|
|||||||
// Exec Pipeline
|
// Exec Pipeline
|
||||||
exec_cmd_line(c);
|
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