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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
t_i32 options;
|
||||
|
||||
printf("ft_other_cmd = %s", shcat->strs_input[i]);
|
||||
printf("ft_other_cmd = %s\n", shcat->strs_input[i]);
|
||||
options = 0;
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
t_str str_input;
|
||||
t_str *strs_input;
|
||||
|
||||
void ft_free_utils(t_utils *s)
|
||||
{
|
||||
if (s->name_shell)
|
||||
free(s->name_shell);
|
||||
if (s->str_input)
|
||||
free(str_input);
|
||||
free(s->str_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);
|
||||
}
|
||||
|
||||
void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status)
|
||||
{
|
||||
if (maiboyerlpb)
|
||||
if (maiboyerlpb != NULL)
|
||||
ft_free_utils(maiboyerlpb);
|
||||
printf("exit\n");
|
||||
exit(exit_status);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
if (ft_strcmp(input[i], "exit") == 0)
|
||||
ft_exit(NULL, 0);
|
||||
ft_exit(shcat, 0);
|
||||
else if (ft_strcmp(input[i], "pwd") == 0)
|
||||
ft_pwd();
|
||||
else if (ft_strcmp(input[i], "cmd") == 0)
|
||||
ft_echo("ECHO MAIS PAS ARG BORDEL !\n", "flag");
|
||||
else
|
||||
ft_other_cmd(shcat, i);
|
||||
}
|
||||
|
|
@ -74,18 +76,16 @@ void ft_check(t_utils *shcat, char **input)
|
|||
|
||||
void ft_take_args(t_utils *shcat)
|
||||
{
|
||||
t_i32 i;
|
||||
t_str user_input = NULL;
|
||||
t_str *args = NULL;
|
||||
t_i32 i;
|
||||
|
||||
i = 0;
|
||||
while (1)
|
||||
{
|
||||
shcat->str_input = readline(shcat->name_shell);
|
||||
if (!user_input)
|
||||
shcat->str_input = readline((t_const_str)shcat->name_shell);
|
||||
if (!shcat->str_input)
|
||||
ft_exit(shcat, 0);
|
||||
shcat->strs_input = ft_split(user_input, ' ');
|
||||
if (!args)
|
||||
shcat->strs_input = ft_split(shcat->str_input, ' ');
|
||||
if (!shcat->strs_input)
|
||||
exit(1);
|
||||
ft_check(shcat, shcat->strs_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;
|
||||
|
||||
shcat = (t_utils *)malloc(sizeof(t_utils));
|
||||
shcat = (t_utils *)ft_calloc(sizeof(t_utils), 1);
|
||||
if (argc == 2)
|
||||
shcat->name_shell = ft_strdup(strcat(argv[1], " > "));
|
||||
else
|
||||
shcat->name_shell = ft_strdup("shcat > ");
|
||||
ft_init_arge(arge, shcat);
|
||||
shcat->envp = arge;
|
||||
ft_init_arge(arge, shcat);
|
||||
ft_take_args(shcat);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue