parentheses update
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
minishell
|
minishell
|
||||||
.objs/*
|
.objs/*
|
||||||
srcs/builtins/test.c
|
test.c
|
||||||
|
parser
|
||||||
|
ast.xml
|
||||||
|
|||||||
@@ -12,35 +12,6 @@
|
|||||||
|
|
||||||
#include "ast.h"
|
#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)
|
void setup_cmd(t_ast_n *node, char *cmd, char *args)
|
||||||
{
|
{
|
||||||
node->cmd = ft_strdup(cmd);
|
node->cmd = ft_strdup(cmd);
|
||||||
@@ -58,10 +29,24 @@ int last_tok_subsh(t_node *lst)
|
|||||||
return (0);
|
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)
|
t_node *find_token(char *tok, t_node *lst)
|
||||||
{
|
{
|
||||||
while (lst)
|
while (lst)
|
||||||
{
|
{
|
||||||
|
skip_parentheses(&lst);
|
||||||
if (!ft_strncmp(lst->val, tok, ft_strlen(tok)))
|
if (!ft_strncmp(lst->val, tok, ft_strlen(tok)))
|
||||||
return (lst);
|
return (lst);
|
||||||
lst = lst->next;
|
lst = lst->next;
|
||||||
@@ -129,6 +114,10 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent)
|
|||||||
(void)token;
|
(void)token;
|
||||||
(void)parent;
|
(void)parent;
|
||||||
|
|
||||||
|
node->left = NULL;
|
||||||
|
node->right = NULL;
|
||||||
|
node->pline = NULL;
|
||||||
|
|
||||||
/*if (node->state == _PLINE)*/
|
/*if (node->state == _PLINE)*/
|
||||||
/*create_pline(node, lst, token);*/
|
/*create_pline(node, lst, token);*/
|
||||||
/*else if (node->state == _CMD)*/
|
/*else if (node->state == _CMD)*/
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void draw_pline_part(t_ast_n *node, t_elems *e, int fd, int node_id)
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
e->rect.y += e->rect.h + 50;
|
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_dst = print_ast(node->pline[i++], e, fd);
|
||||||
e->arrow.id_src = node_id;
|
e->arrow.id_src = node_id;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ char *replace_ampercent(char *src)
|
|||||||
i = -1;
|
i = -1;
|
||||||
j = 0;
|
j = 0;
|
||||||
amp_count = get_amp_count(src);
|
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])
|
while (src[++i])
|
||||||
{
|
{
|
||||||
if (src[i] == '&')
|
if (src[i] == '&')
|
||||||
|
|||||||
Reference in New Issue
Block a user