ast bigest fix + norm
This commit is contained in:
@@ -39,7 +39,7 @@ int builtin_export(char **arg, t_ast_n *head);
|
|||||||
|
|
||||||
//UTILS
|
//UTILS
|
||||||
int count_char(char *str);
|
int count_char(char *str);
|
||||||
int is_append(char *str);
|
int is_append(char *str);
|
||||||
char **key_value(char *str);
|
char **key_value(char *str);
|
||||||
void set_new_export(char *str, t_ast_n *node);
|
void set_new_export(char *str, t_ast_n *node);
|
||||||
int count_args(char **tab);
|
int count_args(char **tab);
|
||||||
|
|||||||
@@ -19,5 +19,7 @@ typedef struct s_msh t_msh;
|
|||||||
void read_hereinput(char *limiter, t_node *lst, t_msh *msh);
|
void read_hereinput(char *limiter, t_node *lst, t_msh *msh);
|
||||||
void parse_heredoc(char *limiter, t_node *lst, t_msh *msh);
|
void parse_heredoc(char *limiter, t_node *lst, t_msh *msh);
|
||||||
void create_heredoc(t_node *lst, t_msh *msh);
|
void create_heredoc(t_node *lst, t_msh *msh);
|
||||||
|
void end_heredoc(char *buf, t_msh *msh, t_node *lst, char *limiter);
|
||||||
|
void exit_heredoc(char *limiter, t_msh *msh, t_node *lst);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ typedef struct s_msh t_msh;
|
|||||||
|
|
||||||
t_ast_n *parser(char *input, t_msh *msh);
|
t_ast_n *parser(char *input, t_msh *msh);
|
||||||
|
|
||||||
|
void interpret_cmd(char **input, t_msh *msh);
|
||||||
|
|
||||||
int unexpected_token(t_node *node);
|
int unexpected_token(t_node *node);
|
||||||
int is_aop_operator(t_node *node);
|
int is_aop_operator(t_node *node);
|
||||||
int is_redir(t_node *cpy);
|
int is_redir(t_node *cpy);
|
||||||
@@ -27,8 +29,7 @@ int syntax_err_mess(char *token_base, int selected);
|
|||||||
int check_unclosed(char *c, t_node *node);
|
int check_unclosed(char *c, t_node *node);
|
||||||
int check_unclosed_quote(char *c, t_node *node);
|
int check_unclosed_quote(char *c, t_node *node);
|
||||||
|
|
||||||
void interpret_cmd(char **input, t_msh *msh);
|
int last_tok_redir(t_node *lst);
|
||||||
void end_heredoc(char *buf, t_msh *msh, t_node *lst, char *limiter);
|
int last_tok_subsh(t_node *lst);
|
||||||
void exit_heredoc(char *limiter, t_msh *msh, t_node *lst);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
make && valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --trace-children=yes --suppressions=valgrind.supp -s ./minishell
|
make && valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --trace-children=yes --suppressions=/home/nalebrun/git/minishell/valgrind.supp -s ./minishell
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ int is_export_valid(char *str)
|
|||||||
while ((++str) < key_end)
|
while ((++str) < key_end)
|
||||||
{
|
{
|
||||||
if (!ft_isalnum(*str) && *str != '_')
|
if (!ft_isalnum(*str) && *str != '_')
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
#include "../../includes/minishell.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int is_append(char *str)
|
int is_append(char *str)
|
||||||
{
|
{
|
||||||
if (*(ft_strchr(str, '=') - 1) == '+')
|
if (*(ft_strchr(str, '=') - 1) == '+')
|
||||||
return (1);
|
return (1);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_new_export(char *str, t_ast_n *node)
|
void set_new_export(char *str, t_ast_n *node)
|
||||||
@@ -37,5 +37,4 @@ void set_new_export(char *str, t_ast_n *node)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
set_var_env(str, NULL, node->msh);
|
set_var_env(str, NULL, node->msh);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,32 +13,6 @@
|
|||||||
#include "../../../../includes/minishell.h"
|
#include "../../../../includes/minishell.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static int last_tok_subsh(t_node *lst)
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
if ((lst->next == NULL) && !ft_strncmp(lst->val, ")", 1))
|
|
||||||
return (1);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int last_tok_redir(t_node *lst)
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
if ((lst->next == NULL || lst->next->pressision == D_RED_R
|
|
||||||
|| lst->next->pressision == RED_R
|
|
||||||
|| lst->next->pressision == RED_L
|
|
||||||
|| lst->next->pressision == HEREDOC) && !ft_strncmp(lst->val,
|
|
||||||
")", 1))
|
|
||||||
return (1);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void skip_parentheses(t_node **lst)
|
static void skip_parentheses(t_node **lst)
|
||||||
{
|
{
|
||||||
if (!ft_strncmp((*lst)->val, "(", 1))
|
if (!ft_strncmp((*lst)->val, "(", 1))
|
||||||
@@ -69,15 +43,31 @@ static t_node *find_token(char *tok, t_node *lst)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static t_node *rfind_token(char *tok, t_node *lst)
|
||||||
|
{
|
||||||
|
t_node *lst_it;
|
||||||
|
|
||||||
|
lst_it = NULL;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
skip_parentheses(&lst);
|
||||||
|
if (lst && !ft_strncmp(lst->val, tok, ft_strlen(tok)))
|
||||||
|
lst_it = lst;
|
||||||
|
if (lst)
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (lst_it);
|
||||||
|
}
|
||||||
|
|
||||||
t_node *get_top_token(t_node *lst, t_state *state)
|
t_node *get_top_token(t_node *lst, t_state *state)
|
||||||
{
|
{
|
||||||
*state = _SUBSH;
|
*state = _SUBSH;
|
||||||
if (find_token("&&", lst))
|
if (rfind_token("&&", lst) > rfind_token("||", lst))
|
||||||
{
|
{
|
||||||
*state = _AND;
|
*state = _AND;
|
||||||
return (find_token("&&", lst));
|
return (find_token("&&", lst));
|
||||||
}
|
}
|
||||||
else if (find_token("||", lst))
|
else if (rfind_token("||", lst) > rfind_token("&&", lst))
|
||||||
{
|
{
|
||||||
*state = _OR;
|
*state = _OR;
|
||||||
return (find_token("||", lst));
|
return (find_token("||", lst));
|
||||||
|
|||||||
39
srcs/parsing/ast/utils/top_token_utils.c
Normal file
39
srcs/parsing/ast/utils/top_token_utils.c
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* top_token_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/02/15 13:28:47 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/02/15 13:31:44 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../../../includes/minishell.h"
|
||||||
|
|
||||||
|
int last_tok_subsh(t_node *lst)
|
||||||
|
{
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
if ((lst->next == NULL) && !ft_strncmp(lst->val, ")", 1))
|
||||||
|
return (1);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_tok_redir(t_node *lst)
|
||||||
|
{
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
if ((lst->next == NULL || lst->next->pressision == D_RED_R
|
||||||
|
|| lst->next->pressision == RED_R
|
||||||
|
|| lst->next->pressision == RED_L
|
||||||
|
|| lst->next->pressision == HEREDOC) && !ft_strncmp(lst->val,
|
||||||
|
")", 1))
|
||||||
|
return (1);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -62,7 +62,6 @@ t_ast_n *parser(char *input, t_msh *msh)
|
|||||||
create_heredoc(lst, msh);
|
create_heredoc(lst, msh);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
dio = drawio_init(DIO_PATH);
|
dio = drawio_init(DIO_PATH);
|
||||||
// gen_dio_linked_list(lst, dio);
|
|
||||||
ast = get_ast(msh, lst);
|
ast = get_ast(msh, lst);
|
||||||
debug_dio_ast(ast, dio);
|
debug_dio_ast(ast, dio);
|
||||||
if (!ast)
|
if (!ast)
|
||||||
|
|||||||
@@ -116,31 +116,17 @@ t_node *tokenize(char *str)
|
|||||||
head = tokenize_base(str);
|
head = tokenize_base(str);
|
||||||
if (!head)
|
if (!head)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
// debug_token_list(head, "tokenizer base");
|
|
||||||
|
|
||||||
if (!trim_nodes(head))
|
if (!trim_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
// debug_token_list(head, "trim");
|
|
||||||
|
|
||||||
if (!unstick_nodes(head))
|
if (!unstick_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
// debug_token_list(head, "unstick");
|
|
||||||
|
|
||||||
stick_quote_node(head, 39);
|
stick_quote_node(head, 39);
|
||||||
stick_quote_node(head, '"');
|
stick_quote_node(head, '"');
|
||||||
// debug_token_list(head, "stick_quote_node");
|
|
||||||
|
|
||||||
set_token(head);
|
set_token(head);
|
||||||
// debug_token_list(head, "set token");
|
|
||||||
|
|
||||||
if (!trim_nodes(head))
|
if (!trim_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
// debug_token_list(head, "trim2");
|
|
||||||
|
|
||||||
del_void_nodes(&head);
|
del_void_nodes(&head);
|
||||||
// debug_token_list(head, "del_void_nodes");
|
|
||||||
debug_token_list(head, "tokenizer");
|
debug_token_list(head, "tokenizer");
|
||||||
|
|
||||||
if (syntax_error(head))
|
if (syntax_error(head))
|
||||||
return (free_linked_list(head), NULL);
|
return (free_linked_list(head), NULL);
|
||||||
return (head);
|
return (head);
|
||||||
|
|||||||
Reference in New Issue
Block a user