diff --git a/Makefile b/Makefile index 95000b1..63ed900 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ $(NAME): $(LIBFT) $(OBJS) # test part -TEST_SRCDIR = tests +TEST_SRCDIR = test TEST_OBJDIR = .TEST_objs TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c") TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS)) @@ -46,8 +46,8 @@ $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c @mkdir -p $(dir $@) @$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK) -tests: $(LIBFT) $(TEST_OBJS) - @$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK) +parser: $(LIBFT) $(TEST_OBJS) + @$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK) @echo "$(CYAN)Test build completed: test$(RESET)" # test part end diff --git a/parser b/parser new file mode 100755 index 0000000..0b98a55 Binary files /dev/null and b/parser differ diff --git a/tests/ast/ast.c b/test/ast/ast.c similarity index 98% rename from tests/ast/ast.c rename to test/ast/ast.c index 2b9f111..d96d73e 100644 --- a/tests/ast/ast.c +++ b/test/ast/ast.c @@ -47,10 +47,11 @@ void setup_cmd(t_ast_n *node, char *cmd, char *args) node->args = ft_split(args, " "); } -t_ast_n *return_hardcode_ast(char **envp) +t_ast_n *get_ast(char **envp, t_node *lst) { t_ast_n *head; + (void)lst; // head head = created_ast_n(_AND, NULL, NULL); head->env = init_env(envp); @@ -72,7 +73,7 @@ t_ast_n *return_hardcode_ast(char **envp) // right head->left->right->right = created_ast_n(_CMD, head->left->right, head); setup_cmd(head->left->right->right, "echo", "echo coucou"); - + // right head->right = created_ast_n(_PLINE, head, head); head->right->pline = malloc(sizeof(t_ast_n *) * 4); @@ -81,11 +82,11 @@ t_ast_n *return_hardcode_ast(char **envp) setup_cmd(head->right->pline[0], "ls", "ls"); // ===1=== head->right->pline[1] = created_ast_n(_AND, head->right, head); - + // left head->right->pline[1]->left = created_ast_n(_CMD, head->right->pline[1], head); setup_cmd(head->right->pline[1]->left, "echo", "echo coucou"); - + // right head->right->pline[1]->right = created_ast_n(_CMD, head->right->pline[1], head); setup_cmd(head->right->pline[1]->right, "echo", "echo coucou"); @@ -93,7 +94,7 @@ t_ast_n *return_hardcode_ast(char **envp) // ===2=== head->right->pline[2] = created_ast_n(_CMD, head->right, head); setup_cmd(head->right->pline[2], "cat", "cat -e"); - + // ===NULL=== head->right->pline[3] = NULL; diff --git a/tests/ast/ast.h b/test/ast/ast.h similarity index 95% rename from tests/ast/ast.h rename to test/ast/ast.h index 3e964c0..accffc0 100644 --- a/tests/ast/ast.h +++ b/test/ast/ast.h @@ -15,6 +15,7 @@ /*# include "../../includes/env.h"*/ # include "../../lib/libft/libft.h" +# include "../tokenizer/tokenizer.h" typedef enum e_state { @@ -54,7 +55,7 @@ typedef struct s_ast_n char **env; } t_ast_n; -t_ast_n *return_hardcode_ast(char **envp); +t_ast_n *get_ast(char **envp, t_node *lst); // env TMP char **init_env(char **envp); diff --git a/tests/drawio/drawio.h b/test/drawio/drawio.h similarity index 100% rename from tests/drawio/drawio.h rename to test/drawio/drawio.h diff --git a/tests/drawio/drawio_ast.c b/test/drawio/drawio_ast.c similarity index 100% rename from tests/drawio/drawio_ast.c rename to test/drawio/drawio_ast.c diff --git a/tests/drawio/drawio_ast_utils.c b/test/drawio/drawio_ast_utils.c similarity index 100% rename from tests/drawio/drawio_ast_utils.c rename to test/drawio/drawio_ast_utils.c diff --git a/tests/drawio/drawio_linklist.c b/test/drawio/drawio_linklist.c similarity index 100% rename from tests/drawio/drawio_linklist.c rename to test/drawio/drawio_linklist.c diff --git a/tests/drawio/drawio_print_ast.c b/test/drawio/drawio_print_ast.c similarity index 100% rename from tests/drawio/drawio_print_ast.c rename to test/drawio/drawio_print_ast.c diff --git a/tests/drawio/drawio_utils.c b/test/drawio/drawio_utils.c similarity index 100% rename from tests/drawio/drawio_utils.c rename to test/drawio/drawio_utils.c diff --git a/tests/parsing.h b/test/parsing.h similarity index 98% rename from tests/parsing.h rename to test/parsing.h index ddb328f..c602430 100644 --- a/tests/parsing.h +++ b/test/parsing.h @@ -13,11 +13,13 @@ #ifndef PARSING_H # define PARSING_H +# define DEBUG 1 + # include "tokenizer/tokenizer.h" # include "ast/ast.h" -# include "drawio/drawio.h" // drawio +# include "drawio/drawio.h" // tmp_env char **init_env(char **envp); diff --git a/tests/test.c b/test/test.c similarity index 78% rename from tests/test.c rename to test/test.c index 6b9190b..97ce4ac 100644 --- a/tests/test.c +++ b/test/test.c @@ -11,7 +11,6 @@ /* ************************************************************************** */ #include "parsing.h" -/*#include "../includes/env.h"*/ void truncate_comment(char *str) { @@ -37,37 +36,34 @@ void truncate_comment(char *str) } } -/*static t_data *init_data(char **envp)*/ -/*{*/ -/* t_data *data;*/ -/**/ -/* data = malloc (sizeof(t_data));*/ -/* data->env = init_env(envp);*/ -/* return (data);*/ -/*}*/ - int main(int ac, char **av, char **envp) { t_node *lst; t_ast_n *ast; int dio; - /*t_data data;*/ if (ac != 3) { ft_error("./test drawio_file command_str\n"); return (1); } - /*data = init_data(envp);*/ truncate_comment(av[1]); lst = tokenize(av[2]); if (!lst) return (1); - dio = drawio_init(av[1]); - gen_dio_linked_list(lst, dio); - /*debug_linked_list(lst, "ff");*/ - ast = return_hardcode_ast(envp); - gen_dio_ast(ast, dio); - drawio_end_file(dio); + if (DEBUG) + { + dio = drawio_init(av[1]); + gen_dio_linked_list(lst, dio); + } + ast = get_ast(envp, lst); + if (!ast) + return (1); + if (DEBUG) + { + gen_dio_ast(ast, dio); + drawio_end_file(dio); + ft_debug(" draw.io file generated !\n"); + } free_linked_list(lst); } diff --git a/tests/tmp_env.c b/test/tmp_env.c similarity index 100% rename from tests/tmp_env.c rename to test/tmp_env.c diff --git a/tests/tokenizer/linked_list.c b/test/tokenizer/linked_list.c similarity index 52% rename from tests/tokenizer/linked_list.c rename to test/tokenizer/linked_list.c index 5e37760..35df924 100644 --- a/tests/tokenizer/linked_list.c +++ b/test/tokenizer/linked_list.c @@ -81,65 +81,3 @@ int merge_with_next_node(t_node *node) node->next = tmp_next; return (1); } - -// have to be deleted after -void debug_linked_list(t_node *head, char *msg) -{ - t_node *current; - char *token; - char *pres; - - current = head; - printf("----------------------------------------------------------{%s} \n", - msg); - while (current != NULL) - { - // set val for base token - if (current->token == OPERATOR) - token = ft_strdup("OPERATOR"); - else if (current->token == WORD) - token = ft_strdup(" WORD"); - else if (current->token == UNSET) - token = ft_strdup(" UNSET"); - else - token = ft_strdup(" ???"); - - // set vals for pressision token - if (current->pressision == COMMAND) - pres = ft_strdup("COMMAND "); - else if (current->pressision == UNDEFINED) - pres = ft_strdup("UNDEF "); - else if (current->pressision == AND) - pres = ft_strdup("AND "); - else if (current->pressision == OR) - pres = ft_strdup("OR "); - else if (current->pressision == PIPE) - pres = ft_strdup("PIPE "); - else if (current->pressision == SUBSH_S) - pres = ft_strdup("SUBSH_S "); - else if (current->pressision == SUBSH_E) - pres = ft_strdup("SUBSH_E "); - else if (current->pressision == RED_L) - pres = ft_strdup("RED_L "); - else if (current->pressision == RED_R) - pres = ft_strdup("RED_R "); - else if (current->pressision == HEREDOC) - pres = ft_strdup("HEREDOC "); - else if (current->pressision == D_RED_R) - pres = ft_strdup("D_RED_R "); - else if (current->pressision == PARAMETER) - pres = ft_strdup("PARAMETER"); - else if (current->pressision == RED_FILE) - pres = ft_strdup("RED_FILE "); - else if (current->pressision == LIM) - pres = ft_strdup("LIM "); - else - pres = ft_strdup("??? "); - - printf("| Node - TOKEN: %s.%s -> val: |%s|\n", token, pres, current->val); - free(token); - free(pres); - current = current->next; - } - printf("----------------------------------------------------------\n\n"); -} diff --git a/tests/tokenizer/token_and_pres.c b/test/tokenizer/token_and_pres.c similarity index 100% rename from tests/tokenizer/token_and_pres.c rename to test/tokenizer/token_and_pres.c diff --git a/tests/tokenizer/tokenizer.c b/test/tokenizer/tokenizer.c similarity index 100% rename from tests/tokenizer/tokenizer.c rename to test/tokenizer/tokenizer.c diff --git a/tests/tokenizer/tokenizer.h b/test/tokenizer/tokenizer.h similarity index 98% rename from tests/tokenizer/tokenizer.h rename to test/tokenizer/tokenizer.h index 42e1fd7..1b15bd9 100644 --- a/tests/tokenizer/tokenizer.h +++ b/test/tokenizer/tokenizer.h @@ -13,7 +13,7 @@ #ifndef TOKENIZER_H # define TOKENIZER_H -# include "../includes/minishell.h" +# include "../../lib/libft/libft.h" typedef enum e_token { diff --git a/tests/tokenizer/tokenizer_utils.c b/test/tokenizer/tokenizer_utils.c similarity index 100% rename from tests/tokenizer/tokenizer_utils.c rename to test/tokenizer/tokenizer_utils.c diff --git a/tests/tokenizer/unstick_node_utils.c b/test/tokenizer/unstick_node_utils.c similarity index 100% rename from tests/tokenizer/unstick_node_utils.c rename to test/tokenizer/unstick_node_utils.c