From 304eeb73eb7384eb5c14cc87951cf759437e4e0e Mon Sep 17 00:00:00 2001 From: Nathan Lebrun Date: Fri, 31 Jan 2025 13:09:35 +0100 Subject: [PATCH] pff --- Makefile | 4 +-- test/ast/ast.c | 4 +-- test/ast/ast.h | 7 +++++ test/ast/cutll.c | 54 ++++++++++++++++++++++++++++++++++++ test/test.c | 21 ++++++++++---- test/tokenizer/linked_list.c | 17 ++++++++---- test/tokenizer/tokenizer.c | 2 +- test/tokenizer/tokenizer.h | 2 +- 8 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 test/ast/cutll.c diff --git a/Makefile b/Makefile index 63ed900..30b7202 100644 --- a/Makefile +++ b/Makefile @@ -44,11 +44,11 @@ TEST_DEPS = $(TEST_OBJS:.o=.d) $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c @mkdir -p $(dir $@) - @$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK) + @$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -o $@ $(LINK) parser: $(LIBFT) $(TEST_OBJS) @$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK) - @echo "$(CYAN)Test build completed: test$(RESET)" + @echo "$(CYAN)Test build completed: parser$(RESET)" # test part end diff --git a/test/ast/ast.c b/test/ast/ast.c index 1716773..e48342d 100644 --- a/test/ast/ast.c +++ b/test/ast/ast.c @@ -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; } } diff --git a/test/ast/ast.h b/test/ast/ast.h index 933b8dc..dfb51c8 100644 --- a/test/ast/ast.h +++ b/test/ast/ast.h @@ -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); diff --git a/test/ast/cutll.c b/test/ast/cutll.c new file mode 100644 index 0000000..b996591 --- /dev/null +++ b/test/ast/cutll.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cutll.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: nalebrun +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/test/test.c b/test/test.c index 97ce4ac..bf495a9 100644 --- a/test/test.c +++ b/test/test.c @@ -39,8 +39,9 @@ void truncate_comment(char *str) int main(int ac, char **av, char **envp) { t_node *lst; - t_ast_n *ast; + // t_ast_n *ast; int dio; + (void)envp; if (ac != 3) { @@ -54,16 +55,24 @@ int main(int ac, char **av, char **envp) if (DEBUG) { dio = drawio_init(av[1]); - gen_dio_linked_list(lst, dio); + // gen_dio_linked_list(lst, dio); } - ast = get_ast(envp, lst); - if (!ast) - return (1); + // ast = get_ast(envp, lst); + // if (!ast) + // return (1); if (DEBUG) { - gen_dio_ast(ast, dio); + // gen_dio_ast(ast, dio); drawio_end_file(dio); ft_debug(" draw.io file generated !\n"); } + + // tmp + t_nodell *lls = cutll(lst, "||", 1); + while (lls) + { + gen_dio_linked_list(lls->node, dio); + lls = lls->next; + } free_linked_list(lst); } diff --git a/test/tokenizer/linked_list.c b/test/tokenizer/linked_list.c index 35df924..5d69486 100644 --- a/test/tokenizer/linked_list.c +++ b/test/tokenizer/linked_list.c @@ -28,14 +28,21 @@ t_node *create_node(char *val, t_token token) return (node); } -int add_node_back(t_node *head, char *val, t_token token) +int add_node_back(t_node **head, char *val, t_token token, t_pres pres) { if (!val) return (0); - while (head->next != NULL) - head = head->next; - head->next = create_node(val, token); - if (head->next == NULL) + if (!(*head)) + { + (*head) = create_node(val, token); + (*head)->pressision = pres; + return (1); + } + while ((*head)->next != NULL) + (*head) = (*head)->next; + (*head)->next = create_node(val, token); + (*head)->next->pressision = pres; + if ((*head)->next == NULL) return (0); return (1); } diff --git a/test/tokenizer/tokenizer.c b/test/tokenizer/tokenizer.c index 108e1d9..01f000c 100644 --- a/test/tokenizer/tokenizer.c +++ b/test/tokenizer/tokenizer.c @@ -27,7 +27,7 @@ static t_node *tokenize_base(char *str) i = 1; while (tab[i]) { - if (!add_node_back(head, tab[i], 0)) + if (!add_node_back(&head, tab[i], 0, 0)) return (free(tab), NULL); i++; } diff --git a/test/tokenizer/tokenizer.h b/test/tokenizer/tokenizer.h index 1b15bd9..839461a 100644 --- a/test/tokenizer/tokenizer.h +++ b/test/tokenizer/tokenizer.h @@ -50,7 +50,7 @@ typedef struct s_node t_node *tokenize(char *str); t_node *create_node(char *val, t_token token); -int add_node_back(t_node *head, char *val, t_token token); +int add_node_back(t_node **head, char *val, t_token token, t_pres pres); int merge_with_next_node(t_node *node); void free_linked_list(t_node *stack); t_token get_token(char *str);