From 2fdfa68256fc665ec8ef08a16784c06eecdb4df5 Mon Sep 17 00:00:00 2001 From: gazhonsepaskwa Date: Mon, 3 Feb 2025 13:00:47 +0100 Subject: [PATCH] gros merge --- .gitignore | 2 - Makefile | 24 +--- includes/ast.h | 58 ---------- includes/{ => exec}/builtins.h | 2 +- includes/{ => exec}/env.h | 2 +- includes/{ => exec}/exec.h | 2 +- includes/minishell.h | 25 +++- {test/ast => includes/parser}/ast.h | 13 +-- {test/drawio => includes/parser}/drawio.h | 4 +- {test => includes/parser}/parsing.h | 11 +- .../tokenizer => includes/parser}/tokenizer.h | 2 +- srcs/ast/ast.c | 109 ------------------ srcs/builtins/cd.c | 2 +- srcs/builtins/echo.c | 2 +- srcs/builtins/env.c | 2 +- srcs/builtins/exit.c | 2 +- srcs/builtins/export.c | 2 +- srcs/builtins/pwd.c | 2 +- srcs/builtins/unset.c | 2 +- srcs/builtins/utils.c | 2 +- srcs/execution/exec.c | 4 +- srcs/main.c | 47 +++----- {test => srcs/parsing}/ast/ast.c | 46 +++----- {test => srcs/parsing}/ast/cutll.c | 2 +- {test => srcs/parsing}/ast/top_token.c | 2 +- {test => srcs/parsing}/drawio/drawio_ast.c | 2 +- .../parsing}/drawio/drawio_ast_utils.c | 2 +- .../parsing}/drawio/drawio_linklist.c | 2 +- .../parsing}/drawio/drawio_print_ast.c | 2 +- {test => srcs/parsing}/drawio/drawio_utils.c | 2 +- test/test.c => srcs/parsing/parser.c | 30 ++--- .../parsing}/tokenizer/linked_list.c | 2 +- .../parsing}/tokenizer/token_and_pres.c | 2 +- {test => srcs/parsing}/tokenizer/tokenizer.c | 2 +- .../parsing}/tokenizer/tokenizer_utils.c | 2 +- .../parsing/tokenizer/unstick_node_utils.c | 43 +++---- test/tokenizer/unstick_node_utils.c | 19 --- 37 files changed, 109 insertions(+), 372 deletions(-) delete mode 100644 includes/ast.h rename includes/{ => exec}/builtins.h (98%) rename includes/{ => exec}/env.h (98%) rename includes/{ => exec}/exec.h (97%) rename {test/ast => includes/parser}/ast.h (86%) rename {test/drawio => includes/parser}/drawio.h (93%) rename {test => includes/parser}/parsing.h (85%) rename {test/tokenizer => includes/parser}/tokenizer.h (98%) delete mode 100644 srcs/ast/ast.c rename {test => srcs/parsing}/ast/ast.c (82%) rename {test => srcs/parsing}/ast/cutll.c (98%) rename {test => srcs/parsing}/ast/top_token.c (97%) rename {test => srcs/parsing}/drawio/drawio_ast.c (96%) rename {test => srcs/parsing}/drawio/drawio_ast_utils.c (98%) rename {test => srcs/parsing}/drawio/drawio_linklist.c (97%) rename {test => srcs/parsing}/drawio/drawio_print_ast.c (98%) rename {test => srcs/parsing}/drawio/drawio_utils.c (97%) rename test/test.c => srcs/parsing/parser.c (73%) rename {test => srcs/parsing}/tokenizer/linked_list.c (98%) rename {test => srcs/parsing}/tokenizer/token_and_pres.c (98%) rename {test => srcs/parsing}/tokenizer/tokenizer.c (98%) rename {test => srcs/parsing}/tokenizer/tokenizer_utils.c (98%) rename test/tmp_env.c => srcs/parsing/tokenizer/unstick_node_utils.c (55%) delete mode 100644 test/tokenizer/unstick_node_utils.c diff --git a/.gitignore b/.gitignore index e71f399..7541b27 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ minishell .objs/* -test.c -parser ast.xml .TEST_objs diff --git a/Makefile b/Makefile index 30b7202..5d51782 100644 --- a/Makefile +++ b/Makefile @@ -32,28 +32,6 @@ $(NAME): $(LIBFT) $(OBJS) @$(CC) $(WFLAGS) $(OBJS) $(LIBFT) -o $(NAME) $(LINK) @echo "$(CYAN)Build completed: $(NAME)$(RESET)" - - -# test part - -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)) -TEST_DEPS = $(TEST_OBJS:.o=.d) - -$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c - @mkdir -p $(dir $@) - @$(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: parser$(RESET)" - -# test part end - - - clean: @rm -rf $(OBJDIR) $(TEST_OBJDIR) @make -C $(LIBFT_DIR) clean @@ -61,7 +39,7 @@ clean: fclean: clean @make -C $(LIBFT_DIR) fclean - @rm $(NAME) test + @rm $(NAME) @echo "$(CYAN)Executable removed$(RESET)" re: fclean all diff --git a/includes/ast.h b/includes/ast.h deleted file mode 100644 index 4828896..0000000 --- a/includes/ast.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ast.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lderidde +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/24 08:23:27 by lderidde #+# #+# */ -/* Updated: 2025/01/28 10:49:53 by lderidde ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef AST_H -# define AST_H - -# include "../lib/libft/libft.h" - -typedef enum e_state -{ - UNDEF, - _AND, - _OR, - _CMD, - _PLINE -} t_state; - -typedef enum e_redir -{ - _NR, - _RED_L, - _RED_R, - _RED_DR -} t_redir; - -typedef struct s_ast_n -{ - t_state state; - struct s_ast_n *parent; - struct s_ast_n *left; - struct s_ast_n *right; - struct s_ast_n **pline; - int ex_code; - struct s_ast_n *head; - char *cmd; - char **args; - int fds[2]; - int _stdout; - int _stdin; - t_redir redir; - char *infile; - char *outfile; - int shlvl; - char **env; -} t_ast_n; - -t_ast_n *return_hardcode_ast(char **envp); - -#endif diff --git a/includes/builtins.h b/includes/exec/builtins.h similarity index 98% rename from includes/builtins.h rename to includes/exec/builtins.h index bee3621..b9e8289 100644 --- a/includes/builtins.h +++ b/includes/exec/builtins.h @@ -14,7 +14,7 @@ # define BUILTINS_H # include "../lib/libft/libft.h" -# include "env.h" +# include "../minishell.h" # include # include # include diff --git a/includes/env.h b/includes/exec/env.h similarity index 98% rename from includes/env.h rename to includes/exec/env.h index 5f88a2a..b82710c 100644 --- a/includes/env.h +++ b/includes/exec/env.h @@ -14,7 +14,7 @@ # define ENV_H # include "../lib/libft/libft.h" -# include "ast.h" +# include "../minishell.h" # include # include # include diff --git a/includes/exec.h b/includes/exec/exec.h similarity index 97% rename from includes/exec.h rename to includes/exec/exec.h index ccfccaa..b915f81 100644 --- a/includes/exec.h +++ b/includes/exec/exec.h @@ -13,12 +13,12 @@ #ifndef EXEC_H #define EXEC_H +# include "../minishell.h" # include # include # include # include # include -# include "ast.h" int execute_command(t_ast_n *node); diff --git a/includes/minishell.h b/includes/minishell.h index db502d8..9b9653b 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -13,6 +13,18 @@ #ifndef MINISHELL_H # define MINISHELL_H +# define DEBUG 1 + +typedef struct s_ast_n t_ast_n; +typedef struct s_node t_node; + +typedef struct s_msh +{ + int ex_code; + t_ast_n *head; + char **env; +} t_msh; + # include # include # include @@ -21,10 +33,14 @@ # include # include "../lib/libft/libft.h" -# include "builtins.h" -# include "env.h" -# include "exec.h" -# include "ast.h" +# include "parser/ast.h" +# include "parser/drawio.h" +# include "parser/tokenizer.h" +# include "parser/parsing.h" +# include "exec/builtins.h" +# include "exec/env.h" +# include "exec/exec.h" + # define POW1 "\033[1;38;2;21;22;26;48;2;92;106;178m" # define POW2 "\033[1;38;2;92;106;178;48;2;54;54;54m" @@ -32,4 +48,5 @@ # define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m" # define POW5 "\033[1;38;2;39;39;39m" + #endif diff --git a/test/ast/ast.h b/includes/parser/ast.h similarity index 86% rename from test/ast/ast.h rename to includes/parser/ast.h index 8ca622e..04f8c51 100644 --- a/test/ast/ast.h +++ b/includes/parser/ast.h @@ -14,8 +14,7 @@ # define AST_H /*# include "../../includes/env.h"*/ -# include "../../lib/libft/libft.h" -# include "../tokenizer/tokenizer.h" +# include "../minishell.h" typedef enum e_state { @@ -42,8 +41,7 @@ typedef struct s_ast_n struct s_ast_n *left; struct s_ast_n *right; struct s_ast_n **pline; - int ex_code; - struct s_ast_n *head; + t_msh *msh; char *cmd; char **args; int fds[2]; @@ -52,8 +50,7 @@ typedef struct s_ast_n t_redir redir; char *infile; char *outfile; - int shlvl; - char **env; + bool sh; } t_ast_n; typedef struct s_nodell @@ -62,9 +59,9 @@ typedef struct s_nodell struct s_nodell *next; } t_nodell; -t_ast_n *get_ast(char **envp, t_node *lst); +t_ast_n *get_ast(t_msh *msh, t_node *lst); t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter); -t_node *get_top_token(t_node *lst, t_state *state); +t_node *get_top_token(t_node *lst, t_state *state); // env TMP char **init_env(char **envp); diff --git a/test/drawio/drawio.h b/includes/parser/drawio.h similarity index 93% rename from test/drawio/drawio.h rename to includes/parser/drawio.h index 43a74d8..85b003d 100644 --- a/test/drawio/drawio.h +++ b/includes/parser/drawio.h @@ -13,9 +13,7 @@ #ifndef DRAWIO_H # define DRAWIO_H -# include "../../lib/libft/libft.h" -# include "../tokenizer/tokenizer.h" -# include "../ast/ast.h" +# include "../minishell.h" typedef struct s_dio_node { diff --git a/test/parsing.h b/includes/parser/parsing.h similarity index 85% rename from test/parsing.h rename to includes/parser/parsing.h index c602430..6caa1f8 100644 --- a/test/parsing.h +++ b/includes/parser/parsing.h @@ -13,15 +13,8 @@ #ifndef PARSING_H # define PARSING_H -# define DEBUG 1 +# include "../minishell.h" -# include "tokenizer/tokenizer.h" -# include "ast/ast.h" - -// drawio -# include "drawio/drawio.h" - -// tmp_env -char **init_env(char **envp); +t_ast_n *parser(char *input, char **envp, t_msh *msh); #endif diff --git a/test/tokenizer/tokenizer.h b/includes/parser/tokenizer.h similarity index 98% rename from test/tokenizer/tokenizer.h rename to includes/parser/tokenizer.h index 839461a..db68daa 100644 --- a/test/tokenizer/tokenizer.h +++ b/includes/parser/tokenizer.h @@ -13,7 +13,7 @@ #ifndef TOKENIZER_H # define TOKENIZER_H -# include "../../lib/libft/libft.h" +# include "../minishell.h" typedef enum e_token { diff --git a/srcs/ast/ast.c b/srcs/ast/ast.c deleted file mode 100644 index 2755431..0000000 --- a/srcs/ast/ast.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ast.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: lderidde +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */ -/* Updated: 2025/01/31 11:01:25 by lderidde ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../../includes/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; - if (prt) - node->shlvl = prt->shlvl; - else - node->shlvl = 0; - node->env = NULL; - return (node); -} - -static int count_var(char **envp) -{ - int i; - - i = 0; - if (!envp) - return (-1); - while (envp[i]) - i++; - return (i); -} - -static char **init_env(char **envp) -{ - char **env; - int i; - - i = 0; - env = malloc(sizeof(char *) * (count_var(envp) + 1)); - if (!env) - return (NULL); - env[count_var(envp)] = NULL; - while (envp[i]) - { - env[i] = ft_strdup(envp[i]); - i++; - } - return (env); -} - -void setup_cmd(t_ast_n *node, char *cmd, char *args) -{ - node->cmd = ft_strdup(cmd); - node->args = ft_split(args, " "); -} - -t_ast_n *return_hardcode_ast(char **envp) -{ - t_ast_n *head; - - // head = created_ast_n(_CMD, NULL, NULL); - // head->head = head; - // setup_cmd(head, "sdd", "ls -l"); - head = created_ast_n(_AND, NULL, NULL); - head->env = init_env(envp); - head->left = created_ast_n(_CMD, head, head); - setup_cmd(head->left, "cd", "cd srcs"); - // head->right = created_ast_n(_AND, head, head); - // head->right->left = created_ast_n(_CMD, head->right, head); - // setup_cmd(head->right->left, "echo", "echo $PWD"); - // head->right->right = created_ast_n(_CMD, head->right, head); - // setup_cmd(head->right->right, "ls", "ls -l"); - head->right = created_ast_n(_PLINE, head, head); - head->right->pline = malloc(sizeof(t_ast_n *) * 5); - head->right->pline[0] = created_ast_n(_CMD, head->right, head); - setup_cmd(head->right->pline[0], "ls", "ls -la"); - head->right->pline[1] = created_ast_n(_CMD, head->right, head); - setup_cmd(head->right->pline[1], "cat", "cat -e"); - head->right->pline[2] = created_ast_n(_CMD, head->right, head); - setup_cmd(head->right->pline[2], "grep", "grep builtins"); - head->right->pline[3] = created_ast_n(_CMD, head->right, head); - setup_cmd(head->right->pline[3], "wc", "wc -l"); - // head->right->pline[1]->redir = _RED_R; - // head->right->pline[1]->outfile = "file"; - // head->right->pline[3]->redir = _RED_R; - // head->right->pline[3]->outfile = "file"; - head->right->pline[4] = NULL; - return (head); -} diff --git a/srcs/builtins/cd.c b/srcs/builtins/cd.c index 25e3b4a..3879174 100644 --- a/srcs/builtins/cd.c +++ b/srcs/builtins/cd.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" void pwd_update(t_ast_n *head, char *src, char *dest) { diff --git a/srcs/builtins/echo.c b/srcs/builtins/echo.c index 3d8855e..2f1da16 100644 --- a/srcs/builtins/echo.c +++ b/srcs/builtins/echo.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int is_silent(char *str) { diff --git a/srcs/builtins/env.c b/srcs/builtins/env.c index d8a6904..d47ccca 100644 --- a/srcs/builtins/env.c +++ b/srcs/builtins/env.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int builtin_env(char **arg, char **envp) { diff --git a/srcs/builtins/exit.c b/srcs/builtins/exit.c index d82685a..5f40577 100644 --- a/srcs/builtins/exit.c +++ b/srcs/builtins/exit.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int ft_isnumeric(char *str) { diff --git a/srcs/builtins/export.c b/srcs/builtins/export.c index 4b2cd62..193f984 100644 --- a/srcs/builtins/export.c +++ b/srcs/builtins/export.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int is_export_valid(char *str) { diff --git a/srcs/builtins/pwd.c b/srcs/builtins/pwd.c index c59efc0..409560f 100644 --- a/srcs/builtins/pwd.c +++ b/srcs/builtins/pwd.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int builtin_pwd(char **arg) { diff --git a/srcs/builtins/unset.c b/srcs/builtins/unset.c index ae74011..da1af0a 100644 --- a/srcs/builtins/unset.c +++ b/srcs/builtins/unset.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" // void builtin_unset(char *str, char **envp) // { diff --git a/srcs/builtins/utils.c b/srcs/builtins/utils.c index 54d2b75..57555af 100644 --- a/srcs/builtins/utils.c +++ b/srcs/builtins/utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" int err_msg_cmd(char *cmd, char *arg, char *msg, int code) { diff --git a/srcs/execution/exec.c b/srcs/execution/exec.c index 5d45e16..c520500 100644 --- a/srcs/execution/exec.c +++ b/srcs/execution/exec.c @@ -10,9 +10,7 @@ /* */ /* ************************************************************************** */ -#include "../../includes/exec.h" -#include "../../lib/libft/libft.h" -#include "../../includes/builtins.h" +#include "../../includes/minishell.h" void handle_file(t_ast_n *node, int check) { diff --git a/srcs/main.c b/srcs/main.c index 0ced367..9151045 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -52,43 +52,22 @@ char **ft_setnewenv(void) return (envp); } -// 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) { - // char *input; - t_ast_n *node; + char *input; + t_msh *msh; (void)ac; (void)av; - // if (!envp[0]) - // env = ft_setnewenv(); - node = return_hardcode_ast(envp); - return (execute_command(node)); - // while (1) - // { - // input = powerline(); - // if (ft_strncmp(input, "exit", 4) == 0) - // builtin_exit(input, true); - // if (ft_strncmp(input, "pwd", 3) == 0) - // builtin_pwd(input); - // if (ft_strncmp(input, "echo", 4) == 0) - // builtin_echo(ft_split(input, " "), data->env); - // if (ft_strncmp(input, "env", 3) == 0) - // builtin_env(input, data->env); - // if (ft_strncmp(input, "unset", 5) == 0) - // builtin_unset(ft_split(input, " "), data); - // if (ft_strncmp(input, "cd", 2) == 0) - // builtin_cd(ft_split(input, " "), data); - // if (ft_strncmp(input, "export", 6) == 0) - // builtin_export(ft_split(input, " "), data); - // free(input); - // } + if (!envp[0]) + msh->env = ft_setnewenv(); + else + msh->env = copy_env_var(envp, count_var(envp)); + while (1) + { + input = powerline(); + msh->head = parser(input, envp, msh); + execute_command(msh->head); + free(input); + } } diff --git a/test/ast/ast.c b/srcs/parsing/ast/ast.c similarity index 82% rename from test/ast/ast.c rename to srcs/parsing/ast/ast.c index fe85e0d..c13549d 100644 --- a/test/ast/ast.c +++ b/srcs/parsing/ast/ast.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "ast.h" +#include "../../../includes/minishell.h" // =================================================================== @@ -19,13 +19,13 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent); // ==================================================================== -void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token) +void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh) { t_nodell *nodell; nodell = cutll(lst, token, 1); - parrent->left = create_ast_n(nodell->node, parrent); - parrent->right = create_ast_n(nodell->next->node, parrent); + parrent->left = create_ast_n(nodell->node, parrent, msh); + parrent->right = create_ast_n(nodell->next->node, parrent, msh); // free_lltab(sublsts); } @@ -117,7 +117,7 @@ void create_cmd(t_ast_n *self, t_node *lst) -void create_pline(t_ast_n *self, t_node *lst, t_node *token) +void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh) { t_nodell *nodell; t_nodell *cpy; @@ -137,7 +137,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token) i = 0; while (cpy) { - self->pline[i] = create_ast_n(cpy->node, self); + self->pline[i] = create_ast_n(cpy->node, self, t_msh *msh); cpy = cpy->next; i++; } @@ -145,10 +145,6 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token) // free_lltab(sublsts); } - - - - //====================================================================== @@ -176,7 +172,7 @@ void remove_parentheses(t_node **lst) } } -void create_subsh(t_ast_n *parent, t_node *lst) +void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh) { t_node *cpy; @@ -194,7 +190,7 @@ void create_subsh(t_ast_n *parent, t_node *lst) ft_printf("%s\n", cpy->val); cpy = cpy->next; } - parent->left = create_ast_n(lst, parent); + parent->left = create_ast_n(lst, parent, msh); } @@ -203,45 +199,33 @@ void create_subsh(t_ast_n *parent, t_node *lst) -t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent) +t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh) { t_ast_n *node; t_node *token; node = malloc(sizeof(t_ast_n)); token = get_top_token(lst, &node->state); - - ft_debug("================\n"); - ft_debug("NEW NODE CREATED\n"); - if (token && token->val) - ft_debug("token val: %s\n", token->val); - else - ft_debug("token val : NULL\n"); - ft_debug("node state : %d\n", node->state); - ft_debug("================\n\n"); - node->left = NULL; node->right = NULL; node->pline = NULL; + node->msh = msh; node->parent = parent; - if (node->state == _AND || node->state == _OR) - create_and_or(node, lst, token); + create_and_or(node, lst, token, msh); else if (node->state == _SUBSH) - create_subsh(node, lst); + create_subsh(node, lst, msh); else if (node->state == _PLINE) - create_pline(node, lst, token); + create_pline(node, lst, token, msh); else create_cmd(node, lst); - return (node); } -t_ast_n *get_ast(char **envp, t_node *lst) +t_ast_n *get_ast(t_msh *msh, t_node *lst) { t_ast_n *head; - (void)envp; - head = create_ast_n(lst, NULL); + head = create_ast_n(lst, NULL, msh); return (head); } diff --git a/test/ast/cutll.c b/srcs/parsing/ast/cutll.c similarity index 98% rename from test/ast/cutll.c rename to srcs/parsing/ast/cutll.c index aa98125..ed9017f 100644 --- a/test/ast/cutll.c +++ b/srcs/parsing/ast/cutll.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "ast.h" +#include "../../../includes/minishell.h" static void add_nodell(t_nodell **nodell, t_node *node) { diff --git a/test/ast/top_token.c b/srcs/parsing/ast/top_token.c similarity index 97% rename from test/ast/top_token.c rename to srcs/parsing/ast/top_token.c index 07dbd1b..ad206df 100644 --- a/test/ast/top_token.c +++ b/srcs/parsing/ast/top_token.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "ast.h" +#include "../../../includes/minishell.h" static int last_tok_subsh(t_node *lst) { diff --git a/test/drawio/drawio_ast.c b/srcs/parsing/drawio/drawio_ast.c similarity index 96% rename from test/drawio/drawio_ast.c rename to srcs/parsing/drawio/drawio_ast.c index e0595ac..9bb2174 100644 --- a/test/drawio/drawio_ast.c +++ b/srcs/parsing/drawio/drawio_ast.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "drawio.h" +#include "../../../includes/minishell.h" void set_ast_rect(t_dio_elem *rect) { diff --git a/test/drawio/drawio_ast_utils.c b/srcs/parsing/drawio/drawio_ast_utils.c similarity index 98% rename from test/drawio/drawio_ast_utils.c rename to srcs/parsing/drawio/drawio_ast_utils.c index 4c8a779..521656a 100644 --- a/test/drawio/drawio_ast_utils.c +++ b/srcs/parsing/drawio/drawio_ast_utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "drawio.h" +#include "../../../includes/minishell.h" const char *translate_state(t_state state) { diff --git a/test/drawio/drawio_linklist.c b/srcs/parsing/drawio/drawio_linklist.c similarity index 97% rename from test/drawio/drawio_linklist.c rename to srcs/parsing/drawio/drawio_linklist.c index a9b03a1..e23f7bd 100644 --- a/test/drawio/drawio_linklist.c +++ b/srcs/parsing/drawio/drawio_linklist.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "drawio.h" +#include "../../../includes/minishell.h" void set_ll_rect(t_dio_elem *rect) { diff --git a/test/drawio/drawio_print_ast.c b/srcs/parsing/drawio/drawio_print_ast.c similarity index 98% rename from test/drawio/drawio_print_ast.c rename to srcs/parsing/drawio/drawio_print_ast.c index 8acdad7..c00c8ff 100644 --- a/test/drawio/drawio_print_ast.c +++ b/srcs/parsing/drawio/drawio_print_ast.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "drawio.h" +#include "../../../includes/minishell.h" char *get_node_txt(t_ast_n *node) { diff --git a/test/drawio/drawio_utils.c b/srcs/parsing/drawio/drawio_utils.c similarity index 97% rename from test/drawio/drawio_utils.c rename to srcs/parsing/drawio/drawio_utils.c index 2ac128f..4723d03 100644 --- a/test/drawio/drawio_utils.c +++ b/srcs/parsing/drawio/drawio_utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "drawio.h" +#include "../../../includes/minishell.h" static int get_char_count(char *str, char c) { diff --git a/test/test.c b/srcs/parsing/parser.c similarity index 73% rename from test/test.c rename to srcs/parsing/parser.c index 6f11a39..62f9a51 100644 --- a/test/test.c +++ b/srcs/parsing/parser.c @@ -3,14 +3,14 @@ /* ::: :::::::: */ /* test.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: lderidde +#+ +:+ +#+ */ +/* By: nalebrun +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/15 08:23:41 by lderidde #+# #+# */ -/* Updated: 2025/01/31 14:05:34 by lderidde ### ########.fr */ +/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */ +/* Updated: 2025/02/03 11:49:21 by nalebrun ### ########.fr */ /* */ /* ************************************************************************** */ -#include "parsing.h" +#include "../../includes/minishell.h" void truncate_comment(char *str) { @@ -36,31 +36,24 @@ void truncate_comment(char *str) } } -int main(int ac, char **av, char **envp) +t_ast_n *parser(char *input, t_msh *msh) { t_node *lst; t_ast_n *ast; int dio; - (void)envp; - if (ac != 3) - { - ft_error("./test drawio_file command_str\n"); - return (1); - } - truncate_comment(av[1]); - lst = tokenize(av[2]); + truncate_comment(input); + lst = tokenize(input); if (!lst) - return (1); + return (NULL); if (DEBUG) { - dio = drawio_init(av[1]); + dio = drawio_init("ast.xml"); gen_dio_linked_list(lst, dio); } - ast = get_ast(envp, lst); + ast = get_ast(msh, lst); if (!ast) - return (1); - + return (NULL); if (DEBUG) { gen_dio_ast(ast, dio); @@ -68,4 +61,5 @@ int main(int ac, char **av, char **envp) ft_debug(" draw.io file generated !\n"); } free_linked_list(lst); + return (ast); } diff --git a/test/tokenizer/linked_list.c b/srcs/parsing/tokenizer/linked_list.c similarity index 98% rename from test/tokenizer/linked_list.c rename to srcs/parsing/tokenizer/linked_list.c index c092c14..19344d7 100644 --- a/test/tokenizer/linked_list.c +++ b/srcs/parsing/tokenizer/linked_list.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "tokenizer.h" +#include "../../../includes/minishell.h" t_node *create_node(char *val, t_token token) { diff --git a/test/tokenizer/token_and_pres.c b/srcs/parsing/tokenizer/token_and_pres.c similarity index 98% rename from test/tokenizer/token_and_pres.c rename to srcs/parsing/tokenizer/token_and_pres.c index 789ddcb..543f8a7 100644 --- a/test/tokenizer/token_and_pres.c +++ b/srcs/parsing/tokenizer/token_and_pres.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "./tokenizer.h" +#include "../../../includes/minishell.h" static t_pres get_operator(char *s) { diff --git a/test/tokenizer/tokenizer.c b/srcs/parsing/tokenizer/tokenizer.c similarity index 98% rename from test/tokenizer/tokenizer.c rename to srcs/parsing/tokenizer/tokenizer.c index 7dce3d7..8f86731 100644 --- a/test/tokenizer/tokenizer.c +++ b/srcs/parsing/tokenizer/tokenizer.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "tokenizer.h" +#include "../../../includes/minishell.h" static t_node *tokenize_base(char *str) { diff --git a/test/tokenizer/tokenizer_utils.c b/srcs/parsing/tokenizer/tokenizer_utils.c similarity index 98% rename from test/tokenizer/tokenizer_utils.c rename to srcs/parsing/tokenizer/tokenizer_utils.c index c099bc9..0e142a0 100644 --- a/test/tokenizer/tokenizer_utils.c +++ b/srcs/parsing/tokenizer/tokenizer_utils.c @@ -10,7 +10,7 @@ /* */ /* ************************************************************************** */ -#include "tokenizer.h" +#include "../../../includes/minishell.h" int is_meta(char c) { diff --git a/test/tmp_env.c b/srcs/parsing/tokenizer/unstick_node_utils.c similarity index 55% rename from test/tmp_env.c rename to srcs/parsing/tokenizer/unstick_node_utils.c index 93fc40e..852ef60 100644 --- a/test/tmp_env.c +++ b/srcs/parsing/tokenizer/unstick_node_utils.c @@ -1,44 +1,31 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* tmp_env.c :+: :+: :+: */ +/* unstick_node_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: nalebrun +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/27 12:35:29 by nalebrun #+# #+# */ -/* Updated: 2025/01/27 12:35:29 by nalebrun ### ########.fr */ +/* Created: 2025/02/03 12:53:08 by nalebrun #+# #+# */ +/* Updated: 2025/02/03 12:53:08 by nalebrun ### ########.fr */ /* */ /* ************************************************************************** */ -#include -#include "../lib/libft/libft.h" +#include "../../../includes/minishell.h" -static int count_var(char **envp) +char *copy_meta_xor(char *val, int *copied, int rev) { - int i; - - i = 0; - if (!envp) - return (-1); - while (envp[i]) - i++; - return (i); -} - -char **init_env(char **envp) -{ - char **env; int i; + int j; + char *out; i = 0; - env = malloc(sizeof(char *) * (count_var(envp) + 1)); - if (!env) - return (NULL); - env[count_var(envp)] = NULL; - while (envp[i]) - { - env[i] = ft_strdup(envp[i]); + while (is_meta(val[i]) ^ rev) i++; - } - return (env); + *copied = i; + out = malloc(i + 1); + j = -1; + while (++j < i) + out[j] = val[j]; + out[i] = 0; + return (out); } diff --git a/test/tokenizer/unstick_node_utils.c b/test/tokenizer/unstick_node_utils.c deleted file mode 100644 index 261a3b2..0000000 --- a/test/tokenizer/unstick_node_utils.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "tokenizer.h" - -char *copy_meta_xor(char *val, int *copied, int rev) -{ - int i; - int j; - char *out; - - i = 0; - while (is_meta(val[i]) ^ rev) - i++; - *copied = i; - out = malloc(i + 1); - j = -1; - while (++j < i) - out[j] = val[j]; - out[i] = 0; - return (out); -}