This commit is contained in:
Nathan Lebrun
2025-01-31 13:09:35 +01:00
parent 2367f6a42d
commit 304eeb73eb
8 changed files with 94 additions and 17 deletions

View File

@@ -29,14 +29,14 @@ int last_tok_subsh(t_node *lst)
return (0);
}
skip_parentheses(t_node **lst)
void 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);
skip_parentheses(&(*lst)->next);
*lst = (*lst)->next;
}
}

View File

@@ -56,7 +56,14 @@ typedef struct s_ast_n
char **env;
} t_ast_n;
typedef struct s_nodell
{
t_node *node;
struct s_nodell *next;
} t_nodell;
t_ast_n *get_ast(char **envp, t_node *lst);
t_nodell *cutll(t_node *lst, char *expected, size_t limiter);
// env TMP
char **init_env(char **envp);

54
test/ast/cutll.c Normal file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cutll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 09:56:34 by nalebrun #+# #+# */
/* Updated: 2025/01/31 10:32:03 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "ast.h"
void add_nodell(t_nodell **nodell, t_node *node)
{
while (*nodell)
*nodell = (*nodell)->next;
(*nodell) = malloc(sizeof(t_nodell));
(*nodell)->node = node;
(*nodell)->next = NULL;
}
t_node *get_node(t_node *lst, char *expected)
{
t_node *node;
node = NULL;
while (lst && ft_strncmp(lst->val, expected, ft_strlen(expected)))
{
add_node_back(&node, lst->val, lst->token, lst->pressision);
lst = lst->next;
}
return (node);
}
t_nodell *cutll(t_node *lst, char *expected, size_t limiter)
{
t_nodell *out;
t_node *node;
size_t i;
i = 0;
out = NULL;
while (i <= limiter)
{
node = get_node(lst, expected);
if (!node)
break;
add_nodell(&out, node);
i++;
}
return (out);
}