diff --git a/.gitignore b/.gitignore index 15e63ff..652bf94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ minishell .objs/* -srcs/builtins/test.c +test.c +parser +ast.xml diff --git a/parser b/parser deleted file mode 100755 index a9b7260..0000000 Binary files a/parser and /dev/null differ diff --git a/test/ast/ast.c b/test/ast/ast.c index ef8099e..1716773 100644 --- a/test/ast/ast.c +++ b/test/ast/ast.c @@ -12,35 +12,6 @@ #include "ast.h" -t_ast_n *created_ast_n(t_state st, t_ast_n *prt, t_ast_n *he) -{ - t_ast_n *node; - - node = malloc(sizeof(t_ast_n)); - if (!node) - return (NULL); - node->state = st; - node->parent = prt; - node->head = he; - node->ex_code = 0; - node->cmd = NULL; - node->args = NULL; - node->_stdout = 1; - node->_stdin = 0; - node->redir = _NR; - node->infile = NULL; - node->outfile = NULL; - node->left = NULL; - node->right = NULL; - node->pline = NULL; - if (prt) - node->shlvl = prt->shlvl; - else - node->shlvl = 0; - node->env = NULL; - return (node); -} - void setup_cmd(t_ast_n *node, char *cmd, char *args) { node->cmd = ft_strdup(cmd); @@ -58,10 +29,24 @@ int last_tok_subsh(t_node *lst) return (0); } +skip_parentheses(t_node **lst) +{ + if (!ft_strncmp((*lst)->val, "(", 1)) + { + while ((*lst)->next && ft_strncmp((*lst)->next->val, ")", 1)) + { + if (!ft_strncmp((*lst)->val, "(", 1)) + skip_parentheses(&lst); + *lst = (*lst)->next; + } + } +} + t_node *find_token(char *tok, t_node *lst) { while (lst) { + skip_parentheses(&lst); if (!ft_strncmp(lst->val, tok, ft_strlen(tok))) return (lst); lst = lst->next; @@ -129,6 +114,10 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent) (void)token; (void)parent; + node->left = NULL; + node->right = NULL; + node->pline = NULL; + /*if (node->state == _PLINE)*/ /*create_pline(node, lst, token);*/ /*else if (node->state == _CMD)*/ diff --git a/test/drawio/drawio_print_ast.c b/test/drawio/drawio_print_ast.c index ef0533e..8acdad7 100644 --- a/test/drawio/drawio_print_ast.c +++ b/test/drawio/drawio_print_ast.c @@ -48,7 +48,7 @@ void draw_pline_part(t_ast_n *node, t_elems *e, int fd, int node_id) i = 0; e->rect.y += e->rect.h + 50; - while (node->pline[i]) + while (node->pline && node->pline[i]) { e->arrow.id_dst = print_ast(node->pline[i++], e, fd); e->arrow.id_src = node_id; diff --git a/test/drawio/drawio_utils.c b/test/drawio/drawio_utils.c index ff43b7c..aed735a 100644 --- a/test/drawio/drawio_utils.c +++ b/test/drawio/drawio_utils.c @@ -38,7 +38,7 @@ char *replace_ampercent(char *src) i = -1; j = 0; amp_count = get_amp_count(src); - out = malloc(ft_strlen(src) + amp_count * 4); + out = malloc(ft_strlen(src) + amp_count * 4 + 1); while (src[++i]) { if (src[i] == '&')