Resolving the leaks problemes of the path good luck maiboyer
This commit is contained in:
parent
56655f5426
commit
dffb6ea577
3 changed files with 21 additions and 20 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/01 01:00:30 by rparodi #+# #+# */
|
/* Created: 2024/04/01 01:00:30 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/04/01 01:54:23 by rparodi ### ########.fr */
|
/* Updated: 2024/04/01 15:48:48 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ void ft_other_cmd(t_utils *shcat, t_usize i)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
t_i32 options;
|
t_i32 options;
|
||||||
|
|
||||||
printf("ft_other_cmd = %s", shcat->strs_input[i]);
|
printf("ft_other_cmd = %s\n", shcat->strs_input[i]);
|
||||||
options = 0;
|
options = 0;
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/04/01 01:16:47 by rparodi ### ########.fr */
|
/* Updated: 2024/04/01 18:21:22 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,21 +25,22 @@ void ft_free_strs(t_str *strs)
|
||||||
free(strs);
|
free(strs);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_str str_input;
|
|
||||||
t_str *strs_input;
|
|
||||||
|
|
||||||
void ft_free_utils(t_utils *s)
|
void ft_free_utils(t_utils *s)
|
||||||
{
|
{
|
||||||
|
if (s->name_shell)
|
||||||
|
free(s->name_shell);
|
||||||
if (s->str_input)
|
if (s->str_input)
|
||||||
free(str_input);
|
free(s->str_input);
|
||||||
if (s->strs_input)
|
if (s->strs_input)
|
||||||
ft_free_strs(strs_input);
|
ft_free_strs(s->strs_input);
|
||||||
|
if (s->path)
|
||||||
|
ft_free_strs(s->path);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status)
|
void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status)
|
||||||
{
|
{
|
||||||
if (maiboyerlpb)
|
if (maiboyerlpb != NULL)
|
||||||
ft_free_utils(maiboyerlpb);
|
ft_free_utils(maiboyerlpb);
|
||||||
printf("exit\n");
|
printf("exit\n");
|
||||||
exit(exit_status);
|
exit(exit_status);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/04/01 01:51:47 by rparodi ### ########.fr */
|
/* Updated: 2024/04/01 18:17:41 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -62,9 +62,11 @@ void ft_check(t_utils *shcat, char **input)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ft_strcmp(input[i], "exit") == 0)
|
if (ft_strcmp(input[i], "exit") == 0)
|
||||||
ft_exit(NULL, 0);
|
ft_exit(shcat, 0);
|
||||||
else if (ft_strcmp(input[i], "pwd") == 0)
|
else if (ft_strcmp(input[i], "pwd") == 0)
|
||||||
ft_pwd();
|
ft_pwd();
|
||||||
|
else if (ft_strcmp(input[i], "cmd") == 0)
|
||||||
|
ft_echo("ECHO MAIS PAS ARG BORDEL !\n", "flag");
|
||||||
else
|
else
|
||||||
ft_other_cmd(shcat, i);
|
ft_other_cmd(shcat, i);
|
||||||
}
|
}
|
||||||
|
|
@ -75,17 +77,15 @@ void ft_check(t_utils *shcat, char **input)
|
||||||
void ft_take_args(t_utils *shcat)
|
void ft_take_args(t_utils *shcat)
|
||||||
{
|
{
|
||||||
t_i32 i;
|
t_i32 i;
|
||||||
t_str user_input = NULL;
|
|
||||||
t_str *args = NULL;
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
shcat->str_input = readline(shcat->name_shell);
|
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||||
if (!user_input)
|
if (!shcat->str_input)
|
||||||
ft_exit(shcat, 0);
|
ft_exit(shcat, 0);
|
||||||
shcat->strs_input = ft_split(user_input, ' ');
|
shcat->strs_input = ft_split(shcat->str_input, ' ');
|
||||||
if (!args)
|
if (!shcat->strs_input)
|
||||||
exit(1);
|
exit(1);
|
||||||
ft_check(shcat, shcat->strs_input);
|
ft_check(shcat, shcat->strs_input);
|
||||||
add_history(shcat->str_input);
|
add_history(shcat->str_input);
|
||||||
|
|
@ -124,12 +124,12 @@ t_i32 main(t_i32 argc, t_str argv[], t_str arge[])
|
||||||
{
|
{
|
||||||
t_utils *shcat;
|
t_utils *shcat;
|
||||||
|
|
||||||
shcat = (t_utils *)malloc(sizeof(t_utils));
|
shcat = (t_utils *)ft_calloc(sizeof(t_utils), 1);
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
shcat->name_shell = ft_strdup(strcat(argv[1], " > "));
|
shcat->name_shell = ft_strdup(strcat(argv[1], " > "));
|
||||||
else
|
else
|
||||||
shcat->name_shell = ft_strdup("shcat > ");
|
shcat->name_shell = ft_strdup("shcat > ");
|
||||||
ft_init_arge(arge, shcat);
|
|
||||||
shcat->envp = arge;
|
shcat->envp = arge;
|
||||||
|
ft_init_arge(arge, shcat);
|
||||||
ft_take_args(shcat);
|
ft_take_args(shcat);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue