parentheses update

This commit is contained in:
gazhonsepaskwa
2025-01-30 10:18:48 +01:00
parent 94e2f26112
commit 615e91f991
5 changed files with 23 additions and 32 deletions

View File

@@ -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)*/

View File

@@ -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;

View File

@@ -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] == '&')