Editing the parsing adding the ; and </> derivation and adding the suppress leak for readlin
This commit is contained in:
parent
5a24e30c6d
commit
8941f67cf1
4 changed files with 61 additions and 9 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/29 11:42:54 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/29 14:46:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,6 +29,6 @@
|
|||
# include <readline/history.h>
|
||||
|
||||
i32 main(void);
|
||||
void ft_exit(u8 exit_status);
|
||||
void ft_exit(i8 *str, u8 exit_status);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/29 11:42:39 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/29 14:46:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
void ft_exit(u8 exit_status)
|
||||
void ft_exit(i8 *str, u8 exit_status)
|
||||
{
|
||||
free(str);
|
||||
printf("exit\n");
|
||||
exit(exit_status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/29 11:53:25 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/03/29 14:58:04 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/minishell.h"
|
||||
|
||||
int ft_check_type_cmd(i8 *cmd)
|
||||
i32 ft_check_type_cmd(i8 *cmd)
|
||||
{
|
||||
usize i;
|
||||
|
||||
|
|
@ -21,11 +21,50 @@ int ft_check_type_cmd(i8 *cmd)
|
|||
{
|
||||
if (cmd[i] == '>')
|
||||
{
|
||||
if (cmd[i + 1] == '>')
|
||||
printf("Have to redirect at the end of the file\n");
|
||||
if (cmd[++i] == '>')
|
||||
printf("Have to redirect at the end of the file after\n");
|
||||
else if (cmd[i] == '&')
|
||||
printf("Have to redirect the stdout in the file\n");
|
||||
else
|
||||
printf("Have to redirect in the file\n");
|
||||
}
|
||||
else if (cmd[i] == '<')
|
||||
{
|
||||
if (cmd[++i] == '<')
|
||||
printf("Have to redirect at the end of the file before\n");
|
||||
else if (cmd[i] == '&')
|
||||
printf("Have to redirect the stdin in the file\n");
|
||||
else
|
||||
printf("Have to redirect in the file\n");
|
||||
}
|
||||
else if (cmd[i] == ';')
|
||||
printf("Have to execute one more command\n");
|
||||
else if (cmd[i] == '"')
|
||||
{
|
||||
i++;
|
||||
while (cmd[i] != '\0')
|
||||
{
|
||||
if (cmd[i] == '"')
|
||||
{
|
||||
printf("Quote span found !\n");
|
||||
break ;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (cmd[i] == '\0')
|
||||
printf("Quote span not found !\n");
|
||||
}
|
||||
else if (cmd[i] == '|')
|
||||
{
|
||||
if (cmd[++i] == '|')
|
||||
printf("Or something\n");
|
||||
else
|
||||
printf("I have to pipe a cmd !\n");
|
||||
|
||||
}
|
||||
else
|
||||
printf("Error!\n");
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -38,7 +77,7 @@ void ft_take_cmd(void)
|
|||
{
|
||||
user_input = readline("shcat > ");
|
||||
if (!user_input || strcmp("exit", user_input) == 0)
|
||||
ft_exit(0);
|
||||
ft_exit(user_input, 0);
|
||||
ft_check_type_cmd(user_input);
|
||||
add_history(user_input);
|
||||
free(user_input);
|
||||
|
|
|
|||
12
valgrind_readline_leaks_ignore.txt
Normal file
12
valgrind_readline_leaks_ignore.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
leak readline
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:readline
|
||||
}
|
||||
{
|
||||
leak add_history
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:add_history
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue