From 362a63a836a455f8515e9a543c6e5f92ca4608bd Mon Sep 17 00:00:00 2001 From: Nathan Lebrun Date: Thu, 6 Feb 2025 10:53:02 +0100 Subject: [PATCH] subsh bool --- .gitignore | 1 + includes/parser/ast.h | 4 ++-- includes/parser/drawio.h | 14 ++++++-------- srcs/parsing/ast/and_or.c | 6 +++--- srcs/parsing/ast/ast.c | 5 +++-- srcs/parsing/ast/pipeline.c | 2 +- srcs/parsing/ast/subsh.c | 3 ++- srcs/parsing/drawio/drawio_ast_utils.c | 8 ++------ srcs/parsing/drawio/drawio_print_ast.c | 14 +++++++++----- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 07d42ac..26f0cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ minishell .objs/* ast.xml +.$ast.xml.bkp .TEST_objs file diff --git a/includes/parser/ast.h b/includes/parser/ast.h index a4478e5..1241b9d 100644 --- a/includes/parser/ast.h +++ b/includes/parser/ast.h @@ -50,7 +50,7 @@ typedef struct s_ast_n int _stdin; int save_stdo; int save_stdi; - t_redir *redir; + t_redir *redir; char *input; char **files; bool sh; @@ -67,7 +67,7 @@ t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter); t_node *get_top_token(t_node *lst, t_state *state); // recurce -t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh); +t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh); // redir t_redir get_redir(t_node *node); void create_redir(t_node *cpy, t_ast_n *self); diff --git a/includes/parser/drawio.h b/includes/parser/drawio.h index 85b003d..5fabd35 100644 --- a/includes/parser/drawio.h +++ b/includes/parser/drawio.h @@ -18,11 +18,9 @@ typedef struct s_dio_node { const char *st; - const char *redir; char *cmd; char *args; - char *inf; - char *outf; + char *files; } t_dio_node; typedef struct s_elems @@ -32,12 +30,12 @@ typedef struct s_elems } t_elems; // internal -char *replace_ampercent(char *src); -char *replace_left_red(char *src); +char *replace_ampercent(char *src); +char *replace_left_red(char *src); t_dio_node get_cmd_txt(t_ast_n *node); -int print_ast(t_ast_n *node, t_elems *e, int fd); +int print_ast(t_ast_n *node, t_elems *e, int fd); // external -void gen_dio_linked_list(t_node *head, int fd); -void gen_dio_ast(t_ast_n *head, int fd); +void gen_dio_linked_list(t_node *head, int fd); +void gen_dio_ast(t_ast_n *head, int fd); #endif diff --git a/srcs/parsing/ast/and_or.c b/srcs/parsing/ast/and_or.c index b4aa5ff..3c57aaf 100644 --- a/srcs/parsing/ast/and_or.c +++ b/srcs/parsing/ast/and_or.c @@ -12,12 +12,12 @@ #include "../../../includes/minishell.h" -void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh) +void create_and_or(t_ast_n *self, 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, msh); - parrent->right = create_ast_n(nodell->next->node, parrent, msh); + self->left = create_ast_n(nodell->node, self, msh, self->sh); + self->right = create_ast_n(nodell->next->node, self, msh, self->sh); // free_lltab(sublsts); } diff --git a/srcs/parsing/ast/ast.c b/srcs/parsing/ast/ast.c index 3a154f5..b916603 100644 --- a/srcs/parsing/ast/ast.c +++ b/srcs/parsing/ast/ast.c @@ -13,7 +13,7 @@ #include "../../../includes/minishell.h" #include -t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh) +t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh) { t_ast_n *node; t_node *token; @@ -29,6 +29,7 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh) node->_stdin = 0; node->save_stdo = 1; node->save_stdi = 0; + node->sh = subsh; if (node->state == _AND || node->state == _OR) create_and_or(node, lst, token, msh); else if (node->state == _SUBSH) @@ -44,6 +45,6 @@ t_ast_n *get_ast(t_msh *msh, t_node *lst) { t_ast_n *head; - head = create_ast_n(lst, NULL, msh); + head = create_ast_n(lst, NULL, msh, false); return (head); } diff --git a/srcs/parsing/ast/pipeline.c b/srcs/parsing/ast/pipeline.c index 793058b..9e905b2 100644 --- a/srcs/parsing/ast/pipeline.c +++ b/srcs/parsing/ast/pipeline.c @@ -32,7 +32,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh) i = 0; while (cpy) { - self->pline[i] = create_ast_n(cpy->node, self, msh); + self->pline[i] = create_ast_n(cpy->node, self, msh, self->sh); cpy = cpy->next; i++; } diff --git a/srcs/parsing/ast/subsh.c b/srcs/parsing/ast/subsh.c index d714f2d..060378e 100644 --- a/srcs/parsing/ast/subsh.c +++ b/srcs/parsing/ast/subsh.c @@ -40,8 +40,9 @@ void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh) { t_node *cutted; + self->sh = true; cutted = remove_parentheses(lst); - self->left = create_ast_n(cutted, self, msh); + self->left = create_ast_n(cutted, self, msh, self->sh); self->files = NULL; self->redir = ft_calloc(1, sizeof(t_redir)); self->redir[0] = _NR; diff --git a/srcs/parsing/drawio/drawio_ast_utils.c b/srcs/parsing/drawio/drawio_ast_utils.c index c1e1546..b7e842d 100644 --- a/srcs/parsing/drawio/drawio_ast_utils.c +++ b/srcs/parsing/drawio/drawio_ast_utils.c @@ -62,17 +62,13 @@ t_dio_node get_cmd_txt(t_ast_n *node) // txt.redir = translate_redir(node->redir); // txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL); // txt.outf = ft_sprintf("Outfile : %s", node->outfile); - txt.redir = ""; - txt.inf = ft_sprintf("Infile : UNCHECKED"); - txt.outf = ft_sprintf("Outfile : UNCHECKED"); + txt.files = ft_sprintf("redir: UNCHECKED\n"); } else { txt.cmd = ft_calloc(1, 1); txt.args = ft_calloc(1, 1); - txt.redir = ""; - txt.inf = ft_calloc(1, 1); - txt.outf = ft_calloc(1, 1); + txt.files = ft_calloc(1, 1); } return (txt); } diff --git a/srcs/parsing/drawio/drawio_print_ast.c b/srcs/parsing/drawio/drawio_print_ast.c index c00c8ff..fde679c 100644 --- a/srcs/parsing/drawio/drawio_print_ast.c +++ b/srcs/parsing/drawio/drawio_print_ast.c @@ -15,15 +15,19 @@ char *get_node_txt(t_ast_n *node) { t_dio_node txt; - char *out; + static char *subsh; + char *out; txt = get_cmd_txt(node); - out = ft_sprintf("%s%s%s%s%s%s%s", txt.st, txt.cmd, txt.args, - NL, txt.redir, txt.inf, txt.outf); + if (node->sh == true) + subsh = " (subsh) "; + else + subsh = ""; + out = ft_sprintf("%s%s%s%s%s", txt.st, txt.cmd, txt.args, + subsh, txt.files); free(txt.cmd); free(txt.args); - free(txt.inf); - free(txt.outf); + free(txt.files); return (out); }